Skip to contentSkip to conversation

net/sched: Introduce tc block ports tracking and use

PATCH Superseded Victor Nogueira 5 participants 20 messages Oct 5, 2023 – Oct 10, 2023

Subsystems (3)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v4 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].

Example setup:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Once the block is created we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action drop

A packet with dst IP matching 192.168.0.0/16 arriving on the ingress of either ens7 or ens8 is dropped.

__This patchset__
Up to this point in the implementation, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the datapath.

For the datapath we provide a use case of the tc block in an action we call "blockcast" in patch 3. This action can be used in an example 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 blockcast

When a packet(matching dst IP 192.168.0.0/16) arrives on the ingress of any of ens7, ens8 or ens9 it will be copied to all ports other than itself. For example, if it arrives on ens8 then a copy of the packet will be "blockcasted";-> to both ens7 and ens9 (unmodified), but not to ens8.

Patch 1 introduces the required infra. Patch 2 exposes the tc block to the tc datapath and patch 3 implements datapath usage via a new tc action "blockcast".

__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

- 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)

Victor Nogueira (3):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_blockcast: Introduce blockcast tc action

 include/net/sch_generic.h    |   8 +
 include/net/tc_wrapper.h     |   5 +
 include/uapi/linux/pkt_cls.h |   1 +
 net/sched/Kconfig            |  13 ++
 net/sched/Makefile           |   1 +
 net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
 net/sched/cls_api.c          |  12 +-
 net/sched/sch_api.c          |  58 +++++++
 net/sched/sch_generic.c      |  34 +++-
 9 files changed, 426 insertions(+), 3 deletions(-)
 create mode 100644 net/sched/act_blockcast.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v4 1/3 net/sched: Introduce tc block netdev tracking infra

The tc block is a collection of netdevs/ports which allow qdiscs to share filter block instances (as opposed to the traditional tc filter per port). Example:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Now we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action drop

Up to this point, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the datapath.

---
 include/net/sch_generic.h |  4 +++
 net/sched/cls_api.c       |  2 ++
 net/sched/sch_api.c       | 58 +++++++++++++++++++++++++++++++++++++++
 net/sched/sch_generic.c   | 34 +++++++++++++++++++++--
 4 files changed, 96 insertions(+), 2 deletions(-)
include/net/sch_generic.h +4 -0
index c7318c73cfd6..a01979b0a2a1 100644
@@ -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;
@@ -126,6 +127,8 @@ struct Qdisc {
 
 	struct rcu_head		rcu;
 	netdevice_tracker	dev_tracker;
+	netdevice_tracker	in_block_tracker;
+	netdevice_tracker	eg_block_tracker;
 	/* private data */
 	long privdata[] ____cacheline_aligned;
 };
@@ -458,6 +461,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
index a193cc7b3241..06b55344a948 100644
@@ -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);
 }
 
@@ -1003,6 +1004,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 +58 -0

70 lines not on this page · raw message

net/sched/sch_generic.c +32 -2
index 4195a4bc26ca..b0c28b2ee713 100644
@@ -1049,7 +1049,12 @@ 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_ops *ops = qdisc->ops;
+	const struct Qdisc_class_ops *cops;
+	struct tcf_block *block;
+	unsigned long cl;
+	u32 block_index;
 
 #ifdef CONFIG_NET_SCHED
 	qdisc_hash_del(qdisc);
@@ -1060,11 +1065,36 @@ static void __qdisc_destroy(struct Qdisc *qdisc)
 
 	qdisc_reset(qdisc);
 
+	cops = ops->cl_ops;
+	if (ops->ingress_block_get) {
+		block_index = ops->ingress_block_get(qdisc);
+		if (block_index) {
+			cl = TC_H_MIN_INGRESS;
+			block = cops->tcf_block(qdisc, cl, NULL);
+			if (block) {
+				if (xa_erase(&block->ports, dev->ifindex))
+					netdev_put(dev, &qdisc->in_block_tracker);
+			}
+		}
+	}
+
+	if (ops->egress_block_get) {
+		block_index = ops->egress_block_get(qdisc);
+		if (block_index) {
+			cl = TC_H_MIN_EGRESS;
+			block = cops->tcf_block(qdisc, cl, NULL);
+			if (block) {
+				if (xa_erase(&block->ports, dev->ifindex))
+					netdev_put(dev, &qdisc->eg_block_tracker);
+			}
+		}
+	}
+
 	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
#2 lore raw

PATCH v4 2/3 net/sched: cls_api: Expose tc block to the datapath

In reply to Victor Nogueira

The datapath can now find the block of the port in which the packet arrived at. It can then use it for various activities.

In the next patch we show a simple action that multicasts to all ports except for the port in which the packet arrived on.

---
 include/net/sch_generic.h |  4 ++++
 net/sched/cls_api.c       | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
include/net/sch_generic.h +4 -0
index a01979b0a2a1..03ab3730ba09 100644
@@ -440,6 +440,8 @@ struct qdisc_skb_cb {
 	};
 #define QDISC_CB_PRIV_LEN 20
 	unsigned char		data[QDISC_CB_PRIV_LEN];
+	/* This should allow eBPF to continue to align */
+	u32                     block_index;
 };
 
 typedef void tcf_chain_head_change_t(struct tcf_proto *tp_head, void *priv);
@@ -488,6 +490,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 +9 -1
index 06b55344a948..c102fe26ac5e 100644
@@ -1012,12 +1012,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)
 {
@@ -1738,9 +1739,13 @@ int tcf_classify(struct sk_buff *skb,
 		 const struct tcf_proto *tp,
 		 struct tcf_result *res, bool compat_mode)
 {
+	struct qdisc_skb_cb *qdisc_cb = qdisc_skb_cb(skb);
+
 #if !IS_ENABLED(CONFIG_NET_TC_SKB_EXT)
 	u32 last_executed_chain = 0;
 
+	qdisc_cb->block_index = block ? block->index : 0;
+
 	return __tcf_classify(skb, tp, tp, res, compat_mode, NULL, 0,
 			      &last_executed_chain);
 #else
@@ -1752,6 +1757,7 @@ int tcf_classify(struct sk_buff *skb,
 	int ret;
 
 	if (block) {
+		qdisc_cb->block_index = block->index;
 		ext = skb_ext_find(skb, TC_SKB_EXT);
 
 		if (ext && (ext->chain || ext->act_miss)) {
@@ -1779,6 +1785,8 @@ int tcf_classify(struct sk_buff *skb,
 			tp = rcu_dereference_bh(fchain->filter_chain);
 			last_executed_chain = fchain->index;
 		}
+	} else {
+		qdisc_cb->block_index = 0;
 	}
 
 	ret = __tcf_classify(skb, tp, orig_tp, res, compat_mode, n, act_index,
Signature · 1 line
2.25.1
#3 lore raw

PATCH v4 3/3 net/sched: act_blockcast: Introduce blockcast tc action

In reply to Victor Nogueira

This action takes advantage of the presence of tc block ports set in the datapath and broadcast a packet to all ports on that set with exception of the port in which it arrived on.

Example usage:

    $ tc qdisc add dev ens7 ingress block 22
    $ tc qdisc add dev ens8 ingress block 22

Now we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action blockcast
---
 include/net/tc_wrapper.h     |   5 +
 include/uapi/linux/pkt_cls.h |   1 +
 net/sched/Kconfig            |  13 ++
 net/sched/Makefile           |   1 +
 net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
 5 files changed, 317 insertions(+)
 create mode 100644 net/sched/act_blockcast.c
include/net/tc_wrapper.h +5 -0
index a6d481b5bcbc..8ef848968be7 100644
@@ -28,6 +28,7 @@ TC_INDIRECT_ACTION_DECLARE(tcf_csum_act);
 TC_INDIRECT_ACTION_DECLARE(tcf_ct_act);
 TC_INDIRECT_ACTION_DECLARE(tcf_ctinfo_act);
 TC_INDIRECT_ACTION_DECLARE(tcf_gact_act);
+TC_INDIRECT_ACTION_DECLARE(tcf_blockcast_run);
 TC_INDIRECT_ACTION_DECLARE(tcf_gate_act);
 TC_INDIRECT_ACTION_DECLARE(tcf_ife_act);
 TC_INDIRECT_ACTION_DECLARE(tcf_ipt_act);
@@ -57,6 +58,10 @@ static inline int tc_act(struct sk_buff *skb, const struct tc_action *a,
 	if (a->ops->act == tcf_mirred_act)
 		return tcf_mirred_act(skb, a, res);
 #endif
+#if IS_BUILTIN(CONFIG_NET_ACT_BLOCKCAST)
+	if (a->ops->act == tcf_blockcast_run)
+		return tcf_blockcast_run(skb, a, res);
+#endif
 #if IS_BUILTIN(CONFIG_NET_ACT_PEDIT)
 	if (a->ops->act == tcf_pedit_act)
 		return tcf_pedit_act(skb, a, res);
include/uapi/linux/pkt_cls.h +1 -0
index c7082cc60d21..e12fc51c1be1 100644
@@ -139,6 +139,7 @@ enum tca_id {
 	TCA_ID_MPLS,
 	TCA_ID_CT,
 	TCA_ID_GATE,
+	TCA_ID_BLOCKCAST,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
net/sched/Kconfig +13 -0
index 470c70deffe2..abf26f0c921f 100644
@@ -780,6 +780,19 @@ config NET_ACT_SIMP
 	  To compile this code as a module, choose M here: the
 	  module will be called act_simple.
 
+config NET_ACT_BLOCKCAST
+	tristate "TC block Multicast"
+	depends on NET_CLS_ACT
+	help
+	  Say Y here to add an action that will multicast an skb to egress of
+	  all netdevs that belong to a tc block except for the netdev on which
+          the skb arrived on
+
+	  If unsure, say N.
+
+	  To compile this code as a module, choose M here: the
+	  module will be called act_blockcast.
+
 config NET_ACT_SKBEDIT
 	tristate "SKB Editing"
 	depends on NET_CLS_ACT
net/sched/Makefile +1 -0
index b5fd49641d91..2cdcf30645eb 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_NET_ACT_IPT)	+= act_ipt.o
 obj-$(CONFIG_NET_ACT_NAT)	+= act_nat.o
 obj-$(CONFIG_NET_ACT_PEDIT)	+= act_pedit.o
 obj-$(CONFIG_NET_ACT_SIMP)	+= act_simple.o
+obj-$(CONFIG_NET_ACT_BLOCKCAST)	+= act_blockcast.o
 obj-$(CONFIG_NET_ACT_SKBEDIT)	+= act_skbedit.o
 obj-$(CONFIG_NET_ACT_CSUM)	+= act_csum.o
 obj-$(CONFIG_NET_ACT_MPLS)	+= act_mpls.o
net/sched/act_blockcast.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#4 lore raw
In reply to Victor Nogueira
Quoted 13 lines · Thu, Oct 05, 2023 at 08:42:25PM CEST, [email protected] 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].

Example setup:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Once the block is created we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
 flower dst_ip 192.168.0.0/16 action drop
Quoted 6 lines

A packet with dst IP matching 192.168.0.0/16 arriving on the ingress of either ens7 or ens8 is dropped.

__This patchset__
Up to this point in the implementation, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the

Odd. You fix a bug. Is there a bug? If yes, you need to describe it. If no, don't use "fix".

Quoted 11 lines

datapath.

For the datapath we provide a use case of the tc block in an action we call "blockcast" in patch 3. This action can be used in an example 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 blockcast

Seems to me a bit odd that the action works with the entity (block) is is connected to. I would expect rather to give the action configuration:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action blockcast block 22
                                                ^^^^^^^^

Then this is more flexible and allows user to use this action for any packet, no matter from where it was received.

Looks like this is functionality-wise similar to mirred redirect. Why can't we have that action extended to accept block number instead of netdev and have something like:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22

This would be very much alike we do either "tc filter add dev X" or "tc filter add block Y".

Regarding the filtering, that could be a simple flag config of mirred action:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22
  srcfilter

Or something like that.

Makes sense?

Quoted 58 lines

When a packet(matching dst IP 192.168.0.0/16) arrives on the ingress of any of ens7, ens8 or ens9 it will be copied to all ports other than itself. For example, if it arrives on ens8 then a copy of the packet will be "blockcasted";-> to both ens7 and ens9 (unmodified), but not to ens8.

Patch 1 introduces the required infra. Patch 2 exposes the tc block to the tc datapath and patch 3 implements datapath usage via a new tc action "blockcast".

__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

- 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)

Victor Nogueira (3):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_blockcast: Introduce blockcast tc action

include/net/sch_generic.h    |   8 +
include/net/tc_wrapper.h     |   5 +
include/uapi/linux/pkt_cls.h |   1 +
net/sched/Kconfig            |  13 ++
net/sched/Makefile           |   1 +
net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
net/sched/cls_api.c          |  12 +-
net/sched/sch_api.c          |  58 +++++++
net/sched/sch_generic.c      |  34 +++-
9 files changed, 426 insertions(+), 3 deletions(-)

create mode 100644 net/sched/act_blockcast.c

Signature · 1 line
2.25.1
maintainer
#5 lore raw
Quoted 18 lines · Jiri Pirko
Quoted 16 lines · Thu, Oct 05, 2023 at 08:42:25PM CEST, [email protected] 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].

Example setup:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Once the block is created we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
 flower dst_ip 192.168.0.0/16 action drop

A packet with dst IP matching 192.168.0.0/16 arriving on the ingress of either ens7 or ens8 is dropped.

Quoted 6 lines
Quoted 3 lines

__This patchset__
Up to this point in the implementation, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the

Odd. You fix a bug. Is there a bug? If yes, you need to describe it. If no, don't use "fix".

Ok, Jiri;-> we will change the language.

Quoted 13 lines
Quoted 7 lines

datapath.

For the datapath we provide a use case of the tc block in an action we call "blockcast" in patch 3. This action can be used in an example as such:

Quoted 5 lines
$ 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 blockcast
Quoted 6 lines

Seems to me a bit odd that the action works with the entity (block) is is connected to. I would expect rather to give the action configuration:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action blockcast block 22
                                                ^^^^^^^^

We are currently passing the blockid in the skb cb field so it is configuration-less. I suppose we could add this as an optional field and use it when specified.

Quoted 7 lines

Then this is more flexible and allows user to use this action for any packet, no matter from where it was received.

Looks like this is functionality-wise similar to mirred redirect. Why can't we have that action extended to accept block number instead of netdev and have something like:

Quoted 6 lines
$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22

This would be very much alike we do either "tc filter add dev X" or "tc filter add block Y".

We did consider it but concluded it is a lot of work to get it done on mirred - just take a look at mirred and you'll see what i mean;-> Based on that review we came to the conclusion that at some point it would be safer to separate mirred's mirror from redirect; there are too many checks to avoid one or the other based on whether you are coming from egress vs ingress etc. This one is simple, it is just a broadcast.

Quoted 9 lines

Regarding the filtering, that could be a simple flag config of mirred action:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22
  srcfilter

Or something like that.

See my comment above.

cheers,
jamal

Quoted 62 lines

Makes sense?

Quoted 58 lines

When a packet(matching dst IP 192.168.0.0/16) arrives on the ingress of any of ens7, ens8 or ens9 it will be copied to all ports other than itself. For example, if it arrives on ens8 then a copy of the packet will be "blockcasted";-> to both ens7 and ens9 (unmodified), but not to ens8.

Patch 1 introduces the required infra. Patch 2 exposes the tc block to the tc datapath and patch 3 implements datapath usage via a new tc action "blockcast".

__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

- 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)

Victor Nogueira (3):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_blockcast: Introduce blockcast tc action

include/net/sch_generic.h    |   8 +
include/net/tc_wrapper.h     |   5 +
include/uapi/linux/pkt_cls.h |   1 +
net/sched/Kconfig            |  13 ++
net/sched/Makefile           |   1 +
net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
net/sched/cls_api.c          |  12 +-
net/sched/sch_api.c          |  58 +++++++
net/sched/sch_generic.c      |  34 +++-
9 files changed, 426 insertions(+), 3 deletions(-)

create mode 100644 net/sched/act_blockcast.c

--
2.25.1

maintainer
#6 lore raw
Quoted 44 lines · Fri, Oct 06, 2023 at 05:37:41PM CEST, [email protected] wrote:
Quoted 18 lines · Jiri Pirko
Quoted 16 lines · Thu, Oct 05, 2023 at 08:42:25PM CEST, [email protected] 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].

Example setup:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Once the block is created we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
 flower dst_ip 192.168.0.0/16 action drop

A packet with dst IP matching 192.168.0.0/16 arriving on the ingress of either ens7 or ens8 is dropped.

Quoted 6 lines
Quoted 3 lines

__This patchset__
Up to this point in the implementation, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the

Odd. You fix a bug. Is there a bug? If yes, you need to describe it. If no, don't use "fix".

Ok, Jiri;-> we will change the language.

Quoted 16 lines
Quoted 7 lines

datapath.

For the datapath we provide a use case of the tc block in an action we call "blockcast" in patch 3. This action can be used in an example as such:

Quoted 5 lines
$ 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 blockcast

Seems to me a bit odd that the action works with the entity (block) is is connected to. I would expect rather to give the action configuration:

Quoted 7 lines
Quoted 3 lines
$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action blockcast block 22
                                                ^^^^^^^^

We are currently passing the blockid in the skb cb field so it is configuration-less. I suppose we could add this as an optional field and use it when specified.

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

Quoted 15 lines
Quoted 8 lines

Then this is more flexible and allows user to use this action for any packet, no matter from where it was received.

Looks like this is functionality-wise similar to mirred redirect. Why can't we have that action extended to accept block number instead of netdev and have something like:

Quoted 6 lines
$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22

This would be very much alike we do either "tc filter add dev X" or "tc filter add block Y".

Quoted 7 lines

We did consider it but concluded it is a lot of work to get it done on mirred - just take a look at mirred and you'll see what i mean;-> Based on that review we came to the conclusion that at some point it would be safer to separate mirred's mirror from redirect; there are too many checks to avoid one or the other based on whether you are coming from egress vs ingress etc. This one is simple, it is just a broadcast.

Perhaps it is a nice opportunity to do such mirred cleanup, prepare the code and implement block send afterwards?

If I omit the code for now, from user perspective, this functionality belongs into mirred, don't you think? Just replace "dev" by "block" and you got what you need.

Quoted 78 lines
Quoted 11 lines

Regarding the filtering, that could be a simple flag config of mirred action:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22
  srcfilter

Or something like that.

See my comment above.

cheers,
jamal

Quoted 62 lines

Makes sense?

Quoted 58 lines

When a packet(matching dst IP 192.168.0.0/16) arrives on the ingress of any of ens7, ens8 or ens9 it will be copied to all ports other than itself. For example, if it arrives on ens8 then a copy of the packet will be "blockcasted";-> to both ens7 and ens9 (unmodified), but not to ens8.

Patch 1 introduces the required infra. Patch 2 exposes the tc block to the tc datapath and patch 3 implements datapath usage via a new tc action "blockcast".

__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

- 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)

Victor Nogueira (3):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_blockcast: Introduce blockcast tc action

include/net/sch_generic.h    |   8 +
include/net/tc_wrapper.h     |   5 +
include/uapi/linux/pkt_cls.h |   1 +
net/sched/Kconfig            |  13 ++
net/sched/Makefile           |   1 +
net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
net/sched/cls_api.c          |  12 +-
net/sched/sch_api.c          |  58 +++++++
net/sched/sch_generic.c      |  34 +++-
9 files changed, 426 insertions(+), 3 deletions(-)

create mode 100644 net/sched/act_blockcast.c

--
2.25.1

maintainer
#7 lore raw
Quoted 50 lines · Jiri Pirko
Quoted 48 lines · Fri, Oct 06, 2023 at 05:37:41PM CEST, [email protected] wrote:
Quoted 18 lines · Jiri Pirko
Quoted 16 lines · Thu, Oct 05, 2023 at 08:42:25PM CEST, [email protected] 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].

Example setup:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Once the block is created we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
 flower dst_ip 192.168.0.0/16 action drop

A packet with dst IP matching 192.168.0.0/16 arriving on the ingress of either ens7 or ens8 is dropped.

Quoted 6 lines
Quoted 3 lines

__This patchset__
Up to this point in the implementation, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the

Odd. You fix a bug. Is there a bug? If yes, you need to describe it. If no, don't use "fix".

Ok, Jiri;-> we will change the language.

Quoted 19 lines
Quoted 7 lines

datapath.

For the datapath we provide a use case of the tc block in an action we call "blockcast" in patch 3. This action can be used in an example as such:

Quoted 5 lines
$ 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 blockcast

Seems to me a bit odd that the action works with the entity (block) is is connected to. I would expect rather to give the action configuration:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action blockcast block 22
                                                ^^^^^^^^
Quoted 6 lines
Quoted 3 lines

We are currently passing the blockid in the skb cb field so it is configuration-less. I suppose we could add this as an optional field and use it when specified.

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

It is not needed really. Think of an L2 switch - the broadcast action is to send to all ports but self.

Quoted 24 lines
Quoted 16 lines
Quoted 9 lines

Then this is more flexible and allows user to use this action for any packet, no matter from where it was received.

Looks like this is functionality-wise similar to mirred redirect. Why can't we have that action extended to accept block number instead of netdev and have something like:

Quoted 6 lines
$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22

This would be very much alike we do either "tc filter add dev X" or "tc filter add block Y".

Quoted 7 lines

We did consider it but concluded it is a lot of work to get it done on mirred - just take a look at mirred and you'll see what i mean;-> Based on that review we came to the conclusion that at some point it would be safer to separate mirred's mirror from redirect; there are too many checks to avoid one or the other based on whether you are coming from egress vs ingress etc. This one is simple, it is just a broadcast.

Quoted 2 lines

Perhaps it is a nice opportunity to do such mirred cleanup, prepare the code and implement block send afterwards?

I was worried about breaking some existing use cases - the code has got too clever.
But probably it is time to show it some love, one of us will invest time into it.

Quoted 3 lines

If I omit the code for now, from user perspective, this functionality belongs into mirred, don't you think? Just replace "dev" by "block" and you got what you need.

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

cheers,
jamal

Quoted 79 lines
Quoted 79 lines
Quoted 12 lines

Regarding the filtering, that could be a simple flag config of mirred action:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22
  srcfilter

Or something like that.

See my comment above.

cheers,
jamal

Quoted 62 lines

Makes sense?

Quoted 58 lines

When a packet(matching dst IP 192.168.0.0/16) arrives on the ingress of any of ens7, ens8 or ens9 it will be copied to all ports other than itself. For example, if it arrives on ens8 then a copy of the packet will be "blockcasted";-> to both ens7 and ens9 (unmodified), but not to ens8.

Patch 1 introduces the required infra. Patch 2 exposes the tc block to the tc datapath and patch 3 implements datapath usage via a new tc action "blockcast".

__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

- 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)

Victor Nogueira (3):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_blockcast: Introduce blockcast tc action

include/net/sch_generic.h    |   8 +
include/net/tc_wrapper.h     |   5 +
include/uapi/linux/pkt_cls.h |   1 +
net/sched/Kconfig            |  13 ++
net/sched/Makefile           |   1 +
net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
net/sched/cls_api.c          |  12 +-
net/sched/sch_api.c          |  58 +++++++
net/sched/sch_generic.c      |  34 +++-
9 files changed, 426 insertions(+), 3 deletions(-)

create mode 100644 net/sched/act_blockcast.c

--
2.25.1

maintainer
#8 lore raw
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

+1, FWIW

Quoted 2 lines

It is not needed really. Think of an L2 switch - the broadcast action is to send to all ports but self.

We do have an implementation of an L2 switch already, what's the use case which necessitates this new action / functionality?

maintainer
#9 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

Quoted 5 lines
Quoted 2 lines

It is not needed really. Think of an L2 switch - the broadcast action is to send to all ports but self.

We do have an implementation of an L2 switch already, what's the use case which necessitates this new action / functionality?

It is not an L2 switch - the L2 example switch was what came to mind of something that does a broadcast (it doesnt depend on MAC addresses for example). Could have called it a hub. Ex: you could match on many different header fields or skb metadata, then first modify the packet using NAT, etc and then "blockcast" it.

cheers,
jamal

maintainer
#10 lore raw
Quoted 11 lines · Sat, Oct 07, 2023 at 01:00:00AM CEST, [email protected] wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

You are getting the configuration from the block/device the action is attached to. Can you point me to another action doing that?

maintainer
#11 lore raw
Quoted 8 lines · Jiri Pirko
Quoted 6 lines · Sat, Oct 07, 2023 at 01:00:00AM CEST, [email protected] wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

You are getting the configuration from the block/device the action is attached to. Can you point me to another action doing that?

We are entering a pedantic road i am afraid. If there is no existing action that has zero config then consider this one the first one. We use skb->metadata all the time as a source of information for actions, classifiers, qdiscs. If i dont need config i dont need to invent one just because, well, all other actions are using one or more config;-> Your suggestion to specify an extra config to select a block - which may be different than the one the one packet on - is a useful feature(it just adds more code) but really should be optional. i.e if you dont specify a block id configuration then we pick the metadata one.

Quoted 7 lines
Quoted 4 lines

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

I don't understand why you need any new action. mirred redirect to block instead of dev is exactly what you need. Isn't it?

The actions have different meanings and lumping them together then selecting via a knob is not the right approach.
There's shared code for sure. Infact the sending code was ripped from mirred so as not to touch the rest because like i said mirred has since grown a couple of horns and tails. In retrospect mirred should have been two actions with shared code - but it is too late to change now because it is very widely used. If someone like me was afraid of touching it is because there's a maintainance challenge. I consider it in the same zone as trying to restructure something in the skb. I agree mirroring to a group of ports with a simple config is a useful feature. Mirroring to a group via a tc block is simpler but adding a list of ports instead is more powerful. So this feature is useful to have in mirred - just the adding of yet one more button to say "skip this port" is my concern.
Lets see how the refactoring goes first then it will be clearer - it is a lot of delicate work - but you are right lets give it some love now.

cheers,
jamal

Quoted 1 line
maintainer
#12 lore raw
Quoted 15 lines · Sat, Oct 07, 2023 at 01:06:43PM CEST, [email protected] wrote:
Quoted 14 lines · Jiri Pirko
Quoted 11 lines · Sat, Oct 07, 2023 at 01:00:00AM CEST, [email protected] wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

Quoted 5 lines
Quoted 2 lines

You are getting the configuration from the block/device the action is attached to. Can you point me to another action doing that?

We are entering a pedantic road i am afraid. If there is no existing action that has zero config then consider this one the first one. We

Nope, nothing pedantic about it. I was just curious if there's anything out there I missed.

Quoted 2 lines

use skb->metadata all the time as a source of information for actions, classifiers, qdiscs. If i dont need config i dont need to invent one

skb->metadata is something that is specific to a packet. That has nothing to do with the actual configuration.

Quoted 6 lines

just because, well, all other actions are using one or more config;-> Your suggestion to specify an extra config to select a block - which may be different than the one the one packet on - is a useful feature(it just adds more code) but really should be optional. i.e if you dont specify a block id configuration then we pick the metadata one.

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Quoted 9 lines
Quoted 8 lines
Quoted 5 lines

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

I don't understand why you need any new action. mirred redirect to block instead of dev is exactly what you need. Isn't it?

Quoted 14 lines

The actions have different meanings and lumping them together then selecting via a knob is not the right approach.
There's shared code for sure. Infact the sending code was ripped from mirred so as not to touch the rest because like i said mirred has since grown a couple of horns and tails. In retrospect mirred should have been two actions with shared code - but it is too late to change now because it is very widely used. If someone like me was afraid of touching it is because there's a maintainance challenge. I consider it in the same zone as trying to restructure something in the skb. I agree mirroring to a group of ports with a simple config is a useful feature. Mirroring to a group via a tc block is simpler but adding a list of ports instead is more powerful. So this feature is useful to have in mirred - just the adding of yet one more button to say "skip this port" is my concern.

Why? Perhaps skb->iif could be used for check in the tx iteration.

Quoted 9 lines

Lets see how the refactoring goes first then it will be clearer - it is a lot of delicate work - but you are right lets give it some love now.

cheers,
jamal

Quoted 1 line
maintainer
#13 lore raw
Quoted 17 lines · Jiri Pirko
Quoted 15 lines · Sat, Oct 07, 2023 at 01:06:43PM CEST, [email protected] wrote:
Quoted 14 lines · Jiri Pirko
Quoted 11 lines · Sat, Oct 07, 2023 at 01:00:00AM CEST, [email protected] wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

You are getting the configuration from the block/device the action is attached to. Can you point me to another action doing that?

We are entering a pedantic road i am afraid. If there is no existing action that has zero config then consider this one the first one. We

Nope, nothing pedantic about it. I was just curious if there's anything out there I missed.

Not sure if you noticed in the patch: the blockid on which the skb arrived on is now available in the tc_cb[] so when it shows up at the action we can just use it.

Quoted 6 lines
Quoted 3 lines

use skb->metadata all the time as a source of information for actions, classifiers, qdiscs. If i dont need config i dont need to invent one

skb->metadata is something that is specific to a packet. That has nothing to do with the actual configuration.

Essentially we turned blockid into skb metadata. A user specifying configuration of a different blockid is certainly useful. My point is we can have both worlds: when such a user config is missing we'll assume a default which happens to be in the skb.

Quoted 10 lines
Quoted 7 lines

just because, well, all other actions are using one or more config;-> Your suggestion to specify an extra config to select a block - which may be different than the one the one packet on - is a useful feature(it just adds more code) but really should be optional. i.e if you dont specify a block id configuration then we pick the metadata one.

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Agreed (and such a feature should be added regardless of this action). The tc block provides a simple abstraction, but do you think it is enough? Alternative is to use a list of ports given to mirred: it allows us to group ports from different tc blocks or even just a subset of what is in a tc block - but it will require a lot more code to express such functionality.

Quoted 26 lines
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

I don't understand why you need any new action. mirred redirect to block instead of dev is exactly what you need. Isn't it?

Quoted 14 lines

The actions have different meanings and lumping them together then selecting via a knob is not the right approach.
There's shared code for sure. Infact the sending code was ripped from mirred so as not to touch the rest because like i said mirred has since grown a couple of horns and tails. In retrospect mirred should have been two actions with shared code - but it is too late to change now because it is very widely used. If someone like me was afraid of touching it is because there's a maintainance challenge. I consider it in the same zone as trying to restructure something in the skb. I agree mirroring to a group of ports with a simple config is a useful feature. Mirroring to a group via a tc block is simpler but adding a list of ports instead is more powerful. So this feature is useful to have in mirred - just the adding of yet one more button to say "skip this port" is my concern.

Quoted 2 lines

Why? Perhaps skb->iif could be used for check in the tx iteration.

We use skb->dev->ifindex to find the exception. Is iif better?. Jiri - but why does this have to be part of mirred::mirror? I am asking the same question of why mirror and redirect have to be part mirred instead of separate actions.

cheers,
jamal

maintainer
#14 lore raw
Quoted 24 lines · Sat, Oct 07, 2023 at 04:09:15PM CEST, [email protected] wrote:
Quoted 23 lines · Jiri Pirko
Quoted 20 lines · Sat, Oct 07, 2023 at 01:06:43PM CEST, [email protected] wrote:
Quoted 8 lines · Jiri Pirko
Quoted 6 lines · Sat, Oct 07, 2023 at 01:00:00AM CEST, [email protected] wrote:
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

You are getting the configuration from the block/device the action is attached to. Can you point me to another action doing that?

We are entering a pedantic road i am afraid. If there is no existing action that has zero config then consider this one the first one. We

Quoted 7 lines
Quoted 3 lines

Nope, nothing pedantic about it. I was just curious if there's anything out there I missed.

Not sure if you noticed in the patch: the blockid on which the skb arrived on is now available in the tc_cb[] so when it shows up at the action we can just use it.

I see, but does it has to be? I don't think so with the solution I'm proposing.

Quoted 24 lines
Quoted 7 lines
Quoted 4 lines

use skb->metadata all the time as a source of information for actions, classifiers, qdiscs. If i dont need config i dont need to invent one

skb->metadata is something that is specific to a packet. That has nothing to do with the actual configuration.

Essentially we turned blockid into skb metadata. A user specifying configuration of a different blockid is certainly useful. My point is we can have both worlds: when such a user config is missing we'll assume a default which happens to be in the skb.

Quoted 10 lines
Quoted 7 lines

just because, well, all other actions are using one or more config;-> Your suggestion to specify an extra config to select a block - which may be different than the one the one packet on - is a useful feature(it just adds more code) but really should be optional. i.e if you dont specify a block id configuration then we pick the metadata one.

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Quoted 6 lines

Agreed (and such a feature should be added regardless of this action). The tc block provides a simple abstraction, but do you think it is enough? Alternative is to use a list of ports given to mirred: it allows us to group ports from different tc blocks or even just a subset of what is in a tc block - but it will require a lot more code to express such functionality.

Again, you attach filter to either dev or block. If you extend mirred redirect to accept the same 2 types of target, I think it would be best.

Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 11 lines
Quoted 8 lines

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

I don't understand why you need any new action. mirred redirect to block instead of dev is exactly what you need. Isn't it?

The actions have different meanings and lumping them together then selecting via a knob is not the right approach.
There's shared code for sure. Infact the sending code was ripped from mirred so as not to touch the rest because like i said mirred has since grown a couple of horns and tails. In retrospect mirred should have been two actions with shared code - but it is too late to change now because it is very widely used. If someone like me was afraid of touching it is because there's a maintainance challenge. I consider it in the same zone as trying to restructure something in the skb. I agree mirroring to a group of ports with a simple config is a useful feature. Mirroring to a group via a tc block is simpler but adding a list of ports instead is more powerful. So this feature is useful to have in mirred - just the adding of yet one more button to say "skip this port" is my concern.

Quoted 4 lines
Quoted 2 lines

Why? Perhaps skb->iif could be used for check in the tx iteration.

We use skb->dev->ifindex to find the exception. Is iif better?.

iif contains ifindex of the actual ingress device. So if the netdev is part of bond for example, this still contains the original ifindex. So I buess that this depends on what you need. Looks to me that skb->dev->ifindex would be probaly better. It contains the netdev that the filter is attached on, right?

Quoted 3 lines

Jiri - but why does this have to be part of mirred::mirror? I am asking the same question of why mirror and redirect have to be part mirred instead of separate actions.

You have to maintain the backwards compatibility. Currently mirred is one action right? Does not matter how you do it in kernel, user should not tell any difference.

Quoted 3 lines

cheers,
jamal

maintainer
#15 lore raw
Quoted 30 lines · Jiri Pirko
Quoted 28 lines · Sat, Oct 07, 2023 at 04:09:15PM CEST, [email protected] wrote:
Quoted 26 lines · Jiri Pirko
Quoted 15 lines · Sat, Oct 07, 2023 at 01:06:43PM CEST, [email protected] wrote:
Quoted 14 lines · Jiri Pirko
Quoted 11 lines · Sat, Oct 07, 2023 at 01:00:00AM CEST, [email protected] wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 6 Oct 2023 15:06:45 -0400 Jamal Hadi Salim wrote:
Quoted 2 lines

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

+1, FWIW

We dont have any rule that says all actions MUST have parameters ;-> There is nothing speacial about any action that doesnt have a parameter.

Quoted 5 lines
Quoted 2 lines

You are getting the configuration from the block/device the action is attached to. Can you point me to another action doing that?

We are entering a pedantic road i am afraid. If there is no existing action that has zero config then consider this one the first one. We

Nope, nothing pedantic about it. I was just curious if there's anything out there I missed.

Quoted 6 lines
Quoted 3 lines

Not sure if you noticed in the patch: the blockid on which the skb arrived on is now available in the tc_cb[] so when it shows up at the action we can just use it.

I see, but does it has to be? I don't think so with the solution I'm proposing.

It's a simplistic use for a broadcast. We should support the one you suggested as well.

Quoted 31 lines
Quoted 24 lines
Quoted 7 lines
Quoted 4 lines

use skb->metadata all the time as a source of information for actions, classifiers, qdiscs. If i dont need config i dont need to invent one

skb->metadata is something that is specific to a packet. That has nothing to do with the actual configuration.

Essentially we turned blockid into skb metadata. A user specifying configuration of a different blockid is certainly useful. My point is we can have both worlds: when such a user config is missing we'll assume a default which happens to be in the skb.

Quoted 10 lines
Quoted 7 lines

just because, well, all other actions are using one or more config;-> Your suggestion to specify an extra config to select a block - which may be different than the one the one packet on - is a useful feature(it just adds more code) but really should be optional. i.e if you dont specify a block id configuration then we pick the metadata one.

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Quoted 6 lines

Agreed (and such a feature should be added regardless of this action). The tc block provides a simple abstraction, but do you think it is enough? Alternative is to use a list of ports given to mirred: it allows us to group ports from different tc blocks or even just a subset of what is in a tc block - but it will require a lot more code to express such functionality.

Quoted 3 lines

Again, you attach filter to either dev or block. If you extend mirred redirect to accept the same 2 types of target, I think it would be best.

We are going to make block work with mirror, it makes sense. I am not sure about the redirect, what is the semantic? mirror to everyone but redirect to the last one?

Quoted 31 lines
Quoted 31 lines
Quoted 30 lines
Quoted 13 lines
Quoted 5 lines
Quoted 7 lines
Quoted 4 lines

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

I don't understand why you need any new action. mirred redirect to block instead of dev is exactly what you need. Isn't it?

Quoted 14 lines

The actions have different meanings and lumping them together then selecting via a knob is not the right approach.
There's shared code for sure. Infact the sending code was ripped from mirred so as not to touch the rest because like i said mirred has since grown a couple of horns and tails. In retrospect mirred should have been two actions with shared code - but it is too late to change now because it is very widely used. If someone like me was afraid of touching it is because there's a maintainance challenge. I consider it in the same zone as trying to restructure something in the skb. I agree mirroring to a group of ports with a simple config is a useful feature. Mirroring to a group via a tc block is simpler but adding a list of ports instead is more powerful. So this feature is useful to have in mirred - just the adding of yet one more button to say "skip this port" is my concern.

Why? Perhaps skb->iif could be used for check in the tx iteration.

Quoted 8 lines
Quoted 1 line

We use skb->dev->ifindex to find the exception. Is iif better?.

iif contains ifindex of the actual ingress device. So if the netdev is part of bond for example, this still contains the original ifindex. So I buess that this depends on what you need. Looks to me that skb->dev->ifindex would be probaly better. It contains the netdev that the filter is attached on, right?

Note: you can use mirred to redirect to either ingress or egress of other ports - I believe one of these ifindices changes to reflect the new ifindex. We'll take a closer look.

Quoted 8 lines
Quoted 4 lines

Jiri - but why does this have to be part of mirred::mirror? I am asking the same question of why mirror and redirect have to be part mirred instead of separate actions.

You have to maintain the backwards compatibility. Currently mirred is one action right? Does not matter how you do it in kernel, user should not tell any difference.

I dont mean to break existing mirred. What i meant was in retrospect i wish i had the insight to separate mirred into two actions(and share the code instead), it would have simplified the code and its maintainance. It is for the same reason i am not in favor of is adding the "skip this port" in mirror. This is in the spirit of unix philosophy, which we have been mostly adhering to: write small features/actions which do one thing well and stitch them together to compose.

cheers,
jamal

Quoted 4 lines
Quoted 4 lines

cheers,
jamal

#16 lore raw
In reply to Jiri Pirko
Quoted 2 lines · Jiri Pirko
Quoted 1 line · Sat, Oct 07, 2023 at 04:09:15PM CEST, [email protected] wrote:

On Sat, Oct 7, 2023 at 8:43 AM Jiri Pirko <[email protected]> wrote:

...

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Agreed (and such a feature should be added regardless of this action). The tc block provides a simple abstraction, but do you think it is enough? Alternative is to use a list of ports given to mirred: it allows us to group ports from different tc blocks or even just a subset of what is in a tc block - but it will require a lot more code to express such functionality.

Quoted 2 lines

Again, you attach filter to either dev or block. If you extend mirred redirect to accept the same 2 types of target, I think it would be best.

The difference here between filter and action here is that you don't really have an option for filters: you either attach it to either dev or block, or you create an entire new class of objects, say, "blockfilter", all while retaining the same filters, parameters, etc. I'm not aware of a single filter that behaves differently over a block than a netdev.

But for actions, there is the option, and despite the fact that both "output packets", the semantics are not that close. It actually helps with parameter parsing, documentation (man pages), testing (as use and test cases can be more easily tracked) and perhaps more
importantly: if I don't want this feature, I can disable the new module.

Later someone will say "hey why not have a hash_dst_selector", so it can implement a load balancer through the block output? And mirred, once a simple use case (with an already complex implementation), becomes a partial implementation of bonding then. :)

In short, I'm not sure if having the user to fiddle through a maze of options that only work in mode A or B or work differently is better than having more specialized actions (which can and should reuse code).

Marcelo

maintainer
#17 lore raw
Quoted 17 lines · Mon, Oct 09, 2023 at 10:54:07PM CEST, [email protected] wrote:
Quoted 2 lines · Jiri Pirko
Quoted 1 line · Sat, Oct 07, 2023 at 04:09:15PM CEST, [email protected] wrote:

On Sat, Oct 7, 2023 at 8:43 AM Jiri Pirko <[email protected]> wrote:

...

Quoted 10 lines
Quoted 9 lines
Quoted 2 lines

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Agreed (and such a feature should be added regardless of this action). The tc block provides a simple abstraction, but do you think it is enough? Alternative is to use a list of ports given to mirred: it allows us to group ports from different tc blocks or even just a subset of what is in a tc block - but it will require a lot more code to express such functionality.

Quoted 2 lines

Again, you attach filter to either dev or block. If you extend mirred redirect to accept the same 2 types of target, I think it would be best.

Quoted 6 lines

The difference here between filter and action here is that you don't really have an option for filters: you either attach it to either dev or block, or you create an entire new class of objects, say, "blockfilter", all while retaining the same filters, parameters, etc. I'm not aware of a single filter that behaves differently over a block than a netdev.

Why do you talk about different behaviour? Nobody suggested that. I have no idea what you mean by "blockfilter".

Quoted 2 lines

But for actions, there is the option, and despite the fact that both

Which option?

Quoted 6 lines

"output packets", the semantics are not that close. It actually helps with parameter parsing, documentation (man pages), testing (as use and test cases can be more easily tracked) and perhaps more
importantly: if I don't want this feature, I can disable the new module.

Quoted 8 lines

Later someone will say "hey why not have a hash_dst_selector", so it can implement a load balancer through the block output? And mirred, once a simple use case (with an already complex implementation), becomes a partial implementation of bonding then. :)

In short, I'm not sure if having the user to fiddle through a maze of options that only work in mode A or B or work differently is better than having more specialized actions (which can and should reuse code).

Sure, you can have "blockmirredredirect" that would only to the redirection for block target. No problem. I don't see why it can't be just a case of mirred redirect, but if people want that separate, why not.

My problem with the action "blockcast" is that it somehow works with configuration of an entity the filter is attached to:
blockX->filterY->blockcastZ

Z goes all the way down to blockX to figure out where to redirect the packet. If that is not odd, then I don't know what else is.

Has other consequences, like what happens if the filter is not attached to block, but dev directly? What happens is blockcast action is shared among filter? Etc.

Configuration should be action property. That is my point.

Quoted 3 lines

Marcelo

#18 lore raw
Quoted 18 lines · Jiri Pirko
Quoted 17 lines · Mon, Oct 09, 2023 at 10:54:07PM CEST, [email protected] wrote:
Quoted 2 lines · Jiri Pirko
Quoted 1 line · Sat, Oct 07, 2023 at 04:09:15PM CEST, [email protected] wrote:

On Sat, Oct 7, 2023 at 8:43 AM Jiri Pirko <[email protected]> wrote:

...

Quoted 12 lines
Quoted 9 lines
Quoted 2 lines

My primary point is, this should be mirred redirect to block instead of what we currently have only for dev. That's it.

Agreed (and such a feature should be added regardless of this action). The tc block provides a simple abstraction, but do you think it is enough? Alternative is to use a list of ports given to mirred: it allows us to group ports from different tc blocks or even just a subset of what is in a tc block - but it will require a lot more code to express such functionality.

Again, you attach filter to either dev or block. If you extend mirred redirect to accept the same 2 types of target, I think it would be best.

Quoted 8 lines
Quoted 6 lines

The difference here between filter and action here is that you don't really have an option for filters: you either attach it to either dev or block, or you create an entire new class of objects, say, "blockfilter", all while retaining the same filters, parameters, etc. I'm not aware of a single filter that behaves differently over a block than a netdev.

Why do you talk about different behaviour? Nobody suggested that. I have

Because if mirred gets updated to support blocks, that's what will happen. It will have options that only make sense for netdev or for blocks.

Quoted 1 line

no idea what you mean by "blockfilter".

Well, it's described above. It was just an example.

Quoted 7 lines
Quoted 5 lines

But for actions, there is the option, and despite the fact that both

Which option?

To create a new action.

Quoted 22 lines
Quoted 8 lines

"output packets", the semantics are not that close. It actually helps with parameter parsing, documentation (man pages), testing (as use and test cases can be more easily tracked) and perhaps more
importantly: if I don't want this feature, I can disable the new module.

Quoted 8 lines

Later someone will say "hey why not have a hash_dst_selector", so it can implement a load balancer through the block output? And mirred, once a simple use case (with an already complex implementation), becomes a partial implementation of bonding then. :)

In short, I'm not sure if having the user to fiddle through a maze of options that only work in mode A or B or work differently is better than having more specialized actions (which can and should reuse code).

Sure, you can have "blockmirredredirect" that would only to the redirection for block target. No problem. I don't see why it can't be just a case of mirred redirect, but if people want that separate, why not.

Quoted 6 lines

My problem with the action "blockcast" is that it somehow works with configuration of an entity the filter is attached to:
blockX->filterY->blockcastZ

Z goes all the way down to blockX to figure out where to redirect the packet. If that is not odd, then I don't know what else is.

Maybe fried eggs with chocolate. :-D
Just joking..

Quoted 4 lines

Has other consequences, like what happens if the filter is not attached to block, but dev directly? What happens is blockcast action is shared among filter? Etc.

Good points!

Quoted 2 lines

Configuration should be action property. That is my point.

Makes sense. Whoever is adding such filter, already knows the block, and can add the parameter to the action as well. Making it automatic is not helping out that much in the end.

Marcelo

maintainer
#19 lore raw
In reply to Jamal Hadi Salim
Quoted 85 lines · Fri, Oct 06, 2023 at 09:06:45PM CEST, [email protected] wrote:
Quoted 50 lines · Jiri Pirko
Quoted 48 lines · Fri, Oct 06, 2023 at 05:37:41PM CEST, [email protected] wrote:
Quoted 18 lines · Jiri Pirko
Quoted 16 lines · Thu, Oct 05, 2023 at 08:42:25PM CEST, [email protected] 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].

Example setup:

$ tc qdisc add dev ens7 ingress block 22
$ tc qdisc add dev ens8 ingress block 22

Once the block is created we can add a filter using the block index:

$ tc filter add block 22 protocol ip pref 25 \
 flower dst_ip 192.168.0.0/16 action drop

A packet with dst IP matching 192.168.0.0/16 arriving on the ingress of either ens7 or ens8 is dropped.

Quoted 6 lines
Quoted 3 lines

__This patchset__
Up to this point in the implementation, the block is unaware of its ports. This patch fixes that and makes the tc block ports available to the

Odd. You fix a bug. Is there a bug? If yes, you need to describe it. If no, don't use "fix".

Ok, Jiri;-> we will change the language.

Quoted 19 lines
Quoted 7 lines

datapath.

For the datapath we provide a use case of the tc block in an action we call "blockcast" in patch 3. This action can be used in an example as such:

Quoted 5 lines
$ 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 blockcast

Seems to me a bit odd that the action works with the entity (block) is is connected to. I would expect rather to give the action configuration:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action blockcast block 22
                                                ^^^^^^^^
Quoted 6 lines
Quoted 3 lines

We are currently passing the blockid in the skb cb field so it is configuration-less. I suppose we could add this as an optional field and use it when specified.

I don't understand the need for configuration less here. You don't have it for the rest of the actions. Why this is special?

It is not needed really. Think of an L2 switch - the broadcast action is to send to all ports but self.

Quoted 24 lines
Quoted 23 lines
Quoted 9 lines

Then this is more flexible and allows user to use this action for any packet, no matter from where it was received.

Looks like this is functionality-wise similar to mirred redirect. Why can't we have that action extended to accept block number instead of netdev and have something like:

Quoted 6 lines
$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22

This would be very much alike we do either "tc filter add dev X" or "tc filter add block Y".

We did consider it but concluded it is a lot of work to get it done on mirred - just take a look at mirred and you'll see what i mean;-> Based on that review we came to the conclusion that at some point it would be safer to separate mirred's mirror from redirect; there are too many checks to avoid one or the other based on whether you are coming from egress vs ingress etc. This one is simple, it is just a broadcast.

Quoted 7 lines
Quoted 2 lines

Perhaps it is a nice opportunity to do such mirred cleanup, prepare the code and implement block send afterwards?

I was worried about breaking some existing use cases - the code has got too clever.
But probably it is time to show it some love, one of us will invest time into it.

Awesome.

Quoted 9 lines
Quoted 4 lines

If I omit the code for now, from user perspective, this functionality belongs into mirred, don't you think? Just replace "dev" by "block" and you got what you need.

If we can adequately cleanup mirred, then we can put it there but certainly now we are adding more buttons to click on mirred. It may make sense to refactor the mirred code then reuse the refactored code in a new action.

I don't understand why you need any new action. mirred redirect to block instead of dev is exactly what you need. Isn't it?

Quoted 83 lines

cheers,
jamal

Quoted 79 lines
Quoted 79 lines
Quoted 12 lines

Regarding the filtering, that could be a simple flag config of mirred action:

$ tc filter add block 22 protocol ip pref 25 \
  flower dst_ip 192.168.0.0/16 action mirred egress redirect block 22
  srcfilter

Or something like that.

See my comment above.

cheers,
jamal

Quoted 62 lines

Makes sense?

Quoted 58 lines

When a packet(matching dst IP 192.168.0.0/16) arrives on the ingress of any of ens7, ens8 or ens9 it will be copied to all ports other than itself. For example, if it arrives on ens8 then a copy of the packet will be "blockcasted";-> to both ens7 and ens9 (unmodified), but not to ens8.

Patch 1 introduces the required infra. Patch 2 exposes the tc block to the tc datapath and patch 3 implements datapath usage via a new tc action "blockcast".

__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

- 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)

Victor Nogueira (3):
net/sched: Introduce tc block netdev tracking infra net/sched: cls_api: Expose tc block to the datapath net/sched: act_blockcast: Introduce blockcast tc action

include/net/sch_generic.h    |   8 +
include/net/tc_wrapper.h     |   5 +
include/uapi/linux/pkt_cls.h |   1 +
net/sched/Kconfig            |  13 ++
net/sched/Makefile           |   1 +
net/sched/act_blockcast.c    | 297 +++++++++++++++++++++++++++++++++++
net/sched/cls_api.c          |  12 +-
net/sched/sch_api.c          |  58 +++++++
net/sched/sch_generic.c      |  34 +++-
9 files changed, 426 insertions(+), 3 deletions(-)

create mode 100644 net/sched/act_blockcast.c

--
2.25.1