]> git.neil.brown.name Git - history.git/commitdiff
net devices: Get network devices to show up in sysfs.
authorPatrick Mochel <mochel@osdl.org>
Mon, 6 Jan 2003 07:50:37 +0000 (01:50 -0600)
committerPatrick Mochel <mochel@osdl.org>
Mon, 6 Jan 2003 07:50:37 +0000 (01:50 -0600)
- declare net_subsys, and register during net_dev_init().
- Add kobject to struct net_device.
- initialize name and register in register_netdevice().
- remove in unregister_netdevice().

This allows one to see the registered network devices in the system via:

# tree /sys/net/
/sys/net/
`-- eth0

include/linux/netdevice.h
net/core/dev.c

index 513b89ca78365c1674ae16630eabaaa004d0a0fc..888d520fd319534629040bf90100167c0f7342cc 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/if.h>
 #include <linux/if_ether.h>
 #include <linux/if_packet.h>
+#include <linux/kobject.h>
 
 #include <asm/atomic.h>
 #include <asm/cache.h>
@@ -438,6 +439,9 @@ struct net_device
        /* this will get initialized at each interface type init routine */
        struct divert_blk       *divert;
 #endif /* CONFIG_NET_DIVERT */
+
+       /* generic object representation */
+       struct kobject kobj;
 };
 
 
index 72f606980694eacdc80fd4984a7c8fce52316df8..9b5ee08067eb26642eb27efe5965b1f2d3d326f0 100644 (file)
@@ -201,6 +201,8 @@ int netdev_fastroute;
 int netdev_fastroute_obstacles;
 #endif
 
+static struct subsystem net_subsys;
+
 
 /*******************************************************************************
 
@@ -2545,7 +2547,10 @@ int register_netdevice(struct net_device *dev)
        notifier_call_chain(&netdev_chain, NETDEV_REGISTER, dev);
 
        net_run_sbin_hotplug(dev, "register");
-       ret = 0;
+
+       snprintf(dev->kobj.name,KOBJ_NAME_LEN,dev->name);
+       kobj_set_kset_s(dev,net_subsys);
+       ret = kobject_register(&dev->kobj);
 
 out:
        return ret;
@@ -2638,7 +2643,7 @@ int unregister_netdevice(struct net_device *dev)
 
        /* Shutdown queueing discipline. */
        dev_shutdown(dev);
-       
+
        net_run_sbin_hotplug(dev, "unregister");
        
        /* Notify protocols, that we are about to destroy
@@ -2671,6 +2676,8 @@ int unregister_netdevice(struct net_device *dev)
                goto out;
        }
 
+       kobject_unregister(&dev->kobj);
+
        /* Last reference is our one */
        if (atomic_read(&dev->refcnt) == 1)
                goto out;
@@ -2749,6 +2756,8 @@ extern void ip_auto_config(void);
 extern void dv_init(void);
 #endif /* CONFIG_NET_DIVERT */
 
+static decl_subsys(net,NULL);
+
 
 /*
  *       This is called single threaded during boot, so no need
@@ -2764,6 +2773,8 @@ static int __init net_dev_init(void)
        if (dev_proc_init())
                goto out;
 
+       subsystem_register(&net_subsys);
+
 #ifdef CONFIG_NET_DIVERT
        dv_init();
 #endif /* CONFIG_NET_DIVERT */