netfilter: nf_tables_offload: support more actions
Subsystems (2)
cover netfilter: nf_tables_offload: support more actions
From: wenxu <[email protected]>
This series patch support fw_nedev and set payload offload. Keep action data in reg through immedidate offload
wenxu (7):
netfilter: nf_flow_offload: add net in offload_ctx
netfilter: nf_tables_offload: add offload_actions callback
netfilter: nft_table_offload: Add rtnl for chain and rule operations
netfilter: nf_tables_offload: split nft_offload_reg to match and
action type
netfilter: nft_immediate: add offload support for actions
netfilter: nft_fwd_netdev: add fw_netdev action support
netfilter: nft_payload: add nft_set_payload offload support
include/net/netfilter/nf_tables.h | 7 ++- include/net/netfilter/nf_tables_offload.h | 25 +++++++-- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nf_tables_offload.c | 23 +++++--- net/netfilter/nft_cmp.c | 10 ++-- net/netfilter/nft_fwd_netdev.c | 30 +++++++++++ net/netfilter/nft_immediate.c | 47 ++++++++++------ net/netfilter/nft_meta.c | 6 ++- net/netfilter/nft_payload.c | 90 ++++++++++++++++++++++++++----- 9 files changed, 191 insertions(+), 49 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/7 netfilter: nf_flow_offload: add net in offload_ctx
From: wenxu <[email protected]>
In the offload_ctx, the net can be used for other actions such as fwd netdev
--- include/net/netfilter/nf_tables_offload.h | 3 ++- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nf_tables_offload.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
include/net/netfilter/nf_tables_offload.h +2 -1
@@ -24,6 +24,7 @@ struct nft_offload_ctx {__be16 l3num;u8 protonum; } dep; +struct net *net;unsigned int num_actions;struct nft_offload_reg regs[NFT_REG32_15 +1 ]; };
@@ -60,7 +61,7 @@ struct nft_flow_rule {#define NFT_OFFLOAD_F_ACTION (1 << 0)struct nft_rule ; -struct nft_flow_rule *nft_flow_rule_create (const struct nft_rule *rule); +struct nft_flow_rule *nft_flow_rule_create (struct net *net,const struct nft_rule *rule);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
@@ -2844,7 +2844,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 (rule); + flow =nft_flow_rule_create (net, rule);if (IS_ERR (flow))return PTR_ERR (flow);
net/netfilter/nf_tables_offload.c +2 -1
@@ -28,12 +28,13 @@ static struct nft_flow_rule *nft_flow_rule_alloc(int num_actions)return flow; } -struct nft_flow_rule *nft_flow_rule_create (const struct nft_rule *rule) +struct nft_flow_rule *nft_flow_rule_create (struct net *net,const struct nft_rule *rule) {struct nft_offload_ctx ctx = { .dep = { .type =NFT_OFFLOAD_DEP_UNSPEC , }, + .net = net, };struct nft_flow_rule *flow;int num_actions =0 , err;
Signature · 1 line
1.8.3.1
PATCH 2/7 netfilter: nf_tables_offload: add offload_actions callback
In reply to [email protected]From: wenxu <[email protected]>
There will be zero one or serval actions for some expr. such as payload set and immediate
--- include/net/netfilter/nf_tables.h | 7 ++++++- include/net/netfilter/nf_tables_offload.h | 2 -- net/netfilter/nf_tables_offload.c | 4 ++-- net/netfilter/nft_immediate.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-)
include/net/netfilter/nf_tables.h +6 -1
@@ -785,7 +785,7 @@ struct nft_expr_ops {int (*offload)(struct nft_offload_ctx *ctx,struct nft_flow_rule *flow,const struct nft_expr *expr); -u32 offload_flags; +int (*offload_actions)(const struct nft_expr *expr);const struct nft_expr_type *type;void *data; };
@@ -794,6 +794,11 @@ struct nft_expr_ops {#define NFT_EXPR_SIZE (size) (sizeof(struct nft_expr) + \ ALIGN(size, __alignof__(struct nft_expr))) +static inline int nft_offload_action (const struct nft_expr *expr) +{ +return 1 ; +} +/** * struct nft_expr - nf_tables expression *
include/net/netfilter/nf_tables_offload.h +0 -2
@@ -58,8 +58,6 @@ struct nft_flow_rule {struct flow_rule *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);void nft_flow_rule_destroy (struct nft_flow_rule *flow);
net/netfilter/nf_tables_offload.c +2 -2
@@ -42,8 +42,8 @@ struct nft_flow_rule *nft_flow_rule_create(struct net *net, const struct nft_rul expr =nft_expr_first (rule);while (expr->ops && expr !=nft_expr_last (rule)) { -if (expr->ops->offload_flags &NFT_OFFLOAD_F_ACTION ) - num_actions++; +if (expr->ops->offload_actions) + num_actions += expr->ops->offload_actions (expr); expr =nft_expr_next (expr); }
net/netfilter/nft_immediate.c +1 -1
@@ -163,7 +163,7 @@ static int nft_immediate_offload(struct nft_offload_ctx *ctx, .dump = nft_immediate_dump, .validate = nft_immediate_validate, .offload = nft_immediate_offload, - .offload_flags = NFT_OFFLOAD_F_ACTION, + .offload_actions = nft_offload_action, };struct nft_expr_type nft_imm_type__read_mostly = {
Signature · 1 line
1.8.3.1
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 2/7] netfilter: nf_tables_offload: add offload_actions callback
Quoted 18 lines · On Tue, Jul 23, 2019 at 08:52:39PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
There will be zero one or serval actions for some expr. such as payload set and immediate
Signed-off-by wenxu <[email protected]>--- include/net/netfilter/nf_tables.h | 7 ++++++- include/net/netfilter/nf_tables_offload.h | 2 -- net/netfilter/nf_tables_offload.c | 4 ++-- net/netfilter/nft_immediate.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-)include/net/netfilter/nf_tables.h +0
-0
include/net/netfilter/nf_tables.h struct nft_expr_ops { · line 788
Quoted 5 lines
include/net/netfilter/nf_tables.h +1
-1@@ -785,7 +785,7 @@ struct nft_expr_ops {int (*offload)(struct nft_offload_ctx *ctx,struct nft_flow_rule *flow,const struct nft_expr *expr); -u32 offload_flags; +int (*offload_actions)(const struct nft_expr *expr);
I don't understand why you need to add this? is it for payload?
Re: [PATCH nf-next 2/7] netfilter: nf_tables_offload: add offload_actions callback
Quoted 14 lines · Pablo Neira Ayuso
Quoted 13 lines · On Tue, Jul 23, 2019 at 08:52:39PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
There will be zero one or serval actions for some expr. such as payload set and immediate
Signed-off-by wenxu <[email protected]>--- include/net/netfilter/nf_tables.h | 7 ++++++- include/net/netfilter/nf_tables_offload.h | 2 -- net/netfilter/nf_tables_offload.c | 4 ++-- net/netfilter/nft_immediate.c | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-)
Quoted 11 lines
include/net/netfilter/nf_tables.h struct nft_expr_ops { · line 788
Quoted 10 lines
include/net/netfilter/nf_tables.h +1
-1@@ -785,7 +785,7 @@ struct nft_expr_ops {int (*offload)(struct nft_offload_ctx *ctx,struct nft_flow_rule *flow,const struct nft_expr *expr); -u32 offload_flags; +int (*offload_actions)(const struct nft_expr *expr);I don't understand why you need to add this? is it for payload?
yes it is used for set payload and immediately actions. It maybe splited to several actions. The immediate action
may conatian 1 or 0 actions
Quoted 1 line
PATCH 3/7 netfilter: nft_table_offload: Add rtnl for chain and rule operations
In reply to [email protected]From: wenxu <[email protected]>
The nft_setup_cb_call and ndo_setup_tc callback should be under rtnl lock
or it will report:
kernel: RTNL: assertion failed at drivers/net/ethernet/mellanox/mlx5/core/en_rep.c (635)
--- net/netfilter/nf_tables_offload.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
net/netfilter/nf_tables_offload.c +12 -4
@@ -115,14 +115,18 @@ static int nft_setup_cb_call(struct nft_base_chain *basechain, enum tc_setup_type type, void *type_data) { struct flow_block_cb *block_cb; -int err; +int err =0 ; +rtnl_lock ();list_for_each_entry (block_cb, &basechain->flow_block.cb_list, list) { err = block_cb->cb (type, type_data, block_cb->cb_priv);if (err <0 ) -return err; + goto out; } -return 0 ; + +out: +rtnl_unlock (); +return err; } static int nft_flow_offload_rule(struct nft_trans *trans,
@@ -204,9 +208,11 @@ static int nft_flow_offload_chain(struct nft_trans *trans, bo.extack = &extack;INIT_LIST_HEAD (&bo.cb_list); +rtnl_lock (); + err = dev->netdev_ops->ndo_setup_tc (dev,FLOW_SETUP_BLOCK , &bo);if (err <0 ) -return err; + goto out;switch (cmd) {case FLOW_BLOCK_BIND :
@@ -217,6 +223,8 @@ static int nft_flow_offload_chain(struct nft_trans *trans,break ; } +out: +rtnl_unlock ();return err; }
Signature · 1 line
1.8.3.1
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 3/7] netfilter: nft_table_offload: Add rtnl for chain and rule operations
Quoted 18 lines · On Tue, Jul 23, 2019 at 08:52:40PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
The
nft_setup_cb_callandndo_setup_tccallback should be under rtnl lockor it will report:
kernel: RTNL: assertion failed atdrivers/net/ethernet/mellanox/mlx5/core/en_rep.c(635)Signed-off-by wenxu <[email protected]>--- net/netfilter/nf_tables_offload.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)net/netfilter/nf_tables_offload.c +0
-0
net/netfilter/nf_tables_offload.c static int nft_setup_cb_call(struct nft_base_chain *basechain, · line 120
Quoted 7 lines
net/netfilter/nf_tables_offload.c +2
-1@@ -115,14 +115,18 @@ static int nft_setup_cb_call(struct nft_base_chain *basechain, enum tc_setup_type type, void *type_data) { struct flow_block_cb *block_cb; -int err; +int err =0 ; +rtnl_lock ();
Please, have a look at 90d2723c6d4cb2ace50fc3b932a2bcc77710450b and review if this assumption is correct. Probably nfnl_lock() is missing from __nft_release_basechain().
I'd like to avoid grabbing the rtnl_lock().
Florian Westphal
maintainerRe: [PATCH nf-next 3/7] netfilter: nft_table_offload: Add rtnl for chain and rule operations
Quoted 25 lines · Pablo Neira Ayuso
Quoted 24 lines · On Tue, Jul 23, 2019 at 08:52:40PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
The
nft_setup_cb_callandndo_setup_tccallback should be under rtnl lockor it will report:
kernel: RTNL: assertion failed atdrivers/net/ethernet/mellanox/mlx5/core/en_rep.c(635)Signed-off-by wenxu <[email protected]>--- net/netfilter/nf_tables_offload.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)net/netfilter/nf_tables_offload.c +1
-1@@ -115,14 +115,18 @@ static int nft_setup_cb_call(struct nft_base_chain *basechain, enum tc_setup_type type, void *type_data) { struct flow_block_cb *block_cb; -int err; +int err =0 ;
Quoted 5 lines
net/netfilter/nf_tables_offload.c static int nft_setup_cb_call(struct nft_base_chain *basechain, · line 120
Quoted 1 line
net/netfilter/nf_tables_offload.c +1
-0+rtnl_lock ();Please, have a look at
90d2723c6d4cb2ace50fc3b932a2bcc77710450band review if this assumption is correct. Probablynfnl_lock()is missing from__nft_release_basechain().
The mlx driver has a ASSERT_RTNL() in the mlx5e_rep_indr_setup_tc_block() callpath. Or are you proposing to remove that assertion? If so, what lock should protect the callback lists?
Re: [PATCH nf-next 3/7] netfilter: nft_table_offload: Add rtnl for chain and rule operations
Quoted 26 lines · Florian Westphal
Quoted 25 lines · Pablo Neira Ayuso
Quoted 24 lines · On Tue, Jul 23, 2019 at 08:52:40PM +0800, [email protected] wrote:
From: wenxu <[email protected]>
The
nft_setup_cb_callandndo_setup_tccallback should be under rtnl lockor it will report:
kernel: RTNL: assertion failed atdrivers/net/ethernet/mellanox/mlx5/core/en_rep.c(635)Signed-off-by wenxu <[email protected]>--- net/netfilter/nf_tables_offload.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)net/netfilter/nf_tables_offload.c +1
-1@@ -115,14 +115,18 @@ static int nft_setup_cb_call(struct nft_base_chain *basechain, enum tc_setup_type type, void *type_data) { struct flow_block_cb *block_cb; -int err; +int err =0 ;
Quoted 7 lines
Quoted 4 lines
net/netfilter/nf_tables_offload.c static int nft_setup_cb_call(struct nft_base_chain *basechain, · line 120
Quoted 1 line
net/netfilter/nf_tables_offload.c +1
-0+rtnl_lock ();Please, have a look at
90d2723c6d4cb2ace50fc3b932a2bcc77710450band review if this assumption is correct. Probablynfnl_lock()is missing from__nft_release_basechain().The mlx driver has a
ASSERT_RTNL()in themlx5e_rep_indr_setup_tc_block()callpath. Or are you proposing to remove that assertion? If so, what lock should protect the callback lists?
yes, most of the setup_tc callback in mlx driver has a
ASSERT_RTNL() directly or indirectly. Maybe remove this is a good idear
Quoted 2 lines
PATCH 4/7 netfilter: nf_tables_offload: split nft_offload_reg to match and action type
In reply to [email protected]From: wenxu <[email protected]>
Currently the nft_offload_reg is only can be used for match condition. Can not be used for action. Add nft_offload_reg_type to make nft_offload_reg can be iused for action also.
--- include/net/netfilter/nf_tables_offload.h | 20 +++++++++++++++++- net/netfilter/nft_cmp.c | 10 ++++----- net/netfilter/nft_meta.c | 6 ++++-- net/netfilter/nft_payload.c | 34 ++++++++++++++++++++----------- 4 files changed, 50 insertions(+), 20 deletions(-)
include/net/netfilter/nf_tables_offload.h +19 -1
@@ -4,7 +4,13 @@#include <net/flow_offload.h> #include <net/netfilter/nf_tables.h> -struct nft_offload_reg { +enum nft_offload_reg_type { +NFT_OFFLOAD_REG_UNSPEC =0 , +NFT_OFFLOAD_REG_MATCH , +NFT_OFFLOAD_REG_ACTION , +}; + +struct nft_offload_match {u32 key;u32 len;u32 base_offset;
@@ -12,6 +18,18 @@ struct nft_offload_reg {struct nft_data mask; }; +struct nft_offload_action { +struct nft_data data; +}; + +struct nft_offload_reg { +enum nft_offload_reg_type type; +union { +struct nft_offload_match match; +struct nft_offload_action action; + }; +}; +enum nft_offload_dep_type {NFT_OFFLOAD_DEP_UNSPEC =0 ,NFT_OFFLOAD_DEP_NETWORK ,
net/netfilter/nft_cmp.c +5 -5
@@ -116,14 +116,14 @@ static int __nft_cmp_offload(struct nft_offload_ctx *ctx,u8 *mask = (u8 *)&flow->match.mask;u8 *key = (u8 *)&flow->match.key; -if (priv->op !=NFT_CMP_EQ ) +if (priv->op !=NFT_CMP_EQ || reg->type !=NFT_OFFLOAD_REG_MATCH )return -EOPNOTSUPP ; -memcpy (key + reg->offset, &priv->data, priv->len); -memcpy (mask + reg->offset, ®->mask, priv->len); +memcpy (key + reg->match.offset, &priv->data, priv->len); +memcpy (mask + reg->match.offset, ®->match.mask, priv->len); - flow->match.dissector.used_keys |=BIT (reg->key); - flow->match.dissector.offset[reg->key] = reg->base_offset; + flow->match.dissector.used_keys |=BIT (reg->match.key); + flow->match.dissector.offset[reg->match.key] = reg->match.base_offset;nft_offload_update_dependency (ctx, &priv->data, priv->len);
net/netfilter/nft_meta.c +4 -2
@@ -498,15 +498,17 @@ static int nft_meta_get_offload(struct nft_offload_ctx *ctx,const struct nft_meta *priv =nft_expr_priv (expr);struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + reg->type =NFT_OFFLOAD_REG_MATCH ; +switch (priv->key) {case NFT_META_PROTOCOL :NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_BASIC , basic, n_proto, -sizeof (__u16), reg); +sizeof (__u16), ®->match);nft_offload_set_dependency (ctx,NFT_OFFLOAD_DEP_NETWORK );break ;case NFT_META_L4PROTO :NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_BASIC , basic, ip_proto, -sizeof (__u8), reg); +sizeof (__u8), ®->match);nft_offload_set_dependency (ctx,NFT_OFFLOAD_DEP_TRANSPORT );break ;default :
net/netfilter/nft_payload.c +22 -12
@@ -159,14 +159,16 @@ static int nft_payload_offload_ll(struct nft_offload_ctx *ctx, {struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + reg->type =NFT_OFFLOAD_REG_MATCH ; +switch (priv->offset) {case offsetof(struct ethhdr , h_source):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_ETH_ADDRS , eth_addrs, - src,ETH_ALEN , reg); + src,ETH_ALEN , ®->match);break ;case offsetof(struct ethhdr , h_dest):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_ETH_ADDRS , eth_addrs, - dst,ETH_ALEN , reg); + dst,ETH_ALEN , ®->match);break ; }
@@ -179,18 +181,20 @@ static int nft_payload_offload_ip(struct nft_offload_ctx *ctx, {struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + reg->type =NFT_OFFLOAD_REG_MATCH ; +switch (priv->offset) {case offsetof(struct iphdr , saddr):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_IPV4_ADDRS , ipv4, src, -sizeof (struct in_addr ), reg); +sizeof (struct in_addr ), ®->match);break ;case offsetof(struct iphdr , daddr):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_IPV4_ADDRS , ipv4, dst, -sizeof (struct in_addr ), reg); +sizeof (struct in_addr ), ®->match);break ;case offsetof(struct iphdr , protocol):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_BASIC , basic, ip_proto, -sizeof (__u8), reg); +sizeof (__u8), ®->match);nft_offload_set_dependency (ctx,NFT_OFFLOAD_DEP_TRANSPORT );break ;default :
@@ -206,18 +210,20 @@ static int nft_payload_offload_ip6(struct nft_offload_ctx *ctx, {struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + reg->type =NFT_OFFLOAD_REG_MATCH ; +switch (priv->offset) {case offsetof(struct ipv6hdr , saddr):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_IPV6_ADDRS , ipv6, src, -sizeof (struct in6_addr ), reg); +sizeof (struct in6_addr ), ®->match);break ;case offsetof(struct ipv6hdr , daddr):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_IPV6_ADDRS , ipv6, dst, -sizeof (struct in6_addr ), reg); +sizeof (struct in6_addr ), ®->match);break ;case offsetof(struct ipv6hdr , nexthdr):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_BASIC , basic, ip_proto, -sizeof (__u8), reg); +sizeof (__u8), ®->match);nft_offload_set_dependency (ctx,NFT_OFFLOAD_DEP_TRANSPORT );break ;default :
@@ -253,14 +259,16 @@ static int nft_payload_offload_tcp(struct nft_offload_ctx *ctx, {struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + reg->type =NFT_OFFLOAD_REG_MATCH ; +switch (priv->offset) {case offsetof(struct tcphdr , source):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_PORTS , tp, src, -sizeof (__be16), reg); +sizeof (__be16), ®->match);break ;case offsetof(struct tcphdr , dest):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_PORTS , tp, dst, -sizeof (__be16), reg); +sizeof (__be16), ®->match);break ;default :return -EOPNOTSUPP ;
@@ -275,14 +283,16 @@ static int nft_payload_offload_udp(struct nft_offload_ctx *ctx, {struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + reg->type =NFT_OFFLOAD_REG_MATCH ; +switch (priv->offset) {case offsetof(struct udphdr , source):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_PORTS , tp, src, -sizeof (__be16), reg); +sizeof (__be16), ®->match);break ;case offsetof(struct udphdr , dest):NFT_OFFLOAD_MATCH (FLOW_DISSECTOR_KEY_PORTS , tp, dst, -sizeof (__be16), reg); +sizeof (__be16), ®->match);break ;default :return -EOPNOTSUPP ;
Signature · 1 line
1.8.3.1
PATCH 5/7 netfilter: nft_immediate: add offload support for actions
In reply to [email protected]From: wenxu <[email protected]>
Immediate offload support for other action to handle the offload_reg
--- net/netfilter/nft_immediate.c | 47 +++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-)
net/netfilter/nft_immediate.c +30 -17
@@ -130,29 +130,42 @@ static int nft_immediate_offload(struct nft_offload_ctx *ctx, const struct nft_expr *expr) {const struct nft_immediate_expr *priv =nft_expr_priv (expr); +const struct nft_data *data = &priv->data;struct flow_action_entry *entry; -const struct nft_data *data; - -if (priv->dreg !=NFT_REG_VERDICT ) -return -EOPNOTSUPP ; - - entry = &flow->rule->action.entries[ctx->num_actions++]; - data = &priv->data; -switch (data->verdict.code) { -case NF_ACCEPT : - entry->id =FLOW_ACTION_ACCEPT ; -break ; -case NF_DROP : - entry->id =FLOW_ACTION_DROP ; -break ; -default : -return -EOPNOTSUPP ; +if (priv->dreg ==NFT_REG_VERDICT ) { + entry = &flow->rule->action.entries[ctx->num_actions++]; + +switch (data->verdict.code) { +case NF_ACCEPT : + entry->id =FLOW_ACTION_ACCEPT ; +break ; +case NF_DROP : + entry->id =FLOW_ACTION_DROP ; +break ; +default : +return -EOPNOTSUPP ; + } + }else { +struct nft_offload_reg *reg = &ctx->regs[priv->dreg]; + + reg->type =NFT_OFFLOAD_REG_ACTION ; +memcpy (®->action.data, data,sizeof (*data)); }return 0 ; } +static int nft_immediate_offload_actions (const struct nft_expr *expr) +{ +const struct nft_immediate_expr *priv =nft_expr_priv (expr); + +if (priv->dreg ==NFT_REG_VERDICT ) +return 1 ; +else +return 0 ; +} +static const struct nft_expr_ops nft_imm_ops = { .type = &nft_imm_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_immediate_expr )),
@@ -163,7 +176,7 @@ static int nft_immediate_offload(struct nft_offload_ctx *ctx, .dump = nft_immediate_dump, .validate = nft_immediate_validate, .offload = nft_immediate_offload, - .offload_actions = nft_offload_action, + .offload_actions = nft_immediate_offload_actions, };struct nft_expr_type nft_imm_type__read_mostly = {
Signature · 1 line
1.8.3.1
PATCH 6/7 netfilter: nft_fwd_netdev: add fw_netdev action support
In reply to [email protected]From: wenxu <[email protected]>
fwd_netdev action offload:
nft --debug=netlink add rule netdev firewall aclout ip daddr 10.0.1.7 fwd to eth0
--- net/netfilter/nft_fwd_netdev.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
net/netfilter/nft_fwd_netdev.c +30 -0
@@ -15,6 +15,7 @@#include <net/netfilter/nf_dup_netdev.h> #include <net/neighbour.h> #include <net/ip.h> +#include <net/netfilter/nf_tables_offload.h> struct nft_fwd_netdev {enum nft_registers sreg_dev:8 ;
@@ -63,6 +64,33 @@ static int nft_fwd_netdev_dump(struct sk_buff *skb, const struct nft_expr *expr)return -1 ; } +static int nft_fwd_netdev_offload (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +const struct nft_expr *expr) +{ +const struct nft_fwd_netdev *priv =nft_expr_priv (expr); +struct nft_offload_reg *reg = &ctx->regs[priv->sreg_dev]; +const struct nft_data *data = ®->action.data; +struct flow_action_entry *entry; +struct net_device *dev; +int oif =-1 ; + +if (reg->type !=NFT_OFFLOAD_REG_ACTION ) +return -EOPNOTSUPP ; + + entry = &flow->rule->action.entries[ctx->num_actions++]; + +memcpy (&oif, data->data,sizeof (oif)); + dev =__dev_get_by_index (ctx->net, oif); +if (!dev) +return -EOPNOTSUPP ; + + entry->id =FLOW_ACTION_REDIRECT ; + entry->dev = dev; + +return 0 ; +} +struct nft_fwd_neigh {enum nft_registers sreg_dev:8 ;enum nft_registers sreg_addr:8 ;
@@ -194,6 +222,8 @@ static int nft_fwd_neigh_dump(struct sk_buff *skb, const struct nft_expr *expr) .eval = nft_fwd_netdev_eval, .init = nft_fwd_netdev_init, .dump = nft_fwd_netdev_dump, + .offload = nft_fwd_netdev_offload, + .offload_actions = nft_offload_action, }; static const struct nft_expr_ops *
Signature · 1 line
1.8.3.1
PATCH 7/7 netfilter: nft_payload: add nft_set_payload offload support
In reply to [email protected]From: wenxu <[email protected]>
currently payload set only support ll header
nft --debug=netlink add rule netdev firewall aclout ip daddr 10.0.1.7 @ll,0,48 set 0x00002e9ca06e2596 @ll,48,48 set 0xfaffffffffff fwd to eth0
--- net/netfilter/nft_payload.c | 56 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
net/netfilter/nft_payload.c +56 -0
@@ -572,12 +572,68 @@ static int nft_payload_set_dump(struct sk_buff *skb, const struct nft_expr *exprreturn -1 ; } +static int nft_payload_set_offload (struct nft_offload_ctx *ctx, +struct nft_flow_rule *flow, +const struct nft_expr *expr) +{ +const struct nft_payload_set *priv =nft_expr_priv (expr); +struct nft_offload_reg *reg = &ctx->regs[priv->sreg]; +const struct nft_data *data = ®->action.data; +struct flow_action_entry *entry; +u32 len = priv->len; +u32 offset, last; +int n_actions, i; + +if (priv->base !=NFT_PAYLOAD_LL_HEADER || len >16 ) +return -EOPNOTSUPP ; + + offset = priv->offset; + n_actions = len >>2 ; + last = len &0x3 ; + +for (i =0 ; i < n_actions; i++) { + entry = &flow->rule->action.entries[ctx->num_actions++]; + + entry->id =FLOW_ACTION_MANGLE ; + entry->mangle.htype =FLOW_ACT_MANGLE_HDR_TYPE_ETH ; + entry->mangle.mask =0 ; + entry->mangle.val = data->data[i]; + entry->mangle.offset = offset; + offset = offset +4 ; + } + +if (last) { + entry = &flow->rule->action.entries[ctx->num_actions++]; + + entry->id =FLOW_ACTION_MANGLE ; + entry->mangle.htype =FLOW_ACT_MANGLE_HDR_TYPE_ETH ; + entry->mangle.mask = ~((1 << (last *8 )) -1 ); + entry->mangle.val = data->data[i]; + entry->mangle.offset = offset; + } + +return 0 ; +} + +static int nft_payload_set_offload_actions (const struct nft_expr *expr) +{ +const struct nft_payload_set *priv =nft_expr_priv (expr); +u32 len = priv->len; + +if (priv->base !=NFT_PAYLOAD_LL_HEADER || len >16 ) +return 0 ; + +return (len >>2 ) + !!(len &3 ); +} +static const struct nft_expr_ops nft_payload_set_ops = { .type = &nft_payload_type, .size =NFT_EXPR_SIZE (sizeof (struct nft_payload_set )), .eval = nft_payload_set_eval, .init = nft_payload_set_init, .dump = nft_payload_set_dump, + .offload = nft_payload_set_offload, + .offload_actions = nft_payload_set_offload_actions, }; static const struct nft_expr_ops *
Signature · 1 line
1.8.3.1