@@ -75,8 +75,7 @@ static struct rtnl_link_ops vxlan_link_ops;
75
75
76
76
static const u8 all_zeros_mac [ETH_ALEN ];
77
77
78
- static struct vxlan_sock * vxlan_sock_add (struct net * net , __be16 port ,
79
- bool no_share , u32 flags );
78
+ static int vxlan_sock_add (struct vxlan_dev * vxlan );
80
79
81
80
/* per-network namespace private data for this module */
82
81
struct vxlan_net {
@@ -1022,8 +1021,9 @@ static bool vxlan_group_used(struct vxlan_net *vn, struct vxlan_dev *dev)
1022
1021
return false;
1023
1022
}
1024
1023
1025
- static void vxlan_sock_release (struct vxlan_sock * vs )
1024
+ static void vxlan_sock_release (struct vxlan_dev * vxlan )
1026
1025
{
1026
+ struct vxlan_sock * vs = vxlan -> vn_sock ;
1027
1027
struct sock * sk = vs -> sock -> sk ;
1028
1028
struct net * net = sock_net (sk );
1029
1029
struct vxlan_net * vn = net_generic (net , vxlan_net_id );
@@ -2244,22 +2244,18 @@ static void vxlan_uninit(struct net_device *dev)
2244
2244
static int vxlan_open (struct net_device * dev )
2245
2245
{
2246
2246
struct vxlan_dev * vxlan = netdev_priv (dev );
2247
- struct vxlan_sock * vs ;
2248
- int ret = 0 ;
2249
-
2250
- vs = vxlan_sock_add (vxlan -> net , vxlan -> cfg .dst_port ,
2251
- vxlan -> cfg .no_share , vxlan -> flags );
2252
- if (IS_ERR (vs ))
2253
- return PTR_ERR (vs );
2247
+ int ret ;
2254
2248
2255
- vxlan_vs_add_dev (vs , vxlan );
2249
+ ret = vxlan_sock_add (vxlan );
2250
+ if (ret < 0 )
2251
+ return ret ;
2256
2252
2257
2253
if (vxlan_addr_multicast (& vxlan -> default_dst .remote_ip )) {
2258
2254
ret = vxlan_igmp_join (vxlan );
2259
2255
if (ret == - EADDRINUSE )
2260
2256
ret = 0 ;
2261
2257
if (ret ) {
2262
- vxlan_sock_release (vs );
2258
+ vxlan_sock_release (vxlan );
2263
2259
return ret ;
2264
2260
}
2265
2261
}
@@ -2294,7 +2290,6 @@ static int vxlan_stop(struct net_device *dev)
2294
2290
{
2295
2291
struct vxlan_dev * vxlan = netdev_priv (dev );
2296
2292
struct vxlan_net * vn = net_generic (vxlan -> net , vxlan_net_id );
2297
- struct vxlan_sock * vs = vxlan -> vn_sock ;
2298
2293
int ret = 0 ;
2299
2294
2300
2295
if (vxlan_addr_multicast (& vxlan -> default_dst .remote_ip ) &&
@@ -2304,7 +2299,7 @@ static int vxlan_stop(struct net_device *dev)
2304
2299
del_timer_sync (& vxlan -> age_timer );
2305
2300
2306
2301
vxlan_flush (vxlan );
2307
- vxlan_sock_release (vs );
2302
+ vxlan_sock_release (vxlan );
2308
2303
2309
2304
return ret ;
2310
2305
}
@@ -2592,27 +2587,29 @@ static struct vxlan_sock *vxlan_socket_create(struct net *net, __be16 port,
2592
2587
return vs ;
2593
2588
}
2594
2589
2595
- static struct vxlan_sock * vxlan_sock_add (struct net * net , __be16 port ,
2596
- bool no_share , u32 flags )
2590
+ static int vxlan_sock_add (struct vxlan_dev * vxlan )
2597
2591
{
2598
- struct vxlan_net * vn = net_generic (net , vxlan_net_id );
2599
- struct vxlan_sock * vs ;
2600
- bool ipv6 = flags & VXLAN_F_IPV6 ;
2592
+ struct vxlan_net * vn = net_generic (vxlan -> net , vxlan_net_id );
2593
+ struct vxlan_sock * vs = NULL ;
2594
+ bool ipv6 = vxlan -> flags & VXLAN_F_IPV6 ;
2601
2595
2602
- if (!no_share ) {
2596
+ if (!vxlan -> cfg . no_share ) {
2603
2597
spin_lock (& vn -> sock_lock );
2604
- vs = vxlan_find_sock (net , ipv6 ? AF_INET6 : AF_INET , port ,
2605
- flags );
2606
- if (vs ) {
2607
- if (!atomic_add_unless (& vs -> refcnt , 1 , 0 ))
2608
- vs = ERR_PTR (- EBUSY );
2598
+ vs = vxlan_find_sock (vxlan -> net , ipv6 ? AF_INET6 : AF_INET ,
2599
+ vxlan -> cfg .dst_port , vxlan -> flags );
2600
+ if (vs && !atomic_add_unless (& vs -> refcnt , 1 , 0 )) {
2609
2601
spin_unlock (& vn -> sock_lock );
2610
- return vs ;
2602
+ return - EBUSY ;
2611
2603
}
2612
2604
spin_unlock (& vn -> sock_lock );
2613
2605
}
2614
-
2615
- return vxlan_socket_create (net , port , flags );
2606
+ if (!vs )
2607
+ vs = vxlan_socket_create (vxlan -> net , vxlan -> cfg .dst_port ,
2608
+ vxlan -> flags );
2609
+ if (IS_ERR (vs ))
2610
+ return PTR_ERR (vs );
2611
+ vxlan_vs_add_dev (vs , vxlan );
2612
+ return 0 ;
2616
2613
}
2617
2614
2618
2615
static int vxlan_dev_configure (struct net * src_net , struct net_device * dev ,
0 commit comments