Skip to content

Commit 823aa87

Browse files
shemmingerdavem330
authored andcommitted
vxlan: allow choosing destination port per vxlan
Allow configuring the default destination port on a per-device basis. Adds new netlink paramater IFLA_VXLAN_PORT to allow setting destination port when creating new vxlan. Signed-off-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7d836a7 commit 823aa87

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

drivers/net/vxlan.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct vxlan_dev {
110110
struct net_device *dev;
111111
struct vxlan_rdst default_dst; /* default destination */
112112
__be32 saddr; /* source address */
113+
__be16 dst_port;
113114
__u16 port_min; /* source port range */
114115
__u16 port_max;
115116
__u8 tos; /* TOS override */
@@ -192,7 +193,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
192193
if (send_ip && nla_put_be32(skb, NDA_DST, rdst->remote_ip))
193194
goto nla_put_failure;
194195

195-
if (rdst->remote_port && rdst->remote_port != htons(vxlan_port) &&
196+
if (rdst->remote_port && rdst->remote_port != vxlan->dst_port &&
196197
nla_put_be16(skb, NDA_PORT, rdst->remote_port))
197198
goto nla_put_failure;
198199
if (rdst->remote_vni != vxlan->default_dst.remote_vni &&
@@ -467,7 +468,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
467468
return -EINVAL;
468469
port = nla_get_be16(tb[NDA_PORT]);
469470
} else
470-
port = htons(vxlan_port);
471+
port = vxlan->dst_port;
471472

472473
if (tb[NDA_VNI]) {
473474
if (nla_len(tb[NDA_VNI]) != sizeof(u32))
@@ -579,7 +580,7 @@ static void vxlan_snoop(struct net_device *dev,
579580
err = vxlan_fdb_create(vxlan, src_mac, src_ip,
580581
NUD_REACHABLE,
581582
NLM_F_EXCL|NLM_F_CREATE,
582-
vxlan_port,
583+
vxlan->dst_port,
583584
vxlan->default_dst.remote_vni,
584585
0, NTF_SELF);
585586
spin_unlock(&vxlan->hash_lock);
@@ -970,7 +971,7 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
970971
__be16 df = 0;
971972
__u8 tos, ttl;
972973

973-
dst_port = rdst->remote_port ? rdst->remote_port : htons(vxlan_port);
974+
dst_port = rdst->remote_port ? rdst->remote_port : vxlan->dst_port;
974975
vni = rdst->remote_vni;
975976
dst = rdst->remote_ip;
976977

@@ -1314,6 +1315,7 @@ static void vxlan_setup(struct net_device *dev)
13141315
inet_get_local_port_range(&low, &high);
13151316
vxlan->port_min = low;
13161317
vxlan->port_max = high;
1318+
vxlan->dst_port = htons(vxlan_port);
13171319

13181320
vxlan->dev = dev;
13191321

@@ -1336,6 +1338,7 @@ static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = {
13361338
[IFLA_VXLAN_RSC] = { .type = NLA_U8 },
13371339
[IFLA_VXLAN_L2MISS] = { .type = NLA_U8 },
13381340
[IFLA_VXLAN_L3MISS] = { .type = NLA_U8 },
1341+
[IFLA_VXLAN_PORT] = { .type = NLA_U16 },
13391342
};
13401343

13411344
static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[])
@@ -1465,6 +1468,9 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
14651468
vxlan->port_max = ntohs(p->high);
14661469
}
14671470

1471+
if (data[IFLA_VXLAN_PORT])
1472+
vxlan->dst_port = nla_get_be16(data[IFLA_VXLAN_PORT]);
1473+
14681474
SET_ETHTOOL_OPS(dev, &vxlan_ethtool_ops);
14691475

14701476
err = register_netdevice(dev);
@@ -1500,6 +1506,7 @@ static size_t vxlan_get_size(const struct net_device *dev)
15001506
nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_AGEING */
15011507
nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LIMIT */
15021508
nla_total_size(sizeof(struct ifla_vxlan_port_range)) +
1509+
nla_total_size(sizeof(__be16))+ /* IFLA_VXLAN_PORT */
15031510
0;
15041511
}
15051512

@@ -1536,7 +1543,8 @@ static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
15361543
nla_put_u8(skb, IFLA_VXLAN_L3MISS,
15371544
!!(vxlan->flags & VXLAN_F_L3MISS)) ||
15381545
nla_put_u32(skb, IFLA_VXLAN_AGEING, vxlan->age_interval) ||
1539-
nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->addrmax))
1546+
nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->addrmax) ||
1547+
nla_put_be16(skb, IFLA_VXLAN_PORT, vxlan->dst_port))
15401548
goto nla_put_failure;
15411549

15421550
if (nla_put(skb, IFLA_VXLAN_PORT_RANGE, sizeof(ports), &ports))

include/uapi/linux/if_link.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,12 @@ enum {
305305
IFLA_VXLAN_LEARNING,
306306
IFLA_VXLAN_AGEING,
307307
IFLA_VXLAN_LIMIT,
308-
IFLA_VXLAN_PORT_RANGE,
308+
IFLA_VXLAN_PORT_RANGE, /* source port */
309309
IFLA_VXLAN_PROXY,
310310
IFLA_VXLAN_RSC,
311311
IFLA_VXLAN_L2MISS,
312312
IFLA_VXLAN_L3MISS,
313+
IFLA_VXLAN_PORT, /* destination port */
313314
__IFLA_VXLAN_MAX
314315
};
315316
#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1)

0 commit comments

Comments
 (0)