af_xdp: fix default xdp program unload fail
Change to get ad->linux_ifindex in af_xdp_create_if() instead of in af_xdp_load_program(), previous if did not load custom XDP program, ad->linux_ifindex will be none, but bpf_xdp_detach() need it, so default xdp program will be not unloaded when delete af_xdp interface. Type: fix Signed-off-by: Yulong Pei <yulong.pei@intel.com> Change-Id: Id8a640204e8d29152f03349a0b58104b275635aa
This commit is contained in:
@ -145,6 +145,39 @@ af_xdp_exit_netns (char *netns, int *fds)
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
af_xdp_remove_program (af_xdp_device_t *ad)
|
||||
{
|
||||
u32 curr_prog_id = 0;
|
||||
int ret;
|
||||
int ns_fds[2];
|
||||
|
||||
af_xdp_enter_netns (ad->netns, ns_fds);
|
||||
ret = bpf_xdp_query_id (ad->linux_ifindex, XDP_FLAGS_UPDATE_IF_NOEXIST,
|
||||
&curr_prog_id);
|
||||
if (ret != 0)
|
||||
{
|
||||
af_xdp_log (VLIB_LOG_LEVEL_ERR, ad, "bpf_xdp_query_id failed\n");
|
||||
goto err0;
|
||||
}
|
||||
|
||||
ret = bpf_xdp_detach (ad->linux_ifindex, XDP_FLAGS_UPDATE_IF_NOEXIST, NULL);
|
||||
if (ret != 0)
|
||||
{
|
||||
af_xdp_log (VLIB_LOG_LEVEL_ERR, ad, "bpf_xdp_detach failed\n");
|
||||
goto err0;
|
||||
}
|
||||
af_xdp_exit_netns (ad->netns, ns_fds);
|
||||
if (ad->bpf_obj)
|
||||
bpf_object__close (ad->bpf_obj);
|
||||
|
||||
return 0;
|
||||
|
||||
err0:
|
||||
af_xdp_exit_netns (ad->netns, ns_fds);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
af_xdp_delete_if (vlib_main_t * vm, af_xdp_device_t * ad)
|
||||
{
|
||||
@ -172,15 +205,8 @@ af_xdp_delete_if (vlib_main_t * vm, af_xdp_device_t * ad)
|
||||
for (i = 0; i < ad->rxq_num; i++)
|
||||
clib_file_del_by_index (&file_main, vec_elt (ad->rxqs, i).file_index);
|
||||
|
||||
if (ad->bpf_obj)
|
||||
{
|
||||
int ns_fds[2];
|
||||
af_xdp_enter_netns (ad->netns, ns_fds);
|
||||
bpf_xdp_detach (ad->linux_ifindex, XDP_FLAGS_UPDATE_IF_NOEXIST, NULL);
|
||||
af_xdp_exit_netns (ad->netns, ns_fds);
|
||||
|
||||
bpf_object__close (ad->bpf_obj);
|
||||
}
|
||||
if (af_xdp_remove_program (ad) != 0)
|
||||
af_xdp_log (VLIB_LOG_LEVEL_ERR, ad, "Error while removing XDP program.\n");
|
||||
|
||||
vec_free (ad->xsk);
|
||||
vec_free (ad->umem);
|
||||
@ -206,16 +232,6 @@ af_xdp_load_program (af_xdp_create_if_args_t * args, af_xdp_device_t * ad)
|
||||
"setrlimit(%s) failed: %s (errno %d)", ad->linux_ifname,
|
||||
strerror (errno), errno);
|
||||
|
||||
ad->linux_ifindex = if_nametoindex (ad->linux_ifname);
|
||||
if (!ad->linux_ifindex)
|
||||
{
|
||||
args->rv = VNET_API_ERROR_INVALID_VALUE;
|
||||
args->error =
|
||||
clib_error_return_unix (0, "if_nametoindex(%s) failed",
|
||||
ad->linux_ifname);
|
||||
goto err0;
|
||||
}
|
||||
|
||||
ad->bpf_obj = bpf_object__open_file (args->prog, NULL);
|
||||
if (libbpf_get_error (ad->bpf_obj))
|
||||
{
|
||||
@ -251,7 +267,6 @@ err1:
|
||||
bpf_object__close (ad->bpf_obj);
|
||||
ad->bpf_obj = 0;
|
||||
err0:
|
||||
ad->linux_ifindex = ~0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -624,6 +639,16 @@ af_xdp_create_if (vlib_main_t * vm, af_xdp_create_if_args_t * args)
|
||||
|
||||
ad->netns = (char *) format (0, "%s", args->netns);
|
||||
|
||||
ad->linux_ifindex = if_nametoindex (ad->linux_ifname);
|
||||
if (!ad->linux_ifindex)
|
||||
{
|
||||
args->rv = VNET_API_ERROR_INVALID_VALUE;
|
||||
args->error = clib_error_return_unix (0, "if_nametoindex(%s) failed",
|
||||
ad->linux_ifname);
|
||||
ad->linux_ifindex = ~0;
|
||||
goto err1;
|
||||
}
|
||||
|
||||
if (args->prog && af_xdp_load_program (args, ad))
|
||||
goto err2;
|
||||
|
||||
|
Reference in New Issue
Block a user