Skip to content

Commit c7995c4

Browse files
iAtsumuWatanabedavem330
authored andcommitted
vxlan: Allow setting destination to unicast address.
This patch allows setting VXLAN destination to unicast address. It allows that VXLAN can be used as peer-to-peer tunnel without multicast. v4: generalize struct vxlan_dev, "gaddr" is replaced with vxlan_rdst. "GROUP" attribute is replaced with "REMOTE". they are based by David Stevens's comments. v3: move a new attribute REMOTE into the last of an enum list based by Stephen Hemminger's comments. v2: use a new attribute REMOTE instead of GROUP based by Cong Wang's comments. Signed-off-by: Atzm Watanabe <[email protected]> Acked-by: David L Stevens <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 184f489 commit c7995c4

File tree

2 files changed

+31
-44
lines changed

2 files changed

+31
-44
lines changed

drivers/net/vxlan.c

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ struct vxlan_fdb {
105105
struct vxlan_dev {
106106
struct hlist_node hlist;
107107
struct net_device *dev;
108-
__u32 vni; /* virtual network id */
109-
__be32 gaddr; /* multicast group */
108+
struct vxlan_rdst default_dst; /* default destination */
110109
__be32 saddr; /* source address */
111-
unsigned int link; /* link to multicast over */
112110
__u16 port_min; /* source port range */
113111
__u16 port_max;
114112
__u8 tos; /* TOS override */
@@ -146,7 +144,7 @@ static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id)
146144
struct vxlan_dev *vxlan;
147145

148146
hlist_for_each_entry_rcu(vxlan, vni_head(net, id), hlist) {
149-
if (vxlan->vni == id)
147+
if (vxlan->default_dst.remote_vni == id)
150148
return vxlan;
151149
}
152150

@@ -194,7 +192,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
194192
if (rdst->remote_port && rdst->remote_port != vxlan_port &&
195193
nla_put_be16(skb, NDA_PORT, rdst->remote_port))
196194
goto nla_put_failure;
197-
if (rdst->remote_vni != vxlan->vni &&
195+
if (rdst->remote_vni != vxlan->default_dst.remote_vni &&
198196
nla_put_be32(skb, NDA_VNI, rdst->remote_vni))
199197
goto nla_put_failure;
200198
if (rdst->remote_ifindex &&
@@ -465,7 +463,7 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
465463
return -EINVAL;
466464
vni = nla_get_u32(tb[NDA_VNI]);
467465
} else
468-
vni = vxlan->vni;
466+
vni = vxlan->default_dst.remote_vni;
469467

470468
if (tb[NDA_IFINDEX]) {
471469
struct net_device *tdev;
@@ -570,7 +568,7 @@ static void vxlan_snoop(struct net_device *dev,
570568
err = vxlan_fdb_create(vxlan, src_mac, src_ip,
571569
NUD_REACHABLE,
572570
NLM_F_EXCL|NLM_F_CREATE,
573-
vxlan_port, vxlan->vni, 0);
571+
vxlan_port, vxlan->default_dst.remote_vni, 0);
574572
spin_unlock(&vxlan->hash_lock);
575573
}
576574
}
@@ -591,7 +589,7 @@ static bool vxlan_group_used(struct vxlan_net *vn,
591589
if (!netif_running(vxlan->dev))
592590
continue;
593591

594-
if (vxlan->gaddr == this->gaddr)
592+
if (vxlan->default_dst.remote_ip == this->default_dst.remote_ip)
595593
return true;
596594
}
597595

@@ -605,8 +603,8 @@ static int vxlan_join_group(struct net_device *dev)
605603
struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
606604
struct sock *sk = vn->sock->sk;
607605
struct ip_mreqn mreq = {
608-
.imr_multiaddr.s_addr = vxlan->gaddr,
609-
.imr_ifindex = vxlan->link,
606+
.imr_multiaddr.s_addr = vxlan->default_dst.remote_ip,
607+
.imr_ifindex = vxlan->default_dst.remote_ifindex,
610608
};
611609
int err;
612610

@@ -633,8 +631,8 @@ static int vxlan_leave_group(struct net_device *dev)
633631
int err = 0;
634632
struct sock *sk = vn->sock->sk;
635633
struct ip_mreqn mreq = {
636-
.imr_multiaddr.s_addr = vxlan->gaddr,
637-
.imr_ifindex = vxlan->link,
634+
.imr_multiaddr.s_addr = vxlan->default_dst.remote_ip,
635+
.imr_ifindex = vxlan->default_dst.remote_ifindex,
638636
};
639637

640638
/* Only leave group when last vxlan is done. */
@@ -1091,7 +1089,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
10911089
struct vxlan_dev *vxlan = netdev_priv(dev);
10921090
struct ethhdr *eth;
10931091
bool did_rsc = false;
1094-
struct vxlan_rdst group, *rdst0, *rdst;
1092+
struct vxlan_rdst *rdst0, *rdst;
10951093
struct vxlan_fdb *f;
10961094
int rc1, rc;
10971095

@@ -1106,14 +1104,9 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)
11061104
f = vxlan_find_mac(vxlan, eth->h_dest);
11071105
if (f == NULL) {
11081106
did_rsc = false;
1109-
group.remote_port = vxlan_port;
1110-
group.remote_vni = vxlan->vni;
1111-
group.remote_ip = vxlan->gaddr;
1112-
group.remote_ifindex = vxlan->link;
1113-
group.remote_next = NULL;
1114-
rdst0 = &group;
1115-
1116-
if (group.remote_ip == htonl(INADDR_ANY) &&
1107+
rdst0 = &vxlan->default_dst;
1108+
1109+
if (rdst0->remote_ip == htonl(INADDR_ANY) &&
11171110
(vxlan->flags & VXLAN_F_L2MISS) &&
11181111
!is_multicast_ether_addr(eth->h_dest))
11191112
vxlan_fdb_miss(vxlan, eth->h_dest);
@@ -1191,7 +1184,7 @@ static int vxlan_open(struct net_device *dev)
11911184
struct vxlan_dev *vxlan = netdev_priv(dev);
11921185
int err;
11931186

1194-
if (vxlan->gaddr) {
1187+
if (IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip))) {
11951188
err = vxlan_join_group(dev);
11961189
if (err)
11971190
return err;
@@ -1225,7 +1218,7 @@ static int vxlan_stop(struct net_device *dev)
12251218
{
12261219
struct vxlan_dev *vxlan = netdev_priv(dev);
12271220

1228-
if (vxlan->gaddr)
1221+
if (IN_MULTICAST(ntohl(vxlan->default_dst.remote_ip)))
12291222
vxlan_leave_group(dev);
12301223

12311224
del_timer_sync(&vxlan->age_timer);
@@ -1311,7 +1304,7 @@ static void vxlan_setup(struct net_device *dev)
13111304

13121305
static const struct nla_policy vxlan_policy[IFLA_VXLAN_MAX + 1] = {
13131306
[IFLA_VXLAN_ID] = { .type = NLA_U32 },
1314-
[IFLA_VXLAN_GROUP] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
1307+
[IFLA_VXLAN_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
13151308
[IFLA_VXLAN_LINK] = { .type = NLA_U32 },
13161309
[IFLA_VXLAN_LOCAL] = { .len = FIELD_SIZEOF(struct iphdr, saddr) },
13171310
[IFLA_VXLAN_TOS] = { .type = NLA_U8 },
@@ -1349,14 +1342,6 @@ static int vxlan_validate(struct nlattr *tb[], struct nlattr *data[])
13491342
return -ERANGE;
13501343
}
13511344

1352-
if (data[IFLA_VXLAN_GROUP]) {
1353-
__be32 gaddr = nla_get_be32(data[IFLA_VXLAN_GROUP]);
1354-
if (!IN_MULTICAST(ntohl(gaddr))) {
1355-
pr_debug("group address is not IPv4 multicast\n");
1356-
return -EADDRNOTAVAIL;
1357-
}
1358-
}
1359-
13601345
if (data[IFLA_VXLAN_PORT_RANGE]) {
13611346
const struct ifla_vxlan_port_range *p
13621347
= nla_data(data[IFLA_VXLAN_PORT_RANGE]);
@@ -1387,6 +1372,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
13871372
struct nlattr *tb[], struct nlattr *data[])
13881373
{
13891374
struct vxlan_dev *vxlan = netdev_priv(dev);
1375+
struct vxlan_rdst *dst = &vxlan->default_dst;
13901376
__u32 vni;
13911377
int err;
13921378

@@ -1398,21 +1384,21 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
13981384
pr_info("duplicate VNI %u\n", vni);
13991385
return -EEXIST;
14001386
}
1401-
vxlan->vni = vni;
1387+
dst->remote_vni = vni;
14021388

1403-
if (data[IFLA_VXLAN_GROUP])
1404-
vxlan->gaddr = nla_get_be32(data[IFLA_VXLAN_GROUP]);
1389+
if (data[IFLA_VXLAN_REMOTE])
1390+
dst->remote_ip = nla_get_be32(data[IFLA_VXLAN_REMOTE]);
14051391

14061392
if (data[IFLA_VXLAN_LOCAL])
14071393
vxlan->saddr = nla_get_be32(data[IFLA_VXLAN_LOCAL]);
14081394

14091395
if (data[IFLA_VXLAN_LINK] &&
1410-
(vxlan->link = nla_get_u32(data[IFLA_VXLAN_LINK]))) {
1396+
(dst->remote_ifindex = nla_get_u32(data[IFLA_VXLAN_LINK]))) {
14111397
struct net_device *lowerdev
1412-
= __dev_get_by_index(net, vxlan->link);
1398+
= __dev_get_by_index(net, dst->remote_ifindex);
14131399

14141400
if (!lowerdev) {
1415-
pr_info("ifindex %d does not exist\n", vxlan->link);
1401+
pr_info("ifindex %d does not exist\n", dst->remote_ifindex);
14161402
return -ENODEV;
14171403
}
14181404

@@ -1464,7 +1450,7 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
14641450

14651451
err = register_netdevice(dev);
14661452
if (!err)
1467-
hlist_add_head_rcu(&vxlan->hlist, vni_head(net, vxlan->vni));
1453+
hlist_add_head_rcu(&vxlan->hlist, vni_head(net, dst->remote_vni));
14681454

14691455
return err;
14701456
}
@@ -1482,7 +1468,7 @@ static size_t vxlan_get_size(const struct net_device *dev)
14821468
{
14831469

14841470
return nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_ID */
1485-
nla_total_size(sizeof(__be32)) +/* IFLA_VXLAN_GROUP */
1471+
nla_total_size(sizeof(__be32)) +/* IFLA_VXLAN_REMOTE */
14861472
nla_total_size(sizeof(__u32)) + /* IFLA_VXLAN_LINK */
14871473
nla_total_size(sizeof(__be32))+ /* IFLA_VXLAN_LOCAL */
14881474
nla_total_size(sizeof(__u8)) + /* IFLA_VXLAN_TTL */
@@ -1501,18 +1487,19 @@ static size_t vxlan_get_size(const struct net_device *dev)
15011487
static int vxlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
15021488
{
15031489
const struct vxlan_dev *vxlan = netdev_priv(dev);
1490+
const struct vxlan_rdst *dst = &vxlan->default_dst;
15041491
struct ifla_vxlan_port_range ports = {
15051492
.low = htons(vxlan->port_min),
15061493
.high = htons(vxlan->port_max),
15071494
};
15081495

1509-
if (nla_put_u32(skb, IFLA_VXLAN_ID, vxlan->vni))
1496+
if (nla_put_u32(skb, IFLA_VXLAN_ID, dst->remote_vni))
15101497
goto nla_put_failure;
15111498

1512-
if (vxlan->gaddr && nla_put_be32(skb, IFLA_VXLAN_GROUP, vxlan->gaddr))
1499+
if (dst->remote_ip && nla_put_be32(skb, IFLA_VXLAN_REMOTE, dst->remote_ip))
15131500
goto nla_put_failure;
15141501

1515-
if (vxlan->link && nla_put_u32(skb, IFLA_VXLAN_LINK, vxlan->link))
1502+
if (dst->remote_ifindex && nla_put_u32(skb, IFLA_VXLAN_LINK, dst->remote_ifindex))
15161503
goto nla_put_failure;
15171504

15181505
if (vxlan->saddr && nla_put_be32(skb, IFLA_VXLAN_LOCAL, vxlan->saddr))

include/uapi/linux/if_link.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ enum macvlan_mode {
296296
enum {
297297
IFLA_VXLAN_UNSPEC,
298298
IFLA_VXLAN_ID,
299-
IFLA_VXLAN_GROUP,
299+
IFLA_VXLAN_REMOTE,
300300
IFLA_VXLAN_LINK,
301301
IFLA_VXLAN_LOCAL,
302302
IFLA_VXLAN_TTL,

0 commit comments

Comments
 (0)