Skip to content

Commit

Permalink
[NETNS][RAW]: Make /proc/net/raw(6) show per-namespace socket list.
Browse files Browse the repository at this point in the history
Pull the struct net pointer up to the showing functions
to filter the sockets depending on their namespaces.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Jan 28, 2008
1 parent be18588 commit f51d599
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
3 changes: 2 additions & 1 deletion include/net/raw.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern int raw_proc_init(void);
extern void raw_proc_exit(void);

struct raw_iter_state {
struct seq_net_private p;
int bucket;
unsigned short family;
struct raw_hashinfo *h;
Expand All @@ -48,7 +49,7 @@ struct raw_iter_state {
void *raw_seq_start(struct seq_file *seq, loff_t *pos);
void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
void raw_seq_stop(struct seq_file *seq, void *v);
int raw_seq_open(struct file *file, struct raw_hashinfo *h,
int raw_seq_open(struct inode *ino, struct file *file, struct raw_hashinfo *h,
unsigned short family);

#endif
Expand Down
20 changes: 12 additions & 8 deletions net/ipv4/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,8 @@ static struct sock *raw_get_first(struct seq_file *seq)
struct hlist_node *node;

sk_for_each(sk, node, &state->h->ht[state->bucket])
if (sk->sk_family == state->family)
if (sk->sk_net == state->p.net &&
sk->sk_family == state->family)
goto found;
}
sk = NULL;
Expand All @@ -876,7 +877,8 @@ static struct sock *raw_get_next(struct seq_file *seq, struct sock *sk)
sk = sk_next(sk);
try_again:
;
} while (sk && sk->sk_family != state->family);
} while (sk && sk->sk_net != state->p.net &&
sk->sk_family != state->family);

if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
sk = sk_head(&state->h->ht[state->bucket]);
Expand Down Expand Up @@ -970,16 +972,18 @@ static const struct seq_operations raw_seq_ops = {
.show = raw_seq_show,
};

int raw_seq_open(struct file *file, struct raw_hashinfo *h,
int raw_seq_open(struct inode *ino, struct file *file, struct raw_hashinfo *h,
unsigned short family)
{
int err;
struct raw_iter_state *i;

i = __seq_open_private(file, &raw_seq_ops,
err = seq_open_net(ino, file, &raw_seq_ops,
sizeof(struct raw_iter_state));
if (i == NULL)
return -ENOMEM;
if (err < 0)
return err;

i = raw_seq_private((struct seq_file *)file->private_data);
i->h = h;
i->family = family;
return 0;
Expand All @@ -988,15 +992,15 @@ EXPORT_SYMBOL_GPL(raw_seq_open);

static int raw_v4_seq_open(struct inode *inode, struct file *file)
{
return raw_seq_open(file, &raw_v4_hashinfo, PF_INET);
return raw_seq_open(inode, file, &raw_v4_hashinfo, PF_INET);
}

static const struct file_operations raw_seq_fops = {
.owner = THIS_MODULE,
.open = raw_v4_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
.release = seq_release_net,
};

int __init raw_proc_init(void)
Expand Down
4 changes: 2 additions & 2 deletions net/ipv6/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1259,15 +1259,15 @@ static const struct seq_operations raw6_seq_ops = {

static int raw6_seq_open(struct inode *inode, struct file *file)
{
return raw_seq_open(file, &raw_v6_hashinfo, PF_INET6);
return raw_seq_open(inode, file, &raw_v6_hashinfo, PF_INET6);
}

static const struct file_operations raw6_seq_fops = {
.owner = THIS_MODULE,
.open = raw6_seq_open,
.read = seq_read,
.llseek = seq_lseek,
.release = seq_release_private,
.release = seq_release_net,
};

int __init raw6_proc_init(void)
Expand Down

0 comments on commit f51d599

Please sign in to comment.