Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / ipv4 / devinet.c
index ea402aa..f7b5ddd 100644 (file)
@@ -32,6 +32,7 @@
 #include <asm/uaccess.h>
 #include <asm/system.h>
 #include <linux/bitops.h>
+#include <linux/capability.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
@@ -58,6 +59,7 @@
 #endif
 #include <linux/kmod.h>
 
+#include <net/arp.h>
 #include <net/ip.h>
 #include <net/route.h>
 #include <net/ip_fib.h>
@@ -79,7 +81,7 @@ static struct ipv4_devconf ipv4_devconf_dflt = {
 
 static void rtmsg_ifa(int event, struct in_ifaddr *);
 
-static struct notifier_block *inetaddr_chain;
+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
@@ -234,7 +236,10 @@ static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
                         int destroy)
 {
        struct in_ifaddr *promote = NULL;
-       struct in_ifaddr *ifa1 = *ifap;
+       struct in_ifaddr *ifa, *ifa1 = *ifap;
+       struct in_ifaddr *last_prim = in_dev->ifa_list;
+       struct in_ifaddr *prev_prom = NULL;
+       int do_promote = IN_DEV_PROMOTE_SECONDARIES(in_dev);
 
        ASSERT_RTNL();
 
@@ -243,22 +248,27 @@ static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
         **/
 
        if (!(ifa1->ifa_flags & IFA_F_SECONDARY)) {
-               struct in_ifaddr *ifa;
                struct in_ifaddr **ifap1 = &ifa1->ifa_next;
 
                while ((ifa = *ifap1) != NULL) {
+                       if (!(ifa->ifa_flags & IFA_F_SECONDARY) && 
+                           ifa1->ifa_scope <= ifa->ifa_scope)
+                               last_prim = ifa;
+
                        if (!(ifa->ifa_flags & IFA_F_SECONDARY) ||
                            ifa1->ifa_mask != ifa->ifa_mask ||
                            !inet_ifa_match(ifa1->ifa_address, ifa)) {
                                ifap1 = &ifa->ifa_next;
+                               prev_prom = ifa;
                                continue;
                        }
 
-                       if (!IN_DEV_PROMOTE_SECONDARIES(in_dev)) {
+                       if (!do_promote) {
                                *ifap1 = ifa->ifa_next;
 
                                rtmsg_ifa(RTM_DELADDR, ifa);
-                               notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa);
+                               blocking_notifier_call_chain(&inetaddr_chain,
+                                               NETDEV_DOWN, ifa);
                                inet_free_ifa(ifa);
                        } else {
                                promote = ifa;
@@ -282,20 +292,34 @@ static void inet_del_ifa(struct in_device *in_dev, struct in_ifaddr **ifap,
           So that, this order is correct.
         */
        rtmsg_ifa(RTM_DELADDR, ifa1);
-       notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1);
+       blocking_notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1);
+
+       if (promote) {
+
+               if (prev_prom) {
+                       prev_prom->ifa_next = promote->ifa_next;
+                       promote->ifa_next = last_prim->ifa_next;
+                       last_prim->ifa_next = promote;
+               }
+
+               promote->ifa_flags &= ~IFA_F_SECONDARY;
+               rtmsg_ifa(RTM_NEWADDR, promote);
+               blocking_notifier_call_chain(&inetaddr_chain,
+                               NETDEV_UP, promote);
+               for (ifa = promote->ifa_next; ifa; ifa = ifa->ifa_next) {
+                       if (ifa1->ifa_mask != ifa->ifa_mask ||
+                           !inet_ifa_match(ifa1->ifa_address, ifa))
+                                       continue;
+                       fib_add_ifaddr(ifa);
+               }
+
+       }
        if (destroy) {
                inet_free_ifa(ifa1);
 
                if (!in_dev->ifa_list)
                        inetdev_destroy(in_dev);
        }
-
-       if (promote && IN_DEV_PROMOTE_SECONDARIES(in_dev)) {
-               /* not sure if we should send a delete notify first? */
-               promote->ifa_flags &= ~IFA_F_SECONDARY;
-               rtmsg_ifa(RTM_NEWADDR, promote);
-               notifier_call_chain(&inetaddr_chain, NETDEV_UP, promote);
-       }
 }
 
 static int inet_insert_ifa(struct in_ifaddr *ifa)
@@ -344,14 +368,14 @@ static int inet_insert_ifa(struct in_ifaddr *ifa)
           Notifier will trigger FIB update, so that
           listeners of netlink will know about new ifaddr */
        rtmsg_ifa(RTM_NEWADDR, ifa);
-       notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
+       blocking_notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
 
        return 0;
 }
 
 static int inet_set_ifa(struct net_device *dev, struct in_ifaddr *ifa)
 {
-       struct in_device *in_dev = __in_dev_get(dev);
+       struct in_device *in_dev = __in_dev_get_rtnl(dev);
 
        ASSERT_RTNL();
 
@@ -449,7 +473,7 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg
                goto out;
 
        rc = -ENOBUFS;
-       if ((in_dev = __in_dev_get(dev)) == NULL) {
+       if ((in_dev = __in_dev_get_rtnl(dev)) == NULL) {
                in_dev = inetdev_init(dev);
                if (!in_dev)
                        goto out;
@@ -507,33 +531,6 @@ static __inline__ int inet_abc_len(u32 addr)
        return rc;
 }
 
-/*
-       Check that a device is not member of the ipv4root assigned to the process
-       Return true if this is the case
-
-       If the process is not bound to specific IP, then it returns 0 (all
-       interface are fine).
-*/
-static inline int devinet_notiproot (struct in_ifaddr *ifa)
-{
-       int ret = 0;
-       struct nx_info *nxi;
-
-       if ((nxi = current->nx_info)) {
-               int i;
-               int nbip = nxi->nbipv4;
-               __u32 addr = ifa->ifa_local;
-               ret = 1;
-               for (i=0; i<nbip; i++) {
-                       if(nxi->ipv4[i] == addr) {
-                               ret = 0;
-                               break;
-                       }
-               }
-       }
-       return ret;
-}
-
 
 int devinet_ioctl(unsigned int cmd, void __user *arg)
 {
@@ -611,7 +608,10 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
        if (colon)
                *colon = ':';
 
-       if ((in_dev = __in_dev_get(dev)) != NULL) {
+       if ((in_dev = __in_dev_get_rtnl(dev)) != NULL) {
+               struct nx_info *nxi = current->nx_info;
+               int hide_netif = vx_flags(VXF_HIDE_NETIF, 0);
+
                if (tryaddrmatch) {
                        /* Matthias Andree */
                        /* compare label and address (4.4BSD style) */
@@ -620,6 +620,8 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
                           This is checked above. */
                        for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
                             ifap = &ifa->ifa_next) {
+                               if (hide_netif && !ifa_in_nx_info(ifa, nxi))
+                                       continue;
                                if (!strcmp(ifr.ifr_name, ifa->ifa_label) &&
                                    sin_orig.sin_addr.s_addr ==
                                                        ifa->ifa_address) {
@@ -632,18 +634,18 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
                   comparing just the label */
                if (!ifa) {
                        for (ifap = &in_dev->ifa_list; (ifa = *ifap) != NULL;
-                            ifap = &ifa->ifa_next)
+                            ifap = &ifa->ifa_next) {
+                               if (hide_netif && !ifa_in_nx_info(ifa, nxi))
+                                       continue;
                                if (!strcmp(ifr.ifr_name, ifa->ifa_label))
                                        break;
+                       }
                }
        }
 
        ret = -EADDRNOTAVAIL;
        if (!ifa && cmd != SIOCSIFADDR && cmd != SIOCSIFFLAGS)
                goto done;
-       if (vx_flags(VXF_HIDE_NETIF, 0) &&
-               !ifa_in_nx_info(ifa, current->nx_info))
-               goto done;
 
        switch(cmd) {
        case SIOCGIFADDR:       /* Get interface address */
@@ -745,6 +747,7 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
                        break;
                ret = 0;
                if (ifa->ifa_mask != sin->sin_addr.s_addr) {
+                       u32 old_mask = ifa->ifa_mask;
                        inet_del_ifa(in_dev, ifap, 0);
                        ifa->ifa_mask = sin->sin_addr.s_addr;
                        ifa->ifa_prefixlen = inet_mask_len(ifa->ifa_mask);
@@ -758,7 +761,7 @@ int devinet_ioctl(unsigned int cmd, void __user *arg)
                        if ((dev->flags & IFF_BROADCAST) &&
                            (ifa->ifa_prefixlen < 31) &&
                            (ifa->ifa_broadcast ==
-                            (ifa->ifa_local|~ifa->ifa_mask))) {
+                            (ifa->ifa_local|~old_mask))) {
                                ifa->ifa_broadcast = (ifa->ifa_local |
                                                      ~sin->sin_addr.s_addr);
                        }
@@ -778,7 +781,7 @@ rarok:
 
 static int inet_gifconf(struct net_device *dev, char __user *buf, int len)
 {
-       struct in_device *in_dev = __in_dev_get(dev);
+       struct in_device *in_dev = __in_dev_get_rtnl(dev);
        struct in_ifaddr *ifa;
        struct ifreq ifr;
        int done = 0;
@@ -824,7 +827,7 @@ u32 inet_select_addr(const struct net_device *dev, u32 dst, int scope)
        struct in_device *in_dev;
 
        rcu_read_lock();
-       in_dev = __in_dev_get(dev);
+       in_dev = __in_dev_get_rcu(dev);
        if (!in_dev)
                goto no_in_dev;
 
@@ -851,7 +854,7 @@ no_in_dev:
        read_lock(&dev_base_lock);
        rcu_read_lock();
        for (dev = dev_base; dev; dev = dev->next) {
-               if ((in_dev = __in_dev_get(dev)) == NULL)
+               if ((in_dev = __in_dev_get_rcu(dev)) == NULL)
                        continue;
 
                for_primary_ifa(in_dev) {
@@ -920,7 +923,7 @@ u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scop
 
        if (dev) {
                rcu_read_lock();
-               if ((in_dev = __in_dev_get(dev)))
+               if ((in_dev = __in_dev_get_rcu(dev)))
                        addr = confirm_addr_indev(in_dev, dst, local, scope);
                rcu_read_unlock();
 
@@ -930,7 +933,7 @@ u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scop
        read_lock(&dev_base_lock);
        rcu_read_lock();
        for (dev = dev_base; dev; dev = dev->next) {
-               if ((in_dev = __in_dev_get(dev))) {
+               if ((in_dev = __in_dev_get_rcu(dev))) {
                        addr = confirm_addr_indev(in_dev, dst, local, scope);
                        if (addr)
                                break;
@@ -948,12 +951,12 @@ u32 inet_confirm_addr(const struct net_device *dev, u32 dst, u32 local, int scop
 
 int register_inetaddr_notifier(struct notifier_block *nb)
 {
-       return notifier_chain_register(&inetaddr_chain, nb);
+       return blocking_notifier_chain_register(&inetaddr_chain, nb);
 }
 
 int unregister_inetaddr_notifier(struct notifier_block *nb)
 {
-       return notifier_chain_unregister(&inetaddr_chain, nb);
+       return blocking_notifier_chain_unregister(&inetaddr_chain, nb);
 }
 
 /* Rename ifa_labels for a device name change. Make some effort to preserve existing
@@ -990,7 +993,7 @@ static int inetdev_event(struct notifier_block *this, unsigned long event,
                         void *ptr)
 {
        struct net_device *dev = ptr;
-       struct in_device *in_dev = __in_dev_get(dev);
+       struct in_device *in_dev = __in_dev_get_rtnl(dev);
 
        ASSERT_RTNL();
 
@@ -1063,14 +1066,13 @@ static struct notifier_block ip_netdev_notifier = {
 };
 
 static int inet_fill_ifaddr(struct sk_buff *skb, struct in_ifaddr *ifa,
-                           u32 pid, u32 seq, int event)
+                           u32 pid, u32 seq, int event, unsigned int flags)
 {
        struct ifaddrmsg *ifm;
        struct nlmsghdr  *nlh;
        unsigned char    *b = skb->tail;
 
-       nlh = NLMSG_PUT(skb, pid, seq, event, sizeof(*ifm));
-       if (pid) nlh->nlmsg_flags |= NLM_F_MULTI;
+       nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*ifm), flags);
        ifm = NLMSG_DATA(nlh);
        ifm->ifa_family = AF_INET;
        ifm->ifa_prefixlen = ifa->ifa_prefixlen;
@@ -1113,7 +1115,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
                if (idx > s_idx)
                        s_ip_idx = 0;
                rcu_read_lock();
-               if ((in_dev = __in_dev_get(dev)) == NULL) {
+               if ((in_dev = __in_dev_get_rcu(dev)) == NULL) {
                        rcu_read_unlock();
                        continue;
                }
@@ -1127,7 +1129,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
                                continue;
                        if (inet_fill_ifaddr(skb, ifa, NETLINK_CB(cb->skb).pid,
                                             cb->nlh->nlmsg_seq,
-                                            RTM_NEWADDR) <= 0) {
+                                            RTM_NEWADDR, NLM_F_MULTI) <= 0) {
                                rcu_read_unlock();
                                goto done;
                        }
@@ -1149,13 +1151,12 @@ static void rtmsg_ifa(int event, struct in_ifaddr* ifa)
        struct sk_buff *skb = alloc_skb(size, GFP_KERNEL);
 
        if (!skb)
-               netlink_set_err(rtnl, 0, RTMGRP_IPV4_IFADDR, ENOBUFS);
-       else if (inet_fill_ifaddr(skb, ifa, 0, 0, event) < 0) {
+               netlink_set_err(rtnl, 0, RTNLGRP_IPV4_IFADDR, ENOBUFS);
+       else if (inet_fill_ifaddr(skb, ifa, 0, 0, event, 0) < 0) {
                kfree_skb(skb);
-               netlink_set_err(rtnl, 0, RTMGRP_IPV4_IFADDR, EINVAL);
+               netlink_set_err(rtnl, 0, RTNLGRP_IPV4_IFADDR, EINVAL);
        } else {
-               NETLINK_CB(skb).dst_groups = RTMGRP_IPV4_IFADDR;
-               netlink_broadcast(rtnl, skb, 0, RTMGRP_IPV4_IFADDR, GFP_KERNEL);
+               netlink_broadcast(rtnl, skb, 0, RTNLGRP_IPV4_IFADDR, GFP_KERNEL);
        }
 }
 
@@ -1188,7 +1189,7 @@ void inet_forward_change(void)
        for (dev = dev_base; dev; dev = dev->next) {
                struct in_device *in_dev;
                rcu_read_lock();
-               in_dev = __in_dev_get(dev);
+               in_dev = __in_dev_get_rcu(dev);
                if (in_dev)
                        in_dev->cnf.forwarding = on;
                rcu_read_unlock();
@@ -1409,6 +1410,14 @@ static struct devinet_sysctl_table {
                        .mode           = 0644,
                        .proc_handler   = &proc_dointvec,
                },
+               {
+                       .ctl_name       = NET_IPV4_CONF_ARP_ACCEPT,
+                       .procname       = "arp_accept",
+                       .data           = &ipv4_devconf.arp_accept,
+                       .maxlen         = sizeof(int),
+                       .mode           = 0644,
+                       .proc_handler   = &proc_dointvec,
+               },
                {
                        .ctl_name       = NET_IPV4_CONF_NOXFRM,
                        .procname       = "disable_xfrm",
@@ -1509,7 +1518,7 @@ static void devinet_sysctl_register(struct in_device *in_dev,
         * by sysctl and we wouldn't want anyone to change it under our feet
         * (see SIOCSIFNAME).
         */     
-       dev_name = net_sysctl_strdup(dev_name);
+       dev_name = kstrdup(dev_name, GFP_KERNEL);
        if (!dev_name)
            goto free;
 
@@ -1562,7 +1571,6 @@ void __init devinet_init(void)
 #endif
 }
 
-EXPORT_SYMBOL(devinet_ioctl);
 EXPORT_SYMBOL(in_dev_finish_destroy);
 EXPORT_SYMBOL(inet_select_addr);
 EXPORT_SYMBOL(inetdev_by_index);