Skip to contentSkip to conversation

net: sched: introduce chain templates support with offloading to mlxsw

PATCH Superseded Jiri Pirko 6 participants 29 messages Jun 28, 2018 – Jul 2, 2018

Subsystems (9)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

v2 cover net: sched: introduce chain templates support with offloading to mlxsw

From: Jiri Pirko <[email protected]>

For the TC clsact offload these days, some of HW drivers need to hold a magic ball. The reason is, with the first inserted rule inside HW they need to guess what fields will be used for the matching. If later on this guess proves to be wrong and user adds a filter with a different field to match, there's a problem. Mlxsw resolves it now with couple of patterns. Those try to cover as many match fields as possible. This aproach is far from optimal, both performance-wise and scale-wise. Also, there is a combination of filters that in certain order won't succeed.

Most of the time, when user inserts filters in chain, he knows right away how the filters are going to look like - what type and option will they have. For example, he knows that he will only insert filters of type flower matching destination IP address. He can specify a template that would cover all the filters in the chain.

This patchset is providing the possibility to user to provide such template to kernel and propagate it all the way down to device drivers.

See the examples below.

Create dummy device with clsact first:

# ip link add type dummy
# tc qdisc add dev dummy0 clsact

There is no template assigned by default:

# tc chaintemplate show dev dummy0 ingress

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22 
  eth_type ipv4
  dst_ip 0.0.0.0/16

Add a filter that fits the template:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:bb:cc:dd:ee:ff/00:00:00:00:00:0F action drop

Addition of filters that does not fit the template would fail:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:11:22:33:44:55/00:00:00:FF:00:00 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Additions of filters to chain 22:

# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/8 action drop
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/24 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Removal of a template from non-empty chain would fail:

# tc chaintemplate del dev dummy0 ingress
Error: The chain is not empty, unable to delete template.
We have an error talking to the kernel, -1

Once the chain is flushed, the template could be removed:

# tc filter del dev dummy0 ingress
# tc chaintemplate del dev dummy0 ingress

---
v1->v2:
- patch 5:
- rebase on top of the reoffload pathset
- patch 6:
- remove leftover extack arg in fl_hw_create_tmplt()
- rebase on top of the reoffload pathset
- patch 9:
- adjust to the userspace cmdline changes

Jiri Pirko (9):
net: sched: push ops lookup bits into tcf_proto_lookup_ops()
net: sched: introduce chain templates
net: sched: cls_flower: move key/mask dumping into a separate function
net: sched: cls_flower: change fl_init_dissector to accept mask and
dissector
net: sched: cls_flower: implement chain templates
net: sched: cls_flower: propagate chain teplate creation and
destruction to drivers
mlxsw: spectrum: Implement chain template hinting
selftests: forwarding: move shblock tc support check to a separate
helper
selftests: forwarding: add tests for TC chain templates

 drivers/net/ethernet/mellanox/mlxsw/spectrum.c     |   5 +
 drivers/net/ethernet/mellanox/mlxsw/spectrum.h     |  12 +-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c |  12 +-
 .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c    |  25 +-
 .../net/ethernet/mellanox/mlxsw/spectrum_flower.c  |  44 ++-
 include/net/pkt_cls.h                              |   2 +
 include/net/sch_generic.h                          |  14 +-
 include/uapi/linux/rtnetlink.h                     |   7 +
 net/sched/cls_api.c                                | 424 +++++++++++++++++++--
 net/sched/cls_basic.c                              |   2 +-
 net/sched/cls_bpf.c                                |   3 +-
 net/sched/cls_cgroup.c                             |   2 +-
 net/sched/cls_flow.c                               |   3 +-
 net/sched/cls_flower.c                             | 250 +++++++++---
 net/sched/cls_fw.c                                 |   3 +-
 net/sched/cls_matchall.c                           |   3 +-
 net/sched/cls_route.c                              |   2 +-
 net/sched/cls_rsvp.h                               |   3 +-
 net/sched/cls_tcindex.c                            |   2 +-
 net/sched/cls_u32.c                                |   2 +-
 security/selinux/nlmsgtab.c                        |   2 +-
 tools/testing/selftests/net/forwarding/lib.sh      |  12 +
 .../selftests/net/forwarding/tc_chaintemplates.sh  | 160 ++++++++
 .../selftests/net/forwarding/tc_shblocks.sh        |   2 +
 24 files changed, 900 insertions(+), 96 deletions(-)
 create mode 100755 tools/testing/selftests/net/forwarding/tc_chaintemplates.sh
Signature · 1 line
2.14.4
author maintainer
#1 lore raw

PATCH v2 1/9 net: sched: push ops lookup bits into tcf_proto_lookup_ops()

From: Jiri Pirko <[email protected]>

Push all bits that take care of ops lookup, including module loading outside tcf_proto_create() function, into tcf_proto_lookup_ops()

---
 net/sched/cls_api.c | 53 +++++++++++++++++++++++++++++++----------------------
 1 file changed, 31 insertions(+), 22 deletions(-)
net/sched/cls_api.c +31 -22
index bbf8dda96b0e..b74909fa68a3 100644
@@ -39,7 +39,7 @@ static DEFINE_RWLOCK(cls_mod_lock);
 
 /* Find classifier type by string name */
 
-static const struct tcf_proto_ops *tcf_proto_lookup_ops(const char *kind)
+static const struct tcf_proto_ops *__tcf_proto_lookup_ops(const char *kind)
 {
 	const struct tcf_proto_ops *t, *res = NULL;
 
@@ -57,6 +57,33 @@ static const struct tcf_proto_ops *tcf_proto_lookup_ops(const char *kind)
 	return res;
 }
 
+static const struct tcf_proto_ops *
+tcf_proto_lookup_ops(const char *kind, struct netlink_ext_ack *extack)
+{
+	const struct tcf_proto_ops *ops;
+
+	ops = __tcf_proto_lookup_ops(kind);
+	if (ops)
+		return ops;
+#ifdef CONFIG_MODULES
+	rtnl_unlock();
+	request_module("cls_%s", kind);
+	rtnl_lock();
+	ops = __tcf_proto_lookup_ops(kind);
+	/* We dropped the RTNL semaphore in order to perform
+	 * the module load. So, even if we succeeded in loading
+	 * the module we have to replay the request. We indicate
+	 * this using -EAGAIN.
+	 */
+	if (ops) {
+		module_put(ops->owner);
+		return ERR_PTR(-EAGAIN);
+	}
+#endif
+	NL_SET_ERR_MSG(extack, "TC classifier not found");
+	return ERR_PTR(-ENOENT);
+}
+
 /* Register(unregister) new classifier type */
 
 int register_tcf_proto_ops(struct tcf_proto_ops *ops)
@@ -133,27 +160,9 @@ static struct tcf_proto *tcf_proto_create(const char *kind, u32 protocol,
 	if (!tp)
 		return ERR_PTR(-ENOBUFS);
 
-	err = -ENOENT;
-	tp->ops = tcf_proto_lookup_ops(kind);
-	if (!tp->ops) {
-#ifdef CONFIG_MODULES
-		rtnl_unlock();
-		request_module("cls_%s", kind);
-		rtnl_lock();
-		tp->ops = tcf_proto_lookup_ops(kind);
-		/* We dropped the RTNL semaphore in order to perform
-		 * the module load. So, even if we succeeded in loading
-		 * the module we have to replay the request. We indicate
-		 * this using -EAGAIN.
-		 */
-		if (tp->ops) {
-			module_put(tp->ops->owner);
-			err = -EAGAIN;
-		} else {
-			NL_SET_ERR_MSG(extack, "TC classifier not found");
-			err = -ENOENT;
-		}
-#endif
+	tp->ops = tcf_proto_lookup_ops(kind, extack);
+	if (IS_ERR(tp->ops)) {
+		err = PTR_ERR(tp->ops);
 		goto errout;
 	}
 	tp->classify = tp->ops->classify;
Signature · 1 line
2.14.4
author maintainer
#2 lore raw

PATCH v2 2/9 net: sched: introduce chain templates

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Introduce a group of new tc-rtnl commands to allow user to set per-chain template. Templates lock down individual chains for particular classifier type/options combinations. The classifier needs to support templates, otherwise kernel would reply with error.

For example, to lock chain 22 to allow only filters of type flower with destination mac address, user needs to do:
chain 22 flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF

In case the chain already contains some filters it is not possible to add or remove template. That is permitted only for empty chains.

Alongside with add/del commands, introduce also get/dump and notifications.

---
 include/net/sch_generic.h      |  14 +-
 include/uapi/linux/rtnetlink.h |   7 +
 net/sched/cls_api.c            | 371 ++++++++++++++++++++++++++++++++++++++++-
 net/sched/cls_basic.c          |   2 +-
 net/sched/cls_bpf.c            |   3 +-
 net/sched/cls_cgroup.c         |   2 +-
 net/sched/cls_flow.c           |   3 +-
 net/sched/cls_flower.c         |   3 +-
 net/sched/cls_fw.c             |   3 +-
 net/sched/cls_matchall.c       |   3 +-
 net/sched/cls_route.c          |   2 +-
 net/sched/cls_rsvp.h           |   3 +-
 net/sched/cls_tcindex.c        |   2 +-
 net/sched/cls_u32.c            |   2 +-
 security/selinux/nlmsgtab.c    |   2 +-
 15 files changed, 405 insertions(+), 17 deletions(-)
include/net/sch_generic.h +13 -1
index 7432100027b7..e826ffa166aa 100644
@@ -238,6 +238,8 @@ struct tcf_result {
 	};
 };
 
+struct tcf_chain;
+
 struct tcf_proto_ops {
 	struct list_head	head;
 	char			kind[IFNAMSIZ];
@@ -253,7 +255,7 @@ struct tcf_proto_ops {
 	int			(*change)(struct net *net, struct sk_buff *,
 					struct tcf_proto*, unsigned long,
 					u32 handle, struct nlattr **,
-					void **, bool,
+					void **, bool, void *tmplt_priv,
 					struct netlink_ext_ack *);
 	int			(*delete)(struct tcf_proto *tp, void *arg,
 					  bool *last,
@@ -263,10 +265,18 @@ struct tcf_proto_ops {
 					     tc_setup_cb_t *cb, void *cb_priv,
 					     struct netlink_ext_ack *extack);
 	void			(*bind_class)(void *, u32, unsigned long);
+	void *			(*tmplt_create)(struct net *net,
+						struct tcf_chain *chain,
+						struct nlattr **tca,
+						struct netlink_ext_ack *extack);
+	void			(*tmplt_destroy)(void *tmplt_priv);
 
 	/* rtnetlink specific */
 	int			(*dump)(struct net*, struct tcf_proto*, void *,
 					struct sk_buff *skb, struct tcmsg*);
+	int			(*tmplt_dump)(struct sk_buff *skb,
+					      struct net *net,
+					      void *tmplt_priv);
 
 	struct module		*owner;
 };
@@ -305,6 +315,8 @@ struct tcf_chain {
 	struct tcf_block *block;
 	u32 index; /* chain index */
 	unsigned int refcnt;
+	const struct tcf_proto_ops *tmplt_ops;
+	void *tmplt_priv;
 };
 
 struct tcf_block {
include/uapi/linux/rtnetlink.h +7 -0
index 7d8502313c99..45fd8cc1fdb2 100644
@@ -150,6 +150,13 @@ enum {
 	RTM_NEWCACHEREPORT = 96,
 #define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
 
+	RTM_NEWCHAINTMPLT = 100,
+#define RTM_NEWCHAINTMPLT RTM_NEWCHAINTMPLT
+	RTM_DELCHAINTMPLT,
+#define RTM_DELCHAINTMPLT RTM_DELCHAINTMPLT
+	RTM_GETCHAINTMPLT,
+#define RTM_GETCHAINTMPLT RTM_GETCHAINTMPLT
+
 	__RTM_MAX,
 #define RTM_MAX		(((__RTM_MAX + 3) & ~3) - 1)
 };
net/sched/cls_api.c +367 -4

415 lines not on this page · raw message

net/sched/cls_basic.c +1 -1
index 95367f37098d..a690acac7e6e 100644
@@ -168,7 +168,7 @@ static int basic_set_parms(struct net *net, struct tcf_proto *tp,
 static int basic_change(struct net *net, struct sk_buff *in_skb,
 			struct tcf_proto *tp, unsigned long base, u32 handle,
 			struct nlattr **tca, void **arg, bool ovr,
-			struct netlink_ext_ack *extack)
+			void *tmplt_priv, struct netlink_ext_ack *extack)
 {
 	int err;
 	struct basic_head *head = rtnl_dereference(tp->root);
net/sched/cls_bpf.c +2 -1
index 66e0ac9811f9..d46af854f0c8 100644
@@ -457,7 +457,8 @@ static int cls_bpf_set_parms(struct net *net, struct tcf_proto *tp,
 static int cls_bpf_change(struct net *net, struct sk_buff *in_skb,
 			  struct tcf_proto *tp, unsigned long base,
 			  u32 handle, struct nlattr **tca,
-			  void **arg, bool ovr, struct netlink_ext_ack *extack)
+			  void **arg, bool ovr, void *tmplt_priv,
+			  struct netlink_ext_ack *extack)
 {
 	struct cls_bpf_head *head = rtnl_dereference(tp->root);
 	struct cls_bpf_prog *oldprog = *arg;
net/sched/cls_cgroup.c +1 -1
index 3bc01bdde165..ca5d0315432c 100644
@@ -78,7 +78,7 @@ static void cls_cgroup_destroy_work(struct work_struct *work)
 static int cls_cgroup_change(struct net *net, struct sk_buff *in_skb,
 			     struct tcf_proto *tp, unsigned long base,
 			     u32 handle, struct nlattr **tca,
-			     void **arg, bool ovr,
+			     void **arg, bool ovr, void *tmplt_priv,
 			     struct netlink_ext_ack *extack)
 {
 	struct nlattr *tb[TCA_CGROUP_MAX + 1];
net/sched/cls_flow.c +2 -1
index 2bb043cd436b..2a21e26fcee0 100644
@@ -391,7 +391,8 @@ static void flow_destroy_filter_work(struct work_struct *work)
 static int flow_change(struct net *net, struct sk_buff *in_skb,
 		       struct tcf_proto *tp, unsigned long base,
 		       u32 handle, struct nlattr **tca,
-		       void **arg, bool ovr, struct netlink_ext_ack *extack)
+		       void **arg, bool ovr, void *tmplt_priv,
+		       struct netlink_ext_ack *extack)
 {
 	struct flow_head *head = rtnl_dereference(tp->root);
 	struct flow_filter *fold, *fnew;
net/sched/cls_flower.c +2 -1
index 352876bb901b..62efa7289ac4 100644
@@ -929,7 +929,8 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp,
 static int fl_change(struct net *net, struct sk_buff *in_skb,
 		     struct tcf_proto *tp, unsigned long base,
 		     u32 handle, struct nlattr **tca,
-		     void **arg, bool ovr, struct netlink_ext_ack *extack)
+		     void **arg, bool ovr, void *tmplt_priv,
+		     struct netlink_ext_ack *extack)
 {
 	struct cls_fl_head *head = rtnl_dereference(tp->root);
 	struct cls_fl_filter *fold = *arg;
net/sched/cls_fw.c +2 -1
index 29eeeaf3ea44..a1d40d48aa24 100644
@@ -250,7 +250,8 @@ static int fw_set_parms(struct net *net, struct tcf_proto *tp,
 static int fw_change(struct net *net, struct sk_buff *in_skb,
 		     struct tcf_proto *tp, unsigned long base,
 		     u32 handle, struct nlattr **tca, void **arg,
-		     bool ovr, struct netlink_ext_ack *extack)
+		     bool ovr, void *tmplt_priv,
+		     struct netlink_ext_ack *extack)
 {
 	struct fw_head *head = rtnl_dereference(tp->root);
 	struct fw_filter *f = *arg;
net/sched/cls_matchall.c +2 -1
index af16f36ed578..013cf0db5b22 100644
@@ -154,7 +154,8 @@ static int mall_set_parms(struct net *net, struct tcf_proto *tp,
 static int mall_change(struct net *net, struct sk_buff *in_skb,
 		       struct tcf_proto *tp, unsigned long base,
 		       u32 handle, struct nlattr **tca,
-		       void **arg, bool ovr, struct netlink_ext_ack *extack)
+		       void **arg, bool ovr, void *tmplt_priv,
+		       struct netlink_ext_ack *extack)
 {
 	struct cls_mall_head *head = rtnl_dereference(tp->root);
 	struct nlattr *tb[TCA_MATCHALL_MAX + 1];
net/sched/cls_route.c +1 -1
index 0404aa5fa7cb..321eb746fe01 100644
@@ -468,7 +468,7 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
 static int route4_change(struct net *net, struct sk_buff *in_skb,
 			 struct tcf_proto *tp, unsigned long base, u32 handle,
 			 struct nlattr **tca, void **arg, bool ovr,
-			 struct netlink_ext_ack *extack)
+			 void *tmplt_priv, struct netlink_ext_ack *extack)
 {
 	struct route4_head *head = rtnl_dereference(tp->root);
 	struct route4_filter __rcu **fp;
net/sched/cls_rsvp.h +2 -1
index e9ccf7daea7d..371618720ef2 100644
@@ -477,7 +477,8 @@ static int rsvp_change(struct net *net, struct sk_buff *in_skb,
 		       struct tcf_proto *tp, unsigned long base,
 		       u32 handle,
 		       struct nlattr **tca,
-		       void **arg, bool ovr, struct netlink_ext_ack *extack)
+		       void **arg, bool ovr, void *tmplt_priv,
+		       struct netlink_ext_ack *extack)
 {
 	struct rsvp_head *data = rtnl_dereference(tp->root);
 	struct rsvp_filter *f, *nfp;
net/sched/cls_tcindex.c +1 -1
index 32f4bbd82f35..d9fb5d56c60d 100644
@@ -500,7 +500,7 @@ tcindex_set_parms(struct net *net, struct tcf_proto *tp, unsigned long base,
 static int
 tcindex_change(struct net *net, struct sk_buff *in_skb,
 	       struct tcf_proto *tp, unsigned long base, u32 handle,
-	       struct nlattr **tca, void **arg, bool ovr,
+	       struct nlattr **tca, void **arg, bool ovr, void *tmplt_priv,
 	       struct netlink_ext_ack *extack)
 {
 	struct nlattr *opt = tca[TCA_OPTIONS];
net/sched/cls_u32.c +1 -1
index d5d2a6dc3921..6300514a5a7c 100644
@@ -905,7 +905,7 @@ static struct tc_u_knode *u32_init_knode(struct tcf_proto *tp,
 static int u32_change(struct net *net, struct sk_buff *in_skb,
 		      struct tcf_proto *tp, unsigned long base, u32 handle,
 		      struct nlattr **tca, void **arg, bool ovr,
-		      struct netlink_ext_ack *extack)
+		      void *tmplt_priv, struct netlink_ext_ack *extack)
 {
 	struct tc_u_common *tp_c = tp->data;
 	struct tc_u_hnode *ht;
security/selinux/nlmsgtab.c +1 -1
index 7b7433a1a34c..825777efc83e 100644
@@ -159,7 +159,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)
 	switch (sclass) {
 	case SECCLASS_NETLINK_ROUTE_SOCKET:
 		/* RTM_MAX always point to RTM_SETxxxx, ie RTM_NEWxxx + 3 */
-		BUILD_BUG_ON(RTM_MAX != (RTM_NEWCACHEREPORT + 3));
+		BUILD_BUG_ON(RTM_MAX != (RTM_NEWCHAINTMPLT + 3));
 		err = nlmsg_perm(nlmsg_type, perm, nlmsg_route_perms,
 				 sizeof(nlmsg_route_perms));
 		break;
Signature · 1 line
2.14.4
author maintainer
#3 lore raw

PATCH v2 3/9 net: sched: cls_flower: move key/mask dumping into a separate function

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Push key/mask dumping from fl_dump() into a separate function fl_dump_key(), that will be reused for template dumping.

---
 net/sched/cls_flower.c | 62 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 37 insertions(+), 25 deletions(-)
net/sched/cls_flower.c +37 -25
index 62efa7289ac4..0e8991e49860 100644
@@ -1260,29 +1260,9 @@ static int fl_dump_key_flags(struct sk_buff *skb, u32 flags_key, u32 flags_mask)
 	return nla_put(skb, TCA_FLOWER_KEY_FLAGS_MASK, 4, &_mask);
 }
 
-static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
-		   struct sk_buff *skb, struct tcmsg *t)
+static int fl_dump_key(struct sk_buff *skb, struct net *net,
+		       struct fl_flow_key *key, struct fl_flow_key *mask)
 {
-	struct cls_fl_filter *f = fh;
-	struct nlattr *nest;
-	struct fl_flow_key *key, *mask;
-
-	if (!f)
-		return skb->len;
-
-	t->tcm_handle = f->handle;
-
-	nest = nla_nest_start(skb, TCA_OPTIONS);
-	if (!nest)
-		goto nla_put_failure;
-
-	if (f->res.classid &&
-	    nla_put_u32(skb, TCA_FLOWER_CLASSID, f->res.classid))
-		goto nla_put_failure;
-
-	key = &f->key;
-	mask = &f->mask->key;
-
 	if (mask->indev_ifindex) {
 		struct net_device *dev;
 
@@ -1291,9 +1271,6 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
 			goto nla_put_failure;
 	}
 
-	if (!tc_skip_hw(f->flags))
-		fl_hw_update_stats(tp, f);
-
 	if (fl_dump_key_val(skb, key->eth.dst, TCA_FLOWER_KEY_ETH_DST,
 			    mask->eth.dst, TCA_FLOWER_KEY_ETH_DST_MASK,
 			    sizeof(key->eth.dst)) ||
@@ -1447,6 +1424,41 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
 	if (fl_dump_key_flags(skb, key->control.flags, mask->control.flags))
 		goto nla_put_failure;
 
+	return 0;
+
+nla_put_failure:
+	return -EMSGSIZE;
+}
+
+static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
+		   struct sk_buff *skb, struct tcmsg *t)
+{
+	struct cls_fl_filter *f = fh;
+	struct nlattr *nest;
+	struct fl_flow_key *key, *mask;
+
+	if (!f)
+		return skb->len;
+
+	t->tcm_handle = f->handle;
+
+	nest = nla_nest_start(skb, TCA_OPTIONS);
+	if (!nest)
+		goto nla_put_failure;
+
+	if (f->res.classid &&
+	    nla_put_u32(skb, TCA_FLOWER_CLASSID, f->res.classid))
+		goto nla_put_failure;
+
+	key = &f->key;
+	mask = &f->mask->key;
+
+	if (fl_dump_key(skb, net, key, mask))
+		goto nla_put_failure;
+
+	if (!tc_skip_hw(f->flags))
+		fl_hw_update_stats(tp, f);
+
 	if (f->flags && nla_put_u32(skb, TCA_FLOWER_FLAGS, f->flags))
 		goto nla_put_failure;
 
Signature · 1 line
2.14.4
author maintainer
#4 lore raw

PATCH v2 4/9 net: sched: cls_flower: change fl_init_dissector to accept mask and dissector

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

This function is going to be used for templates as well, so we need to pass the pointer separately.

---
 net/sched/cls_flower.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)
net/sched/cls_flower.c +20 -19
index 0e8991e49860..0f753260594d 100644
@@ -795,47 +795,48 @@ static int fl_init_mask_hashtable(struct fl_flow_mask *mask)
 			FL_KEY_SET(keys, cnt, id, member);			\
 	} while(0);
 
-static void fl_init_dissector(struct fl_flow_mask *mask)
+static void fl_init_dissector(struct flow_dissector *dissector,
+			      struct fl_flow_key *mask)
 {
 	struct flow_dissector_key keys[FLOW_DISSECTOR_KEY_MAX];
 	size_t cnt = 0;
 
 	FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_CONTROL, control);
 	FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_BASIC, basic);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ETH_ADDRS, eth);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_IPV4_ADDRS, ipv4);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_IPV6_ADDRS, ipv6);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_PORTS, tp);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_IP, ip);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_TCP, tcp);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ICMP, icmp);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ARP, arp);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_MPLS, mpls);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_VLAN, vlan);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ENC_KEYID, enc_key_id);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS, enc_ipv4);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS, enc_ipv6);
-	if (FL_KEY_IS_MASKED(&mask->key, enc_ipv4) ||
-	    FL_KEY_IS_MASKED(&mask->key, enc_ipv6))
+	if (FL_KEY_IS_MASKED(mask, enc_ipv4) ||
+	    FL_KEY_IS_MASKED(mask, enc_ipv6))
 		FL_KEY_SET(keys, cnt, FLOW_DISSECTOR_KEY_ENC_CONTROL,
 			   enc_control);
-	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+	FL_KEY_SET_IF_MASKED(mask, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ENC_PORTS, enc_tp);
 
-	skb_flow_dissector_init(&mask->dissector, keys, cnt);
+	skb_flow_dissector_init(dissector, keys, cnt);
 }
 
 static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,
@@ -854,7 +855,7 @@ static struct fl_flow_mask *fl_create_new_mask(struct cls_fl_head *head,
 	if (err)
 		goto errout_free;
 
-	fl_init_dissector(newmask);
+	fl_init_dissector(&newmask->dissector, &newmask->key);
 
 	INIT_LIST_HEAD_RCU(&newmask->filters);
 
Signature · 1 line
2.14.4
author maintainer
#5 lore raw

PATCH v2 5/9 net: sched: cls_flower: implement chain templates

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Use the previously introduced template extension and implement callback to create, destroy and dump chain template. The existing parsing and dumping functions are re-used. Also, check if newly added filters fit the template if it is set.

---
v1->v2:
- rebase on top of the reoffload pathset

---
 net/sched/cls_flower.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 106 insertions(+), 1 deletion(-)
net/sched/cls_flower.c +106 -1
index 0f753260594d..8bcd40756a2d 100644
@@ -70,6 +70,13 @@ struct fl_flow_mask {
 	struct list_head list;
 };
 
+struct fl_flow_tmplt {
+	struct fl_flow_key dummy_key;
+	struct fl_flow_key mask;
+	struct flow_dissector dissector;
+	struct tcf_chain *chain;
+};
+
 struct cls_fl_head {
 	struct rhashtable ht;
 	struct list_head masks;
@@ -145,6 +152,23 @@ static void fl_set_masked_key(struct fl_flow_key *mkey, struct fl_flow_key *key,
 		*lmkey++ = *lkey++ & *lmask++;
 }
 
+static bool fl_mask_fits_tmplt(struct fl_flow_tmplt *tmplt,
+			       struct fl_flow_mask *mask)
+{
+	const long *lmask = fl_key_get_start(&mask->key, mask);
+	const long *ltmplt;
+	int i;
+
+	if (!tmplt)
+		return true;
+	ltmplt = fl_key_get_start(&tmplt->mask, mask);
+	for (i = 0; i < fl_mask_range(mask); i += sizeof(long)) {
+		if (~*ltmplt++ & *lmask++)
+			return false;
+	}
+	return true;
+}
+
 static void fl_clear_masked_range(struct fl_flow_key *key,
 				  struct fl_flow_mask *mask)
 {
@@ -904,6 +928,7 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp,
 			struct cls_fl_filter *f, struct fl_flow_mask *mask,
 			unsigned long base, struct nlattr **tb,
 			struct nlattr *est, bool ovr,
+			struct fl_flow_tmplt *tmplt,
 			struct netlink_ext_ack *extack)
 {
 	int err;
@@ -924,6 +949,11 @@ static int fl_set_parms(struct net *net, struct tcf_proto *tp,
 	fl_mask_update_range(mask);
 	fl_set_masked_key(&f->mkey, &f->key, mask);
 
+	if (!fl_mask_fits_tmplt(tmplt, mask)) {
+		NL_SET_ERR_MSG_MOD(extack, "Mask does not fit the template");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
@@ -934,6 +964,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
 		     struct netlink_ext_ack *extack)
 {
 	struct cls_fl_head *head = rtnl_dereference(tp->root);
+	struct fl_flow_tmplt *tmplt = tmplt_priv;
 	struct cls_fl_filter *fold = *arg;
 	struct cls_fl_filter *fnew;
 	struct nlattr **tb;
@@ -990,7 +1021,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb,
 	}
 
 	err = fl_set_parms(net, tp, fnew, &mask, base, tb, tca[TCA_RATE], ovr,
-			   extack);
+			   tmplt, extack);
 	if (err)
 		goto errout_idr;
 
@@ -1132,6 +1163,52 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
 	return 0;
 }
 
+static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,
+			     struct nlattr **tca,
+			     struct netlink_ext_ack *extack)
+{
+	struct fl_flow_tmplt *tmplt;
+	struct nlattr **tb;
+	int err;
+
+	if (!tca[TCA_OPTIONS])
+		return ERR_PTR(-EINVAL);
+
+	tb = kcalloc(TCA_FLOWER_MAX + 1, sizeof(struct nlattr *), GFP_KERNEL);
+	if (!tb)
+		return ERR_PTR(-ENOBUFS);
+	err = nla_parse_nested(tb, TCA_FLOWER_MAX, tca[TCA_OPTIONS],
+			       fl_policy, NULL);
+	if (err)
+		goto errout_tb;
+
+	tmplt = kzalloc(sizeof(*tmplt), GFP_KERNEL);
+	if (!tmplt)
+		goto errout_tb;
+	tmplt->chain = chain;
+	err = fl_set_key(net, tb, &tmplt->dummy_key, &tmplt->mask, extack);
+	if (err)
+		goto errout_tmplt;
+	kfree(tb);
+
+	fl_init_dissector(&tmplt->dissector, &tmplt->mask);
+
+	return tmplt;
+
+errout_tmplt:
+	kfree(tmplt);
+errout_tb:
+	kfree(tb);
+	return ERR_PTR(err);
+}
+
+static void fl_tmplt_destroy(void *tmplt_priv)
+{
+	struct fl_flow_tmplt *tmplt = tmplt_priv;
+
+	kfree(tmplt);
+}
+
 static int fl_dump_key_val(struct sk_buff *skb,
 			   void *val, int val_type,
 			   void *mask, int mask_type, int len)
@@ -1478,6 +1555,31 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, void *fh,
 	return -1;
 }
 
+static int fl_tmplt_dump(struct sk_buff *skb, struct net *net, void *tmplt_priv)
+{
+	struct fl_flow_tmplt *tmplt = tmplt_priv;
+	struct fl_flow_key *key, *mask;
+	struct nlattr *nest;
+
+	nest = nla_nest_start(skb, TCA_OPTIONS);
+	if (!nest)
+		goto nla_put_failure;
+
+	key = &tmplt->dummy_key;
+	mask = &tmplt->mask;
+
+	if (fl_dump_key(skb, net, key, mask))
+		goto nla_put_failure;
+
+	nla_nest_end(skb, nest);
+
+	return skb->len;
+
+nla_put_failure:
+	nla_nest_cancel(skb, nest);
+	return -EMSGSIZE;
+}
+
 static void fl_bind_class(void *fh, u32 classid, unsigned long cl)
 {
 	struct cls_fl_filter *f = fh;
@@ -1498,6 +1600,9 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
 	.reoffload	= fl_reoffload,
 	.dump		= fl_dump,
 	.bind_class	= fl_bind_class,
+	.tmplt_create	= fl_tmplt_create,
+	.tmplt_destroy	= fl_tmplt_destroy,
+	.tmplt_dump	= fl_tmplt_dump,
 	.owner		= THIS_MODULE,
 };
 
Signature · 1 line
2.14.4
author maintainer
#6 lore raw

PATCH v2 6/9 net: sched: cls_flower: propagate chain teplate creation and destruction to drivers

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Introduce a couple of flower offload commands in order to propagate template creation/destruction events down to device drivers. Drivers may use this information to prepare HW in an optimal way for future filter insertions.

---
v1->v2:
- remove leftover extack arg in fl_hw_create_tmplt()
- rebase on top of the reoffload pathset

---
 include/net/pkt_cls.h  |  2 ++
 net/sched/cls_flower.c | 39 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
include/net/pkt_cls.h +2 -0
index 4070b8eb6d14..ce671ca5d331 100644
@@ -720,6 +720,8 @@ enum tc_fl_command {
 	TC_CLSFLOWER_REPLACE,
 	TC_CLSFLOWER_DESTROY,
 	TC_CLSFLOWER_STATS,
+	TC_CLSFLOWER_TMPLT_CREATE,
+	TC_CLSFLOWER_TMPLT_DESTROY,
 };
 
 struct tc_cls_flower_offload {
net/sched/cls_flower.c +39 -0
index 8bcd40756a2d..f827356bb2cb 100644
@@ -1163,6 +1163,42 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, tc_setup_cb_t *cb,
 	return 0;
 }
 
+static void fl_hw_create_tmplt(struct tcf_chain *chain,
+			       struct fl_flow_tmplt *tmplt)
+{
+	struct tc_cls_flower_offload cls_flower = {};
+	struct tcf_block *block = chain->block;
+	struct tcf_exts dummy_exts = { 0, };
+
+	cls_flower.common.chain_index = chain->index;
+	cls_flower.command = TC_CLSFLOWER_TMPLT_CREATE;
+	cls_flower.cookie = (unsigned long) tmplt;
+	cls_flower.dissector = &tmplt->dissector;
+	cls_flower.mask = &tmplt->mask;
+	cls_flower.key = &tmplt->dummy_key;
+	cls_flower.exts = &dummy_exts;
+
+	/* We don't care if driver (any of them) fails to handle this
+	 * call. It serves just as a hint for it.
+	 */
+	tc_setup_cb_call(block, NULL, TC_SETUP_CLSFLOWER,
+			 &cls_flower, false);
+}
+
+static void fl_hw_destroy_tmplt(struct tcf_chain *chain,
+				struct fl_flow_tmplt *tmplt)
+{
+	struct tc_cls_flower_offload cls_flower = {};
+	struct tcf_block *block = chain->block;
+
+	cls_flower.common.chain_index = chain->index;
+	cls_flower.command = TC_CLSFLOWER_TMPLT_DESTROY;
+	cls_flower.cookie = (unsigned long) tmplt;
+
+	tc_setup_cb_call(block, NULL, TC_SETUP_CLSFLOWER,
+			 &cls_flower, false);
+}
+
 static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,
 			     struct nlattr **tca,
 			     struct netlink_ext_ack *extack)
@@ -1193,6 +1229,8 @@ static void *fl_tmplt_create(struct net *net, struct tcf_chain *chain,
 
 	fl_init_dissector(&tmplt->dissector, &tmplt->mask);
 
+	fl_hw_create_tmplt(chain, tmplt);
+
 	return tmplt;
 
 errout_tmplt:
@@ -1206,6 +1244,7 @@ static void fl_tmplt_destroy(void *tmplt_priv)
 {
 	struct fl_flow_tmplt *tmplt = tmplt_priv;
 
+	fl_hw_destroy_tmplt(tmplt->chain, tmplt);
 	kfree(tmplt);
 }
 
Signature · 1 line
2.14.4
author maintainer
#7 lore raw

PATCH v2 7/9 mlxsw: spectrum: Implement chain template hinting

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Since cld_flower provides information about the filter template for specific chain, use this information in order to prepare a region. Use the template to find out what elements are going to be used and pass that down to mlxsw_sp_acl_tcam_group_add(). Later on, when the first filter is inserted, the mlxsw_sp_acl_tcam_group_use_patterns() function would use this element usage information instead of looking up a pattern.

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum.c     |  5 +++
 drivers/net/ethernet/mellanox/mlxsw/spectrum.h     | 12 +++++-
 drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c | 12 ++++--
 .../ethernet/mellanox/mlxsw/spectrum_acl_tcam.c    | 25 ++++++++++--
 .../net/ethernet/mellanox/mlxsw/spectrum_flower.c  | 44 ++++++++++++++++++++--
 5 files changed, 86 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +5 -0
index 52437363766a..155db238e65a 100644
@@ -1441,6 +1441,11 @@ mlxsw_sp_setup_tc_cls_flower(struct mlxsw_sp_acl_block *acl_block,
 		return 0;
 	case TC_CLSFLOWER_STATS:
 		return mlxsw_sp_flower_stats(mlxsw_sp, acl_block, f);
+	case TC_CLSFLOWER_TMPLT_CREATE:
+		return mlxsw_sp_flower_tmplt_create(mlxsw_sp, acl_block, f);
+	case TC_CLSFLOWER_TMPLT_DESTROY:
+		mlxsw_sp_flower_tmplt_destroy(mlxsw_sp, acl_block, f);
+		return 0;
 	default:
 		return -EOPNOTSUPP;
 	}
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +10 -2
index 4a519d8edec8..b0a8e611e730 100644
@@ -459,7 +459,8 @@ enum mlxsw_sp_acl_profile {
 struct mlxsw_sp_acl_profile_ops {
 	size_t ruleset_priv_size;
 	int (*ruleset_add)(struct mlxsw_sp *mlxsw_sp,
-			   void *priv, void *ruleset_priv);
+			   void *priv, void *ruleset_priv,
+			   struct mlxsw_afk_element_usage *tmplt_elusage);
 	void (*ruleset_del)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv);
 	int (*ruleset_bind)(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
 			    struct mlxsw_sp_port *mlxsw_sp_port,
@@ -514,7 +515,8 @@ mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
 struct mlxsw_sp_acl_ruleset *
 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
 			 struct mlxsw_sp_acl_block *block, u32 chain_index,
-			 enum mlxsw_sp_acl_profile profile);
+			 enum mlxsw_sp_acl_profile profile,
+			 struct mlxsw_afk_element_usage *tmplt_elusage);
 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
 			      struct mlxsw_sp_acl_ruleset *ruleset);
 u16 mlxsw_sp_acl_ruleset_group_id(struct mlxsw_sp_acl_ruleset *ruleset);
@@ -594,6 +596,12 @@ void mlxsw_sp_flower_destroy(struct mlxsw_sp *mlxsw_sp,
 int mlxsw_sp_flower_stats(struct mlxsw_sp *mlxsw_sp,
 			  struct mlxsw_sp_acl_block *block,
 			  struct tc_cls_flower_offload *f);
+int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
+				 struct mlxsw_sp_acl_block *block,
+				 struct tc_cls_flower_offload *f);
+void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
+				   struct mlxsw_sp_acl_block *block,
+				   struct tc_cls_flower_offload *f);
 
 /* spectrum_qdisc.c */
 int mlxsw_sp_tc_qdisc_init(struct mlxsw_sp_port *mlxsw_sp_port);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +8 -4
index 79b1fa27a9a4..ea42605c451d 100644
@@ -319,7 +319,8 @@ int mlxsw_sp_acl_block_unbind(struct mlxsw_sp *mlxsw_sp,
 static struct mlxsw_sp_acl_ruleset *
 mlxsw_sp_acl_ruleset_create(struct mlxsw_sp *mlxsw_sp,
 			    struct mlxsw_sp_acl_block *block, u32 chain_index,
-			    const struct mlxsw_sp_acl_profile_ops *ops)
+			    const struct mlxsw_sp_acl_profile_ops *ops,
+			    struct mlxsw_afk_element_usage *tmplt_elusage)
 {
 	struct mlxsw_sp_acl *acl = mlxsw_sp->acl;
 	struct mlxsw_sp_acl_ruleset *ruleset;
@@ -339,7 +340,8 @@ mlxsw_sp_acl_ruleset_create(struct mlxsw_sp *mlxsw_sp,
 	if (err)
 		goto err_rhashtable_init;
 
-	err = ops->ruleset_add(mlxsw_sp, acl->priv, ruleset->priv);
+	err = ops->ruleset_add(mlxsw_sp, acl->priv, ruleset->priv,
+			       tmplt_elusage);
 	if (err)
 		goto err_ops_ruleset_add;
 
@@ -421,7 +423,8 @@ mlxsw_sp_acl_ruleset_lookup(struct mlxsw_sp *mlxsw_sp,
 struct mlxsw_sp_acl_ruleset *
 mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
 			 struct mlxsw_sp_acl_block *block, u32 chain_index,
-			 enum mlxsw_sp_acl_profile profile)
+			 enum mlxsw_sp_acl_profile profile,
+			 struct mlxsw_afk_element_usage *tmplt_elusage)
 {
 	const struct mlxsw_sp_acl_profile_ops *ops;
 	struct mlxsw_sp_acl *acl = mlxsw_sp->acl;
@@ -436,7 +439,8 @@ mlxsw_sp_acl_ruleset_get(struct mlxsw_sp *mlxsw_sp,
 		mlxsw_sp_acl_ruleset_ref_inc(ruleset);
 		return ruleset;
 	}
-	return mlxsw_sp_acl_ruleset_create(mlxsw_sp, block, chain_index, ops);
+	return mlxsw_sp_acl_ruleset_create(mlxsw_sp, block, chain_index, ops,
+					   tmplt_elusage);
 }
 
 void mlxsw_sp_acl_ruleset_put(struct mlxsw_sp *mlxsw_sp,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +22 -3
index ad1b548e3cac..d6e4e00dfd3d 100644
@@ -157,6 +157,8 @@ struct mlxsw_sp_acl_tcam_group {
 	struct mlxsw_sp_acl_tcam_group_ops *ops;
 	const struct mlxsw_sp_acl_tcam_pattern *patterns;
 	unsigned int patterns_count;
+	bool tmplt_elusage_set;
+	struct mlxsw_afk_element_usage tmplt_elusage;
 };
 
 struct mlxsw_sp_acl_tcam_region {
@@ -216,13 +218,19 @@ mlxsw_sp_acl_tcam_group_add(struct mlxsw_sp *mlxsw_sp,
 			    struct mlxsw_sp_acl_tcam *tcam,
 			    struct mlxsw_sp_acl_tcam_group *group,
 			    const struct mlxsw_sp_acl_tcam_pattern *patterns,
-			    unsigned int patterns_count)
+			    unsigned int patterns_count,
+			    struct mlxsw_afk_element_usage *tmplt_elusage)
 {
 	int err;
 
 	group->tcam = tcam;
 	group->patterns = patterns;
 	group->patterns_count = patterns_count;
+	if (tmplt_elusage) {
+		group->tmplt_elusage_set = true;
+		memcpy(&group->tmplt_elusage, tmplt_elusage,
+		       sizeof(group->tmplt_elusage));
+	}
 	INIT_LIST_HEAD(&group->region_list);
 	err = mlxsw_sp_acl_tcam_group_id_get(tcam, &group->id);
 	if (err)
@@ -431,6 +439,15 @@ mlxsw_sp_acl_tcam_group_use_patterns(struct mlxsw_sp_acl_tcam_group *group,
 	const struct mlxsw_sp_acl_tcam_pattern *pattern;
 	int i;
 
+	/* In case the template is set, we don't have to look up the pattern
+	 * and just use the template.
+	 */
+	if (group->tmplt_elusage_set) {
+		memcpy(out, &group->tmplt_elusage, sizeof(*out));
+		WARN_ON(!mlxsw_afk_element_usage_subset(elusage, out));
+		return;
+	}
+
 	for (i = 0; i < group->patterns_count; i++) {
 		pattern = &group->patterns[i];
 		mlxsw_afk_element_usage_fill(out, pattern->elements,
@@ -1019,14 +1036,16 @@ struct mlxsw_sp_acl_tcam_flower_rule {
 
 static int
 mlxsw_sp_acl_tcam_flower_ruleset_add(struct mlxsw_sp *mlxsw_sp,
-				     void *priv, void *ruleset_priv)
+				     void *priv, void *ruleset_priv,
+				     struct mlxsw_afk_element_usage *tmplt_elusage)
 {
 	struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
 	struct mlxsw_sp_acl_tcam *tcam = priv;
 
 	return mlxsw_sp_acl_tcam_group_add(mlxsw_sp, tcam, &ruleset->group,
 					   mlxsw_sp_acl_tcam_patterns,
-					   MLXSW_SP_ACL_TCAM_PATTERNS_COUNT);
+					   MLXSW_SP_ACL_TCAM_PATTERNS_COUNT,
+					   tmplt_elusage);
 }
 
 static void
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +41 -3

65 lines not on this page · raw message

Signature · 1 line
2.14.4
author maintainer
#8 lore raw

PATCH v2 8/9 selftests: forwarding: move shblock tc support check to a separate helper

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

The shared block support is only needed for tc_shblock.sh. No need to require that for other test.

---
 tools/testing/selftests/net/forwarding/lib.sh         | 3 +++
 tools/testing/selftests/net/forwarding/tc_shblocks.sh | 2 ++
 2 files changed, 5 insertions(+)
tools/testing/selftests/net/forwarding/lib.sh +3 -0
index 1dfdf14894e2..df589ac1eac0 100644
@@ -28,7 +28,10 @@ check_tc_version()
 		echo "SKIP: iproute2 too old; tc is missing JSON support"
 		exit 1
 	fi
+}
 
+check_tc_shblock_support()
+{
 	tc filter help 2>&1 | grep block &> /dev/null
 	if [[ $? -ne 0 ]]; then
 		echo "SKIP: iproute2 too old; tc is missing shared block support"
tools/testing/selftests/net/forwarding/tc_shblocks.sh +2 -0
index b5b917203815..9826a446e2c0 100755
@@ -105,6 +105,8 @@ cleanup()
 	ip link set $swp2 address $swp2origmac
 }
 
+check_tc_shblock_support
+
 trap cleanup EXIT
 
 setup_prepare
Signature · 1 line
2.14.4
author maintainer
#9 lore raw

PATCH v2 9/9 selftests: forwarding: add tests for TC chain templates

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add basic sanity tests for TC chain templates.

---
v1->v2:
- adjust to the userspace cmdline changes

---
 tools/testing/selftests/net/forwarding/lib.sh      |   9 ++
 .../selftests/net/forwarding/tc_chaintemplates.sh  | 160 +++++++++++++++++++++
 2 files changed, 169 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/tc_chaintemplates.sh
tools/testing/selftests/net/forwarding/lib.sh +9 -0
index df589ac1eac0..20be128709b1 100644
@@ -39,6 +39,15 @@ check_tc_shblock_support()
 	fi
 }
 
+check_tc_chaintemplate_support()
+{
+	tc help 2>&1|grep chaintemplate &> /dev/null
+	if [[ $? -ne 0 ]]; then
+		echo "SKIP: iproute2 too old; tc is missing chain template support"
+		exit 1
+	fi
+}
+
 if [[ "$(id -u)" -ne 0 ]]; then
 	echo "SKIP: need root privileges"
 	exit 0
tools/testing/selftests/net/forwarding/tc_chaintemplates.sh new file +160 -0

160 lines not on this page · raw message

Signature · 1 line
2.14.4
author maintainer
#10 lore raw

PATCH v2 1/1 tc: introduce support for chain templates

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

---
v1->v2:
- moved the template handling
from "tc filter template" to "tc chaintemplate"

---
 include/uapi/linux/rtnetlink.h |   7 +++
 man/man8/tc.8                  |  26 ++++++++++
 tc/tc.c                        |   5 +-
 tc/tc_common.h                 |   1 +
 tc/tc_filter.c                 | 106 ++++++++++++++++++++++++++++++-----------
 tc/tc_monitor.c                |   5 +-
 6 files changed, 121 insertions(+), 29 deletions(-)
include/uapi/linux/rtnetlink.h +7 -0
index c3a7d8ecc7b9..dddb05e5cca8 100644
@@ -150,6 +150,13 @@ enum {
 	RTM_NEWCACHEREPORT = 96,
 #define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
 
+	RTM_NEWCHAINTMPLT = 100,
+#define RTM_NEWCHAINTMPLT RTM_NEWCHAINTMPLT
+	RTM_DELCHAINTMPLT,
+#define RTM_DELCHAINTMPLT RTM_DELCHAINTMPLT
+	RTM_GETCHAINTMPLT,
+#define RTM_GETCHAINTMPLT RTM_GETCHAINTMPLT
+
 	__RTM_MAX,
 #define RTM_MAX		(((__RTM_MAX + 3) & ~3) - 1)
 };
man/man8/tc.8 +26 -0
index 840880fbdba6..3eee1aceaae4 100644
@@ -58,6 +58,22 @@ tc \- show / manipulate traffic control settings
 .B flowid
 \fIflow-id\fR
 
+.B tc
+.RI "[ " OPTIONS " ]"
+.B chaintemplate [ add | delete | get ] dev
+\fIDEV\fR
+.B [ parent
+\fIqdisc-id\fR
+.B | root ]\fR filtertype
+[ filtertype specific parameters ]
+
+.B tc
+.RI "[ " OPTIONS " ]"
+.B chaintemplate [ add | delete | get ] block
+\fIBLOCK_INDEX\fR filtertype
+[ filtertype specific parameters ]
+
+
 .B tc
 .RI "[ " OPTIONS " ]"
 .RI "[ " FORMAT " ]"
@@ -80,6 +96,16 @@ tc \- show / manipulate traffic control settings
 .RI "[ " OPTIONS " ]"
 .B filter show block
 \fIBLOCK_INDEX\fR
+.P
+.B tc
+.RI "[ " OPTIONS " ]"
+.B chaintemplate show dev
+\fIDEV\fR
+.P
+.B tc
+.RI "[ " OPTIONS " ]"
+.B chaintemplate show block
+\fIBLOCK_INDEX\fR
 
 .P
 .B tc
tc/tc.c +4 -1
index 0d223281ba25..8a0592c45800 100644
@@ -197,7 +197,8 @@ static void usage(void)
 	fprintf(stderr,
 		"Usage: tc [ OPTIONS ] OBJECT { COMMAND | help }\n"
 		"       tc [-force] -batch filename\n"
-		"where  OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
+		"where  OBJECT := { qdisc | class | filter | chaintemplate |\n"
+		"                   action | monitor | exec }\n"
 		"       OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[aw] |\n"
 		"                    -o[neline] | -j[son] | -p[retty] | -c[olor]\n"
 		"                    -b[atch] [filename] | -n[etns] name |\n"
@@ -212,6 +213,8 @@ static int do_cmd(int argc, char **argv, void *buf, size_t buflen)
 		return do_class(argc-1, argv+1);
 	if (matches(*argv, "filter") == 0)
 		return do_filter(argc-1, argv+1, buf, buflen);
+	if (matches(*argv, "chaintemplate") == 0)
+		return do_chaintmplt(argc-1, argv+1, buf, buflen);
 	if (matches(*argv, "actions") == 0)
 		return do_action(argc-1, argv+1, buf, buflen);
 	if (matches(*argv, "monitor") == 0)
tc/tc_common.h +1 -0
index 49c24616c2c3..16cefe896109 100644
@@ -8,6 +8,7 @@ extern struct rtnl_handle rth;
 extern int do_qdisc(int argc, char **argv);
 extern int do_class(int argc, char **argv);
 extern int do_filter(int argc, char **argv, void *buf, size_t buflen);
+extern int do_chaintmplt(int argc, char **argv, void *buf, size_t buflen);
 extern int do_action(int argc, char **argv, void *buf, size_t buflen);
 extern int do_tcmonitor(int argc, char **argv);
 extern int do_exec(int argc, char **argv);
tc/tc_filter.c +79 -27

201 lines not on this page · raw message

tc/tc_monitor.c +4 -1
index 077b138d1ec5..33633837432c 100644
@@ -43,7 +43,10 @@ static int accept_tcmsg(const struct sockaddr_nl *who,
 	if (timestamp)
 		print_timestamp(fp);
 
-	if (n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) {
+	if (n->nlmsg_type == RTM_NEWTFILTER ||
+	    n->nlmsg_type == RTM_DELTFILTER ||
+	    n->nlmsg_type == RTM_NEWCHAINTMPLT ||
+	    n->nlmsg_type == RTM_DELCHAINTMPLT) {
 		print_filter(who, n, arg);
 		return 0;
 	}
Signature · 1 line
2.14.4
author maintainer
#11 lore raw
In reply to Jiri Pirko

Oh, this is v3 already. The changelog should be:

---
v2->v3:
- patch 5:
- rebase on top of the reoffload pathset
- patch 6:
- rebase on top of the reoffload pathset
- patch 9:
- adjust to the userspace cmdline changes
v1->v2:
- patch 6:
- remove leftover extack arg in fl_hw_create_tmplt()

#12 lore raw
In reply to Jiri Pirko
Quoted 47 lines · Jiri Pirko

Create dummy device with clsact first:

# ip link add type dummy
# tc qdisc add dev dummy0 clsact

There is no template assigned by default:

# tc chaintemplate show dev dummy0 ingress

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22 
  eth_type ipv4
  dst_ip 0.0.0.0/16

Add a filter that fits the template:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:bb:cc:dd:ee:ff/00:00:00:00:00:0F action drop

Addition of filters that does not fit the template would fail:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:11:22:33:44:55/00:00:00:FF:00:00 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Additions of filters to chain 22:

# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/8 action drop
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/24 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
Quoted 4 lines

Removal of a template from non-empty chain would fail:

# tc chaintemplate del dev dummy0 ingress
Error: The chain is not empty, unable to delete template.
We have an error talking to the kernel, -1

Why this restriction? It's a template, so why can't it be removed regardless of whether there are filters?

Quoted 5 lines

Once the chain is flushed, the template could be removed:

# tc filter del dev dummy0 ingress
# tc chaintemplate del dev dummy0 ingress
author maintainer
#13 lore raw
Quoted 48 lines · Thu, Jun 28, 2018 at 04:18:47PM CEST, [email protected] wrote:
Quoted 47 lines · Jiri Pirko

Create dummy device with clsact first:

# ip link add type dummy
# tc qdisc add dev dummy0 clsact

There is no template assigned by default:

# tc chaintemplate show dev dummy0 ingress

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22 
  eth_type ipv4
  dst_ip 0.0.0.0/16

Add a filter that fits the template:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:bb:cc:dd:ee:ff/00:00:00:00:00:0F action drop

Addition of filters that does not fit the template would fail:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:11:22:33:44:55/00:00:00:FF:00:00 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Additions of filters to chain 22:

# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/8 action drop
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/24 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
Quoted 7 lines
Quoted 4 lines

Removal of a template from non-empty chain would fail:

# tc chaintemplate del dev dummy0 ingress
Error: The chain is not empty, unable to delete template.
We have an error talking to the kernel, -1

Why this restriction? It's a template, so why can't it be removed regardless of whether there are filters?

That means you could start to insert filters that does not match the original template. I wanted to avoid it. The chain is utilized in hw for the original template, the filter insertion would have to be sanitized in driver. With this restriction, drivers can depend on filters always be fitting.

Quoted 7 lines
Quoted 6 lines

Once the chain is flushed, the template could be removed:

# tc filter del dev dummy0 ingress
# tc chaintemplate del dev dummy0 ingress
#14 lore raw
Quoted 54 lines · Jiri Pirko
Quoted 53 lines · Thu, Jun 28, 2018 at 04:18:47PM CEST, [email protected] wrote:
Quoted 51 lines · Jiri Pirko

Create dummy device with clsact first:

# ip link add type dummy
# tc qdisc add dev dummy0 clsact

There is no template assigned by default:

# tc chaintemplate show dev dummy0 ingress

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22 
  eth_type ipv4
  dst_ip 0.0.0.0/16

Add a filter that fits the template:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:bb:cc:dd:ee:ff/00:00:00:00:00:0F action drop

Addition of filters that does not fit the template would fail:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:11:22:33:44:55/00:00:00:FF:00:00 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Additions of filters to chain 22:

# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/8 action drop
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/24 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Removal of a template from non-empty chain would fail:

# tc chaintemplate del dev dummy0 ingress
Error: The chain is not empty, unable to delete template.
We have an error talking to the kernel, -1
Quoted 9 lines
Quoted 2 lines

Why this restriction? It's a template, so why can't it be removed regardless of whether there are filters?

That means you could start to insert filters that does not match the original template. I wanted to avoid it. The chain is utilized in hw for the original template, the filter insertion would have to be sanitized in driver. With this restriction, drivers can depend on filters always be fitting.

Then the hardware driver should have that restriction not the core tc code.

author maintainer
#15 lore raw
Quoted 58 lines · Thu, Jun 28, 2018 at 05:10:45PM CEST, [email protected] wrote:
Quoted 57 lines · Jiri Pirko
Quoted 55 lines · Thu, Jun 28, 2018 at 04:18:47PM CEST, [email protected] wrote:
Quoted 47 lines · Jiri Pirko

Create dummy device with clsact first:

# ip link add type dummy
# tc qdisc add dev dummy0 clsact

There is no template assigned by default:

# tc chaintemplate show dev dummy0 ingress

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0 
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22 
  eth_type ipv4
  dst_ip 0.0.0.0/16

Add a filter that fits the template:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:bb:cc:dd:ee:ff/00:00:00:00:00:0F action drop

Addition of filters that does not fit the template would fail:

# tc filter add dev dummy0 ingress proto ip flower dst_mac aa:11:22:33:44:55/00:00:00:FF:00:00 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1

Additions of filters to chain 22:

# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/8 action drop
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
# tc filter add dev dummy0 ingress proto ip chain 22 flower dst_ip 10.0.0.1/24 action drop
Error: Mask does not fit the template.
We have an error talking to the kernel, -1
Quoted 4 lines

Removal of a template from non-empty chain would fail:

# tc chaintemplate del dev dummy0 ingress
Error: The chain is not empty, unable to delete template.
We have an error talking to the kernel, -1

Why this restriction? It's a template, so why can't it be removed regardless of whether there are filters?

Quoted 8 lines
Quoted 6 lines

That means you could start to insert filters that does not match the original template. I wanted to avoid it. The chain is utilized in hw for the original template, the filter insertion would have to be sanitized in driver. With this restriction, drivers can depend on filters always be fitting.

Then the hardware driver should have that restriction not the core tc code.

But why? The same restriction would be in all drivers. I believe it is better to have in in tc in single place. Drivers can then depend on it. Do you have a usecase where you need to remove template for non-empty chain?

#16 lore raw
Quoted 11 lines · Jiri Pirko
Quoted 11 lines
Quoted 10 lines
Quoted 3 lines

Why this restriction? It's a template, so why can't it be removed regardless of whether there are filters?

That means you could start to insert filters that does not match the original template. I wanted to avoid it. The chain is utilized in hw for the original template, the filter insertion would have to be sanitized in driver. With this restriction, drivers can depend on filters always be fitting.

Quoted 7 lines
Quoted 1 line

Then the hardware driver should have that restriction not the core tc code.

But why? The same restriction would be in all drivers. I believe it is better to have in in tc in single place. Drivers can then depend on it. Do you have a usecase where you need to remove template for non-empty chain?

If the hardware has the limitation then the driver should be rejecting a change.

author maintainer
#17 lore raw
Quoted 14 lines · Thu, Jun 28, 2018 at 05:50:08PM CEST, [email protected] wrote:
Quoted 13 lines · Jiri Pirko
Quoted 12 lines
Quoted 10 lines
Quoted 3 lines

Why this restriction? It's a template, so why can't it be removed regardless of whether there are filters?

That means you could start to insert filters that does not match the original template. I wanted to avoid it. The chain is utilized in hw for the original template, the filter insertion would have to be sanitized in driver. With this restriction, drivers can depend on filters always be fitting.

Then the hardware driver should have that restriction not the core tc code.

Quoted 8 lines
Quoted 5 lines

But why? The same restriction would be in all drivers. I believe it is better to have in in tc in single place. Drivers can then depend on it. Do you have a usecase where you need to remove template for non-empty chain?

If the hardware has the limitation then the driver should be rejecting a change.

The behaviour I defend is symmetrical with "template add". There is also possible to add the template only if the chain is empty.

#18 lore raw
In reply to Jiri Pirko
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22
  eth_type ipv4
  dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...

Isn't it more elegant?

author maintainer
#19 lore raw
Quoted 39 lines · Fri, Jun 29, 2018 at 12:25:53AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
  dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
  eth_type ipv4
chaintemplate flower chain 22
  eth_type ipv4
  dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...
Quoted 1 line

Isn't it more elegant?

Well, that is just another iproute2 command. It would use the same kernel uapi. Filters+templates. Sure, why not. Can be easily introduced. Let's do it in a follow-up iproute2 patch.

maintainer
#20 lore raw
Quoted 40 lines · Jiri Pirko
Quoted 39 lines · Fri, Jun 29, 2018 at 12:25:53AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4
chaintemplate flower chain 22
   eth_type ipv4
   dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...
Quoted 6 lines
Quoted 1 line

Isn't it more elegant?

Well, that is just another iproute2 command. It would use the same kernel uapi. Filters+templates. Sure, why not. Can be easily introduced. Let's do it in a follow-up iproute2 patch.

Half a dozen or 6 - take your pick, really.
I would call the template an attribute as opposed to a stand alone object i.e A chain of filters may have a template. If you have to introduce a new object then Sridhar's suggested syntax seems appealing.

cheers,
jamal

author maintainer
#21 lore raw
Quoted 48 lines · Fri, Jun 29, 2018 at 02:12:21PM CEST, [email protected] wrote:
Quoted 40 lines · Jiri Pirko
Quoted 39 lines · Fri, Jun 29, 2018 at 12:25:53AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4
chaintemplate flower chain 22
   eth_type ipv4
   dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...
Quoted 6 lines
Quoted 1 line

Isn't it more elegant?

Well, that is just another iproute2 command. It would use the same kernel uapi. Filters+templates. Sure, why not. Can be easily introduced. Let's do it in a follow-up iproute2 patch.

Quoted 4 lines

Half a dozen or 6 - take your pick, really.
I would call the template an attribute as opposed to a stand alone object i.e A chain of filters may have a template. If you have to introduce a new object then Sridhar's suggested syntax seems appealing.

I think what I have makes sense. Maps nicely to what it really is inside kernel. What Cong proposes looks like nice extension of userspace app to do more things in one go. Will address that in followup iproute2 patch.

Quoted 3 lines

cheers,
jamal

#22 lore raw
Quoted 49 lines · Jiri Pirko
Quoted 48 lines · Fri, Jun 29, 2018 at 02:12:21PM CEST, [email protected] wrote:
Quoted 46 lines · Jiri Pirko
Quoted 39 lines · Fri, Jun 29, 2018 at 12:25:53AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4
chaintemplate flower chain 22
   eth_type ipv4
   dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...
Quoted 1 line

Isn't it more elegant?

Well, that is just another iproute2 command. It would use the same kernel uapi. Filters+templates. Sure, why not. Can be easily introduced. Let's do it in a follow-up iproute2 patch.

Quoted 8 lines
Quoted 4 lines

Half a dozen or 6 - take your pick, really.
I would call the template an attribute as opposed to a stand alone object i.e A chain of filters may have a template. If you have to introduce a new object then Sridhar's suggested syntax seems appealing.

I think what I have makes sense. Maps nicely to what it really is inside kernel. What Cong proposes looks like nice extension of userspace app to do more things in one go. Will address that in followup iproute2 patch.

The resolution of the syntax affect the uapi changes proposed. You are wanting to add new RTM commands which suggests new objects. If a template is an attribute of an existing object then the netlink API should indicate that.

author maintainer
#23 lore raw
Quoted 55 lines · Fri, Jun 29, 2018 at 02:54:36PM CEST, [email protected] wrote:
Quoted 54 lines · Jiri Pirko
Quoted 52 lines · Fri, Jun 29, 2018 at 02:12:21PM CEST, [email protected] wrote:
Quoted 40 lines · Jiri Pirko
Quoted 39 lines · Fri, Jun 29, 2018 at 12:25:53AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
   dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
   eth_type ipv4
chaintemplate flower chain 22
   eth_type ipv4
   dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...
Quoted 6 lines
Quoted 1 line

Isn't it more elegant?

Well, that is just another iproute2 command. It would use the same kernel uapi. Filters+templates. Sure, why not. Can be easily introduced. Let's do it in a follow-up iproute2 patch.

Half a dozen or 6 - take your pick, really.
I would call the template an attribute as opposed to a stand alone object i.e A chain of filters may have a template. If you have to introduce a new object then Sridhar's suggested syntax seems appealing.

Quoted 8 lines
Quoted 3 lines

I think what I have makes sense. Maps nicely to what it really is inside kernel. What Cong proposes looks like nice extension of userspace app to do more things in one go. Will address that in followup iproute2 patch.

The resolution of the syntax affect the uapi changes proposed. You are wanting to add new RTM commands which suggests new objects. If a template is an attribute of an existing object then the netlink API should indicate that.

There is no existing "chain" object. So no, no uapi changes.

#24 lore raw
Quoted 52 lines · Jiri Pirko
Quoted 51 lines · Fri, Jun 29, 2018 at 02:54:36PM CEST, [email protected] wrote:
Quoted 50 lines · Jiri Pirko
Quoted 49 lines · Fri, Jun 29, 2018 at 02:12:21PM CEST, [email protected] wrote:
Quoted 39 lines · Jiri Pirko
Quoted 38 lines · Fri, Jun 29, 2018 at 12:25:53AM CEST, [email protected] wrote:
Quoted 11 lines · Jiri Pirko

Add a template of type flower allowing to insert rules matching on last 2 bytes of destination mac address:

# tc chaintemplate add dev dummy0 ingress proto ip flower dst_mac 00:00:00:00:00:00/00:00:00:00:FF:FF

The template is now showed in the list:

# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
    dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
    eth_type ipv4

Add another template, this time for chain number 22:

Quoted 8 lines
# tc chaintemplate add dev dummy0 ingress proto ip chain 22 flower dst_ip 0.0.0.0/16
# tc chaintemplate show dev dummy0 ingress
chaintemplate flower chain 0
    dst_mac 00:00:00:00:00:00/00:00:00:00:ff:ff
    eth_type ipv4
chaintemplate flower chain 22
    eth_type ipv4
    dst_ip 0.0.0.0/16

So, if I want to check the template of a chain, I have to use 'tc chaintemplate... chain X'.

If I want to check the filters in a chain, I have to use 'tc filter show .... chain X'.

If you introduce 'tc chain', it would just need one command:
tc chain show ... X which could list its template first and followed by filters in this chain, something like:

# tc chain show dev eth0 chain X
template: # could be none
....
filter1
...
filter2
...
Quoted 5 lines
Quoted 1 line

Isn't it more elegant?

Well, that is just another iproute2 command. It would use the same kernel uapi. Filters+templates. Sure, why not. Can be easily introduced. Let's do it in a follow-up iproute2 patch.

Half a dozen or 6 - take your pick, really.
I would call the template an attribute as opposed to a stand alone object i.e A chain of filters may have a template. If you have to introduce a new object then Sridhar's suggested syntax seems appealing.

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

I think what I have makes sense. Maps nicely to what it really is inside kernel. What Cong proposes looks like nice extension of userspace app to do more things in one go. Will address that in followup iproute2 patch.

The resolution of the syntax affect the uapi changes proposed. You are wanting to add new RTM commands which suggests new objects. If a template is an attribute of an existing object then the netlink API should indicate that.

There is no existing "chain" object. So no, no uapi changes.

So instead of introducing 'chaintemplate' object in the kernel, can't we add 'chain' object in the kernel that takes the 'template' as an attribute?

#25 lore raw
Quoted 3 lines · Sridhar

So instead of introducing 'chaintemplate' object in the kernel, can't we add 'chain' object in the kernel that takes the 'template' as an attribute?

This is exactly what I mean above. Making the chain a standalone object in kernel would benefit:

1. Align with 'tc chain' in iproute2, add/del an object is natural

2. Template is an attribute of this object when creating it:

# tc chain add template ....
# tc chain add ... # non-template chain

3. Easier for sharing by qdiscs:

# tc chain add X block Y ...
# tc filter add ... chain X block Y ...
# tc qdisc add dev eth0 block Y ...

The current 'ingress_block 22 ingress' syntax is ugly.

author maintainer
#26 lore raw
Quoted 6 lines · Sat, Jun 30, 2018 at 12:18:02AM CEST, [email protected] wrote:
Quoted 3 lines · Sridhar

So instead of introducing 'chaintemplate' object in the kernel, can't we add 'chain' object in the kernel that takes the 'template' as an attribute?

Quoted 8 lines

This is exactly what I mean above. Making the chain a standalone object in kernel would benefit:

1. Align with 'tc chain' in iproute2, add/del an object is natural

2. Template is an attribute of this object when creating it:

# tc chain add template ....
# tc chain add ... # non-template chain

Okay. So that would allow either create a chain or "chain with template". Once that is done, there would be no means to manipulate the template. One can only remove the chain.

What about refounting? I think it would make sense that this implicit chain addition would take one reference. That means if later on the last filter is removed, the chain would stay there until user removes it by hand.

Okay. Sounds good to me. Will do.

Thanks!

Quoted 7 lines

3. Easier for sharing by qdiscs:

# tc chain add X block Y ...
# tc filter add ... chain X block Y ...
# tc qdisc add dev eth0 block Y ...

The current 'ingress_block 22 ingress' syntax is ugly.

#27 lore raw
Quoted 8 lines · Jiri Pirko

Okay. So that would allow either create a chain or "chain with template". Once that is done, there would be no means to manipulate the template. One can only remove the chain.

What about refounting? I think it would make sense that this implicit chain addition would take one reference. That means if later on the last filter is removed, the chain would stay there until user removes it by hand.

Yeah, it is very similar to tc actions. So you can take a look at how tc actions are refcnt'ed.

maintainer
#28 lore raw
In reply to David Ahern

From: David Ahern <[email protected]>
Date: Fri, 29 Jun 2018 06:54:36 -0600

Quoted 4 lines

The resolution of the syntax affect the uapi changes proposed. You are wanting to add new RTM commands which suggests new objects. If a template is an attribute of an existing object then the netlink API should indicate that.

+1