Skip to content

Commit efe0f94

Browse files
p-roopadavem330
authored andcommitted
vxlan_core: add helper vxlan_vni_in_use
more users in follow up patches Signed-off-by: Roopa Prabhu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a9508d1 commit efe0f94

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3554,13 +3554,38 @@ static int vxlan_sock_add(struct vxlan_dev *vxlan)
35543554
return ret;
35553555
}
35563556

3557+
static int vxlan_vni_in_use(struct net *src_net, struct vxlan_dev *vxlan,
3558+
struct vxlan_config *conf, __be32 vni)
3559+
{
3560+
struct vxlan_net *vn = net_generic(src_net, vxlan_net_id);
3561+
struct vxlan_dev *tmp;
3562+
3563+
list_for_each_entry(tmp, &vn->vxlan_list, next) {
3564+
if (tmp == vxlan)
3565+
continue;
3566+
if (tmp->cfg.vni != vni)
3567+
continue;
3568+
if (tmp->cfg.dst_port != conf->dst_port)
3569+
continue;
3570+
if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) !=
3571+
(conf->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)))
3572+
continue;
3573+
3574+
if ((conf->flags & VXLAN_F_IPV6_LINKLOCAL) &&
3575+
tmp->cfg.remote_ifindex != conf->remote_ifindex)
3576+
continue;
3577+
3578+
return -EEXIST;
3579+
}
3580+
3581+
return 0;
3582+
}
3583+
35573584
static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf,
35583585
struct net_device **lower,
35593586
struct vxlan_dev *old,
35603587
struct netlink_ext_ack *extack)
35613588
{
3562-
struct vxlan_net *vn = net_generic(src_net, vxlan_net_id);
3563-
struct vxlan_dev *tmp;
35643589
bool use_ipv6 = false;
35653590

35663591
if (conf->flags & VXLAN_F_GPE) {
@@ -3693,22 +3718,7 @@ static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf,
36933718
if (!conf->age_interval)
36943719
conf->age_interval = FDB_AGE_DEFAULT;
36953720

3696-
list_for_each_entry(tmp, &vn->vxlan_list, next) {
3697-
if (tmp == old)
3698-
continue;
3699-
3700-
if (tmp->cfg.vni != conf->vni)
3701-
continue;
3702-
if (tmp->cfg.dst_port != conf->dst_port)
3703-
continue;
3704-
if ((tmp->cfg.flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)) !=
3705-
(conf->flags & (VXLAN_F_RCV_FLAGS | VXLAN_F_IPV6)))
3706-
continue;
3707-
3708-
if ((conf->flags & VXLAN_F_IPV6_LINKLOCAL) &&
3709-
tmp->cfg.remote_ifindex != conf->remote_ifindex)
3710-
continue;
3711-
3721+
if (vxlan_vni_in_use(src_net, old, conf, conf->vni)) {
37123722
NL_SET_ERR_MSG(extack,
37133723
"A VXLAN device with the specified VNI already exists");
37143724
return -EEXIST;

0 commit comments

Comments
 (0)