@@ -3554,13 +3554,38 @@ static int vxlan_sock_add(struct vxlan_dev *vxlan)
3554
3554
return ret ;
3555
3555
}
3556
3556
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
+
3557
3584
static int vxlan_config_validate (struct net * src_net , struct vxlan_config * conf ,
3558
3585
struct net_device * * lower ,
3559
3586
struct vxlan_dev * old ,
3560
3587
struct netlink_ext_ack * extack )
3561
3588
{
3562
- struct vxlan_net * vn = net_generic (src_net , vxlan_net_id );
3563
- struct vxlan_dev * tmp ;
3564
3589
bool use_ipv6 = false;
3565
3590
3566
3591
if (conf -> flags & VXLAN_F_GPE ) {
@@ -3693,22 +3718,7 @@ static int vxlan_config_validate(struct net *src_net, struct vxlan_config *conf,
3693
3718
if (!conf -> age_interval )
3694
3719
conf -> age_interval = FDB_AGE_DEFAULT ;
3695
3720
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 )) {
3712
3722
NL_SET_ERR_MSG (extack ,
3713
3723
"A VXLAN device with the specified VNI already exists" );
3714
3724
return - EEXIST ;
0 commit comments