Commit f51d599fbecf4881a36466f0355da6b0b346ea70

Authored by Pavel Emelyanov
Committed by David S. Miller
1 parent be185884b3

[NETNS][RAW]: Make /proc/net/raw(6) show per-namespace socket list.

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>

Showing 3 changed files with 16 additions and 11 deletions Side-by-side Diff

... ... @@ -39,6 +39,7 @@
39 39 extern void raw_proc_exit(void);
40 40  
41 41 struct raw_iter_state {
  42 + struct seq_net_private p;
42 43 int bucket;
43 44 unsigned short family;
44 45 struct raw_hashinfo *h;
... ... @@ -48,7 +49,7 @@
48 49 void *raw_seq_start(struct seq_file *seq, loff_t *pos);
49 50 void *raw_seq_next(struct seq_file *seq, void *v, loff_t *pos);
50 51 void raw_seq_stop(struct seq_file *seq, void *v);
51   -int raw_seq_open(struct file *file, struct raw_hashinfo *h,
  52 +int raw_seq_open(struct inode *ino, struct file *file, struct raw_hashinfo *h,
52 53 unsigned short family);
53 54  
54 55 #endif
... ... @@ -860,7 +860,8 @@
860 860 struct hlist_node *node;
861 861  
862 862 sk_for_each(sk, node, &state->h->ht[state->bucket])
863   - if (sk->sk_family == state->family)
  863 + if (sk->sk_net == state->p.net &&
  864 + sk->sk_family == state->family)
864 865 goto found;
865 866 }
866 867 sk = NULL;
... ... @@ -876,7 +877,8 @@
876 877 sk = sk_next(sk);
877 878 try_again:
878 879 ;
879   - } while (sk && sk->sk_family != state->family);
  880 + } while (sk && sk->sk_net != state->p.net &&
  881 + sk->sk_family != state->family);
880 882  
881 883 if (!sk && ++state->bucket < RAW_HTABLE_SIZE) {
882 884 sk = sk_head(&state->h->ht[state->bucket]);
883 885  
884 886  
885 887  
886 888  
... ... @@ -970,16 +972,18 @@
970 972 .show = raw_seq_show,
971 973 };
972 974  
973   -int raw_seq_open(struct file *file, struct raw_hashinfo *h,
  975 +int raw_seq_open(struct inode *ino, struct file *file, struct raw_hashinfo *h,
974 976 unsigned short family)
975 977 {
  978 + int err;
976 979 struct raw_iter_state *i;
977 980  
978   - i = __seq_open_private(file, &raw_seq_ops,
  981 + err = seq_open_net(ino, file, &raw_seq_ops,
979 982 sizeof(struct raw_iter_state));
980   - if (i == NULL)
981   - return -ENOMEM;
  983 + if (err < 0)
  984 + return err;
982 985  
  986 + i = raw_seq_private((struct seq_file *)file->private_data);
983 987 i->h = h;
984 988 i->family = family;
985 989 return 0;
... ... @@ -988,7 +992,7 @@
988 992  
989 993 static int raw_v4_seq_open(struct inode *inode, struct file *file)
990 994 {
991   - return raw_seq_open(file, &raw_v4_hashinfo, PF_INET);
  995 + return raw_seq_open(inode, file, &raw_v4_hashinfo, PF_INET);
992 996 }
993 997  
994 998 static const struct file_operations raw_seq_fops = {
... ... @@ -996,7 +1000,7 @@
996 1000 .open = raw_v4_seq_open,
997 1001 .read = seq_read,
998 1002 .llseek = seq_lseek,
999   - .release = seq_release_private,
  1003 + .release = seq_release_net,
1000 1004 };
1001 1005  
1002 1006 int __init raw_proc_init(void)
... ... @@ -1259,7 +1259,7 @@
1259 1259  
1260 1260 static int raw6_seq_open(struct inode *inode, struct file *file)
1261 1261 {
1262   - return raw_seq_open(file, &raw_v6_hashinfo, PF_INET6);
  1262 + return raw_seq_open(inode, file, &raw_v6_hashinfo, PF_INET6);
1263 1263 }
1264 1264  
1265 1265 static const struct file_operations raw6_seq_fops = {
... ... @@ -1267,7 +1267,7 @@
1267 1267 .open = raw6_seq_open,
1268 1268 .read = seq_read,
1269 1269 .llseek = seq_lseek,
1270   - .release = seq_release_private,
  1270 + .release = seq_release_net,
1271 1271 };
1272 1272  
1273 1273 int __init raw6_proc_init(void)