Skip to contentSkip to conversation

net: improve vxlan option process in net_sched and lwtunnel

PATCH In review Xin Long 2 participants 4 messages Sep 13, 2020 – Sep 14, 2020

Subsystems (4)
lore
Share & tools
lore

Xin Long

author
#0 lore raw

cover net: improve vxlan option process in net_sched and lwtunnel

This patch is to do some mask when setting vxlan option in net_sched and lwtunnel, so that only available bits can be set on vxlan md gbp.

This would help when users don't know exactly vxlan's gbp bits, and avoid some mismatch because of some unavailable bits set by users.

Xin Long (2):
net: sched: only keep the available bits when setting vxlan md->gbp
lwtunnel: only keep the available bits when setting vxlan md->gbp

 include/net/vxlan.h        | 3 +++
 net/ipv4/ip_tunnel_core.c  | 1 +
 net/sched/act_tunnel_key.c | 1 +
 net/sched/cls_flower.c     | 4 +++-
 4 files changed, 8 insertions(+), 1 deletion(-)
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH 1/2 net: sched: only keep the available bits when setting vxlan md->gbp

As we can see from vxlan_build/parse_gbp_hdr(), when processing metadata on vxlan rx/tx path, only dont_learn/policy_applied/policy_id fields can be set to or parse from the packet for vxlan gbp option.

So we'd better do the mask when set it in act_tunnel_key and cls_flower. Otherwise, when users don't know these bits, they may configure with a value which can never be matched.

---
 include/net/vxlan.h        | 3 +++
 net/sched/act_tunnel_key.c | 1 +
 net/sched/cls_flower.c     | 4 +++-
 3 files changed, 7 insertions(+), 1 deletion(-)
include/net/vxlan.h +3 -0
index 3a41627c..08537aa 100644
@@ -121,6 +121,9 @@ struct vxlanhdr_gbp {
 #define VXLAN_GBP_POLICY_APPLIED	(BIT(3) << 16)
 #define VXLAN_GBP_ID_MASK		(0xFFFF)
 
+#define VXLAN_GBP_MASK (VXLAN_GBP_DONT_LEARN | VXLAN_GBP_POLICY_APPLIED | \
+			VXLAN_GBP_ID_MASK)
+
 /*
  * VXLAN Generic Protocol Extension (VXLAN_F_GPE):
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
net/sched/act_tunnel_key.c +1 -0
index 536c4bc..37f1e10 100644
@@ -156,6 +156,7 @@ tunnel_key_copy_vxlan_opt(const struct nlattr *nla, void *dst, int dst_len,
 		struct vxlan_metadata *md = dst;
 
 		md->gbp = nla_get_u32(tb[TCA_TUNNEL_KEY_ENC_OPT_VXLAN_GBP]);
+		md->gbp &= VXLAN_GBP_MASK;
 	}
 
 	return sizeof(struct vxlan_metadata);
net/sched/cls_flower.c +3 -1
index 19a8fa2..fed18fd 100644
@@ -1175,8 +1175,10 @@ static int fl_set_vxlan_opt(const struct nlattr *nla, struct fl_flow_key *key,
 		return -EINVAL;
 	}
 
-	if (tb[TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP])
+	if (tb[TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP]) {
 		md->gbp = nla_get_u32(tb[TCA_FLOWER_KEY_ENC_OPT_VXLAN_GBP]);
+		md->gbp &= VXLAN_GBP_MASK;
+	}
 
 	return sizeof(*md);
 }
Signature · 1 line
2.1.0
author
#2 lore raw

PATCH 2/2 lwtunnel: only keep the available bits when setting vxlan md->gbp

As we can see from vxlan_build/parse_gbp_hdr(), when processing metadata on vxlan rx/tx path, only dont_learn/policy_applied/policy_id fields can be set to or parse from the packet for vxlan gbp option.

So do the mask when set it in lwtunnel, as it does in act_tunnel_key and cls_flower.

---
 net/ipv4/ip_tunnel_core.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/ip_tunnel_core.c +1 -0
index 75c6013..b2ea1a8 100644
@@ -554,6 +554,7 @@ static int ip_tun_parse_opts_vxlan(struct nlattr *attr,
 
 		attr = tb[LWTUNNEL_IP_OPT_VXLAN_GBP];
 		md->gbp = nla_get_u32(attr);
+		md->gbp &= VXLAN_GBP_MASK;
 		info->key.tun_flags |= TUNNEL_VXLAN_OPT;
 	}
 
Signature · 1 line
2.1.0
maintainer
#3 lore raw
In reply to Xin Long

From: Xin Long <[email protected]>
Date: Sun, 13 Sep 2020 19:51:49 +0800

Quoted 5 lines

This patch is to do some mask when setting vxlan option in net_sched and lwtunnel, so that only available bits can be set on vxlan md gbp.

This would help when users don't know exactly vxlan's gbp bits, and avoid some mismatch because of some unavailable bits set by users.

Series applied, thank you.