Skip to content

Commit 13d782f

Browse files
ebiedermdavem330
authored andcommitted
sctp: Make the proc files per network namespace.
- Convert all of the files under /proc/net/sctp to be per network namespace. - Don't print anything for /proc/net/sctp/snmp except in the initial network namespaces as the snmp counters still have to be converted to be per network namespace. 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 632c928 commit 13d782f

5 files changed

Lines changed: 98 additions & 86 deletions

File tree

‎include/net/netns/sctp.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22
#define __NETNS_SCTP_H__
33

44
struct sock;
5+
struct proc_dir_entry;
56

67
struct netns_sctp {
8+
#ifdef CONFIG_PROC_FS
9+
struct proc_dir_entry *proc_net_sctp;
10+
#endif
11+
712
/* This is the global socket data structure used for responding to
813
* the Out-of-the-blue (OOTB) packets. A control sock will be created
914
* for this socket at the initialization time.

‎include/net/sctp/sctp.h‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ void sctp_backlog_migrate(struct sctp_association *assoc,
172172
/*
173173
* sctp/proc.c
174174
*/
175-
int sctp_snmp_proc_init(void);
176-
void sctp_snmp_proc_exit(void);
177-
int sctp_eps_proc_init(void);
178-
void sctp_eps_proc_exit(void);
179-
int sctp_assocs_proc_init(void);
180-
void sctp_assocs_proc_exit(void);
181-
int sctp_remaddr_proc_init(void);
182-
void sctp_remaddr_proc_exit(void);
175+
int sctp_snmp_proc_init(struct net *net);
176+
void sctp_snmp_proc_exit(struct net *net);
177+
int sctp_eps_proc_init(struct net *net);
178+
void sctp_eps_proc_exit(struct net *net);
179+
int sctp_assocs_proc_init(struct net *net);
180+
void sctp_assocs_proc_exit(struct net *net);
181+
int sctp_remaddr_proc_init(struct net *net);
182+
void sctp_remaddr_proc_exit(struct net *net);
183183

184184

185185
/*
@@ -360,16 +360,16 @@ atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
360360
#define SCTP_DBG_OBJCNT_ENTRY(name) \
361361
{.label= #name, .counter= &sctp_dbg_objcnt_## name}
362362

363-
void sctp_dbg_objcnt_init(void);
364-
void sctp_dbg_objcnt_exit(void);
363+
void sctp_dbg_objcnt_init(struct net *);
364+
void sctp_dbg_objcnt_exit(struct net *);
365365

366366
#else
367367

368368
#define SCTP_DBG_OBJCNT_INC(name)
369369
#define SCTP_DBG_OBJCNT_DEC(name)
370370

371-
static inline void sctp_dbg_objcnt_init(void) { return; }
372-
static inline void sctp_dbg_objcnt_exit(void) { return; }
371+
static inline void sctp_dbg_objcnt_init(struct net *) { return; }
372+
static inline void sctp_dbg_objcnt_exit(struct net *) { return; }
373373

374374
#endif /* CONFIG_SCTP_DBG_OBJCOUNT */
375375

@@ -585,7 +585,6 @@ for (pos = chunk->subh.fwdtsn_hdr->skip;\
585585

586586
extern struct proto sctp_prot;
587587
extern struct proto sctpv6_prot;
588-
extern struct proc_dir_entry *proc_net_sctp;
589588
void sctp_put_port(struct sock *sk);
590589

591590
extern struct idr sctp_assocs_id;

‎net/sctp/objcnt.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ static const struct file_operations sctp_objcnt_ops = {
129129
};
130130

131131
/* Initialize the objcount in the proc filesystem. */
132-
void sctp_dbg_objcnt_init(void)
132+
void sctp_dbg_objcnt_init(struct net *net)
133133
{
134134
struct proc_dir_entry *ent;
135135

136136
ent = proc_create("sctp_dbg_objcnt", 0,
137-
proc_net_sctp, &sctp_objcnt_ops);
137+
net->sctp.proc_net_sctp, &sctp_objcnt_ops);
138138
if (!ent)
139139
pr_warn("sctp_dbg_objcnt: Unable to create /proc entry.\n");
140140
}
141141

142142
/* Cleanup the objcount entry in the proc filesystem. */
143-
void sctp_dbg_objcnt_exit(void)
143+
void sctp_dbg_objcnt_exit(struct net *net)
144144
{
145-
remove_proc_entry("sctp_dbg_objcnt", proc_net_sctp);
145+
remove_proc_entry("sctp_dbg_objcnt", net->sctp.proc_net_sctp);
146146
}
147147

148148

‎net/sctp/proc.c‎

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,12 @@ static const struct snmp_mib sctp_snmp_list[] = {
8080
/* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
8181
static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
8282
{
83+
struct net *net = seq->private;
8384
int i;
8485

86+
if (!net_eq(net, &init_net))
87+
return 0;
88+
8589
for (i = 0; sctp_snmp_list[i].name != NULL; i++)
8690
seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
8791
snmp_fold_field((void __percpu **)sctp_statistics,
@@ -93,7 +97,7 @@ static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
9397
/* Initialize the seq file operations for 'snmp' object. */
9498
static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
9599
{
96-
return single_open(file, sctp_snmp_seq_show, NULL);
100+
return single_open_net(inode, file, sctp_snmp_seq_show);
97101
}
98102

99103
static const struct file_operations sctp_snmp_seq_fops = {
@@ -105,21 +109,22 @@ static const struct file_operations sctp_snmp_seq_fops = {
105109
};
106110

107111
/* Set up the proc fs entry for 'snmp' object. */
108-
int __init sctp_snmp_proc_init(void)
112+
int __net_init sctp_snmp_proc_init(struct net *net)
109113
{
110114
struct proc_dir_entry *p;
111115

112-
p = proc_create("snmp", S_IRUGO, proc_net_sctp, &sctp_snmp_seq_fops);
116+
p = proc_create("snmp", S_IRUGO, net->sctp.proc_net_sctp,
117+
&sctp_snmp_seq_fops);
113118
if (!p)
114119
return -ENOMEM;
115120

116121
return 0;
117122
}
118123

119124
/* Cleanup the proc fs entry for 'snmp' object. */
120-
void sctp_snmp_proc_exit(void)
125+
void sctp_snmp_proc_exit(struct net *net)
121126
{
122-
remove_proc_entry("snmp", proc_net_sctp);
127+
remove_proc_entry("snmp", net->sctp.proc_net_sctp);
123128
}
124129

125130
/* Dump local addresses of an association/endpoint. */
@@ -197,6 +202,7 @@ static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
197202
/* Display sctp endpoints (/proc/net/sctp/eps). */
198203
static int sctp_eps_seq_show(struct seq_file *seq, void *v)
199204
{
205+
struct seq_net_private *priv = seq->private;
200206
struct sctp_hashbucket *head;
201207
struct sctp_ep_common *epb;
202208
struct sctp_endpoint *ep;
@@ -213,6 +219,8 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
213219
sctp_for_each_hentry(epb, node, &head->chain) {
214220
ep = sctp_ep(epb);
215221
sk = epb->sk;
222+
if (!net_eq(sock_net(sk), priv->net))
223+
continue;
216224
seq_printf(seq, "%8pK %8pK %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
217225
sctp_sk(sk)->type, sk->sk_state, hash,
218226
epb->bind_addr.port,
@@ -238,7 +246,8 @@ static const struct seq_operations sctp_eps_ops = {
238246
/* Initialize the seq file operations for 'eps' object. */
239247
static int sctp_eps_seq_open(struct inode *inode, struct file *file)
240248
{
241-
return seq_open(file, &sctp_eps_ops);
249+
return seq_open_net(inode, file, &sctp_eps_ops,
250+
sizeof(struct seq_net_private));
242251
}
243252

244253
static const struct file_operations sctp_eps_seq_fops = {
@@ -249,21 +258,22 @@ static const struct file_operations sctp_eps_seq_fops = {
249258
};
250259

251260
/* Set up the proc fs entry for 'eps' object. */
252-
int __init sctp_eps_proc_init(void)
261+
int __net_init sctp_eps_proc_init(struct net *net)
253262
{
254263
struct proc_dir_entry *p;
255264

256-
p = proc_create("eps", S_IRUGO, proc_net_sctp, &sctp_eps_seq_fops);
265+
p = proc_create("eps", S_IRUGO, net->sctp.proc_net_sctp,
266+
&sctp_eps_seq_fops);
257267
if (!p)
258268
return -ENOMEM;
259269

260270
return 0;
261271
}
262272

263273
/* Cleanup the proc fs entry for 'eps' object. */
264-
void sctp_eps_proc_exit(void)
274+
void sctp_eps_proc_exit(struct net *net)
265275
{
266-
remove_proc_entry("eps", proc_net_sctp);
276+
remove_proc_entry("eps", net->sctp.proc_net_sctp);
267277
}
268278

269279

@@ -300,6 +310,7 @@ static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
300310
/* Display sctp associations (/proc/net/sctp/assocs). */
301311
static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
302312
{
313+
struct seq_net_private *priv = seq->private;
303314
struct sctp_hashbucket *head;
304315
struct sctp_ep_common *epb;
305316
struct sctp_association *assoc;
@@ -316,6 +327,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
316327
sctp_for_each_hentry(epb, node, &head->chain) {
317328
assoc = sctp_assoc(epb);
318329
sk = epb->sk;
330+
if (!net_eq(sock_net(sk), priv->net))
331+
continue;
319332
seq_printf(seq,
320333
"%8pK %8pK %-3d %-3d %-2d %-4d "
321334
"%4d %8d %8d %7d %5lu %-5d %5d ",
@@ -354,7 +367,8 @@ static const struct seq_operations sctp_assoc_ops = {
354367
/* Initialize the seq file operations for 'assocs' object. */
355368
static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
356369
{
357-
return seq_open(file, &sctp_assoc_ops);
370+
return seq_open_net(inode, file, &sctp_assoc_ops,
371+
sizeof(struct seq_net_private));
358372
}
359373

360374
static const struct file_operations sctp_assocs_seq_fops = {
@@ -365,11 +379,11 @@ static const struct file_operations sctp_assocs_seq_fops = {
365379
};
366380

367381
/* Set up the proc fs entry for 'assocs' object. */
368-
int __init sctp_assocs_proc_init(void)
382+
int __net_init sctp_assocs_proc_init(struct net *net)
369383
{
370384
struct proc_dir_entry *p;
371385

372-
p = proc_create("assocs", S_IRUGO, proc_net_sctp,
386+
p = proc_create("assocs", S_IRUGO, net->sctp.proc_net_sctp,
373387
&sctp_assocs_seq_fops);
374388
if (!p)
375389
return -ENOMEM;
@@ -378,9 +392,9 @@ int __init sctp_assocs_proc_init(void)
378392
}
379393

380394
/* Cleanup the proc fs entry for 'assocs' object. */
381-
void sctp_assocs_proc_exit(void)
395+
void sctp_assocs_proc_exit(struct net *net)
382396
{
383-
remove_proc_entry("assocs", proc_net_sctp);
397+
remove_proc_entry("assocs", net->sctp.proc_net_sctp);
384398
}
385399

386400
static void *sctp_remaddr_seq_start(struct seq_file *seq, loff_t *pos)
@@ -412,6 +426,7 @@ static void sctp_remaddr_seq_stop(struct seq_file *seq, void *v)
412426

413427
static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
414428
{
429+
struct seq_net_private *priv = seq->private;
415430
struct sctp_hashbucket *head;
416431
struct sctp_ep_common *epb;
417432
struct sctp_association *assoc;
@@ -426,6 +441,8 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
426441
sctp_local_bh_disable();
427442
read_lock(&head->lock);
428443
sctp_for_each_hentry(epb, node, &head->chain) {
444+
if (!net_eq(sock_net(epb->sk), priv->net))
445+
continue;
429446
assoc = sctp_assoc(epb);
430447
list_for_each_entry(tsp, &assoc->peer.transport_addr_list,
431448
transports) {
@@ -489,14 +506,15 @@ static const struct seq_operations sctp_remaddr_ops = {
489506
};
490507

491508
/* Cleanup the proc fs entry for 'remaddr' object. */
492-
void sctp_remaddr_proc_exit(void)
509+
void sctp_remaddr_proc_exit(struct net *net)
493510
{
494-
remove_proc_entry("remaddr", proc_net_sctp);
511+
remove_proc_entry("remaddr", net->sctp.proc_net_sctp);
495512
}
496513

497514
static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
498515
{
499-
return seq_open(file, &sctp_remaddr_ops);
516+
return seq_open_net(inode, file, &sctp_remaddr_ops,
517+
sizeof(struct seq_net_private));
500518
}
501519

502520
static const struct file_operations sctp_remaddr_seq_fops = {
@@ -506,11 +524,12 @@ static const struct file_operations sctp_remaddr_seq_fops = {
506524
.release = seq_release,
507525
};
508526

509-
int __init sctp_remaddr_proc_init(void)
527+
int __net_init sctp_remaddr_proc_init(struct net *net)
510528
{
511529
struct proc_dir_entry *p;
512530

513-
p = proc_create("remaddr", S_IRUGO, proc_net_sctp, &sctp_remaddr_seq_fops);
531+
p = proc_create("remaddr", S_IRUGO, net->sctp.proc_net_sctp,
532+
&sctp_remaddr_seq_fops);
514533
if (!p)
515534
return -ENOMEM;
516535
return 0;

0 commit comments

Comments
 (0)