[NETFILTER]: nf_ct_h323: remove ipv6 module dependency
[safe/jmp/linux-2.6] / net / ipv4 / devinet.c
index e7f2b02..9e2747a 100644 (file)
@@ -98,8 +98,7 @@ static BLOCKING_NOTIFIER_HEAD(inetaddr_chain);
 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 *in_dev,
-                                   struct ipv4_devconf *p);
+static void devinet_sysctl_register(struct in_device *idev);
 static void devinet_sysctl_unregister(struct ipv4_devconf *p);
 #endif
 
@@ -173,7 +172,7 @@ static struct in_device *inetdev_init(struct net_device *dev)
        in_dev_hold(in_dev);
 
 #ifdef CONFIG_SYSCTL
-       devinet_sysctl_register(in_dev, &in_dev->cnf);
+       devinet_sysctl_register(in_dev);
 #endif
        ip_mc_init_dev(in_dev);
        if (dev->flags & IFF_UP)
@@ -441,6 +440,7 @@ struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
 
 static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 {
+       struct net *net = skb->sk->sk_net;
        struct nlattr *tb[IFA_MAX+1];
        struct in_device *in_dev;
        struct ifaddrmsg *ifm;
@@ -449,6 +449,9 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg
 
        ASSERT_RTNL();
 
+       if (net != &init_net)
+               return -EINVAL;
+
        err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX, ifa_ipv4_policy);
        if (err < 0)
                goto errout;
@@ -516,8 +519,6 @@ static struct in_ifaddr *rtm_to_ifaddr(struct nlmsghdr *nlh)
                goto errout;
        }
 
-       ipv4_devconf_setall(in_dev);
-
        ifa = inet_alloc_ifa();
        if (ifa == NULL) {
                /*
@@ -528,6 +529,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct nlmsghdr *nlh)
                goto errout;
        }
 
+       ipv4_devconf_setall(in_dev);
        in_dev_hold(in_dev);
 
        if (tb[IFA_ADDRESS] == NULL)
@@ -561,10 +563,14 @@ errout:
 
 static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
 {
+       struct net *net = skb->sk->sk_net;
        struct in_ifaddr *ifa;
 
        ASSERT_RTNL();
 
+       if (net != &init_net)
+               return -EINVAL;
+
        ifa = rtm_to_ifaddr(nlh);
        if (IS_ERR(ifa))
                return PTR_ERR(ifa);
@@ -1028,7 +1034,7 @@ static void inetdev_changename(struct net_device *dev, struct in_device *in_dev)
                memcpy(ifa->ifa_label, dev->name, IFNAMSIZ);
                if (named++ == 0)
                        continue;
-               dot = strchr(ifa->ifa_label, ':');
+               dot = strchr(old, ':');
                if (dot == NULL) {
                        sprintf(old, ":%d", named);
                        dot = old;
@@ -1059,7 +1065,7 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
                        in_dev = inetdev_init(dev);
                        if (!in_dev)
                                return notifier_from_errno(-ENOMEM);
-                       if (dev == loopback_dev) {
+                       if (dev->flags & IFF_LOOPBACK) {
                                IN_DEV_CONF_SET(in_dev, NOXFRM, 1);
                                IN_DEV_CONF_SET(in_dev, NOPOLICY, 1);
                        }
@@ -1075,7 +1081,7 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
        case NETDEV_UP:
                if (dev->mtu < 68)
                        break;
-               if (dev == loopback_dev) {
+               if (dev->flags & IFF_LOOPBACK) {
                        struct in_ifaddr *ifa;
                        if ((ifa = inet_alloc_ifa()) != NULL) {
                                ifa->ifa_local =
@@ -1112,7 +1118,7 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
                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_register(in_dev, &in_dev->cnf);
+               devinet_sysctl_register(in_dev);
 #endif
                break;
        }
@@ -1175,12 +1181,16 @@ nla_put_failure:
 
 static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 {
+       struct net *net = skb->sk->sk_net;
        int idx, ip_idx;
        struct net_device *dev;
        struct in_device *in_dev;
        struct in_ifaddr *ifa;
        int s_ip_idx, s_idx = cb->args[0];
 
+       if (net != &init_net)
+               return 0;
+
        s_ip_idx = ip_idx = cb->args[1];
        idx = 0;
        for_each_netdev(&init_net, dev) {
@@ -1229,10 +1239,10 @@ static void rtmsg_ifa(int event, struct in_ifaddr* ifa, struct nlmsghdr *nlh,
                kfree_skb(skb);
                goto errout;
        }
-       err = rtnl_notify(skb, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL);
+       err = rtnl_notify(skb, &init_net, pid, RTNLGRP_IPV4_IFADDR, nlh, GFP_KERNEL);
 errout:
        if (err < 0)
-               rtnl_set_sk_err(RTNLGRP_IPV4_IFADDR, err);
+               rtnl_set_sk_err(&init_net, RTNLGRP_IPV4_IFADDR, err);
 }
 
 #ifdef CONFIG_SYSCTL
@@ -1420,11 +1430,8 @@ int ipv4_doint_and_flush_strategy(ctl_table *table, int __user *name, int nlen,
 
 static struct devinet_sysctl_table {
        struct ctl_table_header *sysctl_header;
-       ctl_table               devinet_vars[__NET_IPV4_CONF_MAX];
-       ctl_table               devinet_dev[2];
-       ctl_table               devinet_conf_dir[2];
-       ctl_table               devinet_proto_dir[2];
-       ctl_table               devinet_root_dir[2];
+       struct ctl_table devinet_vars[__NET_IPV4_CONF_MAX];
+       char *dev_name;
 } devinet_sysctl = {
        .devinet_vars = {
                DEVINET_SYSCTL_COMPLEX_ENTRY(FORWARDING, "forwarding",
@@ -1456,101 +1463,74 @@ static struct devinet_sysctl_table {
                DEVINET_SYSCTL_FLUSHING_ENTRY(PROMOTE_SECONDARIES,
                                              "promote_secondaries"),
        },
-       .devinet_dev = {
-               {
-                       .ctl_name       = NET_PROTO_CONF_ALL,
-                       .procname       = "all",
-                       .mode           = 0555,
-                       .child          = devinet_sysctl.devinet_vars,
-               },
-       },
-       .devinet_conf_dir = {
-               {
-                       .ctl_name       = NET_IPV4_CONF,
-                       .procname       = "conf",
-                       .mode           = 0555,
-                       .child          = devinet_sysctl.devinet_dev,
-               },
-       },
-       .devinet_proto_dir = {
-               {
-                       .ctl_name       = NET_IPV4,
-                       .procname       = "ipv4",
-                       .mode           = 0555,
-                       .child          = devinet_sysctl.devinet_conf_dir,
-               },
-       },
-       .devinet_root_dir = {
-               {
-                       .ctl_name       = CTL_NET,
-                       .procname       = "net",
-                       .mode           = 0555,
-                       .child          = devinet_sysctl.devinet_proto_dir,
-               },
-       },
 };
 
-static void devinet_sysctl_register(struct in_device *in_dev,
-                                   struct ipv4_devconf *p)
+static void __devinet_sysctl_register(char *dev_name, int ctl_name,
+               struct ipv4_devconf *p)
 {
        int i;
-       struct net_device *dev = in_dev ? in_dev->dev : NULL;
-       struct devinet_sysctl_table *t = kmemdup(&devinet_sysctl, sizeof(*t),
-                                                GFP_KERNEL);
-       char *dev_name = NULL;
+       struct devinet_sysctl_table *t;
+
+#define DEVINET_CTL_PATH_DEV   3
+
+       struct ctl_path devinet_ctl_path[] = {
+               { .procname = "net", .ctl_name = CTL_NET, },
+               { .procname = "ipv4", .ctl_name = NET_IPV4, },
+               { .procname = "conf", .ctl_name = NET_IPV4_CONF, },
+               { /* to be set */ },
+               { },
+       };
 
+       t = kmemdup(&devinet_sysctl, sizeof(*t), GFP_KERNEL);
        if (!t)
-               return;
+               goto out;
+
        for (i = 0; i < ARRAY_SIZE(t->devinet_vars) - 1; i++) {
                t->devinet_vars[i].data += (char *)p - (char *)&ipv4_devconf;
                t->devinet_vars[i].extra1 = p;
        }
 
-       if (dev) {
-               dev_name = dev->name;
-               t->devinet_dev[0].ctl_name = dev->ifindex;
-       } else {
-               dev_name = "default";
-               t->devinet_dev[0].ctl_name = NET_PROTO_CONF_DEFAULT;
-       }
-
        /*
         * Make a copy of dev_name, because '.procname' is regarded as const
         * by sysctl and we wouldn't want anyone to change it under our feet
         * (see SIOCSIFNAME).
         */
-       dev_name = kstrdup(dev_name, GFP_KERNEL);
-       if (!dev_name)
-           goto free;
+       t->dev_name = kstrdup(dev_name, GFP_KERNEL);
+       if (!t->dev_name)
+               goto free;
 
-       t->devinet_dev[0].procname    = dev_name;
-       t->devinet_dev[0].child       = t->devinet_vars;
-       t->devinet_conf_dir[0].child  = t->devinet_dev;
-       t->devinet_proto_dir[0].child = t->devinet_conf_dir;
-       t->devinet_root_dir[0].child  = t->devinet_proto_dir;
+       devinet_ctl_path[DEVINET_CTL_PATH_DEV].procname = t->dev_name;
+       devinet_ctl_path[DEVINET_CTL_PATH_DEV].ctl_name = ctl_name;
 
-       t->sysctl_header = register_sysctl_table(t->devinet_root_dir);
+       t->sysctl_header = register_sysctl_paths(devinet_ctl_path,
+                       t->devinet_vars);
        if (!t->sysctl_header)
-           goto free_procname;
+               goto free_procname;
 
        p->sysctl = t;
        return;
 
-       /* error path */
- free_procname:
-       kfree(dev_name);
- free:
+free_procname:
+       kfree(t->dev_name);
+free:
        kfree(t);
+out:
        return;
 }
 
+static void devinet_sysctl_register(struct in_device *idev)
+{
+       return __devinet_sysctl_register(idev->dev->name, idev->dev->ifindex,
+                       &idev->cnf);
+}
+
 static void devinet_sysctl_unregister(struct ipv4_devconf *p)
 {
        if (p->sysctl) {
                struct devinet_sysctl_table *t = p->sysctl;
                p->sysctl = NULL;
                unregister_sysctl_table(t->sysctl_header);
-               kfree(t->devinet_dev[0].procname);
+               kfree(t->dev_name);
                kfree(t);
        }
 }
@@ -1565,9 +1545,10 @@ void __init devinet_init(void)
        rtnl_register(PF_INET, RTM_DELADDR, inet_rtm_deladdr, NULL);
        rtnl_register(PF_INET, RTM_GETADDR, NULL, inet_dump_ifaddr);
 #ifdef CONFIG_SYSCTL
-       devinet_sysctl.sysctl_header =
-               register_sysctl_table(devinet_sysctl.devinet_root_dir);
-       devinet_sysctl_register(NULL, &ipv4_devconf_dflt);
+       __devinet_sysctl_register("all", NET_PROTO_CONF_ALL,
+                       &ipv4_devconf);
+       __devinet_sysctl_register("default", NET_PROTO_CONF_DEFAULT,
+                       &ipv4_devconf_dflt);
 #endif
 }