netfilter: nft_payload: fix C-VLAN offload support
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH 1/3 netfilter: nft_payload: fix C-VLAN offload support
- add another struct flow_dissector_key_vlan for C-VLAN
- update layer 3 dependency to allow to match on IPv4/IPv6
--- include/net/netfilter/nf_tables_offload.h | 1 + net/netfilter/nft_payload.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-)
include/net/netfilter/nf_tables_offload.h +1 -0
@@ -45,6 +45,7 @@ struct nft_flow_key {struct flow_dissector_key_ports tp;struct flow_dissector_key_ip ip;struct flow_dissector_key_vlan vlan; +struct flow_dissector_key_vlan cvlan;struct flow_dissector_key_eth_addrs eth_addrs;struct flow_dissector_key_meta meta; }__aligned(BITS_PER_LONG / 8) ;/* Ensure that we can do comparisons as longs. */
net/netfilter/nft_payload.c +3 -2
@@ -241,7 +241,7 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,if (!nft_payload_offload_mask (reg, priv->len,sizeof (__be16)))return -EOPNOTSUPP ; -NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_CVLAN , vlan, +NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_CVLAN , cvlan, vlan_tci,sizeof (__be16), reg);break ; case offsetof(struct vlan_ethhdr, h_vlan_encapsulated_proto) +
@@ -249,8 +249,9 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,if (!nft_payload_offload_mask (reg, priv->len,sizeof (__be16)))return -EOPNOTSUPP ; -NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_CVLAN , vlan, +NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_CVLAN , cvlan, vlan_tpid,sizeof (__be16), reg); +nft_offload_set_dependency (ctx,NFT_OFFLOAD_DEP_NETWORK );break ;default :return -EOPNOTSUPP ;
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 2/3 netfilter: nftables_offload: VLAN id needs host byteorder in flow dissector
The flow dissector representation expects the VLAN id in host byteorder. Add the NFT_OFFLOAD_F_NETWORK2HOST flag to swap the bytes from nft_cmp.
--- include/net/netfilter/nf_tables_offload.h | 11 +++++- net/netfilter/nft_cmp.c | 41 +++++++++++++++++++++-- net/netfilter/nft_payload.c | 10 +++--- 3 files changed, 55 insertions(+), 7 deletions(-)
include/net/netfilter/nf_tables_offload.h +10 -1
@@ -4,11 +4,16 @@#include <net/flow_offload.h> #include <net/netfilter/nf_tables.h> +enum nft_offload_reg_flags { +NFT_OFFLOAD_F_NETWORK2HOST = (1 <<0 ), +}; +struct nft_offload_reg {u32 key;u32 len;u32 base_offset;u32 offset; +u32 flags;struct nft_data data;struct nft_data mask; };
@@ -72,13 +77,17 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, const struct nft_rulvoid nft_flow_rule_destroy (struct nft_flow_rule *flow);int nft_flow_rule_offload_commit (struct net *net); -#define NFT_OFFLOAD_MATCH (__key, __base, __field, __len, __reg) \ +#define NFT_OFFLOAD_MATCH_FLAGS (__key, __base, __field, __len, __reg, __flags) \ (__reg)->base_offset = \ offsetof(struct nft_flow_key, __base); \ (__reg)->offset = \ offsetof(struct nft_flow_key, __base.__field); \ (__reg)->len = __len; \ (__reg)->key = __key; \ + (__reg)->flags = __flags; + +#define NFT_OFFLOAD_MATCH (__key, __base, __field, __len, __reg) \ + NFT_OFFLOAD_MATCH_FLAGS(__key, __base, __field, __len, __reg, 0)#define NFT_OFFLOAD_MATCH_EXACT (__key, __base, __field, __len, __reg) \ NFT_OFFLOAD_MATCH(__key, __base, __field, __len, __reg) \
net/netfilter/nft_cmp.c +39 -2
58 lines not on this page · raw message
net/netfilter/nft_payload.c +6 -4
@@ -226,8 +226,9 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,if (!nft_payload_offload_mask (reg, priv->len,sizeof (__be16)))return -EOPNOTSUPP ; -NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_VLAN , vlan, - vlan_tci,sizeof (__be16), reg); +NFT_OFFLOAD_MATCH_FLAGS (FLOW_DISSECTOR_KEY_VLAN , vlan, + vlan_tci,sizeof (__be16), reg, +NFT_OFFLOAD_F_NETWORK2HOST );break ;case offsetof(struct vlan_ethhdr , h_vlan_encapsulated_proto):if (!nft_payload_offload_mask (reg, priv->len,sizeof (__be16)))
@@ -241,8 +242,9 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx,if (!nft_payload_offload_mask (reg, priv->len,sizeof (__be16)))return -EOPNOTSUPP ; -NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_CVLAN , cvlan, - vlan_tci,sizeof (__be16), reg); +NFT_OFFLOAD_MATCH_FLAGS (FLOW_DISSECTOR_KEY_CVLAN , cvlan, + vlan_tci,sizeof (__be16), reg, +NFT_OFFLOAD_F_NETWORK2HOST );break ;case offsetof(struct vlan_ethhdr , h_vlan_encapsulated_proto) +sizeof (struct vlan_hdr ):
Signature · 1 line
2.30.2
Pablo Neira Ayuso
maintainerPATCH 3/3 netfilter: nftables_offload: special ethertype handling for VLAN
In reply to Pablo Neira AyusoThe nftables offload parser sets FLOW_DISSECTOR_KEY_BASIC .n_proto to the ethertype field in in the ethertype frame. However:
- FLOW_DISSECTOR_KEY_BASIC .n_proto field always stores either IPv4 or IPv6 ethertypes.
- FLOW_DISSECTOR_KEY_VLAN .vlan_tpid stores either the 802.1q and 802.1ad ethertypes. Same as for C-VLAN.
This function adjusts the flow dissector to handle three scenarios:
1) FLOW_DISSECTOR_KEY_VLAN and FLOW_DISSECTOR_KEY_CVLAN are set. Then, transfer the .n_proto field to FLOW_DISSECTOR_KEY_VLAN .tpid, and FLOW_DISSECTOR_KEY_VLAN .tpid to FLOW_DISSECTOR_KEY_CVLAN .tpid. Finally set .n_proto to FLOW_DISSECTOR_KEY_CVLAN .tpid.
2) FLOW_DISSECTOR_KEY_VLAN is set. Swap the .n_proto and the FLOW_DISSECTOR_KEY_VLAN .tpid fields.
3) ethertype is set to 802.1q or 802.1ad, in this case, transfer the .n_proto field to FLOW_DISSECTOR_KEY_VLAN .vlan_tpid.
--- net/netfilter/nf_tables_offload.c | 41 +++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
net/netfilter/nf_tables_offload.c +41 -0
@@ -47,6 +47,45 @@ void nft_flow_rule_set_addr_type(struct nft_flow_rule *flow, offsetof(struct nft_flow_key , control); } +struct nft_offload_ethertype { +__be16 value; +__be16 mask; +}; + +void nft_flow_rule_transfer_vlan (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow) +{ +struct nft_flow_match *match = &flow->match; +struct nft_offload_ethertype ethertype = { + .value = match->key.basic.n_proto, + .mask = match->mask.basic.n_proto, + }; + +if ((flow->match.dissector.used_keys & + (BIT (FLOW_DISSECTOR_KEY_VLAN ) |BIT (FLOW_DISSECTOR_KEY_CVLAN ))) == + (BIT (FLOW_DISSECTOR_KEY_VLAN ) |BIT (FLOW_DISSECTOR_KEY_CVLAN ))) { + match->key.basic.n_proto = match->key.cvlan.vlan_tpid; + match->mask.basic.n_proto = match->mask.cvlan.vlan_tpid; + match->key.cvlan.vlan_tpid = match->key.vlan.vlan_tpid; + match->mask.cvlan.vlan_tpid = match->mask.vlan.vlan_tpid; + match->key.vlan.vlan_tpid = ethertype.value; + match->mask.vlan.vlan_tpid = ethertype.mask; + }else if (flow->match.dissector.used_keys & (BIT (FLOW_DISSECTOR_KEY_VLAN ))) { + match->key.basic.n_proto = match->key.vlan.vlan_tpid; + match->mask.basic.n_proto = match->mask.vlan.vlan_tpid; + match->key.vlan.vlan_tpid = ethertype.value; + match->mask.vlan.vlan_tpid = ethertype.mask; + }else if (match->key.basic.n_proto ==htons (ETH_P_8021Q ) || + match->key.basic.n_proto ==htons (ETH_P_8021AD )) { + match->key.vlan.vlan_tpid = ethertype.value; + match->mask.vlan.vlan_tpid = ethertype.mask; + match->dissector.used_keys |=BIT (FLOW_DISSECTOR_KEY_VLAN ); + match->key.basic.n_proto =0 ; + match->mask.basic.n_proto =0 ; + match->dissector.used_keys &= ~BIT (FLOW_DISSECTOR_KEY_BASIC ); + } +} +struct nft_flow_rule *nft_flow_rule_create (struct net *net,const struct nft_rule *rule) {
@@ -91,6 +130,8 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, expr =nft_expr_next (expr); } +nft_flow_rule_transfer_vlan (ctx, flow); + flow->proto = ctx->dep.l3num;kfree (ctx);
Signature · 1 line
2.30.2
kernel test robot
build botRe: [PATCH nf-next 3/3] netfilter: nftables_offload: special ethertype handling for VLAN
I love your patch! Perhaps something to improve:
Hi Pablo,
I love your patch! Perhaps something to improve:
[auto build test WARNING on nf-next/master]
url: https://github.com/0day-ci/linux/commits/Pablo-Neira-Ayuso/netfilter-nft_payload-fix-C-VLAN-offload-support/20210412-211319 base: https://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf-next.git master config: m68k-allmodconfig (attached as .config) compiler: m68k-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/09978fe09a0a0b8a4dcdd065502b6bd73f1d3e5d
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Pablo-Neira-Ayuso/netfilter-nft_payload-fix-C-VLAN-offload-support/20210412-211319 git checkout 09978fe09a0a0b8a4dcdd065502b6bd73f1d3e5d
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=m68k
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> net/netfilter/nf_tables_offload.c:55:6: warning: no previous prototype for 'nft_flow_rule_transfer_vlan' [-Wmissing-prototypes]
55 | void nft_flow_rule_transfer_vlan(struct nft_offload_ctx *ctx,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/nft_flow_rule_transfer_vlan +55 net/netfilter/nf_tables_offload.c
54
> 55 void nft_flow_rule_transfer_vlan(struct nft_offload_ctx *ctx,
56 struct nft_flow_rule *flow)
57 {
58 struct nft_flow_match *match = &flow->match;
59 struct nft_offload_ethertype ethertype = {
60 .value = match->key.basic.n_proto,
61 .mask = match->mask.basic.n_proto,
62 };
63
64 if ((flow->match.dissector.used_keys &
65 (BIT(FLOW_DISSECTOR_KEY_VLAN) | BIT(FLOW_DISSECTOR_KEY_CVLAN))) ==
66 (BIT(FLOW_DISSECTOR_KEY_VLAN) | BIT(FLOW_DISSECTOR_KEY_CVLAN))) {
67 match->key.basic.n_proto = match->key.cvlan.vlan_tpid;
68 match->mask.basic.n_proto = match->mask.cvlan.vlan_tpid;
69 match->key.cvlan.vlan_tpid = match->key.vlan.vlan_tpid;
70 match->mask.cvlan.vlan_tpid = match->mask.vlan.vlan_tpid;
71 match->key.vlan.vlan_tpid = ethertype.value;
72 match->mask.vlan.vlan_tpid = ethertype.mask;
73 } else if (flow->match.dissector.used_keys & (BIT(FLOW_DISSECTOR_KEY_VLAN))) {
74 match->key.basic.n_proto = match->key.vlan.vlan_tpid;
75 match->mask.basic.n_proto = match->mask.vlan.vlan_tpid;
76 match->key.vlan.vlan_tpid = ethertype.value;
77 match->mask.vlan.vlan_tpid = ethertype.mask;
78 } else if (match->key.basic.n_proto == htons(ETH_P_8021Q) ||
79 match->key.basic.n_proto == htons(ETH_P_8021AD)) {
80 match->key.vlan.vlan_tpid = ethertype.value;
81 match->mask.vlan.vlan_tpid = ethertype.mask;
82 match->dissector.used_keys |= BIT(FLOW_DISSECTOR_KEY_VLAN);
83 match->key.basic.n_proto = 0;
84 match->mask.basic.n_proto = 0;
85 match->dissector.used_keys &= ~BIT(FLOW_DISSECTOR_KEY_BASIC);
86 }
87 }
88 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org