Skip to contentSkip to conversation

net: sched: support vxlan and erspan options

PATCH Superseded Xin Long 4 participants 16 messages Nov 19, 2019 – Nov 21, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Xin Long

author
#0 lore raw

cover net: sched: support vxlan and erspan options

This patchset is to add vxlan and erspan options support in cls_flower and act_tunnel_key. The form is pretty much like geneve_opts in:

https://patchwork.ozlabs.org/patch/935272/
https://patchwork.ozlabs.org/patch/954564/

but only one option is allowed for vxlan and erspan.

Xin Long (4):
net: sched: add vxlan option support to act_tunnel_key
net: sched: add erspan option support to act_tunnel_key
net: sched: allow flower to match vxlan options
net: sched: allow flower to match erspan options

 include/uapi/linux/pkt_cls.h              |  29 ++++
 include/uapi/linux/tc_act/tc_tunnel_key.h |  29 ++++
 net/sched/act_tunnel_key.c                | 191 +++++++++++++++++++++-
 net/sched/cls_flower.c                    | 252 ++++++++++++++++++++++++++++++
 4 files changed, 500 insertions(+), 1 deletion(-)
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH 1/4 net: sched: add vxlan option support to act_tunnel_key

This patch is to allow setting vxlan options using the act_tunnel_key action. Different from geneve options, only one option can be set. And also, geneve options and vxlan options can't be set at the same time.

gbp is the only param for vxlan options:

  # ip link add name vxlan0 type vxlan dstport 0 external
  # tc qdisc add dev eth0 ingress
  # tc filter add dev eth0 protocol ip parent ffff: \
           flower indev eth0 \
              ip_proto udp \
              action tunnel_key \
                  set src_ip 10.0.99.192 \
                  dst_ip 10.0.99.193 \
                  dst_port 6081 \
                  id 11 \
  		  vxlan_opts 01020304 \
          action mirred egress redirect dev vxlan0
---
 include/uapi/linux/tc_act/tc_tunnel_key.h | 13 +++++
 net/sched/act_tunnel_key.c                | 83 ++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 1 deletion(-)
include/uapi/linux/tc_act/tc_tunnel_key.h +13 -0
index 41c8b46..f302c2a 100644
@@ -50,6 +50,10 @@ enum {
 						 * TCA_TUNNEL_KEY_ENC_OPTS_
 						 * attributes
 						 */
+	TCA_TUNNEL_KEY_ENC_OPTS_VXLAN,		/* Nested
+						 * TCA_TUNNEL_KEY_ENC_OPTS_
+						 * attributes
+						 */
 	__TCA_TUNNEL_KEY_ENC_OPTS_MAX,
 };
 
@@ -67,4 +71,13 @@ enum {
 #define TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX \
 	(__TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX - 1)
 
+enum {
+	TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC,
+	TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GBP,		/* u32 */
+	__TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX,
+};
+
+#define TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX \
+	(__TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX - 1)
+
 #endif
net/sched/act_tunnel_key.c +82 -1

140 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#2 lore raw

PATCH 2/4 net: sched: add erspan option support to act_tunnel_key

This patch is to allow setting erspan options using the act_tunnel_key action. Different from geneve options, only one option can be set. And also, geneve options, vxlan options or erspan options can't be set at the same time.

Options are expressed as ver:index:dir:hwid, when ver is set to 1, index will be applied while dir and hwid will be ignored, and when ver is set to 2, dir and hwid will be used while index will be ignored.

  # ip link add name erspan1 type erspan external
  # tc qdisc add dev eth0 ingress
  # tc filter add dev eth0 protocol ip parent ffff: \
           flower indev eth0 \
              ip_proto udp \
              action tunnel_key \
                  set src_ip 10.0.99.192 \
                  dst_ip 10.0.99.193 \
                  dst_port 6081 \
                  id 11 \
  		erspan_opts 1:2:0:0 \
          action mirred egress redirect dev erspan1
---
 include/uapi/linux/tc_act/tc_tunnel_key.h |  16 +++++
 net/sched/act_tunnel_key.c                | 108 ++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+)
include/uapi/linux/tc_act/tc_tunnel_key.h +16 -0
index f302c2a..3f10dc4 100644
@@ -54,6 +54,10 @@ enum {
 						 * TCA_TUNNEL_KEY_ENC_OPTS_
 						 * attributes
 						 */
+	TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN,		/* Nested
+						 * TCA_TUNNEL_KEY_ENC_OPTS_
+						 * attributes
+						 */
 	__TCA_TUNNEL_KEY_ENC_OPTS_MAX,
 };
 
@@ -80,4 +84,16 @@ enum {
 #define TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX \
 	(__TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX - 1)
 
+enum {
+	TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_UNSPEC,
+	TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_VER,		/* u8 */
+	TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_INDEX,		/* be32 */
+	TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_DIR,		/* u8 */
+	TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_HWID,		/* u8 */
+	__TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX,
+};
+
+#define TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX \
+	(__TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX - 1)
+
 #endif
net/sched/act_tunnel_key.c +108 -0

156 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#3 lore raw

PATCH 3/4 net: sched: allow flower to match vxlan options

This patch is to allow matching gbp option in vxlan.

The options can be described in the form GBP/GBP_MASK, where GBP is represented as a 32bit hexadecimal value. Different from geneve, only one option can be set. And also, geneve options and vxlan options can't be set at the same time.

  # ip link add name vxlan0 type vxlan dstport 0 external
  # tc qdisc add dev vxlan0 ingress
  # tc filter add dev vxlan0 protocol ip parent ffff: \
      flower \
        enc_src_ip 10.0.99.192 \
        enc_dst_ip 10.0.99.193 \
        enc_key_id 11 \
        vxlan_opts 01020304/ffffffff \
        ip_proto udp \
        action mirred egress redirect dev eth0
---
 include/uapi/linux/pkt_cls.h |  13 ++++++
 net/sched/cls_flower.c       | 107 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 120 insertions(+)
include/uapi/linux/pkt_cls.h +13 -0
index c6ad22f..929825d 100644
@@ -571,6 +571,10 @@ enum {
 					 * TCA_FLOWER_KEY_ENC_OPT_GENEVE_
 					 * attributes
 					 */
+	TCA_FLOWER_KEY_ENC_OPTS_VXLAN,	/* Nested
+					 * TCA_FLOWER_KEY_ENC_OPT_VXLAN_
+					 * attributes
+					 */
 	__TCA_FLOWER_KEY_ENC_OPTS_MAX,
 };
 
@@ -589,6 +593,15 @@ enum {
 		(__TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX - 1)
 
 enum {
+	TCA_FLOWER_KEY_ENC_OPT_VXLAN_UNSPEC,
+	TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP,		/* u32 */
+	__TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX,
+};
+
+#define TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX \
+		(__TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX - 1)
+
+enum {
 	TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
 	TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
 };
net/sched/cls_flower.c +107 -0

155 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#4 lore raw

PATCH 4/4 net: sched: allow flower to match erspan options

This patch is to allow matching options in erspan.

The options can be described in the form:
VER:INDEX:DIR:HWID/VER:INDEX_MASK:DIR_MASK:HWID_MASK. When ver is set to 1, index will be applied while dir and hwid will be ignored, and when ver is set to 2, dir and hwid will be used while index will be ignored.

Different from geneve, only one option can be set. And also, geneve options, vxlan options or erspan options can't be set at the same time.

  # ip link add name erspan1 type erspan external
  # tc qdisc add dev erspan1 ingress
  # tc filter add dev erspan1 protocol ip parent ffff: \
      flower \
        enc_src_ip 10.0.99.192 \
        enc_dst_ip 10.0.99.193 \
        enc_key_id 11 \
        erspan_opts 1:12:0:0/1:ffff:0:0 \
        ip_proto udp \
        action mirred egress redirect dev eth0
---
 include/uapi/linux/pkt_cls.h |  16 +++++
 net/sched/cls_flower.c       | 145 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 161 insertions(+)
include/uapi/linux/pkt_cls.h +16 -0
index 929825d..449a639 100644
@@ -575,6 +575,10 @@ enum {
 					 * TCA_FLOWER_KEY_ENC_OPT_VXLAN_
 					 * attributes
 					 */
+	TCA_FLOWER_KEY_ENC_OPTS_ERSPAN,	/* Nested
+					 * TCA_FLOWER_KEY_ENC_OPT_ERSPAN_
+					 * attributes
+					 */
 	__TCA_FLOWER_KEY_ENC_OPTS_MAX,
 };
 
@@ -602,6 +606,18 @@ enum {
 		(__TCA_FLOWER_KEY_ENC_OPT_VXLAN_MAX - 1)
 
 enum {
+	TCA_FLOWER_KEY_ENC_OPT_ERSPAN_UNSPEC,
+	TCA_FLOWER_KEY_ENC_OPT_ERSPAN_VER,              /* u8 */
+	TCA_FLOWER_KEY_ENC_OPT_ERSPAN_INDEX,            /* be32 */
+	TCA_FLOWER_KEY_ENC_OPT_ERSPAN_DIR,              /* u8 */
+	TCA_FLOWER_KEY_ENC_OPT_ERSPAN_HWID,             /* u8 */
+	__TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX,
+};
+
+#define TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX \
+		(__TCA_FLOWER_KEY_ENC_OPT_ERSPAN_MAX - 1)
+
+enum {
 	TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 << 0),
 	TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 << 1),
 };
net/sched/cls_flower.c +145 -0

187 lines not on this page · raw message

Signature · 1 line
2.1.0
author
#13 lore raw
Quoted 7 lines · Roman Mashak
Quoted 5 lines · Xin Long

This patchset is to add vxlan and erspan options support in cls_flower and act_tunnel_key. The form is pretty much like geneve_opts in:

Quoted 8 lines
Quoted 4 lines

https://patchwork.ozlabs.org/patch/935272/
https://patchwork.ozlabs.org/patch/954564/

but only one option is allowed for vxlan and erspan.

[...]

Are you considering to add tdc tests for the new features in separate patch?

You mean in selftests?
I will post iproute2 side patch to support these first, then considering to add selftests.
(this patch series is the kernel side only)

#14 lore raw
Quoted 13 lines · Xin Long
Quoted 12 lines · Roman Mashak
Quoted 9 lines · Xin Long

This patchset is to add vxlan and erspan options support in cls_flower and act_tunnel_key. The form is pretty much like geneve_opts in:

https://patchwork.ozlabs.org/patch/935272/
https://patchwork.ozlabs.org/patch/954564/

but only one option is allowed for vxlan and erspan.

Quoted 7 lines
Quoted 3 lines

[...]

Are you considering to add tdc tests for the new features in separate patch?

You mean in selftests?
I will post iproute2 side patch to support these first, then considering to add selftests.
(this patch series is the kernel side only)

Yes, I mean tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json

author
#15 lore raw
Quoted 18 lines · Roman Mashak
Quoted 15 lines · Xin Long
Quoted 14 lines · Roman Mashak
Quoted 9 lines · Xin Long

This patchset is to add vxlan and erspan options support in cls_flower and act_tunnel_key. The form is pretty much like geneve_opts in:

https://patchwork.ozlabs.org/patch/935272/
https://patchwork.ozlabs.org/patch/954564/

but only one option is allowed for vxlan and erspan.

[...]

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Are you considering to add tdc tests for the new features in separate patch?

You mean in selftests?
I will post iproute2 side patch to support these first, then considering to add selftests.
(this patch series is the kernel side only)

Yes, I mean tools/testing/selftests/tc-testing/tc-tests/actions/tunnel_key.json

Sure, and it can only be done after tc userspace supports it. Thanks for pointing this .json file out.

#7 lore raw

Re: [PATCH net-next 1/4] net: sched: add vxlan option support to act_tunnel_key

In reply to Xin Long

net/sched/act_tunnel_key.c static int tunnel_key_act(struct sk_buff *skb, const struct tc_action *a, · line 56

Quoted 3 lines · Xin Long
net/sched/act_tunnel_key.c +0 -0
@@ -54,6 +55,7 @@ static int tunnel_key_act(struct sk_buff *skb, const struct tc_action *a,
 static const struct nla_policy
 enc_opts_policy[TCA_TUNNEL_KEY_ENC_OPTS_MAX + 1] = {

[TCA_TUNNEL_KEY_ENC_OPTS_UNSPEC] =

	{ .strict_start_type = TCA_TUNNEL_KEY_ENC_OPTS_VXLAN, }

net/sched/act_tunnel_key.c geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { · line 70

Quoted 11 lines
net/sched/act_tunnel_key.c +3 -0
 	[TCA_TUNNEL_KEY_ENC_OPTS_GENEVE]	= { .type = NLA_NESTED },
+	[TCA_TUNNEL_KEY_ENC_OPTS_VXLAN]		= { .type = NLA_NESTED },
 };
 
 static const struct nla_policy
@@ -64,6 +66,11 @@ geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = {
 						       .len = 128 },
 };
 
+static const struct nla_policy
+vxlan_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX + 1] = {

[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC] =

	{ .strict_type_start = TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC + 1,	}
Quoted 6 lines
net/sched/act_tunnel_key.c +3 -0
+	[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GBP]	   = { .type = NLA_U32 },
+};
+
 static int
 tunnel_key_copy_geneve_opt(const struct nlattr *nla, void *dst, int dst_len,
 			   struct netlink_ext_ack *extack)
#5 lore raw

Re: [PATCH net-next 2/4] net: sched: add erspan option support to act_tunnel_key

In reply to Xin Long
Quoted 30 lines · Xin Long
net/sched/act_tunnel_key.c +26 -0
@@ -149,6 +159,49 @@ tunnel_key_copy_vxlan_opt(const struct nlattr *nla, void *dst, int dst_len,
 	return sizeof(struct vxlan_metadata);
 }
 
+static int
+tunnel_key_copy_erspan_opt(const struct nlattr *nla, void *dst, int dst_len,
+			   struct netlink_ext_ack *extack)
+{
+	struct nlattr *tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX + 1];
+	int err;
+
+	err = nla_parse_nested(tb, TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX, nla,
+			       erspan_opt_policy, extack);
+	if (err < 0)
+		return err;
+
+	if (!tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_VER]) {
+		NL_SET_ERR_MSG(extack, "Missing tunnel key erspan option ver");
+		return -EINVAL;
+	}
+
+	if (dst) {
+		struct erspan_metadata *md = dst;
+
+		nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_VER];
+		md->version = nla_get_u8(nla);
+
+		if (md->version == 1 &&
+		    tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_INDEX]) {
+			nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_INDEX];

net/sched/act_tunnel_key.c tunnel_key_copy_vxlan_opt(const struct nlattr *nla, void *dst, int dst_len, · line 197

Quoted 10 lines
net/sched/act_tunnel_key.c +10 -0
+			md->u.index = nla_get_be32(nla);
+		} else if (md->version == 2 &&
+			   tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_DIR] &&
+			   tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_HWID]) {
+			nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_DIR];
+			md->u.md2.dir = nla_get_u8(nla);
+			nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_HWID];
+			set_hwid(&md->u.md2, nla_get_u8(nla));
+		} else {
+			NL_SET_ERR_MSG(extack, "erspan ver is incorrect or some option is missed");

I think s/missed/missing/

But I think it'd be better if the validation was done also when dst is not yet allocated. I don't think it matters today, just think it'd be cleaner.

Quoted 11 lines
net/sched/act_tunnel_key.c +7 -0
+			return -EINVAL;
+		}
+	}
+
+	return sizeof(struct erspan_metadata);
+}
+
 static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,
 				int dst_len, struct netlink_ext_ack *extack)
 {

net/sched/act_tunnel_key.c static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst, · line 248

Quoted 6 lines
net/sched/act_tunnel_key.c +3 -0
@@ -190,6 +243,18 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,
 			opts_len += opt_len;
 			type = TUNNEL_VXLAN_OPT;
 			break;
+		case TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN:
+			if (type) {
+				NL_SET_ERR_MSG(extack, "Wrong type for erspan options");

Wrong or duplicate, right? If I'm reading this right unlike for Geneve opts there can be only one instance of opts for other types.

Quoted 12 lines
net/sched/act_tunnel_key.c +9 -0
+				return -EINVAL;
+			}
+			opt_len = tunnel_key_copy_erspan_opt(attr, dst,
+							     dst_len, extack);
+			if (opt_len < 0)
+				return opt_len;
+			opts_len += opt_len;
+			type = TUNNEL_ERSPAN_OPT;
+			break;
 		}
 	}
 
author
#8 lore raw

Re: [PATCH net-next 1/4] net: sched: add vxlan option support to act_tunnel_key

In reply to Jakub Kicinski
Quoted 12 lines · Jakub Kicinski

net/sched/act_tunnel_key.c static int tunnel_key_act(struct sk_buff *skb, const struct tc_action *a, · line 56

Quoted 3 lines · Xin Long
net/sched/act_tunnel_key.c +0 -0
@@ -54,6 +55,7 @@ static int tunnel_key_act(struct sk_buff *skb, const struct tc_action *a,
 static const struct nla_policy
 enc_opts_policy[TCA_TUNNEL_KEY_ENC_OPTS_MAX + 1] = {

[TCA_TUNNEL_KEY_ENC_OPTS_UNSPEC] =

        { .strict_start_type = TCA_TUNNEL_KEY_ENC_OPTS_VXLAN, }
Quoted 3 lines
net/sched/act_tunnel_key.c +1 -0
      [TCA_TUNNEL_KEY_ENC_OPTS_GENEVE]        = { .type = NLA_NESTED },
+     [TCA_TUNNEL_KEY_ENC_OPTS_VXLAN]         = { .type = NLA_NESTED },
 };

Agree, this one is necessary.

Quoted 10 lines

net/sched/act_tunnel_key.c geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { · line 70

Quoted 8 lines
net/sched/act_tunnel_key.c +2 -0
 static const struct nla_policy
@@ -64,6 +66,11 @@ geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = {
                                                     .len = 128 },
 };
 
+static const struct nla_policy
+vxlan_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX + 1] = {

[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC] =

Quoted 5 lines
        { .strict_type_start = TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC + 1, }

net/sched/act_tunnel_key.c geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { · line 73

Quoted 3 lines
net/sched/act_tunnel_key.c +3 -0
+     [TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GBP]         = { .type = NLA_U32 },
+};
+

But vxlan_opt_policy is a new policy, and it will be parsed by nla_parse_nested()
where NL_VALIDATE_STRICT has been used.

.strict_type_start is used for setting NL_VALIDATE_STRICT for some new option appending on an old policy.

So I think .strict_type_start is not needed here.

Quoted 3 lines
Quoted 3 lines
net/sched/act_tunnel_key.c +0 -0
 static int
 tunnel_key_copy_geneve_opt(const struct nlattr *nla, void *dst, int dst_len,
                         struct netlink_ext_ack *extack)
author
#6 lore raw

Re: [PATCH net-next 2/4] net: sched: add erspan option support to act_tunnel_key

In reply to Jakub Kicinski
Quoted 36 lines · Jakub Kicinski
Quoted 34 lines · Xin Long
net/sched/act_tunnel_key.c +30 -0
@@ -149,6 +159,49 @@ tunnel_key_copy_vxlan_opt(const struct nlattr *nla, void *dst, int dst_len,
      return sizeof(struct vxlan_metadata);
 }
 
+static int
+tunnel_key_copy_erspan_opt(const struct nlattr *nla, void *dst, int dst_len,
+                        struct netlink_ext_ack *extack)
+{
+     struct nlattr *tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX + 1];
+     int err;
+
+     err = nla_parse_nested(tb, TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_MAX, nla,
+                            erspan_opt_policy, extack);
+     if (err < 0)
+             return err;
+
+     if (!tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_VER]) {
+             NL_SET_ERR_MSG(extack, "Missing tunnel key erspan option ver");
+             return -EINVAL;
+     }
+
+     if (dst) {
+             struct erspan_metadata *md = dst;
+
+             nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_VER];
+             md->version = nla_get_u8(nla);
+
+             if (md->version == 1 &&
+                 tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_INDEX]) {
+                     nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_INDEX];
+                     md->u.index = nla_get_be32(nla);
+             } else if (md->version == 2 &&
+                        tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_DIR] &&
+                        tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_HWID]) {
Quoted 8 lines

net/sched/act_tunnel_key.c tunnel_key_copy_vxlan_opt(const struct nlattr *nla, void *dst, int dst_len, · line 197

Quoted 6 lines
net/sched/act_tunnel_key.c +6 -0
+                     nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_DIR];
+                     md->u.md2.dir = nla_get_u8(nla);
+                     nla = tb[TCA_TUNNEL_KEY_ENC_OPT_ERSPAN_HWID];
+                     set_hwid(&md->u.md2, nla_get_u8(nla));
+             } else {
+                     NL_SET_ERR_MSG(extack, "erspan ver is incorrect or some option is missed");

I think s/missed/missing/

ah right.

Quoted 4 lines

But I think it'd be better if the validation was done also when dst is not yet allocated. I don't think it matters today, just think it'd be cleaner.

sure, I can improve in that way.

Quoted 13 lines
Quoted 13 lines
net/sched/act_tunnel_key.c +7 -0
+                     return -EINVAL;
+             }
+     }
+
+     return sizeof(struct erspan_metadata);
+}
+
 static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,
                              int dst_len, struct netlink_ext_ack *extack)
 {
@@ -190,6 +243,18 @@ static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst,
                      opts_len += opt_len;
Quoted 8 lines

net/sched/act_tunnel_key.c static int tunnel_key_copy_opts(const struct nlattr *nla, u8 *dst, · line 248

Quoted 5 lines
net/sched/act_tunnel_key.c +3 -0
                      type = TUNNEL_VXLAN_OPT;
                      break;
+             case TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN:
+                     if (type) {
+                             NL_SET_ERR_MSG(extack, "Wrong type for erspan options");

Wrong or duplicate, right? If I'm reading this right unlike for Geneve opts there can be only one instance of opts for other types.

yes, 'Duplicate' is better,
will change to "Duplicate type for erspan options", as well as for vxlan.

Thanks.

Quoted 13 lines
Quoted 13 lines
net/sched/act_tunnel_key.c +9 -0
+                             return -EINVAL;
+                     }
+                     opt_len = tunnel_key_copy_erspan_opt(attr, dst,
+                                                          dst_len, extack);
+                     if (opt_len < 0)
+                             return opt_len;
+                     opts_len += opt_len;
+                     type = TUNNEL_ERSPAN_OPT;
+                     break;
              }
      }
 
#9 lore raw

Re: [PATCH net-next 1/4] net: sched: add vxlan option support to act_tunnel_key

In reply to Xin Long
Quoted 14 lines · Xin Long
Quoted 5 lines
Quoted 5 lines

static const struct nla_policy

net/sched/act_tunnel_key.c +0 -0
@@ -64,6 +66,11 @@ geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = {
                                                     .len = 128 },
 };
 
Quoted 9 lines

net/sched/act_tunnel_key.c geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { · line 70

Quoted 2 lines
net/sched/act_tunnel_key.c +2 -0
+static const struct nla_policy
+vxlan_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX + 1] = {  

[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC] =

        { .strict_type_start = TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC + 1, }
Quoted 3 lines
net/sched/act_tunnel_key.c +3 -0
+     [TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GBP]         = { .type = NLA_U32 },
+};
+  
Quoted 8 lines

But vxlan_opt_policy is a new policy, and it will be parsed by nla_parse_nested()
where NL_VALIDATE_STRICT has been used.

.strict_type_start is used for setting NL_VALIDATE_STRICT for some new option appending on an old policy.

So I think .strict_type_start is not needed here.

Hm, that's what I thought but then we were asked to add it in act_mpls.c. I should've checked the code.

Anyway, we should probably clean up act_mpls.c and act_ct.c so people don't copy it unnecessarily.

author
#10 lore raw

Re: [PATCH net-next 1/4] net: sched: add vxlan option support to act_tunnel_key

Quoted 23 lines · Jakub Kicinski
Quoted 21 lines · Xin Long
Quoted 9 lines

net/sched/act_tunnel_key.c geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { · line 70

Quoted 7 lines

static const struct nla_policy

net/sched/act_tunnel_key.c +2 -0
@@ -64,6 +66,11 @@ geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = {
                                                     .len = 128 },
 };
 
+static const struct nla_policy
+vxlan_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_MAX + 1] = {

[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC] =

Quoted 5 lines
        { .strict_type_start = TCA_TUNNEL_KEY_ENC_OPT_VXLAN_UNSPEC + 1, }

net/sched/act_tunnel_key.c geneve_opt_policy[TCA_TUNNEL_KEY_ENC_OPT_GENEVE_MAX + 1] = { · line 73

Quoted 3 lines
net/sched/act_tunnel_key.c +3 -0
+     [TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GBP]         = { .type = NLA_U32 },
+};
+

But vxlan_opt_policy is a new policy, and it will be parsed by nla_parse_nested()
where NL_VALIDATE_STRICT has been used.

.strict_type_start is used for setting NL_VALIDATE_STRICT for some new option appending on an old policy.

Quoted 7 lines
Quoted 1 line

So I think .strict_type_start is not needed here.

Hm, that's what I thought but then we were asked to add it in act_mpls.c. I should've checked the code.

Anyway, we should probably clean up act_mpls.c and act_ct.c so people don't copy it unnecessarily.

will send a cleanup, also for the one in net/ipv4/nexthop.c. Thanks.

#11 lore raw

Re: [PATCH net-next 1/4] net: sched: add vxlan option support to act_tunnel_key

Quoted 6 lines · Xin Long
Quoted 5 lines

Hm, that's what I thought but then we were asked to add it in act_mpls.c. I should've checked the code.

Anyway, we should probably clean up act_mpls.c and act_ct.c so people don't copy it unnecessarily.

will send a cleanup, also for the one in net/ipv4/nexthop.c.

thanks. Clearly, I forgot .strict_type_start does not apply to users of the new API.