aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Emelyanov <xemul@openvz.org>2007-12-05 04:44:58 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:56:31 -0500
commit68dd299bc84dede6aef32e6f4777a676314f5d21 (patch)
tree665132d14a68b3d5676b3fc87424c8be79c28487
parent4d43b78ac27ca50fe42718192ac7c80474417389 (diff)
[INET]: Merge sys.net.ipv4.ip_forward and sys.net.ipv4.conf.all.forwarding
AFAIS these two entries should do the same thing - change the forwarding state on ipv4_devconf and on all the devices. I propose to merge the handlers together using ctl paths. The inet_forward_change() is static after this and I move it higher to be closer to other "propagation" helpers and to avoid diff making patches based on { and } matching :) i.e. - make them easier to read. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/inetdevice.h1
-rw-r--r--net/ipv4/devinet.c66
-rw-r--r--net/ipv4/sysctl_net_ipv4.c65
3 files changed, 44 insertions, 88 deletions
diff --git a/include/linux/inetdevice.h b/include/linux/inetdevice.h
index d83fee2dc643..dd093ea4c489 100644
--- a/include/linux/inetdevice.h
+++ b/include/linux/inetdevice.h
@@ -135,7 +135,6 @@ extern struct in_device *inetdev_by_index(int);
135extern __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope); 135extern __be32 inet_select_addr(const struct net_device *dev, __be32 dst, int scope);
136extern __be32 inet_confirm_addr(const struct net_device *dev, __be32 dst, __be32 local, int scope); 136extern __be32 inet_confirm_addr(const struct net_device *dev, __be32 dst, __be32 local, int scope);
137extern struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, __be32 mask); 137extern struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix, __be32 mask);
138extern void inet_forward_change(void);
139 138
140static __inline__ int inet_ifa_match(__be32 addr, struct in_ifaddr *ifa) 139static __inline__ int inet_ifa_match(__be32 addr, struct in_ifaddr *ifa)
141{ 140{
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 9e2747aab252..d1dc0150647d 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1263,6 +1263,28 @@ static void devinet_copy_dflt_conf(int i)
1263 read_unlock(&dev_base_lock); 1263 read_unlock(&dev_base_lock);
1264} 1264}
1265 1265
1266static void inet_forward_change(void)
1267{
1268 struct net_device *dev;
1269 int on = IPV4_DEVCONF_ALL(FORWARDING);
1270
1271 IPV4_DEVCONF_ALL(ACCEPT_REDIRECTS) = !on;
1272 IPV4_DEVCONF_DFLT(FORWARDING) = on;
1273
1274 read_lock(&dev_base_lock);
1275 for_each_netdev(&init_net, dev) {
1276 struct in_device *in_dev;
1277 rcu_read_lock();
1278 in_dev = __in_dev_get_rcu(dev);
1279 if (in_dev)
1280 IN_DEV_CONF_SET(in_dev, FORWARDING, on);
1281 rcu_read_unlock();
1282 }
1283 read_unlock(&dev_base_lock);
1284
1285 rt_cache_flush(0);
1286}
1287
1266static int devinet_conf_proc(ctl_table *ctl, int write, 1288static int devinet_conf_proc(ctl_table *ctl, int write,
1267 struct file* filp, void __user *buffer, 1289 struct file* filp, void __user *buffer,
1268 size_t *lenp, loff_t *ppos) 1290 size_t *lenp, loff_t *ppos)
@@ -1332,28 +1354,6 @@ static int devinet_conf_sysctl(ctl_table *table, int __user *name, int nlen,
1332 return 1; 1354 return 1;
1333} 1355}
1334 1356
1335void inet_forward_change(void)
1336{
1337 struct net_device *dev;
1338 int on = IPV4_DEVCONF_ALL(FORWARDING);
1339
1340 IPV4_DEVCONF_ALL(ACCEPT_REDIRECTS) = !on;
1341 IPV4_DEVCONF_DFLT(FORWARDING) = on;
1342
1343 read_lock(&dev_base_lock);
1344 for_each_netdev(&init_net, dev) {
1345 struct in_device *in_dev;
1346 rcu_read_lock();
1347 in_dev = __in_dev_get_rcu(dev);
1348 if (in_dev)
1349 IN_DEV_CONF_SET(in_dev, FORWARDING, on);
1350 rcu_read_unlock();
1351 }
1352 read_unlock(&dev_base_lock);
1353
1354 rt_cache_flush(0);
1355}
1356
1357static int devinet_sysctl_forward(ctl_table *ctl, int write, 1357static int devinet_sysctl_forward(ctl_table *ctl, int write,
1358 struct file* filp, void __user *buffer, 1358 struct file* filp, void __user *buffer,
1359 size_t *lenp, loff_t *ppos) 1359 size_t *lenp, loff_t *ppos)
@@ -1536,6 +1536,27 @@ static void devinet_sysctl_unregister(struct ipv4_devconf *p)
1536} 1536}
1537#endif 1537#endif
1538 1538
1539static struct ctl_table ctl_forward_entry[] = {
1540 {
1541 .ctl_name = NET_IPV4_FORWARD,
1542 .procname = "ip_forward",
1543 .data = &ipv4_devconf.data[
1544 NET_IPV4_CONF_FORWARDING - 1],
1545 .maxlen = sizeof(int),
1546 .mode = 0644,
1547 .proc_handler = devinet_sysctl_forward,
1548 .strategy = devinet_conf_sysctl,
1549 .extra1 = &ipv4_devconf,
1550 },
1551 { },
1552};
1553
1554static __initdata struct ctl_path net_ipv4_path[] = {
1555 { .procname = "net", .ctl_name = CTL_NET, },
1556 { .procname = "ipv4", .ctl_name = NET_IPV4, },
1557 { },
1558};
1559
1539void __init devinet_init(void) 1560void __init devinet_init(void)
1540{ 1561{
1541 register_gifconf(PF_INET, inet_gifconf); 1562 register_gifconf(PF_INET, inet_gifconf);
@@ -1549,6 +1570,7 @@ void __init devinet_init(void)
1549 &ipv4_devconf); 1570 &ipv4_devconf);
1550 __devinet_sysctl_register("default", NET_PROTO_CONF_DEFAULT, 1571 __devinet_sysctl_register("default", NET_PROTO_CONF_DEFAULT,
1551 &ipv4_devconf_dflt); 1572 &ipv4_devconf_dflt);
1573 register_sysctl_paths(net_ipv4_path, ctl_forward_entry);
1552#endif 1574#endif
1553} 1575}
1554 1576
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
index bfd0dec6238d..844f26fab06f 100644
--- a/net/ipv4/sysctl_net_ipv4.c
+++ b/net/ipv4/sysctl_net_ipv4.c
@@ -27,62 +27,6 @@ static int tcp_retr1_max = 255;
27static int ip_local_port_range_min[] = { 1, 1 }; 27static int ip_local_port_range_min[] = { 1, 1 };
28static int ip_local_port_range_max[] = { 65535, 65535 }; 28static int ip_local_port_range_max[] = { 65535, 65535 };
29 29
30static
31int ipv4_sysctl_forward(ctl_table *ctl, int write, struct file * filp,
32 void __user *buffer, size_t *lenp, loff_t *ppos)
33{
34 int val = IPV4_DEVCONF_ALL(FORWARDING);
35 int ret;
36
37 ret = proc_dointvec(ctl, write, filp, buffer, lenp, ppos);
38
39 if (write && IPV4_DEVCONF_ALL(FORWARDING) != val)
40 inet_forward_change();
41
42 return ret;
43}
44
45static int ipv4_sysctl_forward_strategy(ctl_table *table,
46 int __user *name, int nlen,
47 void __user *oldval, size_t __user *oldlenp,
48 void __user *newval, size_t newlen)
49{
50 int *valp = table->data;
51 int new;
52
53 if (!newval || !newlen)
54 return 0;
55
56 if (newlen != sizeof(int))
57 return -EINVAL;
58
59 if (get_user(new, (int __user *)newval))
60 return -EFAULT;
61
62 if (new == *valp)
63 return 0;
64
65 if (oldval && oldlenp) {
66 size_t len;
67
68 if (get_user(len, oldlenp))
69 return -EFAULT;
70
71 if (len) {
72 if (len > table->maxlen)
73 len = table->maxlen;
74 if (copy_to_user(oldval, valp, len))
75 return -EFAULT;
76 if (put_user(len, oldlenp))
77 return -EFAULT;
78 }
79 }
80
81 *valp = new;
82 inet_forward_change();
83 return 1;
84}
85
86extern seqlock_t sysctl_port_range_lock; 30extern seqlock_t sysctl_port_range_lock;
87extern int sysctl_local_port_range[2]; 31extern int sysctl_local_port_range[2];
88 32
@@ -282,15 +226,6 @@ static struct ctl_table ipv4_table[] = {
282 .proc_handler = &proc_dointvec 226 .proc_handler = &proc_dointvec
283 }, 227 },
284 { 228 {
285 .ctl_name = NET_IPV4_FORWARD,
286 .procname = "ip_forward",
287 .data = &IPV4_DEVCONF_ALL(FORWARDING),
288 .maxlen = sizeof(int),
289 .mode = 0644,
290 .proc_handler = &ipv4_sysctl_forward,
291 .strategy = &ipv4_sysctl_forward_strategy
292 },
293 {
294 .ctl_name = NET_IPV4_DEFAULT_TTL, 229 .ctl_name = NET_IPV4_DEFAULT_TTL,
295 .procname = "ip_default_ttl", 230 .procname = "ip_default_ttl",
296 .data = &sysctl_ip_default_ttl, 231 .data = &sysctl_ip_default_ttl,