From 6ed6b9bf5b5d80581ebfcc3fa2738ee386b78cd1 Mon Sep 17 00:00:00 2001 From: Patrick Mochel Date: Mon, 6 Jan 2003 01:50:37 -0600 Subject: net devices: Get network devices to show up in sysfs. - 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 | 4 ++++ net/core/dev.c | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 513b89ca7836..888d520fd319 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -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; }; diff --git a/net/core/dev.c b/net/core/dev.c index 72f606980694..9b5ee08067eb 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -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 */ -- cgit v1.2.3