Blame view
net/sysctl_net.c
2.79 KB
1da177e4c
|
1 2 3 4 5 6 |
/* -*- linux-c -*- * sysctl_net.c: sysctl interface to net subsystem. * * Begun April 1, 1996, Mike Shaver. * Added /proc/sys/net directories for each protocol family. [MS] * |
1da177e4c
|
7 8 9 10 11 12 |
* Revision 1.2 1996/05/08 20:24:40 shaver * Added bits for NET_BRIDGE and the NET_IPV4_ARP stuff and * NET_IPV4_IP_FORWARD. * * */ |
1da177e4c
|
13 |
#include <linux/mm.h> |
bc3b2d7fb
|
14 |
#include <linux/export.h> |
1da177e4c
|
15 |
#include <linux/sysctl.h> |
95bdfccb2
|
16 |
#include <linux/nsproxy.h> |
1da177e4c
|
17 |
|
496a22b08
|
18 |
#include <net/sock.h> |
1da177e4c
|
19 |
#ifdef CONFIG_INET |
20380731b
|
20 |
#include <net/ip.h> |
1da177e4c
|
21 |
#endif |
1da177e4c
|
22 |
#ifdef CONFIG_NET |
20380731b
|
23 |
#include <linux/if_ether.h> |
1da177e4c
|
24 |
#endif |
734550921
|
25 |
static struct ctl_table_set * |
95bdfccb2
|
26 27 |
net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces) { |
734550921
|
28 29 30 31 32 33 |
return &namespaces->net_ns->sysctls; } static int is_seen(struct ctl_table_set *set) { return ¤t->nsproxy->net_ns->sysctls == set; |
95bdfccb2
|
34 |
} |
4ecb90090
|
35 |
/* Return standard mode bits for table entry. */ |
73f7ef435
|
36 |
static int net_ctl_permissions(struct ctl_table_header *head, |
4ecb90090
|
37 38 |
struct ctl_table *table) { |
cff109768
|
39 40 41 |
struct net *net = container_of(head->set, struct net, sysctls); kuid_t root_uid = make_kuid(net->user_ns, 0); kgid_t root_gid = make_kgid(net->user_ns, 0); |
4ecb90090
|
42 |
/* Allow network administrator to have same access as root. */ |
cff109768
|
43 |
if (ns_capable(net->user_ns, CAP_NET_ADMIN) || |
2433c8f09
|
44 |
uid_eq(root_uid, current_euid())) { |
4ecb90090
|
45 46 47 |
int mode = (table->mode >> 6) & 7; return (mode << 6) | (mode << 3) | mode; } |
86937c05c
|
48 |
/* Allow netns root group to have the same access as the root group */ |
2433c8f09
|
49 |
if (in_egroup_p(root_gid)) { |
cff109768
|
50 |
int mode = (table->mode >> 3) & 7; |
86937c05c
|
51 |
return (mode << 3) | mode; |
cff109768
|
52 |
} |
4ecb90090
|
53 54 |
return table->mode; } |
95bdfccb2
|
55 56 |
static struct ctl_table_root net_sysctl_root = { .lookup = net_ctl_header_lookup, |
4ecb90090
|
57 |
.permissions = net_ctl_permissions, |
95bdfccb2
|
58 |
}; |
2c8c1e729
|
59 |
static int __net_init sysctl_net_init(struct net *net) |
95bdfccb2
|
60 |
{ |
9eb47c26f
|
61 |
setup_sysctl_set(&net->sysctls, &net_sysctl_root, is_seen); |
95bdfccb2
|
62 63 |
return 0; } |
2c8c1e729
|
64 |
static void __net_exit sysctl_net_exit(struct net *net) |
95bdfccb2
|
65 |
{ |
97324cd80
|
66 |
retire_sysctl_set(&net->sysctls); |
95bdfccb2
|
67 68 69 70 71 72 |
} static struct pernet_operations sysctl_pernet_ops = { .init = sysctl_net_init, .exit = sysctl_net_exit, }; |
bc8a36942
|
73 |
static struct ctl_table_header *net_header; |
2ca794e5e
|
74 |
__init int net_sysctl_init(void) |
95bdfccb2
|
75 |
{ |
bc8a36942
|
76 77 78 79 80 81 82 83 84 |
static struct ctl_table empty[1]; int ret = -ENOMEM; /* Avoid limitations in the sysctl implementation by * registering "/proc/sys/net" as an empty directory not in a * network namespace. */ net_header = register_sysctl("net", empty); if (!net_header) goto out; |
95bdfccb2
|
85 86 87 |
ret = register_pernet_subsys(&sysctl_pernet_ops); if (ret) goto out; |
bd295b56c
|
88 |
register_sysctl_root(&net_sysctl_root); |
95bdfccb2
|
89 90 91 |
out: return ret; } |
95bdfccb2
|
92 |
|
ab41a2ca5
|
93 94 95 96 97 98 |
struct ctl_table_header *register_net_sysctl(struct net *net, const char *path, struct ctl_table *table) { return __register_sysctl_table(&net->sysctls, path, table); } EXPORT_SYMBOL_GPL(register_net_sysctl); |
95bdfccb2
|
99 100 |
void unregister_net_sysctl_table(struct ctl_table_header *header) { |
ab59859de
|
101 |
unregister_sysctl_table(header); |
95bdfccb2
|
102 103 |
} EXPORT_SYMBOL_GPL(unregister_net_sysctl_table); |