Blame view
net/sysctl_net.c
2.79 KB
1da177e4c Linux-2.6.12-rc2 |
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 Linux-2.6.12-rc2 |
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 Linux-2.6.12-rc2 |
13 |
#include <linux/mm.h> |
bc3b2d7fb net: Add export.h... |
14 |
#include <linux/export.h> |
1da177e4c Linux-2.6.12-rc2 |
15 |
#include <linux/sysctl.h> |
95bdfccb2 [NET]: Implement ... |
16 |
#include <linux/nsproxy.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
|
496a22b08 [NET]: Fix "sysct... |
18 |
#include <net/sock.h> |
1da177e4c Linux-2.6.12-rc2 |
19 |
#ifdef CONFIG_INET |
20380731b [NET]: Fix sparse... |
20 |
#include <net/ip.h> |
1da177e4c Linux-2.6.12-rc2 |
21 |
#endif |
1da177e4c Linux-2.6.12-rc2 |
22 |
#ifdef CONFIG_NET |
20380731b [NET]: Fix sparse... |
23 |
#include <linux/if_ether.h> |
1da177e4c Linux-2.6.12-rc2 |
24 |
#endif |
734550921 [PATCH] beginning... |
25 |
static struct ctl_table_set * |
95bdfccb2 [NET]: Implement ... |
26 27 |
net_ctl_header_lookup(struct ctl_table_root *root, struct nsproxy *namespaces) { |
734550921 [PATCH] beginning... |
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 [NET]: Implement ... |
34 |
} |
4ecb90090 sysctl: allow ove... |
35 |
/* Return standard mode bits for table entry. */ |
73f7ef435 sysctl: Pass usef... |
36 |
static int net_ctl_permissions(struct ctl_table_header *head, |
4ecb90090 sysctl: allow ove... |
37 38 |
struct ctl_table *table) { |
cff109768 net: Update the p... |
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 sysctl: allow ove... |
42 |
/* Allow network administrator to have same access as root. */ |
cff109768 net: Update the p... |
43 |
if (ns_capable(net->user_ns, CAP_NET_ADMIN) || |
2433c8f09 net: Update the s... |
44 |
uid_eq(root_uid, current_euid())) { |
4ecb90090 sysctl: allow ove... |
45 46 47 |
int mode = (table->mode >> 6) & 7; return (mode << 6) | (mode << 3) | mode; } |
86937c05c user_ns: get rid ... |
48 |
/* Allow netns root group to have the same access as the root group */ |
2433c8f09 net: Update the s... |
49 |
if (in_egroup_p(root_gid)) { |
cff109768 net: Update the p... |
50 |
int mode = (table->mode >> 3) & 7; |
86937c05c user_ns: get rid ... |
51 |
return (mode << 3) | mode; |
cff109768 net: Update the p... |
52 |
} |
4ecb90090 sysctl: allow ove... |
53 54 |
return table->mode; } |
95bdfccb2 [NET]: Implement ... |
55 56 |
static struct ctl_table_root net_sysctl_root = { .lookup = net_ctl_header_lookup, |
4ecb90090 sysctl: allow ove... |
57 |
.permissions = net_ctl_permissions, |
95bdfccb2 [NET]: Implement ... |
58 |
}; |
2c8c1e729 net: spread __net... |
59 |
static int __net_init sysctl_net_init(struct net *net) |
95bdfccb2 [NET]: Implement ... |
60 |
{ |
9eb47c26f sysctl: Add a roo... |
61 |
setup_sysctl_set(&net->sysctls, &net_sysctl_root, is_seen); |
95bdfccb2 [NET]: Implement ... |
62 63 |
return 0; } |
2c8c1e729 net: spread __net... |
64 |
static void __net_exit sysctl_net_exit(struct net *net) |
95bdfccb2 [NET]: Implement ... |
65 |
{ |
97324cd80 sysctl: Implement... |
66 |
retire_sysctl_set(&net->sysctls); |
95bdfccb2 [NET]: Implement ... |
67 68 69 70 71 72 |
} static struct pernet_operations sysctl_pernet_ops = { .init = sysctl_net_init, .exit = sysctl_net_exit, }; |
bc8a36942 net sysctl: Regis... |
73 |
static struct ctl_table_header *net_header; |
2ca794e5e net sysctl: Initi... |
74 |
__init int net_sysctl_init(void) |
95bdfccb2 [NET]: Implement ... |
75 |
{ |
bc8a36942 net sysctl: Regis... |
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 [NET]: Implement ... |
85 86 87 |
ret = register_pernet_subsys(&sysctl_pernet_ops); if (ret) goto out; |
bd295b56c sysctl: Remove th... |
88 |
register_sysctl_root(&net_sysctl_root); |
95bdfccb2 [NET]: Implement ... |
89 90 91 |
out: return ret; } |
95bdfccb2 [NET]: Implement ... |
92 |
|
ab41a2ca5 net: Implement re... |
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 [NET]: Implement ... |
99 100 |
void unregister_net_sysctl_table(struct ctl_table_header *header) { |
ab59859de net: fix returnin... |
101 |
unregister_sysctl_table(header); |
95bdfccb2 [NET]: Implement ... |
102 103 |
} EXPORT_SYMBOL_GPL(unregister_net_sysctl_table); |