Skip to contentSkip to conversation

add tcp flags match support to flower and offload it

PATCH Superseded Jiri Pirko 4 participants 12 messages May 23, 2017

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

cover add tcp flags match support to flower and offload it

From: Jiri Pirko <[email protected]>

This patch adds support to dissect tcp flags, match on them using flower classifier and offload such rules to mlxsw Spectrum devices.

Jiri Pirko (5):
net: sched: cls_api: make reclassify return all the way back to the
original tp
net: flow_dissector: add support for dissection of tcp flags net/sched: flower: add support for matching on tcp flags
mlxsw: acl: Add tcp flags acl element
mlxsw: spectrum: Add acl block containing tcp flags for ipv4

 .../ethernet/mellanox/mlxsw/core_acl_flex_keys.h   |  2 ++
 .../mellanox/mlxsw/spectrum_acl_flex_keys.h        |  6 +++++
 .../net/ethernet/mellanox/mlxsw/spectrum_flower.c  |  1 +
 include/net/flow_dissector.h                       |  9 +++++++
 include/uapi/linux/pkt_cls.h                       |  3 +++
 net/core/flow_dissector.c                          | 31 ++++++++++++++++++++++
 net/sched/cls_api.c                                |  8 +++---
 net/sched/cls_flower.c                             | 13 ++++++++-
 8 files changed, 69 insertions(+), 4 deletions(-)
Signature · 1 line
2.9.3
author maintainer
#1 lore raw

PATCH 1/5 net: sched: cls_api: make reclassify return all the way back to the original tp

From: Jiri Pirko <[email protected]>

With the introduction of chain goto action, the reclassification would cause the re-iteration of the actual chain. It makes more sense to restart the whole thing and re-iterate starting from the original tp - start of chain 0.

---
 net/sched/cls_api.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
net/sched/cls_api.c +5 -3
index 01a8b8b..89fbb35 100644
@@ -300,7 +300,8 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 	__be16 protocol = tc_skb_protocol(skb);
 #ifdef CONFIG_NET_CLS_ACT
 	const int max_reclassify_loop = 4;
-	const struct tcf_proto *old_tp = tp;
+	const struct tcf_proto *orig_tp = tp;
+	const struct tcf_proto *first_tp;
 	int limit = 0;
 
 reclassify:
@@ -315,9 +316,10 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 		err = tp->classify(skb, tp, res);
 #ifdef CONFIG_NET_CLS_ACT
 		if (unlikely(err == TC_ACT_RECLASSIFY && !compat_mode)) {
+			first_tp = orig_tp;
 			goto reset;
 		} else if (unlikely(TC_ACT_EXT_CMP(err, TC_ACT_GOTO_CHAIN))) {
-			old_tp = res->goto_tp;
+			first_tp = res->goto_tp;
 			goto reset;
 		}
 #endif
@@ -335,7 +337,7 @@ int tcf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 		return TC_ACT_SHOT;
 	}
 
-	tp = old_tp;
+	tp = first_tp;
 	protocol = tc_skb_protocol(skb);
 	goto reclassify;
 #endif
Signature · 1 line
2.9.3
author maintainer
#2 lore raw

PATCH 2/5 net: flow_dissector: add support for dissection of tcp flags

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add support for dissection of tcp flags. Uses similar function call to tcp dissection function as arp, mpls and others.

---
 include/net/flow_dissector.h |  9 +++++++++
 net/core/flow_dissector.c    | 31 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)
include/net/flow_dissector.h +9 -0
index 8d21d44..efe34eec 100644
@@ -157,6 +157,14 @@ struct flow_dissector_key_eth_addrs {
 	unsigned char src[ETH_ALEN];
 };
 
+/**
+ * struct flow_dissector_key_tcp:
+ * @flags: flags
+ */
+struct flow_dissector_key_tcp {
+	__be16 flags;
+};
+
 enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_BASIC, /* struct flow_dissector_key_basic */
@@ -177,6 +185,7 @@ enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_ENC_CONTROL, /* struct flow_dissector_key_control */
 	FLOW_DISSECTOR_KEY_ENC_PORTS, /* struct flow_dissector_key_ports */
 	FLOW_DISSECTOR_KEY_MPLS, /* struct flow_dissector_key_mpls */
+	FLOW_DISSECTOR_KEY_TCP, /* struct flow_dissector_key_tcp */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
net/core/flow_dissector.c +31 -0
index 28d94bc..3fb3388 100644
@@ -18,6 +18,7 @@
 #include <linux/stddef.h>
 #include <linux/if_ether.h>
 #include <linux/mpls.h>
+#include <linux/tcp.h>
 #include <net/flow_dissector.h>
 #include <scsi/fc/fc_fcoe.h>
 
@@ -342,6 +343,30 @@ __skb_flow_dissect_gre(const struct sk_buff *skb,
 	return FLOW_DISSECT_RET_OUT_PROTO_AGAIN;
 }
 
+static void
+__skb_flow_dissect_tcp(const struct sk_buff *skb,
+		       struct flow_dissector *flow_dissector,
+		       void *target_container, void *data, int thoff, int hlen)
+{
+	struct flow_dissector_key_tcp *key_tcp;
+	struct tcphdr *th, _th;
+
+	if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_TCP))
+		return;
+
+	th = __skb_header_pointer(skb, thoff, sizeof(_th), data, hlen, &_th);
+	if (!th)
+		return;
+
+	if (unlikely(__tcp_hdrlen(th) < sizeof(_th)))
+		return;
+
+	key_tcp = skb_flow_dissector_target(flow_dissector,
+					    FLOW_DISSECTOR_KEY_TCP,
+					    target_container);
+	key_tcp->flags = (*(__be16 *) &tcp_flag_word(th) & htons(0x0FFF));
+}
+
 /**
  * __skb_flow_dissect - extract the flow_keys struct and return it
  * @skb: sk_buff to extract the flow from, can be NULL if the rest are specified
@@ -683,6 +708,12 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
 	case IPPROTO_MPLS:
 		proto = htons(ETH_P_MPLS_UC);
 		goto mpls;
+	case IPPROTO_TCP:
+		__skb_flow_dissect_tcp(skb, flow_dissector, target_container,
+				       data, nhoff, hlen);
+		/* Regardless of the return value, continue to process TCP
+		 * ports dissection below.
+		 */
 	default:
 		break;
 	}
Signature · 1 line
2.9.3
Acked-by on v1 2/5
#3 lore raw

Re: [patch net-next 2/5] net: flow_dissector: add support for dissection of tcp flags

net/core/flow_dissector.c bool __skb_flow_dissect(const struct sk_buff *skb, · line 716

Quoted 10 lines · Jiri Pirko
net/core/flow_dissector.c +6 -0
@@ -683,6 +708,12 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
  	case IPPROTO_MPLS:
  		proto = htons(ETH_P_MPLS_UC);
  		goto mpls;
+	case IPPROTO_TCP:
+		__skb_flow_dissect_tcp(skb, flow_dissector, target_container,
+				       data, nhoff, hlen);
+		/* Regardless of the return value, continue to process TCP
+		 * ports dissection below.
+		 */

the comment here is a bit misleading, since __skb_flow_dissect_tcp is void

other-wise

author maintainer
#4 lore raw

Re: [patch net-next 2/5] net: flow_dissector: add support for dissection of tcp flags

Quoted 13 lines · Tue, May 23, 2017 at 05:18:33PM CEST, [email protected] wrote:

net/core/flow_dissector.c bool __skb_flow_dissect(const struct sk_buff *skb, · line 716

Quoted 10 lines · Jiri Pirko
net/core/flow_dissector.c +6 -0
@@ -683,6 +708,12 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
  	case IPPROTO_MPLS:
  		proto = htons(ETH_P_MPLS_UC);
  		goto mpls;
+	case IPPROTO_TCP:
+		__skb_flow_dissect_tcp(skb, flow_dissector, target_container,
+				       data, nhoff, hlen);
+		/* Regardless of the return value, continue to process TCP
+		 * ports dissection below.
+		 */

the comment here is a bit misleading, since __skb_flow_dissect_tcp is void

Fixed for v2

Quoted 4 lines

other-wise

Thanks

author maintainer
#5 lore raw

PATCH 3/5 net/sched: flower: add support for matching on tcp flags

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Benefit from the support of tcp flags dissection and allow user to insert rules matching on tcp flags.

---
 include/uapi/linux/pkt_cls.h |  3 +++
 net/sched/cls_flower.c       | 13 ++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)
include/uapi/linux/pkt_cls.h +3 -0
index 1b9aa9e..c6e8cf5 100644
@@ -451,6 +451,9 @@ enum {
 	TCA_FLOWER_KEY_MPLS_TC,		/* u8 - 3 bits */
 	TCA_FLOWER_KEY_MPLS_LABEL,	/* be32 - 20 bits */
 
+	TCA_FLOWER_KEY_TCP_FLAGS,	/* be16 */
+	TCA_FLOWER_KEY_TCP_FLAGS_MASK,	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
net/sched/cls_flower.c +12 -1
index ca526c0..fb74a47 100644
@@ -49,6 +49,7 @@ struct fl_flow_key {
 	};
 	struct flow_dissector_key_ports enc_tp;
 	struct flow_dissector_key_mpls mpls;
+	struct flow_dissector_key_tcp tcp;
 } __aligned(BITS_PER_LONG / 8); /* Ensure that we can do comparisons as longs. */
 
 struct fl_flow_mask_range {
@@ -424,6 +425,8 @@ static const struct nla_policy fl_policy[TCA_FLOWER_MAX + 1] = {
 	[TCA_FLOWER_KEY_MPLS_BOS]	= { .type = NLA_U8 },
 	[TCA_FLOWER_KEY_MPLS_TC]	= { .type = NLA_U8 },
 	[TCA_FLOWER_KEY_MPLS_LABEL]	= { .type = NLA_U32 },
+	[TCA_FLOWER_KEY_TCP_FLAGS]	= { .type = NLA_U16 },
+	[TCA_FLOWER_KEY_TCP_FLAGS_MASK]	= { .type = NLA_U16 },
 };
 
 static void fl_set_key_val(struct nlattr **tb,
@@ -596,6 +599,9 @@ static int fl_set_key(struct net *net, struct nlattr **tb,
 		fl_set_key_val(tb, &key->tp.dst, TCA_FLOWER_KEY_TCP_DST,
 			       &mask->tp.dst, TCA_FLOWER_KEY_TCP_DST_MASK,
 			       sizeof(key->tp.dst));
+		fl_set_key_val(tb, &key->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS,
+			       &mask->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS_MASK,
+			       sizeof(key->tcp.flags));
 	} else if (key->basic.ip_proto == IPPROTO_UDP) {
 		fl_set_key_val(tb, &key->tp.src, TCA_FLOWER_KEY_UDP_SRC,
 			       &mask->tp.src, TCA_FLOWER_KEY_UDP_SRC_MASK,
@@ -767,6 +773,8 @@ static void fl_init_dissector(struct cls_fl_head *head,
 	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
 			     FLOW_DISSECTOR_KEY_PORTS, tp);
 	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
+			     FLOW_DISSECTOR_KEY_TCP, tcp);
+	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ICMP, icmp);
 	FL_KEY_SET_IF_MASKED(&mask->key, keys, cnt,
 			     FLOW_DISSECTOR_KEY_ARP, arp);
@@ -1215,7 +1223,10 @@ static int fl_dump(struct net *net, struct tcf_proto *tp, unsigned long fh,
 			     sizeof(key->tp.src)) ||
 	     fl_dump_key_val(skb, &key->tp.dst, TCA_FLOWER_KEY_TCP_DST,
 			     &mask->tp.dst, TCA_FLOWER_KEY_TCP_DST_MASK,
-			     sizeof(key->tp.dst))))
+			     sizeof(key->tp.dst)) ||
+	     fl_dump_key_val(skb, &key->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS,
+			     &mask->tcp.flags, TCA_FLOWER_KEY_TCP_FLAGS_MASK,
+			     sizeof(key->tcp.flags))))
 		goto nla_put_failure;
 	else if (key->basic.ip_proto == IPPROTO_UDP &&
 		 (fl_dump_key_val(skb, &key->tp.src, TCA_FLOWER_KEY_UDP_SRC,
Signature · 1 line
2.9.3
author maintainer
#6 lore raw

PATCH 4/5 mlxsw: acl: Add tcp flags acl element

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Define new element for tcp flags and place it into scratch area.

---
 drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h | 2 ++
 drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c    | 1 +
 2 files changed, 3 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/core_acl_flex_keys.h +2 -0
index c75e914..9807ef8 100644
@@ -56,6 +56,7 @@ enum mlxsw_afk_element {
 	MLXSW_AFK_ELEMENT_SRC_L4_PORT,
 	MLXSW_AFK_ELEMENT_VID,
 	MLXSW_AFK_ELEMENT_PCP,
+	MLXSW_AFK_ELEMENT_TCP_FLAGS,
 	MLXSW_AFK_ELEMENT_MAX,
 };
 
@@ -102,6 +103,7 @@ static const struct mlxsw_afk_element_info mlxsw_afk_element_infos[] = {
 	MLXSW_AFK_ELEMENT_INFO_U32(IP_PROTO, 0x10, 0, 8),
 	MLXSW_AFK_ELEMENT_INFO_U32(VID, 0x10, 8, 12),
 	MLXSW_AFK_ELEMENT_INFO_U32(PCP, 0x10, 20, 3),
+	MLXSW_AFK_ELEMENT_INFO_U32(TCP_FLAGS, 0x10, 23, 9),
 	MLXSW_AFK_ELEMENT_INFO_U32(SRC_IP4, 0x18, 0, 32),
 	MLXSW_AFK_ELEMENT_INFO_U32(DST_IP4, 0x1C, 0, 32),
 	MLXSW_AFK_ELEMENT_INFO_BUF(SRC_IP6_HI, 0x18, 8),
drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c +1 -0
index cc99de0..f7a8c3c 100644
@@ -198,6 +198,7 @@ static int mlxsw_sp_flower_parse(struct mlxsw_sp *mlxsw_sp,
 	      BIT(FLOW_DISSECTOR_KEY_IPV4_ADDRS) |
 	      BIT(FLOW_DISSECTOR_KEY_IPV6_ADDRS) |
 	      BIT(FLOW_DISSECTOR_KEY_PORTS) |
+	      BIT(FLOW_DISSECTOR_KEY_TCP) |
 	      BIT(FLOW_DISSECTOR_KEY_VLAN))) {
 		dev_err(mlxsw_sp->bus_info->dev, "Unsupported key\n");
 		return -EOPNOTSUPP;
Signature · 1 line
2.9.3
author maintainer
#8 lore raw

PATCH 5/5 mlxsw: spectrum: Add acl block containing tcp flags for ipv4

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Add acl block called "ipv4" which contains tcp flags.

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.h | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_flex_keys.h +6 -0
index af7b7ba..85d5001 100644
@@ -68,6 +68,11 @@ static struct mlxsw_afk_element_inst mlxsw_sp_afk_element_info_ipv4_dip[] = {
 	MLXSW_AFK_ELEMENT_INST_U32(SRC_SYS_PORT, 0x0C, 0, 16),
 };
 
+static struct mlxsw_afk_element_inst mlxsw_sp_afk_element_info_ipv4[] = {
+	MLXSW_AFK_ELEMENT_INST_U32(SRC_IP4, 0x00, 0, 32),
+	MLXSW_AFK_ELEMENT_INST_U32(TCP_FLAGS, 0x08, 8, 9), /* TCP_CONTROL+TCP_ECN */
+};
+
 static struct mlxsw_afk_element_inst mlxsw_sp_afk_element_info_ipv4_ex[] = {
 	MLXSW_AFK_ELEMENT_INST_U32(VID, 0x00, 0, 12),
 	MLXSW_AFK_ELEMENT_INST_U32(PCP, 0x08, 29, 3),
@@ -102,6 +107,7 @@ static const struct mlxsw_afk_block mlxsw_sp_afk_blocks[] = {
 	MLXSW_AFK_BLOCK(0x12, mlxsw_sp_afk_element_info_l2_smac_ex),
 	MLXSW_AFK_BLOCK(0x30, mlxsw_sp_afk_element_info_ipv4_sip),
 	MLXSW_AFK_BLOCK(0x31, mlxsw_sp_afk_element_info_ipv4_dip),
+	MLXSW_AFK_BLOCK(0x32, mlxsw_sp_afk_element_info_ipv4),
 	MLXSW_AFK_BLOCK(0x33, mlxsw_sp_afk_element_info_ipv4_ex),
 	MLXSW_AFK_BLOCK(0x60, mlxsw_sp_afk_element_info_ipv6_dip),
 	MLXSW_AFK_BLOCK(0x65, mlxsw_sp_afk_element_info_ipv6_ex1),
Signature · 1 line
2.9.3
author maintainer
#9 lore raw

PATCH 1/1 tc: flower: add support for tcp flags

In reply to Jiri Pirko

From: Jiri Pirko <[email protected]>

Allow user to insert a flower classifier filter rule which includes match for tcp flags.

---
 include/linux/pkt_cls.h |  3 +++
 man/man8/tc-flower.8    |  8 +++++++
 tc/f_flower.c           | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)
include/linux/pkt_cls.h +3 -0
index d613be3..ce9dfb9 100644
@@ -450,6 +450,9 @@ enum {
 	TCA_FLOWER_KEY_MPLS_TC,		/* u8 - 3 bits */
 	TCA_FLOWER_KEY_MPLS_LABEL,	/* be32 - 20 bits */
 
+	TCA_FLOWER_KEY_TCP_FLAGS,	/* be16 */
+	TCA_FLOWER_KEY_TCP_FLAGS_MASK,	/* be16 */
+
 	__TCA_FLOWER_MAX,
 };
 
man/man8/tc-flower.8 +8 -0
index ba29065..7648079 100644
@@ -35,6 +35,8 @@ flower \- flow based traffic control filter
 .IR PREFIX " | { "
 .BR dst_port " | " src_port " } "
 .IR port_number " } | "
+.B tcp_flags
+.IR MASKED_TCP_FLAGS " | "
 .B type
 .IR MASKED_TYPE " | "
 .B code
@@ -136,6 +138,12 @@ Match on layer 4 protocol source or destination port number. Only available for
 .BR ip_proto " values " udp ", " tcp  " and " sctp
 which have to be specified in beforehand.
 .TP
+.BI tcp_flags " MASKED_TCP_FLAGS"
+Match on TCP flags represented as 12bit bitfield in in hexadecimal format.
+A mask may be optionally provided to limit the bits which are matched. A mask
+is provided by following the value with a slash and then the mask. If the mask
+is missing then a match on all bits is assumed.
+.TP
 .BI type " MASKED_TYPE"
 .TQ
 .BI code " MASKED_CODE"
tc/f_flower.c +63 -0

93 lines not on this page · raw message

Signature · 1 line
2.9.3
author maintainer
#10 lore raw
In reply to Jiri Pirko
Quoted 4 lines · Tue, May 23, 2017 at 04:31:05PM CEST, [email protected] wrote:

From: Jiri Pirko <[email protected]>

This patch adds support to dissect tcp flags, match on them using flower classifier and offload such rules to mlxsw Spectrum devices.

I shifted the git format patch one commit. Will send v2. Sorry.

maintainer
#11 lore raw

From: Jiri Pirko <[email protected]>
Date: Tue, 23 May 2017 17:11:20 +0200

Quoted 7 lines
Quoted 4 lines · Tue, May 23, 2017 at 04:31:05PM CEST, [email protected] wrote:

From: Jiri Pirko <[email protected]>

This patch adds support to dissect tcp flags, match on them using flower classifier and offload such rules to mlxsw Spectrum devices.

I shifted the git format patch one commit. Will send v2. Sorry.

Ok.