Skip to content

Commit 4db67e8

Browse files
ebiedermdavem330
authored andcommitted
sctp: Make the address lists per network namespace
- Move the address lists into struct net - Add per network namespace initialization and cleanup - Pass around struct net so it is everywhere I need it. - Rename all of the global variable references into references to the variables moved into struct net Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4110cc2 commit 4db67e8

9 files changed

Lines changed: 132 additions & 103 deletions

File tree

‎include/net/net_namespace.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <net/netns/packet.h>
1616
#include <net/netns/ipv4.h>
1717
#include <net/netns/ipv6.h>
18+
#include <net/netns/sctp.h>
1819
#include <net/netns/dccp.h>
1920
#include <net/netns/x_tables.h>
2021
#if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
@@ -81,6 +82,9 @@ struct net {
8182
#if IS_ENABLED(CONFIG_IPV6)
8283
struct netns_ipv6 ipv6;
8384
#endif
85+
#if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE)
86+
struct netns_sctp sctp;
87+
#endif
8488
#if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
8589
struct netns_dccp dccp;
8690
#endif

‎include/net/netns/sctp.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef __NETNS_SCTP_H__
2+
#define __NETNS_SCTP_H__
3+
4+
struct netns_sctp {
5+
/* This is the global local address list.
6+
* We actively maintain this complete list of addresses on
7+
* the system by catching address add/delete events.
8+
*
9+
* It is a list of sctp_sockaddr_entry.
10+
*/
11+
struct list_head local_addr_list;
12+
struct list_head addr_waitq;
13+
struct timer_list addr_wq_timer;
14+
struct list_head auto_asconf_splist;
15+
spinlock_t addr_wq_lock;
16+
17+
/* Lock that protects the local_addr_list writers */
18+
spinlock_t local_addr_lock;
19+
};
20+
21+
#endif /* __NETNS_SCTP_H__ */

‎include/net/sctp/sctp.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@
115115
* sctp/protocol.c
116116
*/
117117
extern struct sock *sctp_get_ctl_sock(void);
118-
extern int sctp_copy_local_addr_list(struct sctp_bind_addr *,
118+
extern int sctp_copy_local_addr_list(struct net *, struct sctp_bind_addr *,
119119
sctp_scope_t, gfp_t gfp,
120120
int flags);
121121
extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family);
122122
extern int sctp_register_pf(struct sctp_pf *, sa_family_t);
123-
extern void sctp_addr_wq_mgmt(struct sctp_sockaddr_entry *, int);
123+
extern void sctp_addr_wq_mgmt(struct net *, struct sctp_sockaddr_entry *, int);
124124

125125
/*
126126
* sctp/socket.c

‎include/net/sctp/structs.h‎

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,7 @@ extern struct sctp_globals {
205205
int port_hashsize;
206206
struct sctp_bind_hashbucket *port_hashtable;
207207

208-
/* This is the global local address list.
209-
* We actively maintain this complete list of addresses on
210-
* the system by catching address add/delete events.
211-
*
212-
* It is a list of sctp_sockaddr_entry.
213-
*/
214-
struct list_head local_addr_list;
215208
int default_auto_asconf;
216-
struct list_head addr_waitq;
217-
struct timer_list addr_wq_timer;
218-
struct list_head auto_asconf_splist;
219-
spinlock_t addr_wq_lock;
220-
221-
/* Lock that protects the local_addr_list writers */
222-
spinlock_t addr_list_lock;
223209

224210
/* Flag to indicate if addip is enabled. */
225211
int addip_enable;
@@ -278,12 +264,6 @@ extern struct sctp_globals {
278264
#define sctp_assoc_hashtable (sctp_globals.assoc_hashtable)
279265
#define sctp_port_hashsize (sctp_globals.port_hashsize)
280266
#define sctp_port_hashtable (sctp_globals.port_hashtable)
281-
#define sctp_local_addr_list (sctp_globals.local_addr_list)
282-
#define sctp_local_addr_lock (sctp_globals.addr_list_lock)
283-
#define sctp_auto_asconf_splist (sctp_globals.auto_asconf_splist)
284-
#define sctp_addr_waitq (sctp_globals.addr_waitq)
285-
#define sctp_addr_wq_timer (sctp_globals.addr_wq_timer)
286-
#define sctp_addr_wq_lock (sctp_globals.addr_wq_lock)
287267
#define sctp_default_auto_asconf (sctp_globals.default_auto_asconf)
288268
#define sctp_scope_policy (sctp_globals.ipv4_scope_policy)
289269
#define sctp_addip_enable (sctp_globals.addip_enable)
@@ -1241,7 +1221,7 @@ struct sctp_bind_addr {
12411221

12421222
void sctp_bind_addr_init(struct sctp_bind_addr *, __u16 port);
12431223
void sctp_bind_addr_free(struct sctp_bind_addr *);
1244-
int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
1224+
int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
12451225
const struct sctp_bind_addr *src,
12461226
sctp_scope_t scope, gfp_t gfp,
12471227
int flags);

‎net/sctp/associola.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,7 +1544,8 @@ int sctp_assoc_set_bind_addr_from_ep(struct sctp_association *asoc,
15441544
if (asoc->peer.ipv6_address)
15451545
flags |= SCTP_ADDR6_PEERSUPP;
15461546

1547-
return sctp_bind_addr_copy(&asoc->base.bind_addr,
1547+
return sctp_bind_addr_copy(sock_net(asoc->base.sk),
1548+
&asoc->base.bind_addr,
15481549
&asoc->ep->base.bind_addr,
15491550
scope, gfp, flags);
15501551
}

‎net/sctp/bind_addr.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
#include <net/sctp/sm.h>
5353

5454
/* Forward declarations for internal helpers. */
55-
static int sctp_copy_one_addr(struct sctp_bind_addr *, union sctp_addr *,
56-
sctp_scope_t scope, gfp_t gfp,
55+
static int sctp_copy_one_addr(struct net *, struct sctp_bind_addr *,
56+
union sctp_addr *, sctp_scope_t scope, gfp_t gfp,
5757
int flags);
5858
static void sctp_bind_addr_clean(struct sctp_bind_addr *);
5959

@@ -62,7 +62,7 @@ static void sctp_bind_addr_clean(struct sctp_bind_addr *);
6262
/* Copy 'src' to 'dest' taking 'scope' into account. Omit addresses
6363
* in 'src' which have a broader scope than 'scope'.
6464
*/
65-
int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
65+
int sctp_bind_addr_copy(struct net *net, struct sctp_bind_addr *dest,
6666
const struct sctp_bind_addr *src,
6767
sctp_scope_t scope, gfp_t gfp,
6868
int flags)
@@ -75,7 +75,7 @@ int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
7575

7676
/* Extract the addresses which are relevant for this scope. */
7777
list_for_each_entry(addr, &src->address_list, list) {
78-
error = sctp_copy_one_addr(dest, &addr->a, scope,
78+
error = sctp_copy_one_addr(net, dest, &addr->a, scope,
7979
gfp, flags);
8080
if (error < 0)
8181
goto out;
@@ -87,7 +87,7 @@ int sctp_bind_addr_copy(struct sctp_bind_addr *dest,
8787
*/
8888
if (list_empty(&dest->address_list) && (SCTP_SCOPE_GLOBAL == scope)) {
8989
list_for_each_entry(addr, &src->address_list, list) {
90-
error = sctp_copy_one_addr(dest, &addr->a,
90+
error = sctp_copy_one_addr(net, dest, &addr->a,
9191
SCTP_SCOPE_LINK, gfp,
9292
flags);
9393
if (error < 0)
@@ -448,15 +448,15 @@ union sctp_addr *sctp_find_unmatch_addr(struct sctp_bind_addr *bp,
448448
}
449449

450450
/* Copy out addresses from the global local address list. */
451-
static int sctp_copy_one_addr(struct sctp_bind_addr *dest,
451+
static int sctp_copy_one_addr(struct net *net, struct sctp_bind_addr *dest,
452452
union sctp_addr *addr,
453453
sctp_scope_t scope, gfp_t gfp,
454454
int flags)
455455
{
456456
int error = 0;
457457

458458
if (sctp_is_any(NULL, addr)) {
459-
error = sctp_copy_local_addr_list(dest, scope, gfp, flags);
459+
error = sctp_copy_local_addr_list(net, dest, scope, gfp, flags);
460460
} else if (sctp_in_scope(addr, scope)) {
461461
/* Now that the address is in scope, check to see if
462462
* the address type is supported by local sock as

‎net/sctp/ipv6.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
9999
struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
100100
struct sctp_sockaddr_entry *addr = NULL;
101101
struct sctp_sockaddr_entry *temp;
102+
struct net *net = dev_net(ifa->idev->dev);
102103
int found = 0;
103104

104105
switch (ev) {
@@ -110,27 +111,27 @@ static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
110111
addr->a.v6.sin6_addr = ifa->addr;
111112
addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex;
112113
addr->valid = 1;
113-
spin_lock_bh(&sctp_local_addr_lock);
114-
list_add_tail_rcu(&addr->list, &sctp_local_addr_list);
115-
sctp_addr_wq_mgmt(addr, SCTP_ADDR_NEW);
116-
spin_unlock_bh(&sctp_local_addr_lock);
114+
spin_lock_bh(&net->sctp.local_addr_lock);
115+
list_add_tail_rcu(&addr->list, &net->sctp.local_addr_list);
116+
sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_NEW);
117+
spin_unlock_bh(&net->sctp.local_addr_lock);
117118
}
118119
break;
119120
case NETDEV_DOWN:
120-
spin_lock_bh(&sctp_local_addr_lock);
121+
spin_lock_bh(&net->sctp.local_addr_lock);
121122
list_for_each_entry_safe(addr, temp,
122-
&sctp_local_addr_list, list) {
123+
&net->sctp.local_addr_list, list) {
123124
if (addr->a.sa.sa_family == AF_INET6 &&
124125
ipv6_addr_equal(&addr->a.v6.sin6_addr,
125126
&ifa->addr)) {
126-
sctp_addr_wq_mgmt(addr, SCTP_ADDR_DEL);
127+
sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
127128
found = 1;
128129
addr->valid = 0;
129130
list_del_rcu(&addr->list);
130131
break;
131132
}
132133
}
133-
spin_unlock_bh(&sctp_local_addr_lock);
134+
spin_unlock_bh(&net->sctp.local_addr_lock);
134135
if (found)
135136
kfree_rcu(addr, rcu);
136137
break;

0 commit comments

Comments
 (0)