af_xdp: AF_XDP input plugin

Type: feature

Change-Id: I85aa4ad6b68c1aa0e51938002dc691a4b11c545c
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Benoît Ganne <bganne@cisco.com>
diff --git a/build/external/Makefile b/build/external/Makefile
index e5dff3c..b0e3cee 100644
--- a/build/external/Makefile
+++ b/build/external/Makefile
@@ -39,13 +39,14 @@
 include packages/quicly.mk
 include packages/dpdk.mk
 include packages/rdma-core.mk
+include packages/libbpf.mk
 
 .PHONY: clean
 clean:
 	@rm -rf $(B) $(I)
 
 .PHONY: install
-install: dpdk-install rdma-core-install quicly-install
+install: dpdk-install rdma-core-install quicly-install libbpf-install
 
 .PHONY: config
 config: dpdk-config rdma-core-config
diff --git a/build/external/packages/libbpf.mk b/build/external/packages/libbpf.mk
new file mode 100644
index 0000000..90ff54b
--- /dev/null
+++ b/build/external/packages/libbpf.mk
@@ -0,0 +1,55 @@
+# Copyright (c) 2018 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LIBBPF_DEBUG?=n
+
+libbpf_version             := 0.1.0
+libbpf_tarball             := v$(libbpf_version).tar.gz
+libbpf_tarball_md5sum_0.1.0 := 00b991a6e2d28d797a56ab1575ed40e1
+libbpf_tarball_md5sum      := $(libbpf_tarball_md5sum_$(libbpf_version))
+libbpf_tarball_strip_dirs  := 1
+libbpf_url                 := https://github.com/libbpf/libbpf/archive/$(libbpf_tarball)
+
+LIBBPF_CFLAGS:=-g -Werror -Wall -fPIC -fvisibility=hidden
+ifeq ($(LIBBPF_DEBUG),y)
+  LIBBPF_CFLAGS+= -O0
+else
+  LIBBPF_CFLAGS+= -O2
+endif
+
+IF_XDP:=$(shell echo "\#include <linux/if_xdp.h>" | $(CC) -E -xc - > /dev/null 2>&1)
+IF_XDP:=$(.SHELLSTATUS)
+
+define  libbpf_config_cmds
+	@true
+endef
+
+define  libbpf_build_cmds__
+	BUILD_STATIC_ONLY=y OBJDIR='$(libbpf_build_dir)' PREFIX='' DESTDIR='$(libbpf_install_dir)' CFLAGS='$(LIBBPF_CFLAGS)' make -C '$(libbpf_src_dir)/src' $(1) > $(2)
+endef
+
+define  libbpf_build_cmds
+	$(call libbpf_build_cmds__,,$(libbpf_build_log))
+endef
+
+define  libbpf_install_cmds
+	$(call libbpf_build_cmds__,install,$(libbpf_install_log))
+endef
+
+ifneq ($(IF_XDP),0)
+  $(warning "linux/if_xdp.h was not found on this system. libbpf will be skipped.")
+libbpf-install:
+	@true
+else
+  $(eval $(call package,libbpf))
+endif