net/sched: Introduce tc block ports tracking and use
Subsystems (3)
v8 cover net/sched: Introduce tc block ports tracking and use
__context__
The "tc block" is a collection of netdevs/ports which allow qdiscs to share match-action block instances (as opposed to the traditional tc filter per netdev/port)[1].
Up to this point in the implementation, the block is unaware of its ports. This patch makes the tc block ports available to the datapath.
For the datapath we provide a use case of the tc block in a mirred action in patch 3. For users can levarage mirred to do something like the following:
$ tc qdisc add dev ens7 ingress_block 22 clsact $ tc qdisc add dev ens8 ingress_block 22 clsact $ tc qdisc add dev ens9 ingress_block 22 clsact $ tc filter add block 22 protocol ip pref 25 \ flower dst_ip 192.168.0.0/16 action mirred egress mirror blockid 22
In this case, if the packet arrives on ens8, it will be copied and sent to all ports in the block excluding ens8. Note that the packet is still in the pipeline at this point - meaning other actions could be added after the mirror because mirred copies/clones the skb. Example the following is valid:
$ tc filter add block 22 protocol ip pref 25 flower dst_ip 192.168.0.0/16 \ action mirred egress mirror blockid 22 \ action vlan push id 123 \ action mirred egress redirect dev dummy0
redirect behavior always steals the packet from the pipeline and therefore the skb is no longer available for a subsequent action as illustrated above (in redirecting to dummy0).
The behavior of redirecting to a tc block is therefore adapted to work in the same manner. So a setup as such:
$ tc qdisc add dev ens7 ingress_block 22 $ tc qdisc add dev ens8 ingress_block 22 $ tc qdisc add dev ens9 ingress_block 22 $ tc filter add block 22 protocol ip pref 25 \ flower dst_ip 192.168.0.0/16 action mirred egress redirect blockid 22
for a matching packet arriving on ens7 will first send a copy/clone to ens8 (as in the "mirror" behavior) then to ens9 as in the redirect behavior above. Once this processing is done - no other actions are able to process this skb. i.e it is removed from the "pipeline".
In this case, if the packet arrives on ens8, it will be copied and sent to all ports in the block excluding ens8.
Patch 1 separates/exports mirror and redirect functions from act_mirred Patch 2 introduces the required infra.
Patch 3 Allows mirred to blocks
Subsequent patches will come with tdc test cases.
__Acknowledgements__
Suggestions from Vlad Buslov and Marcelo Ricardo Leitner made this patchset better. The idea of integrating the ports into the tc block was suggested by Jiri Pirko.
[1] See commit ca46abd6f89f ("Merge branch'net-sched-allow-qdiscs-to-share-filter-block-instances'")
Changes in v2:
- Remove RFC tag
- Add more details in patch 0(Jiri)
- When CONFIG_NET_TC_SKB_EXT is selected we have unused qdisc_cb
[email protected])
- Fix bad dev dereference in printk of blockcast action (Simon)
Changes in v3:
- Add missing xa_destroy (pointed out by Vlad)
- Remove bugfix pointed by Vlad (will send in separate patch)
- Removed ports from subject in patch #2 and typos (suggested by Marcelo)
- Remove net_notice_ratelimited debug messages in error cases (suggested by Marcelo)
- Minor changes to appease sparse's lock context warning
Changes in v4:
- Avoid code repetition using gotos in cast_one (suggested by Paolo)
- Fix typo in cover letter (pointed out by Paolo)
- Create a module description for act_blockcast
(reported by Paolo and CI)
Changes in v5:
- Add new patch which separated mirred into mirror and redirect functions (suggested by Jiri)
- Instead of repeating the code to mirror in blockcast use mirror exported function by patch1 (tcf_mirror_act)
- Make Block ID into act_blockcast's parameter passed by user space instead of always getting it from SKB (suggested by Jiri)
- Add tx_type parameter which will specify what transmission behaviour we want (as described earlier)
Changes in v6:
- Remove blockcast and make it a part of mirred (suggestd by Jiri)
- Block ID is now a mirred parameter
- We now allow redirecting and mirroring to either ingress or egress
Changes in v7:
- Remove set but not used variable in tcf_mirred_act (pointed out by Jakub)
Changes in v8:
- Fix uapi issues (pointed out by Jiri)
- Separate last patch into 3 - two as preparations for adding block ID to mirred and one allowing mirred to block (suggested by Jiri)
- Remove declaration initialisation of eg_block and in_block in qdisc_block_add_dev (suggested by Jiri)
- Avoid unnecessary if guards in qdisc_block_add_dev (suggested by Jiri)
- Remove unncessary block_index retrieval in __qdisc_destroy (suggested by Jiri)
Victor Nogueira (5):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_mirred: Create function tcf_mirred_to_dev and improve
readability
net/sched: act_mirred: Add helper function tcf_mirred_replace_dev net/sched: act_mirred: Allow mirred to block
include/net/sch_generic.h | 4 + include/net/tc_act/tc_mirred.h | 1 + include/uapi/linux/tc_act/tc_mirred.h | 1 + net/sched/act_mirred.c | 263 ++++++++++++++++++++------ net/sched/cls_api.c | 5 +- net/sched/sch_api.c | 41 ++++ net/sched/sch_generic.c | 18 +- 7 files changed, 268 insertions(+), 65 deletions(-)
Signature · 1 line
2.25.1
PATCH v8 1/5 net/sched: Introduce tc block netdev tracking infra
This commit makes tc blocks track which ports have been added to them. And, with that, we'll be able to use this new information to send packets to the block's ports. Which will be done in the patch #3 of this series.
--- include/net/sch_generic.h | 2 ++ net/sched/cls_api.c | 2 ++ net/sched/sch_api.c | 41 +++++++++++++++++++++++++++++++++++++++ net/sched/sch_generic.c | 18 ++++++++++++++++- 4 files changed, 62 insertions(+), 1 deletion(-)
include/net/sch_generic.h +2 -0
@@ -19,6 +19,7 @@#include <net/gen_stats.h> #include <net/rtnetlink.h> #include <net/flow_offload.h> +#include <linux/xarray.h> struct Qdisc_ops ;struct qdisc_walker ;
@@ -457,6 +458,7 @@ struct tcf_chain { };struct tcf_block { +struct xarray ports;/* datapath accessible */ /* Lock protects tcf_block and lifetime-management data of chains * attached to the block (refcnt, action_refcnt, explicitly_created). */
net/sched/cls_api.c +2 -0
@@ -531,6 +531,7 @@ static void tcf_block_destroy(struct tcf_block *block) {mutex_destroy (&block->lock);mutex_destroy (&block->proto_destroy_lock); +xa_destroy (&block->ports);kfree_rcu (block, rcu); }
@@ -1002,6 +1003,7 @@ static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,refcount_set (&block->refcnt,1 ); block->net = net; block->index = block_index; +xa_init (&block->ports);/* Don't store q pointer for blocks which are shared */ if (!tcf_block_shared (block))
net/sched/sch_api.c +41 -0
53 lines not on this page · raw message
net/sched/sch_generic.c +17 -1
@@ -1051,6 +1051,9 @@ static void qdisc_free_cb(struct rcu_head *head)static void __qdisc_destroy (struct Qdisc *qdisc) {const struct Qdisc_ops *ops = qdisc->ops; +struct net_device *dev =qdisc_dev (qdisc); +const struct Qdisc_class_ops *cops; +struct tcf_block *block;#ifdef CONFIG_NET_SCHED qdisc_hash_del (qdisc);
@@ -1061,11 +1064,24 @@ static void __qdisc_destroy(struct Qdisc *qdisc)qdisc_reset (qdisc); + cops = ops->cl_ops; +if (ops->ingress_block_get) { + block = cops->tcf_block (qdisc,TC_H_MIN_INGRESS ,NULL ); +if (block) +xa_erase (&block->ports, dev->ifindex); + } + +if (ops->egress_block_get) { + block = cops->tcf_block (qdisc,TC_H_MIN_EGRESS ,NULL ); +if (block) +xa_erase (&block->ports, dev->ifindex); + } +if (ops->destroy) ops->destroy (qdisc);module_put (ops->owner); -netdev_put (qdisc_dev (qdisc), &qdisc->dev_tracker); +netdev_put (dev, &qdisc->dev_tracker);trace_qdisc_destroy (qdisc);
Signature · 1 line
2.25.1
Re: [PATCH net-next v8 1/5] net/sched: Introduce tc block netdev tracking infra
Quoted 16 lines · Victor Nogueira
net/sched/sch_api.c +16
-0+static int qdisc_block_add_dev (struct Qdisc *sch,struct net_device *dev, +struct netlink_ext_ack *extack) +{ +const struct Qdisc_class_ops *cl_ops = sch->ops->cl_ops; +struct tcf_block *block; +int err; + + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL ); +if (block) { + err =xa_insert (&block->ports, dev->ifindex, dev,GFP_KERNEL ); +if (err) { +NL_SET_ERR_MSG (extack, +"ingress block dev insert failed" ); +return err; + } + }
net/sched/sch_api.c static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, · line 1208
Quoted 10 lines
net/sched/sch_api.c +10
-0+ + block = cl_ops->tcf_block (sch,TC_H_MIN_EGRESS ,NULL ); +if (block) { + err =xa_insert (&block->ports, dev->ifindex, dev,GFP_KERNEL ); +if (err) { +NL_SET_ERR_MSG (extack, +"Egress block dev insert failed" ); + goto err_out; + } + }
The following fails after this patch:
# tc qdisc add dev swp1 ingress Error: Egress block dev insert failed.
Probably because ingress_tcf_block() ignores the 'cl' argument.
Quoted 10 lines
net/sched/sch_api.c +10
-0+ +return 0 ; + +err_out: + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL ); +if (block) +xa_erase (&block->ports, dev->ifindex); + +return err; +}
Re: [PATCH net-next v8 1/5] net/sched: Introduce tc block netdev tracking infra
In reply to Victor Nogueiranet/sched/sch_api.c static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, · line 1190
Quoted 8 lines · Victor Nogueira
net/sched/sch_api.c +8
-0+static int qdisc_block_add_dev (struct Qdisc *sch,struct net_device *dev, +struct netlink_ext_ack *extack) +{ +const struct Qdisc_class_ops *cl_ops = sch->ops->cl_ops; +struct tcf_block *block; +int err; + + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL );
Another problem, shouldn't there be a check that these operations are actually implemented? The following now crashes with a NULL pointer dereference:
# tc qdisc replace dev swp1 root handle 1: tbf rate 1Mbit burst 256k limit 1M
Quoted 43 lines
net/sched/sch_api.c +33
-0+if (block) { + err =xa_insert (&block->ports, dev->ifindex, dev,GFP_KERNEL ); +if (err) { +NL_SET_ERR_MSG (extack, +"ingress block dev insert failed" ); +return err; + } + } + + block = cl_ops->tcf_block (sch,TC_H_MIN_EGRESS ,NULL ); +if (block) { + err =xa_insert (&block->ports, dev->ifindex, dev,GFP_KERNEL ); +if (err) { +NL_SET_ERR_MSG (extack, +"Egress block dev insert failed" ); + goto err_out; + } + } + +return 0 ; + +err_out: + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL ); +if (block) +xa_erase (&block->ports, dev->ifindex); + +return err; +} +static int qdisc_block_indexes_set (struct Qdisc *sch,struct nlattr **tca,struct netlink_ext_ack *extack) {@@ -1350,6 +1387,10 @@ static struct Qdisc *qdisc_create(struct net_device *dev,qdisc_hash_add (sch, false);trace_qdisc_create (ops, dev, parent); + err =qdisc_block_add_dev (sch, dev, extack); +if (err) + goto err_out4; +return sch; err_out4:
Jamal Hadi Salim
maintainerRe: [PATCH net-next v8 1/5] net/sched: Introduce tc block netdev tracking infra
Quoted 15 lines · Ido Schimmel
net/sched/sch_api.c static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, · line 1190
Quoted 8 lines · Victor Nogueira
net/sched/sch_api.c +8
-0+static int qdisc_block_add_dev (struct Qdisc *sch,struct net_device *dev, +struct netlink_ext_ack *extack) +{ +const struct Qdisc_class_ops *cl_ops = sch->ops->cl_ops; +struct tcf_block *block; +int err; + + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL );Another problem, shouldn't there be a check that these operations are actually implemented? The following now crashes with a NULL pointer dereference:
Quoted 1 line
# tc qdisc replace dev swp1 root handle 1: tbf rate 1Mbit burst 256k limit 1M
I think this broke from v7->v8. Thanks for catching this. We'll send a fix shortly.
cheers,
jamal
Quoted 43 lines
Quoted 43 lines
net/sched/sch_api.c +33
-0+if (block) { + err =xa_insert (&block->ports, dev->ifindex, dev,GFP_KERNEL ); +if (err) { +NL_SET_ERR_MSG (extack, +"ingress block dev insert failed" ); +return err; + } + } + + block = cl_ops->tcf_block (sch,TC_H_MIN_EGRESS ,NULL ); +if (block) { + err =xa_insert (&block->ports, dev->ifindex, dev,GFP_KERNEL ); +if (err) { +NL_SET_ERR_MSG (extack, +"Egress block dev insert failed" ); + goto err_out; + } + } + +return 0 ; + +err_out: + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL ); +if (block) +xa_erase (&block->ports, dev->ifindex); + +return err; +} +static int qdisc_block_indexes_set (struct Qdisc *sch,struct nlattr **tca,struct netlink_ext_ack *extack) {@@ -1350,6 +1387,10 @@ static struct Qdisc *qdisc_create(struct net_device *dev,qdisc_hash_add (sch, false);trace_qdisc_create (ops, dev, parent); + err =qdisc_block_add_dev (sch, dev, extack); +if (err) + goto err_out4; +return sch; err_out4:
Re: [PATCH net-next v8 1/5] net/sched: Introduce tc block netdev tracking infra
Quoted 16 lines · Jamal Hadi Salim
Quoted 15 lines · Ido Schimmel
net/sched/sch_api.c static int qdisc_graft(struct net_device *dev, struct Qdisc *parent, · line 1190
Quoted 8 lines · Victor Nogueira
net/sched/sch_api.c +8
-0+static int qdisc_block_add_dev (struct Qdisc *sch,struct net_device *dev, +struct netlink_ext_ack *extack) +{ +const struct Qdisc_class_ops *cl_ops = sch->ops->cl_ops; +struct tcf_block *block; +int err; + + block = cl_ops->tcf_block (sch,TC_H_MIN_INGRESS ,NULL );Another problem, shouldn't there be a check that these operations are actually implemented? The following now crashes with a NULL pointer dereference:
Quoted 5 lines
Quoted 1 line
# tc qdisc replace dev swp1 root handle 1: tbf rate 1Mbit burst 256k limit 1MI think this broke from
v7->v8. Thanks for catching this. We'll send a fix shortly.
Just sent a fix to net-next because the original patch hasn't been propagated to net yet.
cheers,
Victor
PATCH v8 2/5 net/sched: cls_api: Expose tc block to the datapath
In reply to Victor NogueiraThe datapath can now find the block of the port in which the packet arrived at.
In the next patch we show a possible usage of this patch in a new version of mirred that multicasts to all ports except for the port in which the packet arrived on.
--- include/net/sch_generic.h | 2 ++ net/sched/cls_api.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-)
include/net/sch_generic.h +2 -0
@@ -485,6 +485,8 @@ struct tcf_block {struct mutex proto_destroy_lock;/* Lock for proto_destroy hashtable. */ }; +struct tcf_block *tcf_block_lookup (struct net *net,u32 block_index); +static inline bool lockdep_tcf_chain_is_locked (struct tcf_chain *chain) {return lockdep_is_held (&chain->filter_chain_lock);
net/sched/cls_api.c +2 -1
@@ -1011,12 +1011,13 @@ static struct tcf_block *tcf_block_create(struct net *net, struct Qdisc *q,return block; } -static struct tcf_block *tcf_block_lookup (struct net *net,u32 block_index) +struct tcf_block *tcf_block_lookup (struct net *net,u32 block_index) {struct tcf_net *tn =net_generic (net, tcf_net_id);return idr_find (&tn->idr, block_index); } +EXPORT_SYMBOL (tcf_block_lookup);static struct tcf_block *tcf_block_refcnt_get (struct net *net,u32 block_index) {
Signature · 1 line
2.25.1
PATCH v8 3/5 net/sched: act_mirred: Create function tcf_mirred_to_dev and improve readability
In reply to Victor NogueiraAs a preparation for adding block ID to mirred, separate the part of mirred that redirect/mirrors to a dev into a specific function so that it can be called by blockcast for each dev.
Also improve readability. Eg. rename use_reinsert to dont_clone and skb2 to skb_to_send.
--- net/sched/act_mirred.c | 129 +++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 57 deletions(-)
net/sched/act_mirred.c +72 -57
@@ -225,48 +225,26 @@ static int tcf_mirred_forward(bool want_ingress, struct sk_buff *skb)return err; } -TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, -const struct tc_action *a, -struct tcf_result *res) +static int tcf_mirred_to_dev (struct sk_buff *skb,struct tcf_mirred *m, +struct net_device *dev, +const bool m_mac_header_xmit,int m_eaction, +int retval) { -struct tcf_mirred *m =to_mirred (a); -struct sk_buff *skb2 = skb; -bool m_mac_header_xmit; -struct net_device *dev; -unsigned int nest_level; -int retval, err =0 ; -bool use_reinsert; +struct sk_buff *skb_to_send = skb;bool want_ingress;bool is_redirect;bool expects_nh;bool at_ingress; -int m_eaction; +bool dont_clone;int mac_len;bool at_nh; +int err; - nest_level =__this_cpu_inc_return (mirred_nest_level); -if (unlikely (nest_level >MIRRED_NEST_LIMIT )) { -net_warn_ratelimited ("Packet exceeded mirred recursion limit on dev %s\n" , -netdev_name (skb->dev)); -__this_cpu_dec (mirred_nest_level); -return TC_ACT_SHOT ; - } - -tcf_lastuse_update (&m->tcf_tm); -tcf_action_update_bstats (&m->common, skb); - - m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); - m_eaction =READ_ONCE (m->tcfm_eaction); - retval =READ_ONCE (m->tcf_action); - dev =rcu_dereference_bh (m->tcfm_dev); -if (unlikely (!dev)) { -pr_notice_once ("tc mirred: target device is gone\n" ); - goto out; - } - + is_redirect =tcf_mirred_is_act_redirect (m_eaction);if (unlikely (!(dev->flags &IFF_UP )) || !netif_carrier_ok (dev)) {net_notice_ratelimited ("tc mirred to Houston: device %s is down\n" , dev->name); + err = -ENODEV ; goto out; }
@@ -274,61 +252,98 @@ TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb,* since we can't easily detect the clsact caller, skip clone only for * ingress - that covers the TC S/W datapath. */ - is_redirect =tcf_mirred_is_act_redirect (m_eaction); at_ingress =skb_at_tc_ingress (skb); - use_reinsert = at_ingress && is_redirect && -tcf_mirred_can_reinsert (retval); -if (!use_reinsert) { - skb2 =skb_clone (skb,GFP_ATOMIC ); -if (!skb2) + dont_clone =skb_at_tc_ingress (skb) && is_redirect && +tcf_mirred_can_reinsert (retval); +if (!dont_clone) { + skb_to_send =skb_clone (skb,GFP_ATOMIC ); +if (!skb_to_send) { + err = -ENOMEM ; goto out; + } } want_ingress =tcf_mirred_act_wants_ingress (m_eaction);/* All mirred/redirected skbs should clear previous ct info */ -nf_reset_ct (skb2); +nf_reset_ct (skb_to_send);if (want_ingress && !at_ingress)/* drop dst for egress -> ingress */ -skb_dst_drop (skb2); +skb_dst_drop (skb_to_send); expects_nh = want_ingress || !m_mac_header_xmit; at_nh = skb->data ==skb_network_header (skb);if (at_nh != expects_nh) { - mac_len =skb_at_tc_ingress (skb) ? skb->mac_len : + mac_len = at_ingress ? skb->mac_len :skb_network_offset (skb);if (expects_nh) {/* target device/action expect data at nh */ -skb_pull_rcsum (skb2, mac_len); +skb_pull_rcsum (skb_to_send, mac_len); }else {/* target device/action expect data at mac */ -skb_push_rcsum (skb2, mac_len); +skb_push_rcsum (skb_to_send, mac_len); } } - skb2->skb_iif = skb->dev->ifindex; - skb2->dev = dev; + skb_to_send->skb_iif = skb->dev->ifindex; + skb_to_send->dev = dev; -/* mirror is always swallowed */ if (is_redirect) { -skb_set_redirected (skb2, skb2->tc_at_ingress); - -/* let's the caller reinsert the packet, if possible */ -if (use_reinsert) { - err =tcf_mirred_forward (want_ingress, skb); -if (err) -tcf_action_inc_overlimit_qstats (&m->common); -__this_cpu_dec (mirred_nest_level); -return TC_ACT_CONSUMED ; - } +if (skb == skb_to_send) + retval =TC_ACT_CONSUMED ; + +skb_set_redirected (skb_to_send, skb_to_send->tc_at_ingress); + + err =tcf_mirred_forward (want_ingress, skb_to_send); + }else { + err =tcf_mirred_forward (want_ingress, skb_to_send); } - err =tcf_mirred_forward (want_ingress, skb2);if (err) { out:tcf_action_inc_overlimit_qstats (&m->common); -if (tcf_mirred_is_act_redirect (m_eaction)) +if (is_redirect) retval =TC_ACT_SHOT ; } + +return retval; +} + +TC_INDIRECT_SCOPE int tcf_mirred_act(struct sk_buff *skb, +const struct tc_action *a, +struct tcf_result *res) +{ +struct tcf_mirred *m =to_mirred (a); +int retval =READ_ONCE (m->tcf_action); +unsigned int nest_level; +bool m_mac_header_xmit; +struct net_device *dev; +int m_eaction; + + nest_level =__this_cpu_inc_return (mirred_nest_level); +if (unlikely (nest_level >MIRRED_NEST_LIMIT )) { +net_warn_ratelimited ("Packet exceeded mirred recursion limit on dev %s\n" , +netdev_name (skb->dev)); + retval =TC_ACT_SHOT ; + goto dec_nest_level; + } + +tcf_lastuse_update (&m->tcf_tm); +tcf_action_update_bstats (&m->common, skb); + + dev =rcu_dereference_bh (m->tcfm_dev); +if (unlikely (!dev)) { +pr_notice_once ("tc mirred: target device is gone\n" ); +tcf_action_inc_overlimit_qstats (&m->common); + goto dec_nest_level; + } + + m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); + m_eaction =READ_ONCE (m->tcfm_eaction); + + retval =tcf_mirred_to_dev (skb, m, dev, m_mac_header_xmit, m_eaction, + retval); + +dec_nest_level:__this_cpu_dec (mirred_nest_level);return retval;
Signature · 1 line
2.25.1
PATCH v8 4/5 net/sched: act_mirred: Add helper function tcf_mirred_replace_dev
In reply to Victor NogueiraThe act of replacing a device will be repeated by the init logic for the block ID in the patch that allows mirred to a block. Therefore we encapsulate this functionality in a function (tcf_mirred_replace_dev) so that we can reuse it and avoid code repetition.
--- net/sched/act_mirred.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
net/sched/act_mirred.c +12 -4
@@ -89,6 +89,16 @@ static const struct nla_policy mirred_policy[TCA_MIRRED_MAX + 1] = {static struct tc_action_ops act_mirred_ops; +static void tcf_mirred_replace_dev (struct tcf_mirred *m, +struct net_device *ndev) +{ +struct net_device *odev; + + odev =rcu_replace_pointer (m->tcfm_dev, ndev, +lockdep_is_held (&m->tcf_lock)); +netdev_put (odev, &m->tcfm_dev_tracker); +} + static int tcf_mirred_init(struct net *net, struct nlattr *nla, struct nlattr *est, struct tc_action **a, struct tcf_proto *tp,
@@ -170,7 +180,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla,spin_lock_bh (&m->tcf_lock);if (parm->ifindex) { -struct net_device *odev, *ndev; +struct net_device *ndev; ndev =dev_get_by_index (net, parm->ifindex);if (!ndev) {
@@ -179,9 +189,7 @@ static int tcf_mirred_init(struct net *net, struct nlattr *nla, goto put_chain; } mac_header_xmit =dev_is_mac_header_xmit (ndev); - odev =rcu_replace_pointer (m->tcfm_dev, ndev, -lockdep_is_held (&m->tcf_lock)); -netdev_put (odev, &m->tcfm_dev_tracker); +tcf_mirred_replace_dev (m, ndev);netdev_tracker_alloc (ndev, &m->tcfm_dev_tracker,GFP_ATOMIC ); m->tcfm_mac_header_xmit = mac_header_xmit; }
Signature · 1 line
2.25.1
PATCH v8 5/5 net/sched: act_mirred: Allow mirred to block
In reply to Victor NogueiraSo far the mirred action has dealt with syntax that handles mirror/redirection for netdev. A matching packet is redirected or mirrored to a target netdev.
In this patch we enable mirred to mirror to a tc block as well.
IOW, the new syntax looks as follows:
... mirred <ingress | egress> <mirror | redirect> [index INDEX] < <blockid BLOCKID> | <dev <devname>> >
Examples of mirroring or redirecting to a tc block:
$ tc filter add block 22 protocol ip pref 25 \ flower dst_ip 192.168.0.0/16 action mirred egress mirror blockid 22
$ tc filter add block 22 protocol ip pref 25 \ flower dst_ip 10.10.10.10/32 action mirred egress redirect blockid 22
--- include/net/tc_act/tc_mirred.h | 1 + include/uapi/linux/tc_act/tc_mirred.h | 1 + net/sched/act_mirred.c | 119 +++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 2 deletions(-)
include/net/tc_act/tc_mirred.h +1 -0
@@ -8,6 +8,7 @@struct tcf_mirred {struct tc_action common;int tcfm_eaction; +u32 tcfm_blockid;bool tcfm_mac_header_xmit;struct net_device __rcu *tcfm_dev;netdevice_tracker tcfm_dev_tracker;
include/uapi/linux/tc_act/tc_mirred.h +1 -0
@@ -21,6 +21,7 @@ enum {TCA_MIRRED_TM ,TCA_MIRRED_PARMS ,TCA_MIRRED_PAD , +TCA_MIRRED_BLOCKID , __TCA_MIRRED_MAX };#define TCA_MIRRED_MAX (__TCA_MIRRED_MAX - 1)
net/sched/act_mirred.c +117 -2
180 lines not on this page · raw message
Signature · 1 line
2.25.1
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by David S. Miller <[email protected]>:
Quoted 9 lines · On Tue, 19 Dec 2023 15:16:18 -0300 you wrote:
__context__
The "tc block" is a collection of netdevs/ports which allow qdiscs to share match-action block instances (as opposed to the traditional tc filter per netdev/port)[1].Up to this point in the implementation, the block is unaware of its ports. This patch makes the tc block ports available to the datapath.
[...]
Here is the summary with links:
- [net-next,v8,1/5] net/sched: Introduce tc block netdev tracking infra
https://git.kernel.org/netdev/net-next/c/913b47d3424e - [net-next,v8,2/5] net/sched: cls_api: Expose tc block to the datapath https://git.kernel.org/netdev/net-next/c/a7042cf8f231 - [net-next,v8,3/5] net/sched: act_mirred: Create function tcf_mirred_to_dev and improve readability https://git.kernel.org/netdev/net-next/c/16085e48cb48 - [net-next,v8,4/5] net/sched: act_mirred: Add helper function tcf_mirred_replace_dev https://git.kernel.org/netdev/net-next/c/415e38bf1d8d - [net-next,v8,5/5] net/sched: act_mirred: Allow mirred to block https://git.kernel.org/netdev/net-next/c/42f39036cda8
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html