netfilter: nf_tables_offload: support fwd_netdev offload
Subsystems (2)
v5 cover netfilter: nf_tables_offload: support fwd_netdev offload
From: wenxu <[email protected]>
This series patch support fwd_netdev offload:
1). add net in offload ctx to make get the netdevice in the related net. 2). add fw_netdev action offload
This version just split from the orignal big seriese without dependency with each other
wenxu (2):
netfilter: nf_flow_offload: add net in offload_ctx
netfilter: nft_fwd_netdev: add fw_netdev action support
include/net/netfilter/nf_tables_offload.h | 3 ++- net/netfilter/nf_tables_api.c | 2 +- net/netfilter/nf_tables_offload.c | 3 ++- net/netfilter/nft_fwd_netdev.c | 26 ++++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1
PATCH v5 1/2 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
---
v5: no change
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
@@ -25,6 +25,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 ]; };
@@ -61,7 +62,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); void nft_indr_block_get_and_ing_cmd(struct net_device *dev,
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
Re: [PATCH nf-next v5 1/2] netfilter: nf_flow_offload: add net in offload_ctx
Hi pablo,
How about this series?
BR
wenxu
Quoted 67 lines · On 8/21/2019 12:56 PM, [email protected] wrote:
From: wenxu <[email protected]>
In the
offload_ctx, the net can be used for other actions such as fwd netdevSigned-off-by wenxu <[email protected]>---
v5: no changeinclude/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@@ -25,6 +25,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 ]; };@@ -61,7 +62,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); void nft_indr_block_get_and_ing_cmd(struct net_device *dev,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;
PATCH v5 2/2 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
---
v5: no offload_actions callback
net/netfilter/nft_fwd_netdev.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
net/netfilter/nft_fwd_netdev.c +26 -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,30 @@ 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 = ®->data; +struct flow_action_entry *entry; +struct net_device *dev; +int oif =-1 ; + + 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 +219,7 @@ 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, }; static const struct nft_expr_ops *
Signature · 1 line
1.8.3.1