netfilter: nf_tables_offload: support offload iif types meta offload
Subsystems (2)
PATCH 1/1 netfilter: nf_tables_offload: support offload iif types meta offload
From: wenxu <[email protected]>
The offload basechain is based on ingress devices. The netdev chain can bypass offload the iif types meta in the rule build status
The ether header payload match rely on the iiftype meta
nft --debug=netlink add rule netdev firewall zones ether daddr fa:ff:ff:ff:ff:ff netdev firewall zones
[ meta load iiftype => reg 1 ]
[ cmp eq reg 1 0x00000001 ]
[ payload load 6b @ link header + 0 => reg 1 ]
[ cmp eq reg 1 0xfffffffa 0x0000ffff ]
--- include/net/netfilter/nf_tables_offload.h | 17 +++++++- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nf_tables_offload.c | 64 ++++++++++++++++++++++++++++++- net/netfilter/nft_cmp.c | 3 ++ net/netfilter/nft_meta.c | 9 +++++ 5 files changed, 92 insertions(+), 3 deletions(-)
include/net/netfilter/nf_tables_offload.h +16 -1
@@ -19,12 +19,21 @@ enum nft_offload_dep_type { NFT_OFFLOAD_DEP_TRANSPORT, }; +enum nft_offload_idevice_type { +NFT_OFFLOAD_IDEVICE_UNSPEC =0 , +NFT_OFFLOAD_IDEVICE_IIF , +NFT_OFFLOAD_IDEVICE_IIFTYPE , +NFT_OFFLOAD_IDEVICE_IIFGROUP , +}; +struct nft_offload_ctx {struct {enum nft_offload_dep_type type;__be16 l3num;u8 protonum; } dep; +enum nft_offload_idevice_type idevice_type; +struct list_head *hook_list;unsigned int num_actions;struct net *net;struct nft_offload_reg regs[NFT_REG32_15 +1 ];
@@ -34,6 +43,10 @@ void nft_offload_set_dependency(struct nft_offload_ctx *ctx, enum nft_offload_dep_type type);void nft_offload_update_dependency (struct nft_offload_ctx *ctx,const void *data,u32 len); +void nft_offload_set_idevice (struct nft_offload_ctx *ctx, +enum nft_offload_idevice_type type); +int nft_offload_check_idevice (struct nft_offload_ctx *ctx, +const void *data,u32 len);struct nft_flow_key {struct flow_dissector_key_basic basic;
@@ -62,7 +75,9 @@ struct nft_flow_rule {#define NFT_OFFLOAD_F_ACTION (1 << 0)struct nft_rule ; -struct nft_flow_rule *nft_flow_rule_create (struct net *net,const struct nft_rule *rule); +struct nft_flow_rule *nft_flow_rule_create (struct net *net, +const struct nft_rule *rule, +struct nft_chain *chain);void nft_flow_rule_destroy (struct nft_flow_rule *flow);int nft_flow_rule_offload_commit (struct net *net);
net/netfilter/nf_tables_api.c +1 -1
@@ -3108,7 +3108,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,return nft_table_validate (net, table);if (chain->flags &NFT_CHAIN_HW_OFFLOAD ) { - flow =nft_flow_rule_create (net, rule); + flow =nft_flow_rule_create (net, rule, chain);if (IS_ERR (flow))return PTR_ERR (flow);
net/netfilter/nf_tables_offload.c +63 -1
83 lines not on this page · raw message
net/netfilter/nft_cmp.c +3 -0
@@ -119,6 +119,9 @@ static int __nft_cmp_offload(struct nft_offload_ctx *ctx,if (priv->op !=NFT_CMP_EQ )return -EOPNOTSUPP ; +if (ctx->idevice_type !=NFT_OFFLOAD_IDEVICE_UNSPEC ) +return nft_offload_check_idevice (ctx, &priv->data, priv->len); +memcpy (key + reg->offset, &priv->data, priv->len);memcpy (mask + reg->offset, ®->mask, priv->len);
net/netfilter/nft_meta.c +9 -0
@@ -547,6 +547,15 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx, sizeof(__u8), reg);nft_offload_set_dependency (ctx,NFT_OFFLOAD_DEP_TRANSPORT );break ; +case NFT_META_IIF : +nft_offload_set_idevice (ctx,NFT_OFFLOAD_IDEVICE_IIF ); +break ; +case NFT_META_IIFTYPE : +nft_offload_set_idevice (ctx,NFT_OFFLOAD_IDEVICE_IIFTYPE ); +break ; +case NFT_META_IIFGROUP : +nft_offload_set_idevice (ctx,NFT_OFFLOAD_IDEVICE_IIFGROUP ); +break ;default :return -EOPNOTSUPP ; }
Signature · 1 line
1.8.3.1
Pablo Neira Ayuso
maintainerPlease, have a look at:
https://patchwork.ozlabs.org/patch/1185472/
for supporting iif matching.
Thanks.
So it is better to extend the flow_dissector_key_meta to support iiftype match?
BR
wenxu
Quoted 8 lines · Pablo Neira Ayuso
Please, have a look at:
https://patchwork.ozlabs.org/patch/1185472/
for supporting iif matching.
Thanks.
Pablo Neira Ayuso
maintainerQuoted 1 line · wenxu
So it is better to extend the
flow_dissector_key_metato support iiftype match?
This is what the patches that I'm just about to send are doing, yes.