Skip to content

Commit

Permalink
txrx-tsn: Refactor xdp cleanup routine
Browse files Browse the repository at this point in the history
Changes:
- Remove remove_xdp_program due to no bpf program

Signed-off-by: Goh Wei Sheng <wei.sheng.goh@intel.com>
  • Loading branch information
ws-intel committed Jun 23, 2023
1 parent a6b6b4a commit 5a116de
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
25 changes: 2 additions & 23 deletions src/txrx-afxdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,33 +85,12 @@ void afxdp_sigint_handler(int signum)
halt_tx_sig = signum;
}

void remove_xdp_program(void)
{
uint32_t curr_prog_id = 0;

if (bpf_xdp_query_id(glob_ifindex, glob_xdp_flags, &curr_prog_id)) {
fprintf(stderr, "exit: bpf_xdp_query_id failed\n");
exit(EXIT_FAILURE);
}

if (glob_xskinfo_ptr && glob_xskinfo_ptr->bpf_prog_id == curr_prog_id)
bpf_set_link_xdp_fd(glob_ifindex, -1, glob_xdp_flags);
else if (!glob_xskinfo_ptr)
fprintf(stderr, "exit: socket creation incomplete. " \
"Possibly due toincompatible queue.\n");
else if (!curr_prog_id)
fprintf(stderr, "exit: couldn't find a prog id on a given interface\n");
else
fprintf(stderr, "exit: program on interface changed, not removing\n");
}

void xdpsock_cleanup(void)
{
struct xsk_umem *umem = glob_xskinfo_ptr->pktbuff->umem;

xsk_socket__delete(glob_xskinfo_ptr->xskfd);
(void)xsk_umem__delete(umem);
remove_xdp_program();

exit(EXIT_SUCCESS);
}
Expand All @@ -120,7 +99,7 @@ void __afxdp_exit_with_error(int error, const char *file, const char *func, int
{
fprintf(stderr, "%s:%s:%i: errno: %d/\"%s\"\n", file, func,
line, error, strerror(error));
remove_xdp_program();
xdpsock_cleanup();
exit(EXIT_FAILURE);
}

Expand Down Expand Up @@ -201,7 +180,7 @@ static struct xsk_info *create_xsk_info(struct user_opt *opt, struct pkt_buffer
if (ret)
afxdp_exit_with_error(-ret);

ret = bpf_xdp_query_id(opt->ifindex, opt->x_opt.xdp_flags, &temp_xsk->bpf_prog_id);
ret = bpf_xdp_query_id(opt->ifindex, opt->x_opt.xdp_flags, &temp_xsk->prog_id);
if (ret)
afxdp_exit_with_error(-ret);

Expand Down
1 change: 0 additions & 1 deletion src/txrx-afxdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ extern int glob_ifindex;
extern int halt_tx_sig;
extern int verbose;

void remove_xdp_program(void);
void xdpsock_cleanup();
void afxdp_sigint_handler(int sig);
void __afxdp_exit_with_error(int error, const char *file, const char *func, int line);
Expand Down
2 changes: 1 addition & 1 deletion src/txrx.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ struct xsk_info {
struct xsk_socket *xskfd;
struct xsk_ring_cons rx_ring; //User process managed rings
struct xsk_ring_prod tx_ring; // do not access directly
uint32_t bpf_prog_id;
uint32_t prog_id;

uint32_t cur_tx; //to track current addr (pkt count * frame_size)
uint32_t cur_rx;
Expand Down

0 comments on commit 5a116de

Please sign in to comment.