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 <[email protected]> --- bpf/Makefile.am | 11 +++++++---- bpf/xdp_noop.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 bpf/xdp_noop.c 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"; -- 2.25.1 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
