Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* -*- linux-c -*- |
| 2 | * sysctl_net_core.c: sysctl interface to net core subsystem. |
| 3 | * |
| 4 | * Begun April 1, 1996, Mike Shaver. |
| 5 | * Added /proc/sys/net/core directory entry (empty =) ). [MS] |
| 6 | */ |
| 7 | |
| 8 | #include <linux/mm.h> |
| 9 | #include <linux/sysctl.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 11 | #include <linux/socket.h> |
Pavel Emelyanov | a37ae40 | 2007-10-23 21:13:53 -0700 | [diff] [blame] | 12 | #include <linux/netdevice.h> |
Ingo Molnar | 3fff4c4 | 2009-09-22 16:18:09 +0200 | [diff] [blame] | 13 | #include <linux/ratelimit.h> |
Pavel Emelyanov | 33eb9cf | 2007-12-05 01:37:34 -0800 | [diff] [blame] | 14 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Ingo Molnar | 3fff4c4 | 2009-09-22 16:18:09 +0200 | [diff] [blame] | 16 | |
Hannes Eder | 63d819c | 2009-02-25 10:32:14 +0000 | [diff] [blame] | 17 | #include <net/ip.h> |
Arnaldo Carvalho de Melo | 2038073 | 2005-08-16 02:18:02 -0300 | [diff] [blame] | 18 | #include <net/sock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Pavel Emelyanov | 33eb9cf | 2007-12-05 01:37:34 -0800 | [diff] [blame] | 20 | static struct ctl_table net_core_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #ifdef CONFIG_NET |
| 22 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | .procname = "wmem_max", |
| 24 | .data = &sysctl_wmem_max, |
| 25 | .maxlen = sizeof(int), |
| 26 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 27 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | }, |
| 29 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | .procname = "rmem_max", |
| 31 | .data = &sysctl_rmem_max, |
| 32 | .maxlen = sizeof(int), |
| 33 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 34 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | }, |
| 36 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | .procname = "wmem_default", |
| 38 | .data = &sysctl_wmem_default, |
| 39 | .maxlen = sizeof(int), |
| 40 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 41 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | }, |
| 43 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | .procname = "rmem_default", |
| 45 | .data = &sysctl_rmem_default, |
| 46 | .maxlen = sizeof(int), |
| 47 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 48 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | }, |
| 50 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | .procname = "dev_weight", |
| 52 | .data = &weight_p, |
| 53 | .maxlen = sizeof(int), |
| 54 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 55 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | }, |
| 57 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | .procname = "netdev_max_backlog", |
| 59 | .data = &netdev_max_backlog, |
| 60 | .maxlen = sizeof(int), |
| 61 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 62 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }, |
| 64 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | .procname = "message_cost", |
Dave Young | 717115e | 2008-07-25 01:45:58 -0700 | [diff] [blame] | 66 | .data = &net_ratelimit_state.interval, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | .maxlen = sizeof(int), |
| 68 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 69 | .proc_handler = proc_dointvec_jiffies, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | }, |
| 71 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .procname = "message_burst", |
Dave Young | 717115e | 2008-07-25 01:45:58 -0700 | [diff] [blame] | 73 | .data = &net_ratelimit_state.burst, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | .maxlen = sizeof(int), |
| 75 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 76 | .proc_handler = proc_dointvec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }, |
| 78 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | .procname = "optmem_max", |
| 80 | .data = &sysctl_optmem_max, |
| 81 | .maxlen = sizeof(int), |
| 82 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 83 | .proc_handler = proc_dointvec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #endif /* CONFIG_NET */ |
| 86 | { |
Stephen Hemminger | 51b0bde | 2005-06-23 20:14:40 -0700 | [diff] [blame] | 87 | .procname = "netdev_budget", |
| 88 | .data = &netdev_budget, |
| 89 | .maxlen = sizeof(int), |
| 90 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 91 | .proc_handler = proc_dointvec |
Stephen Hemminger | 51b0bde | 2005-06-23 20:14:40 -0700 | [diff] [blame] | 92 | }, |
Stephen Hemminger | a2a316f | 2007-03-08 20:41:08 -0800 | [diff] [blame] | 93 | { |
Stephen Hemminger | a2a316f | 2007-03-08 20:41:08 -0800 | [diff] [blame] | 94 | .procname = "warnings", |
| 95 | .data = &net_msg_warn, |
| 96 | .maxlen = sizeof(int), |
| 97 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 98 | .proc_handler = proc_dointvec |
Stephen Hemminger | a2a316f | 2007-03-08 20:41:08 -0800 | [diff] [blame] | 99 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 100 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; |
Pavel Emelyanov | 33eb9cf | 2007-12-05 01:37:34 -0800 | [diff] [blame] | 102 | |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 103 | static struct ctl_table netns_core_table[] = { |
| 104 | { |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 105 | .procname = "somaxconn", |
| 106 | .data = &init_net.core.sysctl_somaxconn, |
| 107 | .maxlen = sizeof(int), |
| 108 | .mode = 0644, |
Alexey Dobriyan | 6d9f239 | 2008-11-03 18:21:05 -0800 | [diff] [blame] | 109 | .proc_handler = proc_dointvec |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 110 | }, |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 111 | { } |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
Alexey Dobriyan | b27aead | 2008-11-25 18:00:48 -0800 | [diff] [blame] | 114 | __net_initdata struct ctl_path net_core_path[] = { |
Eric W. Biederman | f8572d8 | 2009-11-05 13:32:03 -0800 | [diff] [blame] | 115 | { .procname = "net", }, |
| 116 | { .procname = "core", }, |
Pavel Emelyanov | 33eb9cf | 2007-12-05 01:37:34 -0800 | [diff] [blame] | 117 | { }, |
| 118 | }; |
| 119 | |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 120 | static __net_init int sysctl_core_net_init(struct net *net) |
| 121 | { |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 122 | struct ctl_table *tbl; |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 123 | |
Pavel Emelyanov | 8efa6e9 | 2008-03-31 19:41:14 -0700 | [diff] [blame] | 124 | net->core.sysctl_somaxconn = SOMAXCONN; |
Pavel Emelyanov | b8e1f9b | 2007-12-08 00:12:33 -0800 | [diff] [blame] | 125 | |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 126 | tbl = netns_core_table; |
Octavian Purdila | 09ad9bc | 2009-11-25 15:14:13 -0800 | [diff] [blame] | 127 | if (!net_eq(net, &init_net)) { |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 128 | tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL); |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 129 | if (tbl == NULL) |
| 130 | goto err_dup; |
| 131 | |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 132 | tbl[0].data = &net->core.sysctl_somaxconn; |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 133 | } |
| 134 | |
Pavel Emelyanov | 8efa6e9 | 2008-03-31 19:41:14 -0700 | [diff] [blame] | 135 | net->core.sysctl_hdr = register_net_sysctl_table(net, |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 136 | net_core_path, tbl); |
Pavel Emelyanov | 8efa6e9 | 2008-03-31 19:41:14 -0700 | [diff] [blame] | 137 | if (net->core.sysctl_hdr == NULL) |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 138 | goto err_reg; |
| 139 | |
| 140 | return 0; |
| 141 | |
| 142 | err_reg: |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 143 | if (tbl != netns_core_table) |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 144 | kfree(tbl); |
| 145 | err_dup: |
| 146 | return -ENOMEM; |
| 147 | } |
| 148 | |
| 149 | static __net_exit void sysctl_core_net_exit(struct net *net) |
| 150 | { |
| 151 | struct ctl_table *tbl; |
| 152 | |
Pavel Emelyanov | 8efa6e9 | 2008-03-31 19:41:14 -0700 | [diff] [blame] | 153 | tbl = net->core.sysctl_hdr->ctl_table_arg; |
| 154 | unregister_net_sysctl_table(net->core.sysctl_hdr); |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 155 | BUG_ON(tbl == netns_core_table); |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 156 | kfree(tbl); |
| 157 | } |
| 158 | |
| 159 | static __net_initdata struct pernet_operations sysctl_core_ops = { |
| 160 | .init = sysctl_core_net_init, |
| 161 | .exit = sysctl_core_net_exit, |
| 162 | }; |
| 163 | |
Pavel Emelyanov | 33eb9cf | 2007-12-05 01:37:34 -0800 | [diff] [blame] | 164 | static __init int sysctl_core_init(void) |
| 165 | { |
Alexey Dobriyan | b27aead | 2008-11-25 18:00:48 -0800 | [diff] [blame] | 166 | static struct ctl_table empty[1]; |
| 167 | |
| 168 | register_sysctl_paths(net_core_path, empty); |
Pavel Emelyanov | d5a4502 | 2008-05-19 13:49:52 -0700 | [diff] [blame] | 169 | register_net_sysctl_rotable(net_core_path, net_core_table); |
Pavel Emelyanov | 024626e | 2007-12-08 00:09:24 -0800 | [diff] [blame] | 170 | return register_pernet_subsys(&sysctl_core_ops); |
Pavel Emelyanov | 33eb9cf | 2007-12-05 01:37:34 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Alexey Dobriyan | b27aead | 2008-11-25 18:00:48 -0800 | [diff] [blame] | 173 | fs_initcall(sysctl_core_init); |