Commit 6ed6b9bf authored by Patrick Mochel's avatar Patrick Mochel

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
parent 426f67eb
......@@ -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;
};
......
......@@ -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;
......@@ -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 */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment