Skip to content

Commit

Permalink
sctp: Make the proc files per network namespace.
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
ebiederm authored and davem330 committed Aug 15, 2012
1 parent 632c928 commit 13d782f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 86 deletions.
5 changes: 5 additions & 0 deletions include/net/netns/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
#define __NETNS_SCTP_H__

struct sock;
struct proc_dir_entry;

struct netns_sctp {
#ifdef CONFIG_PROC_FS
struct proc_dir_entry *proc_net_sctp;
#endif

/* This is the global socket data structure used for responding to
* the Out-of-the-blue (OOTB) packets. A control sock will be created
* for this socket at the initialization time.
Expand Down
25 changes: 12 additions & 13 deletions include/net/sctp/sctp.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ void sctp_backlog_migrate(struct sctp_association *assoc,
/*
* sctp/proc.c
*/
int sctp_snmp_proc_init(void);
void sctp_snmp_proc_exit(void);
int sctp_eps_proc_init(void);
void sctp_eps_proc_exit(void);
int sctp_assocs_proc_init(void);
void sctp_assocs_proc_exit(void);
int sctp_remaddr_proc_init(void);
void sctp_remaddr_proc_exit(void);
int sctp_snmp_proc_init(struct net *net);
void sctp_snmp_proc_exit(struct net *net);
int sctp_eps_proc_init(struct net *net);
void sctp_eps_proc_exit(struct net *net);
int sctp_assocs_proc_init(struct net *net);
void sctp_assocs_proc_exit(struct net *net);
int sctp_remaddr_proc_init(struct net *net);
void sctp_remaddr_proc_exit(struct net *net);


/*
Expand Down Expand Up @@ -360,16 +360,16 @@ atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0)
#define SCTP_DBG_OBJCNT_ENTRY(name) \
{.label= #name, .counter= &sctp_dbg_objcnt_## name}

void sctp_dbg_objcnt_init(void);
void sctp_dbg_objcnt_exit(void);
void sctp_dbg_objcnt_init(struct net *);
void sctp_dbg_objcnt_exit(struct net *);

#else

#define SCTP_DBG_OBJCNT_INC(name)
#define SCTP_DBG_OBJCNT_DEC(name)

static inline void sctp_dbg_objcnt_init(void) { return; }
static inline void sctp_dbg_objcnt_exit(void) { return; }
static inline void sctp_dbg_objcnt_init(struct net *) { return; }
static inline void sctp_dbg_objcnt_exit(struct net *) { return; }

#endif /* CONFIG_SCTP_DBG_OBJCOUNT */

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

extern struct proto sctp_prot;
extern struct proto sctpv6_prot;
extern struct proc_dir_entry *proc_net_sctp;
void sctp_put_port(struct sock *sk);

extern struct idr sctp_assocs_id;
Expand Down
8 changes: 4 additions & 4 deletions net/sctp/objcnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ static const struct file_operations sctp_objcnt_ops = {
};

/* Initialize the objcount in the proc filesystem. */
void sctp_dbg_objcnt_init(void)
void sctp_dbg_objcnt_init(struct net *net)
{
struct proc_dir_entry *ent;

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

/* Cleanup the objcount entry in the proc filesystem. */
void sctp_dbg_objcnt_exit(void)
void sctp_dbg_objcnt_exit(struct net *net)
{
remove_proc_entry("sctp_dbg_objcnt", proc_net_sctp);
remove_proc_entry("sctp_dbg_objcnt", net->sctp.proc_net_sctp);
}


59 changes: 39 additions & 20 deletions net/sctp/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ static const struct snmp_mib sctp_snmp_list[] = {
/* Display sctp snmp mib statistics(/proc/net/sctp/snmp). */
static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
{
struct net *net = seq->private;
int i;

if (!net_eq(net, &init_net))
return 0;

for (i = 0; sctp_snmp_list[i].name != NULL; i++)
seq_printf(seq, "%-32s\t%ld\n", sctp_snmp_list[i].name,
snmp_fold_field((void __percpu **)sctp_statistics,
Expand All @@ -93,7 +97,7 @@ static int sctp_snmp_seq_show(struct seq_file *seq, void *v)
/* Initialize the seq file operations for 'snmp' object. */
static int sctp_snmp_seq_open(struct inode *inode, struct file *file)
{
return single_open(file, sctp_snmp_seq_show, NULL);
return single_open_net(inode, file, sctp_snmp_seq_show);
}

static const struct file_operations sctp_snmp_seq_fops = {
Expand All @@ -105,21 +109,22 @@ static const struct file_operations sctp_snmp_seq_fops = {
};

/* Set up the proc fs entry for 'snmp' object. */
int __init sctp_snmp_proc_init(void)
int __net_init sctp_snmp_proc_init(struct net *net)
{
struct proc_dir_entry *p;

p = proc_create("snmp", S_IRUGO, proc_net_sctp, &sctp_snmp_seq_fops);
p = proc_create("snmp", S_IRUGO, net->sctp.proc_net_sctp,
&sctp_snmp_seq_fops);
if (!p)
return -ENOMEM;

return 0;
}

/* Cleanup the proc fs entry for 'snmp' object. */
void sctp_snmp_proc_exit(void)
void sctp_snmp_proc_exit(struct net *net)
{
remove_proc_entry("snmp", proc_net_sctp);
remove_proc_entry("snmp", net->sctp.proc_net_sctp);
}

/* Dump local addresses of an association/endpoint. */
Expand Down Expand Up @@ -197,6 +202,7 @@ static void * sctp_eps_seq_next(struct seq_file *seq, void *v, loff_t *pos)
/* Display sctp endpoints (/proc/net/sctp/eps). */
static int sctp_eps_seq_show(struct seq_file *seq, void *v)
{
struct seq_net_private *priv = seq->private;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_endpoint *ep;
Expand All @@ -213,6 +219,8 @@ static int sctp_eps_seq_show(struct seq_file *seq, void *v)
sctp_for_each_hentry(epb, node, &head->chain) {
ep = sctp_ep(epb);
sk = epb->sk;
if (!net_eq(sock_net(sk), priv->net))
continue;
seq_printf(seq, "%8pK %8pK %-3d %-3d %-4d %-5d %5d %5lu ", ep, sk,
sctp_sk(sk)->type, sk->sk_state, hash,
epb->bind_addr.port,
Expand All @@ -238,7 +246,8 @@ static const struct seq_operations sctp_eps_ops = {
/* Initialize the seq file operations for 'eps' object. */
static int sctp_eps_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &sctp_eps_ops);
return seq_open_net(inode, file, &sctp_eps_ops,
sizeof(struct seq_net_private));
}

static const struct file_operations sctp_eps_seq_fops = {
Expand All @@ -249,21 +258,22 @@ static const struct file_operations sctp_eps_seq_fops = {
};

/* Set up the proc fs entry for 'eps' object. */
int __init sctp_eps_proc_init(void)
int __net_init sctp_eps_proc_init(struct net *net)
{
struct proc_dir_entry *p;

p = proc_create("eps", S_IRUGO, proc_net_sctp, &sctp_eps_seq_fops);
p = proc_create("eps", S_IRUGO, net->sctp.proc_net_sctp,
&sctp_eps_seq_fops);
if (!p)
return -ENOMEM;

return 0;
}

/* Cleanup the proc fs entry for 'eps' object. */
void sctp_eps_proc_exit(void)
void sctp_eps_proc_exit(struct net *net)
{
remove_proc_entry("eps", proc_net_sctp);
remove_proc_entry("eps", net->sctp.proc_net_sctp);
}


Expand Down Expand Up @@ -300,6 +310,7 @@ static void * sctp_assocs_seq_next(struct seq_file *seq, void *v, loff_t *pos)
/* Display sctp associations (/proc/net/sctp/assocs). */
static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
{
struct seq_net_private *priv = seq->private;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_association *assoc;
Expand All @@ -316,6 +327,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
sctp_for_each_hentry(epb, node, &head->chain) {
assoc = sctp_assoc(epb);
sk = epb->sk;
if (!net_eq(sock_net(sk), priv->net))
continue;
seq_printf(seq,
"%8pK %8pK %-3d %-3d %-2d %-4d "
"%4d %8d %8d %7d %5lu %-5d %5d ",
Expand Down Expand Up @@ -354,7 +367,8 @@ static const struct seq_operations sctp_assoc_ops = {
/* Initialize the seq file operations for 'assocs' object. */
static int sctp_assocs_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &sctp_assoc_ops);
return seq_open_net(inode, file, &sctp_assoc_ops,
sizeof(struct seq_net_private));
}

static const struct file_operations sctp_assocs_seq_fops = {
Expand All @@ -365,11 +379,11 @@ static const struct file_operations sctp_assocs_seq_fops = {
};

/* Set up the proc fs entry for 'assocs' object. */
int __init sctp_assocs_proc_init(void)
int __net_init sctp_assocs_proc_init(struct net *net)
{
struct proc_dir_entry *p;

p = proc_create("assocs", S_IRUGO, proc_net_sctp,
p = proc_create("assocs", S_IRUGO, net->sctp.proc_net_sctp,
&sctp_assocs_seq_fops);
if (!p)
return -ENOMEM;
Expand All @@ -378,9 +392,9 @@ int __init sctp_assocs_proc_init(void)
}

/* Cleanup the proc fs entry for 'assocs' object. */
void sctp_assocs_proc_exit(void)
void sctp_assocs_proc_exit(struct net *net)
{
remove_proc_entry("assocs", proc_net_sctp);
remove_proc_entry("assocs", net->sctp.proc_net_sctp);
}

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

static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
{
struct seq_net_private *priv = seq->private;
struct sctp_hashbucket *head;
struct sctp_ep_common *epb;
struct sctp_association *assoc;
Expand All @@ -426,6 +441,8 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
sctp_local_bh_disable();
read_lock(&head->lock);
sctp_for_each_hentry(epb, node, &head->chain) {
if (!net_eq(sock_net(epb->sk), priv->net))
continue;
assoc = sctp_assoc(epb);
list_for_each_entry(tsp, &assoc->peer.transport_addr_list,
transports) {
Expand Down Expand Up @@ -489,14 +506,15 @@ static const struct seq_operations sctp_remaddr_ops = {
};

/* Cleanup the proc fs entry for 'remaddr' object. */
void sctp_remaddr_proc_exit(void)
void sctp_remaddr_proc_exit(struct net *net)
{
remove_proc_entry("remaddr", proc_net_sctp);
remove_proc_entry("remaddr", net->sctp.proc_net_sctp);
}

static int sctp_remaddr_seq_open(struct inode *inode, struct file *file)
{
return seq_open(file, &sctp_remaddr_ops);
return seq_open_net(inode, file, &sctp_remaddr_ops,
sizeof(struct seq_net_private));
}

static const struct file_operations sctp_remaddr_seq_fops = {
Expand All @@ -506,11 +524,12 @@ static const struct file_operations sctp_remaddr_seq_fops = {
.release = seq_release,
};

int __init sctp_remaddr_proc_init(void)
int __net_init sctp_remaddr_proc_init(struct net *net)
{
struct proc_dir_entry *p;

p = proc_create("remaddr", S_IRUGO, proc_net_sctp, &sctp_remaddr_seq_fops);
p = proc_create("remaddr", S_IRUGO, net->sctp.proc_net_sctp,
&sctp_remaddr_seq_fops);
if (!p)
return -ENOMEM;
return 0;
Expand Down
Loading

0 comments on commit 13d782f

Please sign in to comment.