netfilter: flowtable: add flow_offload_tuple() helper
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 8/9 netfilter: flowtable: add flow_offload_tuple() helper
Consolidate code to configure the flow_cls_offload structure into one helper function.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: remove EXPORT_SYMBOL() - wenxu.
net/netfilter/nf_flow_table_offload.c | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-)
net/netfilter/nf_flow_table_offload.c +23 -23
@@ -592,23 +592,25 @@ static void nf_flow_offload_init(struct flow_cls_offload *cls_flow, cls_flow->cookie = (unsigned long )tuple; } -static int flow_offload_tuple_add (struct flow_offload_work *offload, -struct nf_flow_rule *flow_rule, -enum flow_offload_tuple_dir dir) +static int flow_offload_tuple (struct nf_flowtable *flowtable, +struct flow_offload *flow, +struct nf_flow_rule *flow_rule, +enum flow_offload_tuple_dir dir, +int priority,int cmd, +struct list_head *block_cb_list) { -struct nf_flowtable *flowtable = offload->flowtable;struct flow_cls_offload cls_flow = {};struct flow_block_cb *block_cb;struct netlink_ext_ack extack;__be16 proto =ETH_P_ALL ;int err, i =0 ; -nf_flow_offload_init (&cls_flow, proto, offload->priority, -FLOW_CLS_REPLACE , - &offload->flow->tuplehash[dir].tuple, &extack); - cls_flow.rule = flow_rule->rule; +nf_flow_offload_init (&cls_flow, proto, priority, cmd, + &flow->tuplehash[dir].tuple, &extack); +if (cmd ==FLOW_CLS_REPLACE ) + cls_flow.rule = flow_rule->rule; -list_for_each_entry (block_cb, &flowtable->flow_block.cb_list, list) { +list_for_each_entry (block_cb, block_cb_list, list) { err = block_cb->cb (TC_SETUP_CLSFLOWER , &cls_flow, block_cb->cb_priv);if (err <0 )
@@ -620,23 +622,21 @@ static int flow_offload_tuple_add(struct flow_offload_work *offload,return i; } +static int flow_offload_tuple_add (struct flow_offload_work *offload, +struct nf_flow_rule *flow_rule, +enum flow_offload_tuple_dir dir) +{ +return flow_offload_tuple (offload->flowtable, offload->flow, flow_rule, + dir, offload->priority,FLOW_CLS_REPLACE , + &offload->flowtable->flow_block.cb_list); +} +static void flow_offload_tuple_del (struct flow_offload_work *offload,enum flow_offload_tuple_dir dir) { -struct nf_flowtable *flowtable = offload->flowtable; -struct flow_cls_offload cls_flow = {}; -struct flow_block_cb *block_cb; -struct netlink_ext_ack extack; -__be16 proto =ETH_P_ALL ; - -nf_flow_offload_init (&cls_flow, proto, offload->priority, -FLOW_CLS_DESTROY , - &offload->flow->tuplehash[dir].tuple, &extack); - -list_for_each_entry (block_cb, &flowtable->flow_block.cb_list, list) - block_cb->cb (TC_SETUP_CLSFLOWER , &cls_flow, block_cb->cb_priv); - -set_bit (NF_FLOW_HW_DEAD , &offload->flow->flags); +flow_offload_tuple (offload->flowtable, offload->flow,NULL , + dir, offload->priority,FLOW_CLS_DESTROY , + &offload->flowtable->flow_block.cb_list); } static int flow_offload_rule_add(struct flow_offload_work *offload,
Signature · 1 line
2.11.0
Pablo Neira Ayuso
maintainerPATCH v2 9/9 netfilter: flowtable: add nf_flow_table_offload_cmd()
Split nf_flow_table_offload_setup() in two functions to make it more maintainable.
Signed-off-by Pablo Neira Ayuso <[email protected]>
---
v2: Fix incorrect dereference to flow_block_offload structure - wenxu.
net/netfilter/nf_flow_table_offload.c | 40 ++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 12 deletions(-)
net/netfilter/nf_flow_table_offload.c +28 -12
@@ -837,12 +837,12 @@ static int nf_flow_table_block_setup(struct nf_flowtable *flowtable,return err; } -int nf_flow_table_offload_setup (struct nf_flowtable *flowtable, -struct net_device *dev, -enum flow_block_command cmd) +static int nf_flow_table_offload_cmd (struct flow_block_offload *bo, +struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd, +struct netlink_ext_ack *extack) { -struct netlink_ext_ack extack = {}; -struct flow_block_offload bo = {};int err;if (!nf_flowtable_hw_offload (flowtable))
@@ -851,14 +851,30 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,if (!dev->netdev_ops->ndo_setup_tc)return -EOPNOTSUPP ; - bo.net =dev_net (dev); - bo.block = &flowtable->flow_block; - bo.command = cmd; - bo.binder_type =FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ; - bo.extack = &extack; -INIT_LIST_HEAD (&bo.cb_list); +memset (bo,0 ,sizeof (*bo)); + bo->net =dev_net (dev); + bo->block = &flowtable->flow_block; + bo->command = cmd; + bo->binder_type =FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS ; + bo->extack = extack; +INIT_LIST_HEAD (&bo->cb_list); + + err = dev->netdev_ops->ndo_setup_tc (dev,TC_SETUP_FT , bo); +if (err <0 ) +return err; + +return 0 ; +} + +int nf_flow_table_offload_setup (struct nf_flowtable *flowtable, +struct net_device *dev, +enum flow_block_command cmd) +{ +struct netlink_ext_ack extack = {}; +struct flow_block_offload bo; +int err; - err = dev->netdev_ops->ndo_setup_tc (dev,TC_SETUP_FT , &bo); + err =nf_flow_table_offload_cmd (&bo, flowtable, dev, cmd, &extack);if (err <0 )return err;
Signature · 1 line
2.11.0