Skip to content

Commit 1597fbc

Browse files
xemuldavem330
authored andcommitted
[UNIX]: Make the unix sysctl tables per-namespace
This is the core. * add the ctl_table_header on the struct net; * make the unix_sysctl_register and _unregister clone the table; * moves calls to them into per-net init and exit callbacks; * move the .data pointer in the proper place. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Acked-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1d430b9 commit 1597fbc

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

‎include/net/net_namespace.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
struct proc_dir_entry;
1212
struct net_device;
1313
struct sock;
14+
struct ctl_table_header;
15+
1416
struct net {
1517
atomic_t count; /* To decided when the network
1618
* namespace should be freed.
@@ -41,6 +43,7 @@ struct net {
4143

4244
/* unix sockets */
4345
int sysctl_unix_max_dgram_qlen;
46+
struct ctl_table_header *unix_ctl;
4447
};
4548

4649
#ifdef CONFIG_NET

‎net/unix/af_unix.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,10 +2139,14 @@ static int unix_net_init(struct net *net)
21392139
int error = -ENOMEM;
21402140

21412141
net->sysctl_unix_max_dgram_qlen = 10;
2142+
if (unix_sysctl_register(net))
2143+
goto out;
21422144

21432145
#ifdef CONFIG_PROC_FS
2144-
if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops))
2146+
if (!proc_net_fops_create(net, "unix", 0, &unix_seq_fops)) {
2147+
unix_sysctl_unregister(net);
21452148
goto out;
2149+
}
21462150
#endif
21472151
error = 0;
21482152
out:
@@ -2151,6 +2155,7 @@ static int unix_net_init(struct net *net)
21512155

21522156
static void unix_net_exit(struct net *net)
21532157
{
2158+
unix_sysctl_unregister(net);
21542159
proc_net_remove(net, "unix");
21552160
}
21562161

@@ -2175,15 +2180,13 @@ static int __init af_unix_init(void)
21752180

21762181
sock_register(&unix_family_ops);
21772182
register_pernet_subsys(&unix_net_ops);
2178-
unix_sysctl_register(&init_net);
21792183
out:
21802184
return rc;
21812185
}
21822186

21832187
static void __exit af_unix_exit(void)
21842188
{
21852189
sock_unregister(PF_UNIX);
2186-
unix_sysctl_unregister(&init_net);
21872190
proto_unregister(&unix_proto);
21882191
unregister_pernet_subsys(&unix_net_ops);
21892192
}

‎net/unix/sysctl_net_unix.c‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,33 @@ static struct ctl_path unix_path[] = {
3232
{ },
3333
};
3434

35-
static struct ctl_table_header * unix_sysctl_header;
36-
3735
int unix_sysctl_register(struct net *net)
3836
{
39-
unix_sysctl_header = register_sysctl_paths(unix_path, unix_table);
40-
return unix_sysctl_header == NULL ? -ENOMEM : 0;
37+
struct ctl_table *table;
38+
39+
table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
40+
if (table == NULL)
41+
goto err_alloc;
42+
43+
table[0].data = &net->sysctl_unix_max_dgram_qlen;
44+
net->unix_ctl = register_net_sysctl_table(net, unix_path, table);
45+
if (net->unix_ctl == NULL)
46+
goto err_reg;
47+
48+
return 0;
49+
50+
err_reg:
51+
kfree(table);
52+
err_alloc:
53+
return -ENOMEM;
4154
}
4255

4356
void unix_sysctl_unregister(struct net *net)
4457
{
45-
unregister_sysctl_table(unix_sysctl_header);
58+
struct ctl_table *table;
59+
60+
table = net->unix_ctl->ctl_table_arg;
61+
unregister_sysctl_table(net->unix_ctl);
62+
kfree(table);
4663
}
4764

0 commit comments

Comments
 (0)