netfilter: Add the capability to offload flowtable in XDP layer
Subsystems (7)
v4 cover netfilter: Add the capability to offload flowtable in XDP layer
Introduce bpf_xdp_flow_lookup kfunc in order to perform the lookup of a given flowtable entry based on the fib tuple of incoming traffic. bpf_xdp_flow_lookup can be used as building block to offload in XDP the sw flowtable processing when the hw support is not available.
This series has been tested running the xdp_flowtable_offload eBPF program on an ixgbe 10Gbps NIC (eno2) in order to XDP_REDIRECT the TCP traffic to a veth pair (veth0-veth1) based on the content of the nf_flowtable as soon as the TCP connection is in the established state:
[tcp client] (eno1) == LAN == (eno2) xdp_flowtable_offload [XDP_REDIRECT] --> veth0 == veth1 [tcp server]
table inet filter {
flowtable ft {
hook ingress priority filter
devices = { eno2, veth0 }
}
chain forward {
type filter hook forward priority filter
meta l4proto { tcp, udp } flow add @ft
}
}- sw flowtable [1 TCP stream, T = 300s]: ~ 6.2 Gbps
- xdp flowtable [1 TCP stream, T = 300s]: ~ 7.6 Gbps
- sw flowtable [3 TCP stream, T = 300s]: ~ 7.7 Gbps
- xdp flowtable [3 TCP stream, T = 300s]: ~ 8.8 Gbps
Changes since v3:
- move flowtable map utilities in nf_flow_table_xdp.c
Changes since v2:
- introduce bpf_flowtable_opts struct in bpf_xdp_flow_lookup signature
- get rid of xdp_flowtable_offload bpf sample
- get rid of test_xdp_flowtable.sh for selftest and rely on prog_tests instead
- rename bpf_xdp_flow_offload_lookup in bpf_xdp_flow_lookup Changes since v1:
- return NULL in bpf_xdp_flow_offload_lookup kfunc in case of error
- take into account kfunc registration possible failures
Changes since RFC:
- fix compilation error if BTF is not enabled
Florian Westphal (1):
netfilter: nf_tables: add flowtable map for xdp offload
Lorenzo Bianconi (2):
netfilter: add bpf_xdp_flow_lookup kfunc selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc
include/net/netfilter/nf_flow_table.h | 18 ++ net/netfilter/Makefile | 7 +- net/netfilter/nf_flow_table_bpf.c | 117 ++++++++++++ net/netfilter/nf_flow_table_inet.c | 2 +- net/netfilter/nf_flow_table_offload.c | 6 +- net/netfilter/nf_flow_table_xdp.c | 163 +++++++++++++++++ tools/testing/selftests/bpf/config | 13 ++ .../selftests/bpf/prog_tests/xdp_flowtable.c | 168 ++++++++++++++++++ .../selftests/bpf/progs/xdp_flowtable.c | 145 +++++++++++++++ 9 files changed, 635 insertions(+), 4 deletions(-) create mode 100644 net/netfilter/nf_flow_table_bpf.c create mode 100644 net/netfilter/nf_flow_table_xdp.c create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c create mode 100644 tools/testing/selftests/bpf/progs/xdp_flowtable.c
Signature · 1 line
2.45.1
PATCH v4 1/3 netfilter: nf_tables: add flowtable map for xdp offload
From: Florian Westphal <[email protected]>
This adds a small internal mapping table so that a new bpf (xdp) kfunc can perform lookups in a flowtable.
As-is, xdp program has access to the device pointer, but no way to do a lookup in a flowtable -- there is no way to obtain the needed struct without questionable stunts.
This allows to obtain an nf_flowtable pointer given a net_device structure.
In order to keep backward compatibility, the infrastructure allows the user to add a given device to multiple flowtables, but it will always return the first added mapping performing the lookup since it assumes the right configuration is 1:1 mapping between flowtables and net_devices.
--- include/net/netfilter/nf_flow_table.h | 8 ++ net/netfilter/Makefile | 2 +- net/netfilter/nf_flow_table_offload.c | 6 +- net/netfilter/nf_flow_table_xdp.c | 163 ++++++++++++++++++++++++++ 4 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 net/netfilter/nf_flow_table_xdp.c
include/net/netfilter/nf_flow_table.h +8 -0
@@ -305,6 +305,14 @@ struct flow_ports {__be16 source, dest; }; +struct nf_flowtable *nf_flowtable_by_dev (const struct net_device *dev); +int nf_flow_offload_xdp_setup (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd); +void nf_flow_offload_xdp_cancel (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd); +unsigned int nf_flow_offload_ip_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state); unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
net/netfilter/Makefile +1 -1
@@ -142,7 +142,7 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_netdev.o # flow table infrastructure obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o \ - nf_flow_table_offload.o + nf_flow_table_offload.o nf_flow_table_xdp.o nf_flow_table-$(CONFIG_NF_FLOW_TABLE_PROCFS) += nf_flow_table_procfs.o obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
net/netfilter/nf_flow_table_offload.c +4 -2
@@ -1192,7 +1192,7 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,int err;if (!nf_flowtable_hw_offload (flowtable)) -return 0 ; +return nf_flow_offload_xdp_setup (flowtable, dev, cmd);if (dev->netdev_ops->ndo_setup_tc) err = nf_flow_table_offload_cmd(&bo, flowtable, dev, cmd,
@@ -1200,8 +1200,10 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,else err =nf_flow_table_indr_offload_cmd (&bo, flowtable, dev, cmd, &extack); -if (err <0 ) +if (err <0 ) { +nf_flow_offload_xdp_cancel (flowtable, dev, cmd);return err; + }return nf_flow_table_block_setup (flowtable, &bo, cmd); }
net/netfilter/nf_flow_table_xdp.c new file +163 -0
163 lines not on this page · raw message
Signature · 1 line
2.45.1
Re: [PATCH v4 bpf-next 1/3] netfilter: nf_tables: add flowtable map for xdp offload
Quoted 9 lines
From: Florian Westphal <[email protected]>
This adds a small internal mapping table so that a new bpf (xdp) kfunc can perform lookups in a flowtable.
As-is, xdp program has access to the device pointer, but no way to do a lookup in a flowtable -- there is no way to obtain the needed struct without questionable stunts.
Quoted 7 lines
This allows to obtain an
nf_flowtablepointer given anet_devicestructure.In order to keep backward compatibility, the infrastructure allows the user to add a given device to multiple flowtables, but it will always return the first added mapping performing the lookup since it assumes the right configuration is 1:1 mapping between flowtables and
net_devices.
Hi Pablo,
do you have any feedback about nft part? Thanks.
Regards,
Lorenzo
Quoted 242 lines
Signed-off-by Florian Westphal <[email protected]>Co-developed-by Lorenzo Bianconi <[email protected]>Signed-off-by Lorenzo Bianconi <[email protected]>--- include/net/netfilter/nf_flow_table.h | 8 ++ net/netfilter/Makefile | 2 +- net/netfilter/nf_flow_table_offload.c | 6 +- net/netfilter/nf_flow_table_xdp.c | 163 ++++++++++++++++++++++++++ 4 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 net/netfilter/nf_flow_table_xdp.cinclude/net/netfilter/nf_flow_table.h +8
-0@@ -305,6 +305,14 @@ struct flow_ports {__be16 source, dest; }; +struct nf_flowtable *nf_flowtable_by_dev (const struct net_device *dev); +int nf_flow_offload_xdp_setup (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd); +void nf_flow_offload_xdp_cancel (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd); +unsigned int nf_flow_offload_ip_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state); unsigned int nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,net/netfilter/Makefile +1
-1@@ -142,7 +142,7 @@ obj-$(CONFIG_NFT_FWD_NETDEV) += nft_fwd_netdev.o # flow table infrastructure obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o \ - nf_flow_table_offload.o + nf_flow_table_offload.o nf_flow_table_xdp.o nf_flow_table-$(CONFIG_NF_FLOW_TABLE_PROCFS) += nf_flow_table_procfs.o obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.onet/netfilter/nf_flow_table_offload.c +4
-2@@ -1192,7 +1192,7 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,int err;if (!nf_flowtable_hw_offload (flowtable)) -return 0 ; +return nf_flow_offload_xdp_setup (flowtable, dev, cmd);if (dev->netdev_ops->ndo_setup_tc) err = nf_flow_table_offload_cmd(&bo, flowtable, dev, cmd,@@ -1200,8 +1200,10 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,else err =nf_flow_table_indr_offload_cmd (&bo, flowtable, dev, cmd, &extack); -if (err <0 ) +if (err <0 ) { +nf_flow_offload_xdp_cancel (flowtable, dev, cmd);return err; + }return nf_flow_table_block_setup (flowtable, &bo, cmd); }net/netfilter/nf_flow_table_xdp.c new file +163
-0@@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/netfilter.h> +#include <linux/rhashtable.h> +#include <linux/netdevice.h> +#include <net/flow_offload.h> +#include <net/netfilter/nf_flow_table.h> + +struct flow_offload_xdp_ft { +struct list_head head; +struct nf_flowtable *ft; +struct rcu_head rcuhead; +}; + +struct flow_offload_xdp { +struct hlist_node hnode; +unsigned long net_device_addr; +struct list_head head; +}; + +#define NF_XDP_HT_BITS 4 +static DEFINE_HASHTABLE(nf_xdp_hashtable, NF_XDP_HT_BITS); +static DEFINE_MUTEX (nf_xdp_hashtable_lock); + +/* caller must hold rcu read lock */ +struct nf_flowtable *nf_flowtable_by_dev (const struct net_device *dev) +{ +unsigned long key = (unsigned long )dev; +struct flow_offload_xdp *iter; + +hash_for_each_possible_rcu (nf_xdp_hashtable, iter, hnode, key) { +if (key == iter->net_device_addr) { +struct flow_offload_xdp_ft *ft_elem; + +/* The user is supposed to insert a given net_device +* just into a single nf_flowtable so we always return +* the first element here. +*/ + ft_elem =list_first_or_null_rcu (&iter->head, + struct flow_offload_xdp_ft, + head); +return ft_elem ? ft_elem->ft :NULL ; + } + } + +return NULL ; +} + +static int nf_flowtable_by_dev_insert (struct nf_flowtable *ft, +const struct net_device *dev) +{ +struct flow_offload_xdp *iter, *elem =NULL ; +unsigned long key = (unsigned long )dev; +struct flow_offload_xdp_ft *ft_elem; + + ft_elem =kzalloc (sizeof (*ft_elem),GFP_KERNEL_ACCOUNT ); +if (!ft_elem) +return -ENOMEM ; + + ft_elem->ft = ft; + +mutex_lock (&nf_xdp_hashtable_lock); + +hash_for_each_possible (nf_xdp_hashtable, iter, hnode, key) { +if (key == iter->net_device_addr) { + elem = iter; +break ; + } + } + +if (!elem) { + elem =kzalloc (sizeof (*elem),GFP_KERNEL_ACCOUNT ); +if (!elem) + goto err_unlock; + + elem->net_device_addr = key; +INIT_LIST_HEAD (&elem->head); +hash_add_rcu (nf_xdp_hashtable, &elem->hnode, key); + } +list_add_tail_rcu (&ft_elem->head, &elem->head); + +mutex_unlock (&nf_xdp_hashtable_lock); + +return 0 ; + +err_unlock: +mutex_unlock (&nf_xdp_hashtable_lock); +kfree (ft_elem); + +return -ENOMEM ; +} + +static void nf_flowtable_by_dev_remove (struct nf_flowtable *ft, +const struct net_device *dev) +{ +struct flow_offload_xdp *iter, *elem =NULL ; +unsigned long key = (unsigned long )dev; + +mutex_lock (&nf_xdp_hashtable_lock); + +hash_for_each_possible (nf_xdp_hashtable, iter, hnode, key) { +if (key == iter->net_device_addr) { + elem = iter; +break ; + } + } + +if (elem) { +struct flow_offload_xdp_ft *ft_elem, *ft_next; + +list_for_each_entry_safe (ft_elem, ft_next, &elem->head, head) { +if (ft_elem->ft == ft) { +list_del_rcu (&ft_elem->head); +kfree_rcu (ft_elem, rcuhead); + } + } + +if (list_empty (&elem->head)) +hash_del_rcu (&elem->hnode); +else + elem =NULL ; + } + +mutex_unlock (&nf_xdp_hashtable_lock); + +if (elem) { +synchronize_rcu (); +kfree (elem); + } +} + +int nf_flow_offload_xdp_setup (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd) +{ +switch (cmd) { +case FLOW_BLOCK_BIND : +return nf_flowtable_by_dev_insert (flowtable, dev); +case FLOW_BLOCK_UNBIND : +nf_flowtable_by_dev_remove (flowtable, dev); +return 0 ; + } + +WARN_ON_ONCE (1 ); +return 0 ; +} + +void nf_flow_offload_xdp_cancel (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd) +{ +switch (cmd) { +case FLOW_BLOCK_BIND : +nf_flowtable_by_dev_remove (flowtable, dev); +return ; +case FLOW_BLOCK_UNBIND : +/* We do not re-bind in case hw offload would report error +* on *unregister*. +*/ +break ; + } +}Signature · 1 line
2.45.1
PATCH v4 2/3 netfilter: add bpf_xdp_flow_lookup kfunc
In reply to Lorenzo BianconiIntroduce bpf_xdp_flow_lookup kfunc in order to perform the lookup of a given flowtable entry based on a fib tuple of incoming traffic. bpf_xdp_flow_lookup can be used as building block to offload in xdp the processing of sw flowtable when hw flowtable is not available.
--- include/net/netfilter/nf_flow_table.h | 10 +++ net/netfilter/Makefile | 5 ++ net/netfilter/nf_flow_table_bpf.c | 117 ++++++++++++++++++++++++++ net/netfilter/nf_flow_table_inet.c | 2 +- 4 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 net/netfilter/nf_flow_table_bpf.c
include/net/netfilter/nf_flow_table.h +10 -0
@@ -318,6 +318,16 @@ unsigned int nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,unsigned int nf_flow_offload_ipv6_hook (void *priv,struct sk_buff *skb,const struct nf_hook_state *state); +#if (IS_BUILTIN (CONFIG_NF_FLOW_TABLE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF )) || \ + (IS_MODULE (CONFIG_NF_FLOW_TABLE ) &&IS_ENABLED (CONFIG_DEBUG_INFO_BTF_MODULES )) +extern int nf_flow_register_bpf (void ); +#else +static inline int nf_flow_register_bpf (void ) +{ +return 0 ; +} +#endif +#define MODULE_ALIAS_NF_FLOWTABLE (family) \ MODULE_ALIAS("nf-flowtable-" __stringify(family))
net/netfilter/Makefile +5 -0
@@ -144,6 +144,11 @@ obj-$(CONFIG_NF_FLOW_TABLE) += nf_flow_table.o nf_flow_table-objs := nf_flow_table_core.o nf_flow_table_ip.o \ nf_flow_table_offload.o nf_flow_table_xdp.o nf_flow_table-$(CONFIG_NF_FLOW_TABLE_PROCFS) += nf_flow_table_procfs.o +ifeq ($(CONFIG_NF_FLOW_TABLE),m) +nf_flow_table-$(CONFIG_DEBUG_INFO_BTF_MODULES) += nf_flow_table_bpf.o +else ifeq ($(CONFIG_NF_FLOW_TABLE),y) +nf_flow_table-$(CONFIG_DEBUG_INFO_BTF) += nf_flow_table_bpf.o +endif obj-$(CONFIG_NF_FLOW_TABLE_INET) += nf_flow_table_inet.o
net/netfilter/nf_flow_table_bpf.c new file +117 -0
117 lines not on this page · raw message
net/netfilter/nf_flow_table_inet.c +1 -1
@@ -98,7 +98,7 @@ static int __init nf_flow_inet_module_init(void)nft_register_flowtable_type (&flowtable_ipv6);nft_register_flowtable_type (&flowtable_inet); -return 0 ; +return nf_flow_register_bpf (); } static void __exit nf_flow_inet_module_exit(void)
Signature · 1 line
2.45.1
Re: [PATCH v4 bpf-next 2/3] netfilter: add bpf_xdp_flow_lookup kfunc
Quoted 8 lines · Lorenzo Bianconi
Introduce
bpf_xdp_flow_lookupkfunc in order to perform the lookup of a given flowtable entry based on a fib tuple of incoming traffic.bpf_xdp_flow_lookupcan be used as building block to offload in xdp the processing of sw flowtable when hw flowtable is not available.Signed-off-by Lorenzo Bianconi <[email protected]>
lgtm
Waiting for the Ack from netfilter folks...
So we can land it through bpf-next and pass it to net-next a week or so later.
PATCH v4 3/3 selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc
In reply to Lorenzo BianconiIntroduce e2e selftest for bpf_xdp_flow_lookup kfunc through xdp_flowtable utility.
--- tools/testing/selftests/bpf/config | 13 ++ .../selftests/bpf/prog_tests/xdp_flowtable.c | 168 ++++++++++++++++++ .../selftests/bpf/progs/xdp_flowtable.c | 145 +++++++++++++++ 3 files changed, 326 insertions(+) create mode 100644 tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c create mode 100644 tools/testing/selftests/bpf/progs/xdp_flowtable.c
tools/testing/selftests/bpf/config +13 -0
@@ -83,6 +83,19 @@ CONFIG_NF_CONNTRACK_MARK=y CONFIG_NF_CONNTRACK_ZONES=y CONFIG_NF_DEFRAG_IPV4=y CONFIG_NF_DEFRAG_IPV6=y +CONFIG_NF_TABLES=y +CONFIG_NF_TABLES_INET=y +CONFIG_NF_TABLES_NETDEV=y +CONFIG_NF_TABLES_IPV4=y +CONFIG_NF_TABLES_IPV6=y +CONFIG_NETFILTER_INGRESS=y +CONFIG_NF_FLOW_TABLE=y +CONFIG_NF_FLOW_TABLE_INET=y +CONFIG_NETFILTER_NETLINK=y +CONFIG_NFT_FLOW_OFFLOAD=y +CONFIG_IP_NF_IPTABLES=y +CONFIG_IP6_NF_IPTABLES=y +CONFIG_IP6_NF_FILTER=y CONFIG_NF_NAT=y CONFIG_RC_CORE=y CONFIG_SECURITY=y
tools/testing/selftests/bpf/prog_tests/xdp_flowtable.c new file +168 -0
168 lines not on this page · raw message
tools/testing/selftests/bpf/progs/xdp_flowtable.c new file +145 -0
145 lines not on this page · raw message
Signature · 1 line
2.45.1
Daniel Borkmann
maintainerRe: [PATCH v4 bpf-next 3/3] selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc
Quoted 4 lines · Lorenzo Bianconi
Introduce e2e selftest for
bpf_xdp_flow_lookupkfunc throughxdp_flowtableutility.Signed-off-by Lorenzo Bianconi <[email protected]>
[...]
tools/testing/selftests/bpf/progs/xdp_flowtable.c line 21
Quoted 3 lines
tools/testing/selftests/bpf/progs/xdp_flowtable.c new file +3
-0+struct flow_offload_tuple_rhash * +bpf_xdp_flow_lookup (struct xdp_md *,struct bpf_fib_lookup *, +struct bpf_flowtable_opts___local *,u32 ) __ksym;
Btw, this fails CI build :
https://github.com/kernel-patches/bpf/actions/runs/9499749947/job/26190382116
[...]
progs/xdp_flowtable.c:20:1: error: conflicting types for 'bpf_xdp_flow_lookup'
20 | bpf_xdp_flow_lookup(struct xdp_md *, struct bpf_fib_lookup *,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:106755:41: note: previous declaration is here
106755 | extern struct flow_offload_tuple_rhash *bpf_xdp_flow_lookup(struct xdp_md *ctx, struct bpf_fib_lookup *fib_tuple, struct bpf_flowtable_opts *opts, u32 opts_len) __weak __ksym;
| ^
progs/xdp_flowtable.c:134:47: error: incompatible pointer types passing 'struct bpf_flowtable_opts___local *' to parameter of type 'struct bpf_flowtable_opts *' [-Werror,-Wincompatible-pointer-types]
134 | tuplehash = bpf_xdp_flow_lookup(ctx, &tuple, &opts, sizeof(opts));
| ^~~~~ /tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:106755:142: note: passing argument to parameter 'opts' here
106755 | extern struct flow_offload_tuple_rhash *bpf_xdp_flow_lookup(struct xdp_md *ctx, struct bpf_fib_lookup *fib_tuple, struct bpf_flowtable_opts *opts, u32 opts_len) __weak __ksym;
| ^
2 errors generated.
CLNG-BPF [test_maps] kprobe_multi_override.bpf.o
CLNG-BPF [test_maps] tailcall_bpf2bpf1.bpf.o
make: *** [Makefile:654: /tmp/work/bpf/bpf/tools/testing/selftests/bpf/xdp_flowtable.bpf.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory '/tmp/work/bpf/bpf/tools/testing/selftests/bpf'
Error: Process completed with exit code 2.
Re: [PATCH v4 bpf-next 3/3] selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc
Quoted 24 lines · Daniel Borkmann
Quoted 4 lines · Lorenzo Bianconi
Introduce e2e selftest for
bpf_xdp_flow_lookupkfunc throughxdp_flowtableutility.Signed-off-by Lorenzo Bianconi <[email protected]>[...]
tools/testing/selftests/bpf/progs/xdp_flowtable.c line 21
Quoted 3 lines
tools/testing/selftests/bpf/progs/xdp_flowtable.c new file +3
-0+struct flow_offload_tuple_rhash * +bpf_xdp_flow_lookup (struct xdp_md *,struct bpf_fib_lookup *, +struct bpf_flowtable_opts___local *,u32 ) __ksym;Btw, this fails CI build :
https://github.com/kernel-patches/bpf/actions/runs/9499749947/job/26190382116
[...]
progs/xdp_flowtable.c:20:1: error: conflicting types for 'bpf_xdp_flow_lookup'
20 | bpf_xdp_flow_lookup(structxdp_md*, structbpf_fib_lookup*,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:106755:41: note: previous declaration is here
106755 | extern structflow_offload_tuple_rhash*bpf_xdp_flow_lookup(structxdp_md*ctx, structbpf_fib_lookup*fib_tuple, structbpf_flowtable_opts*opts, u32opts_len)__weak__ksym;
| ^
progs/xdp_flowtable.c:134:47: error: incompatible pointer types passing 'structbpf_flowtable_opts___local*' to parameter of type 'structbpf_flowtable_opts*' [-Werror,-Wincompatible-pointer-types]134 | tuplehash = bpf_xdp_flow_lookup(ctx, &tuple, &opts, sizeof(opts)); | ^~~~~
Quoted 11 lines
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:106755:142: note: passing argument to parameter 'opts' here
106755 | extern structflow_offload_tuple_rhash*bpf_xdp_flow_lookup(structxdp_md*ctx, structbpf_fib_lookup*fib_tuple, structbpf_flowtable_opts*opts, u32opts_len)__weak__ksym;
| ^
2 errors generated.
CLNG-BPF [test_maps] kprobe_multi_override.bpf.o
CLNG-BPF [test_maps] tailcall_bpf2bpf1.bpf.o
make: *** [Makefile:654:/tmp/work/bpf/bpf/tools/testing/selftests/bpf/xdp_flowtable.bpf.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory '/tmp/work/bpf/bpf/tools/testing/selftests/bpf'
Error: Process completed with exit code 2.
We'll probably want to do the same thing as in f709124dd72f ("bpf:
selftests: nf: Opt out of using generated kfunc prototypes").
Daniel
Re: [PATCH v4 bpf-next 3/3] selftests/bpf: Add selftest for bpf_xdp_flow_lookup kfunc
Quoted 37 lines · Daniel Borkmann
Quoted 24 lines · Lorenzo Bianconi
Quoted 4 lines
Introduce e2e selftest for
bpf_xdp_flow_lookupkfunc throughxdp_flowtableutility.Signed-off-by Lorenzo Bianconi <[email protected]>[...]
tools/testing/selftests/bpf/progs/xdp_flowtable.c line 21
Quoted 3 lines
tools/testing/selftests/bpf/progs/xdp_flowtable.c new file +3
-0+struct flow_offload_tuple_rhash * +bpf_xdp_flow_lookup (struct xdp_md *,struct bpf_fib_lookup *, +struct bpf_flowtable_opts___local *,u32 ) __ksym;Btw, this fails CI build :
https://github.com/kernel-patches/bpf/actions/runs/9499749947/job/26190382116
[...]
progs/xdp_flowtable.c:20:1: error: conflicting types for 'bpf_xdp_flow_lookup'
20 | bpf_xdp_flow_lookup(structxdp_md*, structbpf_fib_lookup*,
| ^
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:106755:41: note: previous declaration is here
106755 | extern structflow_offload_tuple_rhash*bpf_xdp_flow_lookup(structxdp_md*ctx, structbpf_fib_lookup*fib_tuple, structbpf_flowtable_opts*opts, u32opts_len)__weak__ksym;
| ^
progs/xdp_flowtable.c:134:47: error: incompatible pointer types passing 'structbpf_flowtable_opts___local*' to parameter of type 'structbpf_flowtable_opts*' [-Werror,-Wincompatible-pointer-types]134 | tuplehash = bpf_xdp_flow_lookup(ctx, &tuple, &opts, sizeof(opts)); | ^~~~~Quoted 11 lines
/tmp/work/bpf/bpf/tools/testing/selftests/bpf/tools/include/vmlinux.h:106755:142: note: passing argument to parameter 'opts' here
106755 | extern structflow_offload_tuple_rhash*bpf_xdp_flow_lookup(structxdp_md*ctx, structbpf_fib_lookup*fib_tuple, structbpf_flowtable_opts*opts, u32opts_len)__weak__ksym;
| ^
2 errors generated.
CLNG-BPF [test_maps] kprobe_multi_override.bpf.o
CLNG-BPF [test_maps] tailcall_bpf2bpf1.bpf.o
make: *** [Makefile:654:/tmp/work/bpf/bpf/tools/testing/selftests/bpf/xdp_flowtable.bpf.o] Error 1
make: *** Waiting for unfinished jobs....
make: Leaving directory '/tmp/work/bpf/bpf/tools/testing/selftests/bpf'
Error: Process completed with exit code 2.
Quoted 2 lines
We'll probably want to do the same thing as in
f709124dd72f("bpf:
selftests: nf: Opt out of using generated kfunc prototypes").
ack, I added BPF_NO_KFUNC_PROTOTYPES to selftest patch. CI seems fine now:
https://github.com/kernel-patches/bpf/pull/7202
Regards,
Lorenzo
Quoted 2 lines
Daniel
Pablo Neira Ayuso
maintainerQuoted 4 lines · Lorenzo Bianconi
Introduce
bpf_xdp_flow_lookupkfunc in order to perform the lookup of a given flowtable entry based on the fib tuple of incoming traffic.bpf_xdp_flow_lookupcan be used as building block to offload in XDP the sw flowtable processing when the hw support is not available.