aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorYulong Pei <yulong.pei@intel.com>2023-01-05 02:26:32 +0000
committerBeno�t Ganne <bganne@cisco.com>2023-01-13 09:57:00 +0000
commitf9a17487982ebc231ad0f32f15f261453aef8a88 (patch)
treeedbfdc326ad1b0fc25f2efa083e94010c025c2a8 /src/plugins
parent809eb669c7a353cd06da58ccdf8578053b1233ca (diff)
af_xdp: update af_xdp driver plugin to depend on libxdp
AF_XDP support is deprecated in libbpf since v0.7.0 [1], the libxdp library now provides the functionality which once was in libbpf, this commit updates af_xdp plugin to depend on libxdp, libbpf still remains a dependency even if libxdp is present, as it need use libbpf APIs for program loading. libxdp is distributed within xdp-tool [2], xdp-tools package also include libbpf in it as dependency, so here installed libxdp v1.2.9 and libbpf v0.8.0, both from xdp-tool-1.2.9 package. More information about libxdp compatibility can be found in the libxdp README [3]. In libbpf v0.8.0, The bpf_prog_load function was deprecated and changed to bpf_object__open_file and bpf_object__next_program and bpf_object__load, The bpf_get_link_xdp_id and bpf_set_link_xdp_fd functions were deprecated and changed to bpf_xdp_attach and bpf_xdp_detach, The bpf_object__unload function was deprecated and changed to bpf_object__close. [1] https://github.com/libbpf/libbpf/commit/277846bc6c15 [2] https://github.com/xdp-project/xdp-tools/releases/tag/v1.2.9 [3] https://github.com/xdp-project/xdp-tools/blob/master/lib/libxdp/README.org Type: improvement Change-Id: Ifbf6e3aa38bc6e0b77561f26311fd11c15ddb47e Signed-off-by: Yulong Pei <yulong.pei@intel.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/af_xdp/CMakeLists.txt32
-rw-r--r--src/plugins/af_xdp/af_xdp.h2
-rw-r--r--src/plugins/af_xdp/device.c33
3 files changed, 41 insertions, 26 deletions
diff --git a/src/plugins/af_xdp/CMakeLists.txt b/src/plugins/af_xdp/CMakeLists.txt
index cbe96aa59dd..1097358799b 100644
--- a/src/plugins/af_xdp/CMakeLists.txt
+++ b/src/plugins/af_xdp/CMakeLists.txt
@@ -11,36 +11,37 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-vpp_find_path(BPF_INCLUDE_DIR NAMES bpf/xsk.h)
-if (NOT BPF_INCLUDE_DIR)
- message(WARNING "libbpf headers not found - af_xdp plugin disabled")
+vpp_find_path(XDP_INCLUDE_DIR NAMES xdp/xsk.h)
+if (NOT XDP_INCLUDE_DIR)
+ message(WARNING "libxdp headers not found - af_xdp plugin disabled")
return()
endif()
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS TRUE)
+vpp_plugin_find_library(af_xdp XDP_LIB libxdp.a)
vpp_plugin_find_library(af_xdp BPF_LIB libbpf.a)
-vpp_plugin_find_library(af_xdp BPF_ELF_LIB elf)
-vpp_plugin_find_library(af_xdp BPF_Z_LIB z)
-if (NOT BPF_LIB OR NOT BPF_ELF_LIB OR NOT BPF_Z_LIB)
+vpp_plugin_find_library(af_xdp ELF_LIB elf)
+vpp_plugin_find_library(af_xdp Z_LIB z)
+if (NOT XDP_LIB OR NOT BPF_LIB OR NOT ELF_LIB OR NOT Z_LIB)
message(WARNING "af_xdp plugin - missing libraries - af_xdp plugin disabled")
return()
endif()
set(CMAKE_REQUIRED_FLAGS "-fPIC")
-set(CMAKE_REQUIRED_INCLUDES "${BPF_INCLUDE_DIR}")
-set(CMAKE_REQUIRED_LIBRARIES "${BPF_LIB}" "${BPF_ELF_LIB}" "${BPF_Z_LIB}")
+set(CMAKE_REQUIRED_INCLUDES "${XDP_INCLUDE_DIR}")
+set(CMAKE_REQUIRED_LIBRARIES "${XDP_LIB}" "${BPF_LIB}" "${ELF_LIB}" "${Z_LIB}")
CHECK_C_SOURCE_COMPILES("
-#include <bpf/xsk.h>
+#include <xdp/xsk.h>
int main(void)
{
return xsk_socket__create (0, 0, 0, 0, 0, 0, 0);
-}" BPF_COMPILES_CHECK)
-if (NOT BPF_COMPILES_CHECK)
- message(WARNING "af_xdp plugins - no working libbpf found - af_xdp plugin disabled")
+}" XDP_COMPILES_CHECK)
+if (NOT XDP_COMPILES_CHECK)
+message(WARNING "af_xdp plugins - no working libxdp found - af_xdp plugin disabled")
return()
endif()
-include_directories(${BPF_INCLUDE_DIR})
+include_directories(${XDP_INCLUDE_DIR})
add_vpp_plugin(af_xdp
SOURCES
@@ -65,7 +66,8 @@ add_vpp_plugin(af_xdp
test_api.c
LINK_LIBRARIES
+ ${XDP_LIB}
${BPF_LIB}
- ${BPF_ELF_LIB}
- ${BPF_Z_LIB}
+ ${ELF_LIB}
+ ${Z_LIB}
)
diff --git a/src/plugins/af_xdp/af_xdp.h b/src/plugins/af_xdp/af_xdp.h
index 84fc65f7674..cf364fc86a8 100644
--- a/src/plugins/af_xdp/af_xdp.h
+++ b/src/plugins/af_xdp/af_xdp.h
@@ -20,7 +20,7 @@
#include <vlib/log.h>
#include <vnet/interface.h>
-#include <bpf/xsk.h>
+#include <xdp/xsk.h>
#define AF_XDP_NUM_RX_QUEUES_ALL ((u16)-1)
diff --git a/src/plugins/af_xdp/device.c b/src/plugins/af_xdp/device.c
index cccbf69cfdc..385a6e5e93d 100644
--- a/src/plugins/af_xdp/device.c
+++ b/src/plugins/af_xdp/device.c
@@ -176,10 +176,10 @@ af_xdp_delete_if (vlib_main_t * vm, af_xdp_device_t * ad)
{
int ns_fds[2];
af_xdp_enter_netns (ad->netns, ns_fds);
- bpf_set_link_xdp_fd (ad->linux_ifindex, -1, 0);
+ bpf_xdp_detach (ad->linux_ifindex, XDP_FLAGS_UPDATE_IF_NOEXIST, NULL);
af_xdp_exit_netns (ad->netns, ns_fds);
- bpf_object__unload (ad->bpf_obj);
+ bpf_object__close (ad->bpf_obj);
}
vec_free (ad->xsk);
@@ -198,6 +198,7 @@ static int
af_xdp_load_program (af_xdp_create_if_args_t * args, af_xdp_device_t * ad)
{
int fd;
+ struct bpf_program *bpf_prog;
struct rlimit r = { RLIM_INFINITY, RLIM_INFINITY };
if (setrlimit (RLIMIT_MEMLOCK, &r))
@@ -215,27 +216,39 @@ af_xdp_load_program (af_xdp_create_if_args_t * args, af_xdp_device_t * ad)
goto err0;
}
- if (bpf_prog_load (args->prog, BPF_PROG_TYPE_XDP, &ad->bpf_obj, &fd))
+ ad->bpf_obj = bpf_object__open_file (args->prog, NULL);
+ if (libbpf_get_error (ad->bpf_obj))
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_5;
- args->error =
- clib_error_return_unix (0, "bpf_prog_load(%s) failed", args->prog);
+ args->error = clib_error_return_unix (
+ 0, "bpf_object__open_file(%s) failed", args->prog);
goto err0;
}
- if (bpf_set_link_xdp_fd (ad->linux_ifindex, fd, 0))
+ bpf_prog = bpf_object__next_program (ad->bpf_obj, NULL);
+ if (!bpf_prog)
+ goto err1;
+
+ bpf_program__set_type (bpf_prog, BPF_PROG_TYPE_XDP);
+
+ if (bpf_object__load (ad->bpf_obj))
+ goto err1;
+
+ fd = bpf_program__fd (bpf_prog);
+
+ if (bpf_xdp_attach (ad->linux_ifindex, fd, XDP_FLAGS_UPDATE_IF_NOEXIST,
+ NULL))
{
args->rv = VNET_API_ERROR_SYSCALL_ERROR_6;
- args->error =
- clib_error_return_unix (0, "bpf_set_link_xdp_fd(%s) failed",
- ad->linux_ifname);
+ args->error = clib_error_return_unix (0, "bpf_xdp_attach(%s) failed",
+ ad->linux_ifname);
goto err1;
}
return 0;
err1:
- bpf_object__unload (ad->bpf_obj);
+ bpf_object__close (ad->bpf_obj);
ad->bpf_obj = 0;
err0:
ad->linux_ifindex = ~0;