Skip to content

Commit c6e9dba

Browse files
alcelafranquedavem330
authored andcommitted
vxlan: add support for flowlabel inherit
By default, VXLAN encapsulation over IPv6 sets the flow label to 0, with an option for a fixed value. This commits add the ability to inherit the flow label from the inner packet, like for other tunnel implementations. This enables devices using only L3 headers for ECMP to correctly balance VXLAN-encapsulated IPv6 packets. ``` $ ./ip/ip link add dummy1 type dummy $ ./ip/ip addr add 2001:db8::2/64 dev dummy1 $ ./ip/ip link set up dev dummy1 $ ./ip/ip link add vxlan1 type vxlan id 100 flowlabel inherit remote 2001:db8::1 local 2001:db8::2 $ ./ip/ip link set up dev vxlan1 $ ./ip/ip addr add 2001:db8:1::2/64 dev vxlan1 $ ./ip/ip link set arp off dev vxlan1 $ ping -q 2001:db8:1::1 & $ tshark -d udp.port==8472,vxlan -Vpni dummy1 -c1 [...] Internet Protocol Version 6, Src: 2001:db8::2, Dst: 2001:db8::1 0110 .... = Version: 6 .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) .... 0000 00.. .... .... .... .... .... = Differentiated Services Codepoint: Default (0) .... .... ..00 .... .... .... .... .... = Explicit Congestion Notification: Not ECN-Capable Transport (0) .... 1011 0001 1010 1111 1011 = Flow Label: 0xb1afb [...] Virtual eXtensible Local Area Network Flags: 0x0800, VXLAN Network ID (VNI) Group Policy ID: 0 VXLAN Network Identifier (VNI): 100 [...] Internet Protocol Version 6, Src: 2001:db8:1::2, Dst: 2001:db8:1::1 0110 .... = Version: 6 .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT) .... 0000 00.. .... .... .... .... .... = Differentiated Services Codepoint: Default (0) .... .... ..00 .... .... .... .... .... = Explicit Congestion Notification: Not ECN-Capable Transport (0) .... 1011 0001 1010 1111 1011 = Flow Label: 0xb1afb ``` Signed-off-by: Alce Lafranque <alce@lafranque.net> Co-developed-by: Vincent Bernat <vincent@bernat.ch> Signed-off-by: Vincent Bernat <vincent@bernat.ch> Reviewed-by: Ido Schimmel <idosch@nvidia.com> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 3bdd9fd commit c6e9dba

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-17
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2379,7 +2379,17 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
23792379
else
23802380
udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX);
23812381
#if IS_ENABLED(CONFIG_IPV6)
2382-
key.label = vxlan->cfg.label;
2382+
switch (vxlan->cfg.label_policy) {
2383+
case VXLAN_LABEL_FIXED:
2384+
key.label = vxlan->cfg.label;
2385+
break;
2386+
case VXLAN_LABEL_INHERIT:
2387+
key.label = ip_tunnel_get_flowlabel(old_iph, skb);
2388+
break;
2389+
default:
2390+
DEBUG_NET_WARN_ON_ONCE(1);
2391+
goto drop;
2392+
}
23832393
#endif
23842394
} else {
23852395
if (!info) {
@@ -3366,6 +3376,7 @@ static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = {
33663376
[IFLA_VXLAN_DF] = { .type = NLA_U8 },
33673377
[IFLA_VXLAN_VNIFILTER] = { .type = NLA_U8 },
33683378
[IFLA_VXLAN_LOCALBYPASS] = NLA_POLICY_MAX(NLA_U8, 1),
3379+
[IFLA_VXLAN_LABEL_POLICY] = NLA_POLICY_MAX(NLA_U32, VXLAN_LABEL_MAX),
33693380
};
33703381

33713382
static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[],
@@ -3740,6 +3751,12 @@ static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf,
37403751
return -EINVAL;
37413752
}
37423753

3754+
if (conf->label_policy && !use_ipv6) {
3755+
NL_SET_ERR_MSG(extack,
3756+
"Label policy only applies to IPv6 VXLAN devices");
3757+
return -EINVAL;
3758+
}
3759+
37433760
if (conf->remote_ifindex) {
37443761
struct net_device *lowerdev;
37453762

@@ -4082,6 +4099,8 @@ static int vxlan_nl2conf(struct nlattr *tb[], struct nlattr *data[],
40824099
if (data[IFLA_VXLAN_LABEL])
40834100
conf->label = nla_get_be32(data[IFLA_VXLAN_LABEL]) &
40844101
IPV6_FLOWLABEL_MASK;
4102+
if (data[IFLA_VXLAN_LABEL_POLICY])
4103+
conf->label_policy = nla_get_u32(data[IFLA_VXLAN_LABEL_POLICY]);
40854104

40864105
if (data[IFLA_VXLAN_LEARNING]) {
40874106
err = vxlan_nl2flag(conf, data, IFLA_VXLAN_LEARNING,
@@ -4398,6 +4417,7 @@ static size_t vxlan_get_size(const struct net_device *dev)
43984417
nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TOS */
43994418
nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_DF */
44004419
nla_total_size(sizeof(__be32)) + /* IFLA_VXLAN_LABEL */
4420+
nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LABEL_POLICY */
44014421
nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_LEARNING */
44024422
nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_PROXY */
44034423
nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_RSC */
@@ -4471,6 +4491,7 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
44714491
nla_put_u8(skb, IFLA_VXLAN_TOS, vxlan->cfg.tos) ||
44724492
nla_put_u8(skb, IFLA_VXLAN_DF, vxlan->cfg.df) ||
44734493
nla_put_be32(skb, IFLA_VXLAN_LABEL, vxlan->cfg.label) ||
4494+
nla_put_u32(skb, IFLA_VXLAN_LABEL_POLICY, vxlan->cfg.label_policy) ||
44744495
nla_put_u8(skb, IFLA_VXLAN_LEARNING,
44754496
!!(vxlan->cfg.flags & VXLAN_F_LEARN)) ||
44764497
nla_put_u8(skb, IFLA_VXLAN_PROXY,

include/net/ip_tunnels.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,17 @@ static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
416416
return 0;
417417
}
418418

419+
static inline __be32 ip_tunnel_get_flowlabel(const struct iphdr *iph,
420+
const struct sk_buff *skb)
421+
{
422+
__be16 payload_protocol = skb_protocol(skb, true);
423+
424+
if (payload_protocol == htons(ETH_P_IPV6))
425+
return ip6_flowlabel((const struct ipv6hdr *)iph);
426+
else
427+
return 0;
428+
}
429+
419430
static inline u8 ip_tunnel_get_ttl(const struct iphdr *iph,
420431
const struct sk_buff *skb)
421432
{

include/net/vxlan.h

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,22 +210,23 @@ struct vxlan_rdst {
210210
};
211211

212212
struct vxlan_config {
213-
union vxlan_addr remote_ip;
214-
union vxlan_addr saddr;
215-
__be32 vni;
216-
int remote_ifindex;
217-
int mtu;
218-
__be16 dst_port;
219-
u16 port_min;
220-
u16 port_max;
221-
u8 tos;
222-
u8 ttl;
223-
__be32 label;
224-
u32 flags;
225-
unsigned long age_interval;
226-
unsigned int addrmax;
227-
bool no_share;
228-
enum ifla_vxlan_df df;
213+
union vxlan_addr remote_ip;
214+
union vxlan_addr saddr;
215+
__be32 vni;
216+
int remote_ifindex;
217+
int mtu;
218+
__be16 dst_port;
219+
u16 port_min;
220+
u16 port_max;
221+
u8 tos;
222+
u8 ttl;
223+
__be32 label;
224+
enum ifla_vxlan_label_policy label_policy;
225+
u32 flags;
226+
unsigned long age_interval;
227+
unsigned int addrmax;
228+
bool no_share;
229+
enum ifla_vxlan_df df;
229230
};
230231

231232
enum {

include/uapi/linux/if_link.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ enum {
856856
IFLA_VXLAN_DF,
857857
IFLA_VXLAN_VNIFILTER, /* only applicable with COLLECT_METADATA mode */
858858
IFLA_VXLAN_LOCALBYPASS,
859+
IFLA_VXLAN_LABEL_POLICY, /* IPv6 flow label policy; ifla_vxlan_label_policy */
859860
__IFLA_VXLAN_MAX
860861
};
861862
#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)
@@ -873,6 +874,13 @@ enum ifla_vxlan_df {
873874
VXLAN_DF_MAX = __VXLAN_DF_END - 1,
874875
};
875876

877+
enum ifla_vxlan_label_policy {
878+
VXLAN_LABEL_FIXED = 0,
879+
VXLAN_LABEL_INHERIT = 1,
880+
__VXLAN_LABEL_END,
881+
VXLAN_LABEL_MAX = __VXLAN_LABEL_END - 1,
882+
};
883+
876884
/* GENEVE section */
877885
enum {
878886
IFLA_GENEVE_UNSPEC,

0 commit comments

Comments
 (0)