[IPV4]: Make __devinet_sysctl_register return an error
[deliverable/linux.git] / net / ipv4 / devinet.c
index 9e2747aab252f4d97bf596e040d735fa9075b911..82def2c1c65050db75ea0a7163d00d0bfa72582c 100644 (file)
@@ -99,7 +99,14 @@ static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
                         int destroy);
 #ifdef CONFIG_SYSCTL
 static void devinet_sysctl_register(struct in_device *idev);
-static void devinet_sysctl_unregister(struct ipv4_devconf *p);
+static void devinet_sysctl_unregister(struct in_device *idev);
+#else
+static inline void devinet_sysctl_register(struct in_device *idev)
+{
+}
+static inline void devinet_sysctl_unregister(struct in_device *idev)
+{
+}
 #endif
 
 /* Locks all the inet devices. */
@@ -163,17 +170,10 @@ static struct in_device *inetdev_init(struct net_device *dev)
                goto out_kfree;
        /* Reference in_dev->dev */
        dev_hold(dev);
-#ifdef CONFIG_SYSCTL
-       neigh_sysctl_register(dev, in_dev->arp_parms, NET_IPV4,
-                             NET_IPV4_NEIGH, "ipv4", NULL, NULL);
-#endif
-
        /* Account for reference dev->ip_ptr (below) */
        in_dev_hold(in_dev);
 
-#ifdef CONFIG_SYSCTL
        devinet_sysctl_register(in_dev);
-#endif
        ip_mc_init_dev(in_dev);
        if (dev->flags & IFF_UP)
                ip_mc_up(in_dev);
@@ -212,15 +212,9 @@ static void inetdev_destroy(struct in_device *in_dev)
                inet_free_ifa(ifa);
        }
 
-#ifdef CONFIG_SYSCTL
-       devinet_sysctl_unregister(&in_dev->cnf);
-#endif
-
        dev->ip_ptr = NULL;
 
-#ifdef CONFIG_SYSCTL
-       neigh_sysctl_unregister(in_dev->arp_parms);
-#endif
+       devinet_sysctl_unregister(in_dev);
        neigh_parms_release(&arp_tbl, in_dev->arp_parms);
        arp_ifdown(dev);
 
@@ -1113,13 +1107,8 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
                 */
                inetdev_changename(dev, in_dev);
 
-#ifdef CONFIG_SYSCTL
-               devinet_sysctl_unregister(&in_dev->cnf);
-               neigh_sysctl_unregister(in_dev->arp_parms);
-               neigh_sysctl_register(dev, in_dev->arp_parms, NET_IPV4,
-                                     NET_IPV4_NEIGH, "ipv4", NULL, NULL);
+               devinet_sysctl_unregister(in_dev);
                devinet_sysctl_register(in_dev);
-#endif
                break;
        }
 out:
@@ -1263,6 +1252,28 @@ static void devinet_copy_dflt_conf(int i)
        read_unlock(&dev_base_lock);
 }
 
+static void inet_forward_change(void)
+{
+       struct net_device *dev;
+       int on = IPV4_DEVCONF_ALL(FORWARDING);
+
+       IPV4_DEVCONF_ALL(ACCEPT_REDIRECTS) = !on;
+       IPV4_DEVCONF_DFLT(FORWARDING) = on;
+
+       read_lock(&dev_base_lock);
+       for_each_netdev(&init_net, dev) {
+               struct in_device *in_dev;
+               rcu_read_lock();
+               in_dev = __in_dev_get_rcu(dev);
+               if (in_dev)
+                       IN_DEV_CONF_SET(in_dev, FORWARDING, on);
+               rcu_read_unlock();
+       }
+       read_unlock(&dev_base_lock);
+
+       rt_cache_flush(0);
+}
+
 static int devinet_conf_proc(ctl_table *ctl, int write,
                             struct file* filp, void __user *buffer,
                             size_t *lenp, loff_t *ppos)
@@ -1332,28 +1343,6 @@ static int devinet_conf_sysctl(ctl_table *table, int __user *name, int nlen,
        return 1;
 }
 
-void inet_forward_change(void)
-{
-       struct net_device *dev;
-       int on = IPV4_DEVCONF_ALL(FORWARDING);
-
-       IPV4_DEVCONF_ALL(ACCEPT_REDIRECTS) = !on;
-       IPV4_DEVCONF_DFLT(FORWARDING) = on;
-
-       read_lock(&dev_base_lock);
-       for_each_netdev(&init_net, dev) {
-               struct in_device *in_dev;
-               rcu_read_lock();
-               in_dev = __in_dev_get_rcu(dev);
-               if (in_dev)
-                       IN_DEV_CONF_SET(in_dev, FORWARDING, on);
-               rcu_read_unlock();
-       }
-       read_unlock(&dev_base_lock);
-
-       rt_cache_flush(0);
-}
-
 static int devinet_sysctl_forward(ctl_table *ctl, int write,
                                  struct file* filp, void __user *buffer,
                                  size_t *lenp, loff_t *ppos)
@@ -1465,8 +1454,8 @@ static struct devinet_sysctl_table {
        },
 };
 
-static void __devinet_sysctl_register(char *dev_name, int ctl_name,
-               struct ipv4_devconf *p)
+static int __devinet_sysctl_register(struct net *net, char *dev_name,
+               int ctl_name, struct ipv4_devconf *p)
 {
        int i;
        struct devinet_sysctl_table *t;
@@ -1508,34 +1497,65 @@ static void __devinet_sysctl_register(char *dev_name, int ctl_name,
                goto free_procname;
 
        p->sysctl = t;
-       return;
+       return 0;
 
 free_procname:
        kfree(t->dev_name);
 free:
        kfree(t);
 out:
-       return;
+       return -ENOBUFS;
+}
+
+static void __devinet_sysctl_unregister(struct ipv4_devconf *cnf)
+{
+       struct devinet_sysctl_table *t = cnf->sysctl;
+
+       if (t == NULL)
+               return;
+
+       cnf->sysctl = NULL;
+       unregister_sysctl_table(t->sysctl_header);
+       kfree(t->dev_name);
+       kfree(t);
 }
 
 static void devinet_sysctl_register(struct in_device *idev)
 {
-       return __devinet_sysctl_register(idev->dev->name, idev->dev->ifindex,
+       neigh_sysctl_register(idev->dev, idev->arp_parms, NET_IPV4,
+                       NET_IPV4_NEIGH, "ipv4", NULL, NULL);
+       __devinet_sysctl_register(idev->dev->name, idev->dev->ifindex,
                        &idev->cnf);
 }
 
-static void devinet_sysctl_unregister(struct ipv4_devconf *p)
+static void devinet_sysctl_unregister(struct in_device *idev)
 {
-       if (p->sysctl) {
-               struct devinet_sysctl_table *t = p->sysctl;
-               p->sysctl = NULL;
-               unregister_sysctl_table(t->sysctl_header);
-               kfree(t->dev_name);
-               kfree(t);
-       }
+       __devinet_sysctl_unregister(&idev->cnf);
+       neigh_sysctl_unregister(idev->arp_parms);
 }
 #endif
 
+static struct ctl_table ctl_forward_entry[] = {
+       {
+               .ctl_name       = NET_IPV4_FORWARD,
+               .procname       = "ip_forward",
+               .data           = &ipv4_devconf.data[
+                                       NET_IPV4_CONF_FORWARDING - 1],
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = devinet_sysctl_forward,
+               .strategy       = devinet_conf_sysctl,
+               .extra1         = &ipv4_devconf,
+       },
+       { },
+};
+
+static __initdata struct ctl_path net_ipv4_path[] = {
+       { .procname = "net", .ctl_name = CTL_NET, },
+       { .procname = "ipv4", .ctl_name = NET_IPV4, },
+       { },
+};
+
 void __init devinet_init(void)
 {
        register_gifconf(PF_INET, inet_gifconf);
@@ -1549,6 +1569,7 @@ void __init devinet_init(void)
                        &ipv4_devconf);
        __devinet_sysctl_register("default", NET_PROTO_CONF_DEFAULT,
                        &ipv4_devconf_dflt);
+       register_sysctl_paths(net_ipv4_path, ctl_forward_entry);
 #endif
 }
 
This page took 0.046081 seconds and 5 git commands to generate.