gss_krb5: Introduce encryption type framework
[safe/jmp/linux-2.6] / net / core / net-sysfs.c
index 7d4c575..59cfc7d 100644 (file)
 #include <linux/kernel.h>
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
+#include <linux/slab.h>
 #include <net/sock.h>
 #include <linux/rtnetlink.h>
 #include <linux/wireless.h>
-#include <net/iw_handler.h>
+#include <net/wext.h>
 
 #include "net-sysfs.h"
 
@@ -130,6 +131,48 @@ static ssize_t show_carrier(struct device *dev,
        return -EINVAL;
 }
 
+static ssize_t show_speed(struct device *dev,
+                         struct device_attribute *attr, char *buf)
+{
+       struct net_device *netdev = to_net_dev(dev);
+       int ret = -EINVAL;
+
+       if (!rtnl_trylock())
+               return restart_syscall();
+
+       if (netif_running(netdev) &&
+           netdev->ethtool_ops &&
+           netdev->ethtool_ops->get_settings) {
+               struct ethtool_cmd cmd = { ETHTOOL_GSET };
+
+               if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
+                       ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd));
+       }
+       rtnl_unlock();
+       return ret;
+}
+
+static ssize_t show_duplex(struct device *dev,
+                          struct device_attribute *attr, char *buf)
+{
+       struct net_device *netdev = to_net_dev(dev);
+       int ret = -EINVAL;
+
+       if (!rtnl_trylock())
+               return restart_syscall();
+
+       if (netif_running(netdev) &&
+           netdev->ethtool_ops &&
+           netdev->ethtool_ops->get_settings) {
+               struct ethtool_cmd cmd = { ETHTOOL_GSET };
+
+               if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
+                       ret = sprintf(buf, "%s\n", cmd.duplex ? "full" : "half");
+       }
+       rtnl_unlock();
+       return ret;
+}
+
 static ssize_t show_dormant(struct device *dev,
                            struct device_attribute *attr, char *buf)
 {
@@ -259,6 +302,8 @@ static struct device_attribute net_class_attributes[] = {
        __ATTR(address, S_IRUGO, show_address, NULL),
        __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
        __ATTR(carrier, S_IRUGO, show_carrier, NULL),
+       __ATTR(speed, S_IRUGO, show_speed, NULL),
+       __ATTR(duplex, S_IRUGO, show_duplex, NULL),
        __ATTR(dormant, S_IRUGO, show_dormant, NULL),
        __ATTR(operstate, S_IRUGO, show_operstate, NULL),
        __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
@@ -363,18 +408,17 @@ static ssize_t wireless_show(struct device *d, char *buf,
                                               char *))
 {
        struct net_device *dev = to_net_dev(d);
-       const struct iw_statistics *iw = NULL;
+       const struct iw_statistics *iw;
        ssize_t ret = -EINVAL;
 
-       read_lock(&dev_base_lock);
+       if (!rtnl_trylock())
+               return restart_syscall();
        if (dev_isalive(dev)) {
-               if (dev->wireless_handlers &&
-                   dev->wireless_handlers->get_wireless_stats)
-                       iw = dev->wireless_handlers->get_wireless_stats(dev);
-               if (iw != NULL)
+               iw = get_wireless_stats(dev);
+               if (iw)
                        ret = (*format)(iw, buf);
        }
-       read_unlock(&dev_base_lock);
+       rtnl_unlock();
 
        return ret;
 }
@@ -483,7 +527,7 @@ void netdev_unregister_kobject(struct net_device * net)
 
        kobject_get(&dev->kobj);
 
-       if (dev_net(net) != &init_net)
+       if (!net_eq(dev_net(net), &init_net))
                return;
 
        device_del(dev);
@@ -502,15 +546,22 @@ int netdev_register_kobject(struct net_device *net)
        dev_set_name(dev, "%s", net->name);
 
 #ifdef CONFIG_SYSFS
-       *groups++ = &netstat_group;
+       /* Allow for a device specific group */
+       if (*groups)
+               groups++;
 
+       *groups++ = &netstat_group;
 #ifdef CONFIG_WIRELESS_EXT_SYSFS
-       if (net->wireless_handlers && net->wireless_handlers->get_wireless_stats)
+       if (net->ieee80211_ptr)
                *groups++ = &wireless_group;
+#ifdef CONFIG_WIRELESS_EXT
+       else if (net->wireless_handlers)
+               *groups++ = &wireless_group;
+#endif
 #endif
 #endif /* CONFIG_SYSFS */
 
-       if (dev_net(net) != &init_net)
+       if (!net_eq(dev_net(net), &init_net))
                return 0;
 
        return device_add(dev);