]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - drivers/net/bonding/bond_main.c
[NET]: Make /proc/net per network namespace
[net-next-2.6.git] / drivers / net / bonding / bond_main.c
index 724bce51f936b52450764463b7faf1b707487483..5de648f90a458106e406bf6881ab3b03344263e2 100644 (file)
@@ -75,6 +75,7 @@
 #include <linux/if_vlan.h>
 #include <linux/if_bonding.h>
 #include <net/route.h>
+#include <net/net_namespace.h>
 #include "bonding.h"
 #include "bond_3ad.h"
 #include "bond_alb.h"
@@ -187,7 +188,7 @@ static void bond_send_gratuitous_arp(struct bonding *bond);
 
 /*---------------------------- General routines -----------------------------*/
 
-const char *bond_mode_name(int mode)
+static const char *bond_mode_name(int mode)
 {
        switch (mode) {
        case BOND_MODE_ROUNDROBIN :
@@ -613,38 +614,20 @@ down:
 static int bond_update_speed_duplex(struct slave *slave)
 {
        struct net_device *slave_dev = slave->dev;
-       static int (* ioctl)(struct net_device *, struct ifreq *, int);
-       struct ifreq ifr;
        struct ethtool_cmd etool;
+       int res;
 
        /* Fake speed and duplex */
        slave->speed = SPEED_100;
        slave->duplex = DUPLEX_FULL;
 
-       if (slave_dev->ethtool_ops) {
-               int res;
-
-               if (!slave_dev->ethtool_ops->get_settings) {
-                       return -1;
-               }
-
-               res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
-               if (res < 0) {
-                       return -1;
-               }
-
-               goto verify;
-       }
+       if (!slave_dev->ethtool_ops || !slave_dev->ethtool_ops->get_settings)
+               return -1;
 
-       ioctl = slave_dev->do_ioctl;
-       strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
-       etool.cmd = ETHTOOL_GSET;
-       ifr.ifr_data = (char*)&etool;
-       if (!ioctl || (IOCTL(slave_dev, &ifr, SIOCETHTOOL) < 0)) {
+       res = slave_dev->ethtool_ops->get_settings(slave_dev, &etool);
+       if (res < 0)
                return -1;
-       }
 
-verify:
        switch (etool.speed) {
        case SPEED_10:
        case SPEED_100:
@@ -690,7 +673,6 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
        static int (* ioctl)(struct net_device *, struct ifreq *, int);
        struct ifreq ifr;
        struct mii_ioctl_data *mii;
-       struct ethtool_value etool;
 
        if (bond->params.use_carrier) {
                return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
@@ -721,9 +703,10 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
                }
        }
 
-       /* try SIOCETHTOOL ioctl, some drivers cache ETHTOOL_GLINK */
-       /* for a period of time so we attempt to get link status   */
-       /* from it last if the above MII ioctls fail...            */
+       /*
+        * Some drivers cache ETHTOOL_GLINK for a period of time so we only
+        * attempt to get link status from it if the above MII ioctls fail.
+        */
        if (slave_dev->ethtool_ops) {
                if (slave_dev->ethtool_ops->get_link) {
                        u32 link;
@@ -734,23 +717,9 @@ static int bond_check_dev_link(struct bonding *bond, struct net_device *slave_de
                }
        }
 
-       if (ioctl) {
-               strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
-               etool.cmd = ETHTOOL_GLINK;
-               ifr.ifr_data = (char*)&etool;
-               if (IOCTL(slave_dev, &ifr, SIOCETHTOOL) == 0) {
-                       if (etool.data == 1) {
-                               return BMSR_LSTATUS;
-                       } else {
-                               dprintk("SIOCETHTOOL shows link down\n");
-                               return 0;
-                       }
-               }
-       }
-
        /*
         * If reporting, report that either there's no dev->do_ioctl,
-        * or both SIOCGMIIREG and SIOCETHTOOL failed (meaning that we
+        * or both SIOCGMIIREG and get_link failed (meaning that we
         * cannot report link status).  If not reporting, pretend
         * we're ok.
         */
@@ -1224,7 +1193,8 @@ static void bond_detach_slave(struct bonding *bond, struct slave *slave)
 
 /*---------------------------------- IOCTL ----------------------------------*/
 
-int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
+static int bond_sethwaddr(struct net_device *bond_dev,
+                         struct net_device *slave_dev)
 {
        dprintk("bond_dev=%p\n", bond_dev);
        dprintk("slave_dev=%p\n", slave_dev);
@@ -1233,43 +1203,35 @@ int bond_sethwaddr(struct net_device *bond_dev, struct net_device *slave_dev)
        return 0;
 }
 
-#define BOND_INTERSECT_FEATURES \
-       (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_TSO | NETIF_F_UFO)
+#define BOND_VLAN_FEATURES \
+       (NETIF_F_VLAN_CHALLENGED | NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX | \
+        NETIF_F_HW_VLAN_FILTER)
 
 /* 
  * Compute the common dev->feature set available to all slaves.  Some
- * feature bits are managed elsewhere, so preserve feature bits set on
- * master device that are not part of the examined set.
+ * feature bits are managed elsewhere, so preserve those feature bits
+ * on the master device.
  */
 static int bond_compute_features(struct bonding *bond)
 {
-       unsigned long features = BOND_INTERSECT_FEATURES;
        struct slave *slave;
        struct net_device *bond_dev = bond->dev;
+       unsigned long features = bond_dev->features;
        unsigned short max_hard_header_len = ETH_HLEN;
        int i;
 
+       features &= ~(NETIF_F_ALL_CSUM | BOND_VLAN_FEATURES);
+       features |= NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
+                   NETIF_F_GSO_MASK | NETIF_F_NO_CSUM;
+
        bond_for_each_slave(bond, slave, i) {
-               features &= (slave->dev->features & BOND_INTERSECT_FEATURES);
+               features = netdev_compute_features(features,
+                                                  slave->dev->features);
                if (slave->dev->hard_header_len > max_hard_header_len)
                        max_hard_header_len = slave->dev->hard_header_len;
        }
 
-       if ((features & NETIF_F_SG) && 
-           !(features & NETIF_F_ALL_CSUM))
-               features &= ~NETIF_F_SG;
-
-       /* 
-        * features will include NETIF_F_TSO (NETIF_F_UFO) iff all 
-        * slave devices support NETIF_F_TSO (NETIF_F_UFO), which 
-        * implies that all slaves also support scatter-gather 
-        * (NETIF_F_SG), which implies that features also includes 
-        * NETIF_F_SG. So no need to check whether we have an  
-        * illegal combination of NETIF_F_{TSO,UFO} and 
-        * !NETIF_F_SG 
-        */
-
-       features |= (bond_dev->features & ~BOND_INTERSECT_FEATURES);
+       features |= (bond_dev->features & BOND_VLAN_FEATURES);
        bond_dev->features = features;
        bond_dev->hard_header_len = max_hard_header_len;
 
@@ -1390,6 +1352,11 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                goto err_free;
        }
 
+       res = netdev_set_master(slave_dev, bond_dev);
+       if (res) {
+               dprintk("Error %d calling netdev_set_master\n", res);
+               goto err_close;
+       }
        /* open the slave since the application closed it */
        res = dev_open(slave_dev);
        if (res) {
@@ -1397,12 +1364,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev)
                goto err_restore_mac;
        }
 
-       res = netdev_set_master(slave_dev, bond_dev);
-       if (res) {
-               dprintk("Error %d calling netdev_set_master\n", res);
-               goto err_close;
-       }
-
        new_slave->dev = slave_dev;
        slave_dev->priv_flags |= IFF_BONDING;
 
@@ -3184,7 +3145,7 @@ static void bond_create_proc_dir(void)
 {
        int len = strlen(DRV_NAME);
 
-       for (bond_proc_dir = proc_net->subdir; bond_proc_dir;
+       for (bond_proc_dir = init_net.proc_net->subdir; bond_proc_dir;
             bond_proc_dir = bond_proc_dir->next) {
                if ((bond_proc_dir->namelen == len) &&
                    !memcmp(bond_proc_dir->name, DRV_NAME, len)) {
@@ -3193,7 +3154,7 @@ static void bond_create_proc_dir(void)
        }
 
        if (!bond_proc_dir) {
-               bond_proc_dir = proc_mkdir(DRV_NAME, proc_net);
+               bond_proc_dir = proc_mkdir(DRV_NAME, init_net.proc_net);
                if (bond_proc_dir) {
                        bond_proc_dir->owner = THIS_MODULE;
                } else {
@@ -3228,7 +3189,7 @@ static void bond_destroy_proc_dir(void)
                        bond_proc_dir->owner = NULL;
                }
        } else {
-               remove_proc_entry(DRV_NAME, proc_net);
+               remove_proc_entry(DRV_NAME, init_net.proc_net);
                bond_proc_dir = NULL;
        }
 }
@@ -3461,7 +3422,7 @@ void bond_unregister_arp(struct bonding *bond)
 /*---------------------------- Hashing Policies -----------------------------*/
 
 /*
- * Hash for the the output device based upon layer 3 and layer 4 data. If
+ * Hash for the output device based upon layer 3 and layer 4 data. If
  * the packet is a frag or not TCP or UDP, just use layer 3 data.  If it is
  * altogether not IP, mimic bond_xmit_hash_policy_l2()
  */
@@ -4345,8 +4306,8 @@ static void bond_free_all(void)
                bond_mc_list_destroy(bond);
                /* Release the bonded slaves */
                bond_release_all(bond_dev);
-               unregister_netdevice(bond_dev);
                bond_deinit(bond_dev);
+               unregister_netdevice(bond_dev);
        }
 
 #ifdef CONFIG_PROC_FS