[ovs-dev,RFCv4,1/4] Add libbpf build support.

Message ID 1554158812-44622-2-git-send-email-u9012063@gmail.com
State New
Headers show
Series
  • AF_XDP netdev support for OVS
Related show

Commit Message

William Tu April 1, 2019, 10:46 p.m.
Using AF_XDP depends on libbpf for managing eBPF/XDP program and maps.
This patch checks if libbpf and if_xdp (XDP interface) are availble to
determine if we should enable AF_XDP support.

Signed-off-by: Yi-Hung Wei <yihung.wei@gmail.com>
Co-authored-by: William Tu <u9012063@gmail.com>
---
 acinclude.m4    | 20 ++++++++++++++++++++
 configure.ac    |  1 +
 lib/automake.mk |  1 +
 3 files changed, 22 insertions(+)

Patch

diff --git a/acinclude.m4 b/acinclude.m4
index 9d6b682266e1..d0cd8aac2c1d 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -205,6 +205,26 @@  AC_DEFUN([OVS_CHECK_LINUX_TC], [
                [Define to 1 if TCA_PEDIT_KEY_EX_HDR_TYPE_UDP is available.])])
 ])
 
+dnl OVS_CHECK_LINUX_AF_XDP
+dnl
+dnl Check both Linux kernel AF_XDP and libbpf support
+AC_DEFUN([OVS_CHECK_LINUX_AF_XDP], [
+  AC_MSG_CHECKING([whether AF_XDP is supported])
+  AC_CHECK_HEADER([bpf/libbpf.h],
+                  [HAVE_LIBBPF=yes],
+                  [HAVE_LIBBPF==no])
+  AC_CHECK_HEADER([linux/if_xdp.h],
+                  [HAVE_IF_XDP=yes],
+                  [HAVE_IF_XDP=no])
+  AM_CONDITIONAL([SUPPORT_AF_XDP],
+                 [test "$HAVE_LIBBPF" = yes && test "$HAVE_IF_XDP" = yes])
+  AM_COND_IF([SUPPORT_AF_XDP], [
+    AC_DEFINE([HAVE_AF_XDP], [1], [Define to 1 if linux/if_xdp.h is available.])
+    LIBBPF_LDADD=" -lbpf -lelf"
+    AC_SUBST([LIBBPF_LDADD])
+  ])
+])
+
 dnl OVS_CHECK_DPDK
 dnl
 dnl Configure DPDK source tree
diff --git a/configure.ac b/configure.ac
index 8a05870a43dc..5ce7dc9b33d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,6 +99,7 @@  OVS_CHECK_SPHINX
 OVS_CHECK_DOT
 OVS_CHECK_IF_DL
 OVS_CHECK_STRTOK_R
+OVS_CHECK_LINUX_AF_XDP
 AC_CHECK_DECLS([sys_siglist], [], [], [[#include <signal.h>]])
 AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
   [], [], [[#include <sys/stat.h>]])
diff --git a/lib/automake.mk b/lib/automake.mk
index b1ff495ff1f3..db868933c37a 100644
--- a/lib/automake.mk
+++ b/lib/automake.mk
@@ -9,6 +9,7 @@  lib_LTLIBRARIES += lib/libopenvswitch.la
 
 lib_libopenvswitch_la_LIBADD = $(SSL_LIBS)
 lib_libopenvswitch_la_LIBADD += $(CAPNG_LDADD)
+lib_libopenvswitch_la_LIBADD += $(LIBBPF_LDADD)
 
 if WIN32
 lib_libopenvswitch_la_LIBADD += ${PTHREAD_LIBS}