diff mbox series

[ovs-dev,v4,5/5] bpf: Add dummy program for veth devices

Message ID 20200731025514.1669061-6-toshiaki.makita1@gmail.com
State New
Headers show
Series XDP offload using flow API provider | expand

Commit Message

Toshiaki Makita July 31, 2020, 2:55 a.m. UTC
When we use XDP_REDIRECT on veth, the peer device needs to load some
XDP program to make XDP_REDIRECT work.

For convenience we add xdp_noop.o in bpf directory, which does nothing
but returns XDP_PASS.

Example command to use xdp_noop:

  Assume you use veth0 for OVS port and veth1 is its peer.
  $ ip link set veth1 xdpdrv object /path/to/ovs/bpf/xdp_noop.o section xdp

Signed-off-by: Toshiaki Makita <toshiaki.makita1@gmail.com>
---
 bpf/Makefile.am | 11 +++++++----
 bpf/xdp_noop.c  | 31 +++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)
 create mode 100644 bpf/xdp_noop.c
diff mbox series

Patch

diff --git a/bpf/Makefile.am b/bpf/Makefile.am
index 9937c7325..0b8c359cc 100644
--- a/bpf/Makefile.am
+++ b/bpf/Makefile.am
@@ -1,10 +1,12 @@ 
 AUTOMAKE_OPTIONS = foreign
 
 noinst_DATA = \
-	flowtable_afxdp.o
+	flowtable_afxdp.o \
+	xdp_noop.o
 
 sources = \
-	flowtable_afxdp.c
+	flowtable_afxdp.c \
+	xdp_noop.c
 
 EXTRA_DIST = \
 	$(sources) \
@@ -60,14 +62,15 @@  AM_CFLAGS += -Wshadow
 AM_CFLAGS += -Wcast-align
 AM_CFLAGS += -Wno-unused-value
 AM_CFLAGS += -Wno-compare-distinct-pointer-types
-AM_CFLAGS += -g
 AM_CFLAGS += -O2
 
 %.o: %.c
 
 SUFFIXES+ = .ll
+# Remove BTF for xdp_noop so that ip command can attach the program
 %.ll: %.c $(depdir)/%.d | $(depdir)
-	$(CLANG) $(DEPFLAGS) $(AM_CPPFLAGS) $(AM_CFLAGS) -S \
+	$(CLANG) $(DEPFLAGS) $(AM_CPPFLAGS) $(AM_CFLAGS) \
+		$(if $(subst xdp_noop,,$*),-g,) -S \
 		-target bpf -emit-llvm -c $< -o $@
 CLEANFILES += *.ll
 
diff --git a/bpf/xdp_noop.c b/bpf/xdp_noop.c
new file mode 100644
index 000000000..94e40edf9
--- /dev/null
+++ b/bpf/xdp_noop.c
@@ -0,0 +1,31 @@ 
+/*
+ * Copyright (c) 2020 NTT Corp.
+ *
+ * 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.
+ */
+
+/* linux/types.h is necessary for bpf_helpers.h as it's not self-contained so
+ * that we can alternatively choose vmlinux.h auto-generated from BTF. */
+#include <linux/types.h>
+#include <bpf/bpf_helpers.h>
+#include <linux/bpf.h>
+
+#include "openvswitch/compiler.h"
+
+SEC("xdp") int
+noop(struct xdp_md *ctx OVS_UNUSED)
+{
+    return XDP_PASS;
+}
+
+char _license[] SEC("license") = "Apache-2.0";