2 * net-sysfs.c - network device class and attributes
4 * Copyright (c) 2003 Stephen Hemminger <shemminger@osdl.org>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <linux/capability.h>
13 #include <linux/kernel.h>
14 #include <linux/netdevice.h>
15 #include <linux/if_arp.h>
16 #include <linux/slab.h>
17 #include <linux/nsproxy.h>
19 #include <net/net_namespace.h>
20 #include <linux/rtnetlink.h>
21 #include <linux/wireless.h>
22 #include <linux/vmalloc.h>
25 #include "net-sysfs.h"
28 static const char fmt_hex[] = "%#x\n";
29 static const char fmt_long_hex[] = "%#lx\n";
30 static const char fmt_dec[] = "%d\n";
31 static const char fmt_ulong[] = "%lu\n";
32 static const char fmt_u64[] = "%llu\n";
34 static inline int dev_isalive(const struct net_device *dev)
36 return dev->reg_state <= NETREG_REGISTERED;
39 /* use same locking rules as GIF* ioctl's */
40 static ssize_t netdev_show(const struct device *dev,
41 struct device_attribute *attr, char *buf,
42 ssize_t (*format)(const struct net_device *, char *))
44 struct net_device *net = to_net_dev(dev);
45 ssize_t ret = -EINVAL;
47 read_lock(&dev_base_lock);
49 ret = (*format)(net, buf);
50 read_unlock(&dev_base_lock);
55 /* generate a show function for simple field */
56 #define NETDEVICE_SHOW(field, format_string) \
57 static ssize_t format_##field(const struct net_device *net, char *buf) \
59 return sprintf(buf, format_string, net->field); \
61 static ssize_t show_##field(struct device *dev, \
62 struct device_attribute *attr, char *buf) \
64 return netdev_show(dev, attr, buf, format_##field); \
68 /* use same locking and permission rules as SIF* ioctl's */
69 static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
70 const char *buf, size_t len,
71 int (*set)(struct net_device *, unsigned long))
73 struct net_device *net = to_net_dev(dev);
78 if (!capable(CAP_NET_ADMIN))
81 new = simple_strtoul(buf, &endp, 0);
86 return restart_syscall();
88 if (dev_isalive(net)) {
89 if ((ret = (*set)(net, new)) == 0)
97 NETDEVICE_SHOW(dev_id, fmt_hex);
98 NETDEVICE_SHOW(addr_len, fmt_dec);
99 NETDEVICE_SHOW(iflink, fmt_dec);
100 NETDEVICE_SHOW(ifindex, fmt_dec);
101 NETDEVICE_SHOW(features, fmt_long_hex);
102 NETDEVICE_SHOW(type, fmt_dec);
103 NETDEVICE_SHOW(link_mode, fmt_dec);
105 /* use same locking rules as GIFHWADDR ioctl's */
106 static ssize_t show_address(struct device *dev, struct device_attribute *attr,
109 struct net_device *net = to_net_dev(dev);
110 ssize_t ret = -EINVAL;
112 read_lock(&dev_base_lock);
113 if (dev_isalive(net))
114 ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len);
115 read_unlock(&dev_base_lock);
119 static ssize_t show_broadcast(struct device *dev,
120 struct device_attribute *attr, char *buf)
122 struct net_device *net = to_net_dev(dev);
123 if (dev_isalive(net))
124 return sysfs_format_mac(buf, net->broadcast, net->addr_len);
128 static ssize_t show_carrier(struct device *dev,
129 struct device_attribute *attr, char *buf)
131 struct net_device *netdev = to_net_dev(dev);
132 if (netif_running(netdev)) {
133 return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev));
138 static ssize_t show_speed(struct device *dev,
139 struct device_attribute *attr, char *buf)
141 struct net_device *netdev = to_net_dev(dev);
145 return restart_syscall();
147 if (netif_running(netdev) &&
148 netdev->ethtool_ops &&
149 netdev->ethtool_ops->get_settings) {
150 struct ethtool_cmd cmd = { ETHTOOL_GSET };
152 if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
153 ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd));
159 static ssize_t show_duplex(struct device *dev,
160 struct device_attribute *attr, char *buf)
162 struct net_device *netdev = to_net_dev(dev);
166 return restart_syscall();
168 if (netif_running(netdev) &&
169 netdev->ethtool_ops &&
170 netdev->ethtool_ops->get_settings) {
171 struct ethtool_cmd cmd = { ETHTOOL_GSET };
173 if (!netdev->ethtool_ops->get_settings(netdev, &cmd))
174 ret = sprintf(buf, "%s\n", cmd.duplex ? "full" : "half");
180 static ssize_t show_dormant(struct device *dev,
181 struct device_attribute *attr, char *buf)
183 struct net_device *netdev = to_net_dev(dev);
185 if (netif_running(netdev))
186 return sprintf(buf, fmt_dec, !!netif_dormant(netdev));
191 static const char *const operstates[] = {
193 "notpresent", /* currently unused */
196 "testing", /* currently unused */
201 static ssize_t show_operstate(struct device *dev,
202 struct device_attribute *attr, char *buf)
204 const struct net_device *netdev = to_net_dev(dev);
205 unsigned char operstate;
207 read_lock(&dev_base_lock);
208 operstate = netdev->operstate;
209 if (!netif_running(netdev))
210 operstate = IF_OPER_DOWN;
211 read_unlock(&dev_base_lock);
213 if (operstate >= ARRAY_SIZE(operstates))
214 return -EINVAL; /* should not happen */
216 return sprintf(buf, "%s\n", operstates[operstate]);
219 /* read-write attributes */
220 NETDEVICE_SHOW(mtu, fmt_dec);
222 static int change_mtu(struct net_device *net, unsigned long new_mtu)
224 return dev_set_mtu(net, (int) new_mtu);
227 static ssize_t store_mtu(struct device *dev, struct device_attribute *attr,
228 const char *buf, size_t len)
230 return netdev_store(dev, attr, buf, len, change_mtu);
233 NETDEVICE_SHOW(flags, fmt_hex);
235 static int change_flags(struct net_device *net, unsigned long new_flags)
237 return dev_change_flags(net, (unsigned) new_flags);
240 static ssize_t store_flags(struct device *dev, struct device_attribute *attr,
241 const char *buf, size_t len)
243 return netdev_store(dev, attr, buf, len, change_flags);
246 NETDEVICE_SHOW(tx_queue_len, fmt_ulong);
248 static int change_tx_queue_len(struct net_device *net, unsigned long new_len)
250 net->tx_queue_len = new_len;
254 static ssize_t store_tx_queue_len(struct device *dev,
255 struct device_attribute *attr,
256 const char *buf, size_t len)
258 return netdev_store(dev, attr, buf, len, change_tx_queue_len);
261 static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr,
262 const char *buf, size_t len)
264 struct net_device *netdev = to_net_dev(dev);
268 if (!capable(CAP_NET_ADMIN))
271 /* ignore trailing newline */
272 if (len > 0 && buf[len - 1] == '\n')
276 return restart_syscall();
277 ret = dev_set_alias(netdev, buf, count);
280 return ret < 0 ? ret : len;
283 static ssize_t show_ifalias(struct device *dev,
284 struct device_attribute *attr, char *buf)
286 const struct net_device *netdev = to_net_dev(dev);
290 return restart_syscall();
292 ret = sprintf(buf, "%s\n", netdev->ifalias);
297 static struct device_attribute net_class_attributes[] = {
298 __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
299 __ATTR(dev_id, S_IRUGO, show_dev_id, NULL),
300 __ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias),
301 __ATTR(iflink, S_IRUGO, show_iflink, NULL),
302 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
303 __ATTR(features, S_IRUGO, show_features, NULL),
304 __ATTR(type, S_IRUGO, show_type, NULL),
305 __ATTR(link_mode, S_IRUGO, show_link_mode, NULL),
306 __ATTR(address, S_IRUGO, show_address, NULL),
307 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
308 __ATTR(carrier, S_IRUGO, show_carrier, NULL),
309 __ATTR(speed, S_IRUGO, show_speed, NULL),
310 __ATTR(duplex, S_IRUGO, show_duplex, NULL),
311 __ATTR(dormant, S_IRUGO, show_dormant, NULL),
312 __ATTR(operstate, S_IRUGO, show_operstate, NULL),
313 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
314 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags),
315 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
320 /* Show a given an attribute in the statistics group */
321 static ssize_t netstat_show(const struct device *d,
322 struct device_attribute *attr, char *buf,
323 unsigned long offset)
325 struct net_device *dev = to_net_dev(d);
326 ssize_t ret = -EINVAL;
328 WARN_ON(offset > sizeof(struct rtnl_link_stats64) ||
329 offset % sizeof(u64) != 0);
331 read_lock(&dev_base_lock);
332 if (dev_isalive(dev)) {
333 struct rtnl_link_stats64 temp;
334 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
336 ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset));
338 read_unlock(&dev_base_lock);
342 /* generate a read-only statistics attribute */
343 #define NETSTAT_ENTRY(name) \
344 static ssize_t show_##name(struct device *d, \
345 struct device_attribute *attr, char *buf) \
347 return netstat_show(d, attr, buf, \
348 offsetof(struct rtnl_link_stats64, name)); \
350 static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
352 NETSTAT_ENTRY(rx_packets);
353 NETSTAT_ENTRY(tx_packets);
354 NETSTAT_ENTRY(rx_bytes);
355 NETSTAT_ENTRY(tx_bytes);
356 NETSTAT_ENTRY(rx_errors);
357 NETSTAT_ENTRY(tx_errors);
358 NETSTAT_ENTRY(rx_dropped);
359 NETSTAT_ENTRY(tx_dropped);
360 NETSTAT_ENTRY(multicast);
361 NETSTAT_ENTRY(collisions);
362 NETSTAT_ENTRY(rx_length_errors);
363 NETSTAT_ENTRY(rx_over_errors);
364 NETSTAT_ENTRY(rx_crc_errors);
365 NETSTAT_ENTRY(rx_frame_errors);
366 NETSTAT_ENTRY(rx_fifo_errors);
367 NETSTAT_ENTRY(rx_missed_errors);
368 NETSTAT_ENTRY(tx_aborted_errors);
369 NETSTAT_ENTRY(tx_carrier_errors);
370 NETSTAT_ENTRY(tx_fifo_errors);
371 NETSTAT_ENTRY(tx_heartbeat_errors);
372 NETSTAT_ENTRY(tx_window_errors);
373 NETSTAT_ENTRY(rx_compressed);
374 NETSTAT_ENTRY(tx_compressed);
376 static struct attribute *netstat_attrs[] = {
377 &dev_attr_rx_packets.attr,
378 &dev_attr_tx_packets.attr,
379 &dev_attr_rx_bytes.attr,
380 &dev_attr_tx_bytes.attr,
381 &dev_attr_rx_errors.attr,
382 &dev_attr_tx_errors.attr,
383 &dev_attr_rx_dropped.attr,
384 &dev_attr_tx_dropped.attr,
385 &dev_attr_multicast.attr,
386 &dev_attr_collisions.attr,
387 &dev_attr_rx_length_errors.attr,
388 &dev_attr_rx_over_errors.attr,
389 &dev_attr_rx_crc_errors.attr,
390 &dev_attr_rx_frame_errors.attr,
391 &dev_attr_rx_fifo_errors.attr,
392 &dev_attr_rx_missed_errors.attr,
393 &dev_attr_tx_aborted_errors.attr,
394 &dev_attr_tx_carrier_errors.attr,
395 &dev_attr_tx_fifo_errors.attr,
396 &dev_attr_tx_heartbeat_errors.attr,
397 &dev_attr_tx_window_errors.attr,
398 &dev_attr_rx_compressed.attr,
399 &dev_attr_tx_compressed.attr,
404 static struct attribute_group netstat_group = {
405 .name = "statistics",
406 .attrs = netstat_attrs,
409 #ifdef CONFIG_WIRELESS_EXT_SYSFS
410 /* helper function that does all the locking etc for wireless stats */
411 static ssize_t wireless_show(struct device *d, char *buf,
412 ssize_t (*format)(const struct iw_statistics *,
415 struct net_device *dev = to_net_dev(d);
416 const struct iw_statistics *iw;
417 ssize_t ret = -EINVAL;
420 return restart_syscall();
421 if (dev_isalive(dev)) {
422 iw = get_wireless_stats(dev);
424 ret = (*format)(iw, buf);
431 /* show function template for wireless fields */
432 #define WIRELESS_SHOW(name, field, format_string) \
433 static ssize_t format_iw_##name(const struct iw_statistics *iw, char *buf) \
435 return sprintf(buf, format_string, iw->field); \
437 static ssize_t show_iw_##name(struct device *d, \
438 struct device_attribute *attr, char *buf) \
440 return wireless_show(d, buf, format_iw_##name); \
442 static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL)
444 WIRELESS_SHOW(status, status, fmt_hex);
445 WIRELESS_SHOW(link, qual.qual, fmt_dec);
446 WIRELESS_SHOW(level, qual.level, fmt_dec);
447 WIRELESS_SHOW(noise, qual.noise, fmt_dec);
448 WIRELESS_SHOW(nwid, discard.nwid, fmt_dec);
449 WIRELESS_SHOW(crypt, discard.code, fmt_dec);
450 WIRELESS_SHOW(fragment, discard.fragment, fmt_dec);
451 WIRELESS_SHOW(misc, discard.misc, fmt_dec);
452 WIRELESS_SHOW(retries, discard.retries, fmt_dec);
453 WIRELESS_SHOW(beacon, miss.beacon, fmt_dec);
455 static struct attribute *wireless_attrs[] = {
456 &dev_attr_status.attr,
458 &dev_attr_level.attr,
459 &dev_attr_noise.attr,
461 &dev_attr_crypt.attr,
462 &dev_attr_fragment.attr,
463 &dev_attr_retries.attr,
465 &dev_attr_beacon.attr,
469 static struct attribute_group wireless_group = {
471 .attrs = wireless_attrs,
474 #endif /* CONFIG_SYSFS */
478 * RX queue sysfs structures and functions.
480 struct rx_queue_attribute {
481 struct attribute attr;
482 ssize_t (*show)(struct netdev_rx_queue *queue,
483 struct rx_queue_attribute *attr, char *buf);
484 ssize_t (*store)(struct netdev_rx_queue *queue,
485 struct rx_queue_attribute *attr, const char *buf, size_t len);
487 #define to_rx_queue_attr(_attr) container_of(_attr, \
488 struct rx_queue_attribute, attr)
490 #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj)
492 static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr,
495 struct rx_queue_attribute *attribute = to_rx_queue_attr(attr);
496 struct netdev_rx_queue *queue = to_rx_queue(kobj);
498 if (!attribute->show)
501 return attribute->show(queue, attribute, buf);
504 static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr,
505 const char *buf, size_t count)
507 struct rx_queue_attribute *attribute = to_rx_queue_attr(attr);
508 struct netdev_rx_queue *queue = to_rx_queue(kobj);
510 if (!attribute->store)
513 return attribute->store(queue, attribute, buf, count);
516 static struct sysfs_ops rx_queue_sysfs_ops = {
517 .show = rx_queue_attr_show,
518 .store = rx_queue_attr_store,
521 static ssize_t show_rps_map(struct netdev_rx_queue *queue,
522 struct rx_queue_attribute *attribute, char *buf)
529 if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
533 map = rcu_dereference(queue->rps_map);
535 for (i = 0; i < map->len; i++)
536 cpumask_set_cpu(map->cpus[i], mask);
538 len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
539 if (PAGE_SIZE - len < 3) {
541 free_cpumask_var(mask);
546 free_cpumask_var(mask);
547 len += sprintf(buf + len, "\n");
551 static void rps_map_release(struct rcu_head *rcu)
553 struct rps_map *map = container_of(rcu, struct rps_map, rcu);
558 static ssize_t store_rps_map(struct netdev_rx_queue *queue,
559 struct rx_queue_attribute *attribute,
560 const char *buf, size_t len)
562 struct rps_map *old_map, *map;
565 static DEFINE_SPINLOCK(rps_map_lock);
567 if (!capable(CAP_NET_ADMIN))
570 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
573 err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
575 free_cpumask_var(mask);
579 map = kzalloc(max_t(unsigned,
580 RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
583 free_cpumask_var(mask);
588 for_each_cpu_and(cpu, mask, cpu_online_mask)
589 map->cpus[i++] = cpu;
598 spin_lock(&rps_map_lock);
599 old_map = queue->rps_map;
600 rcu_assign_pointer(queue->rps_map, map);
601 spin_unlock(&rps_map_lock);
604 call_rcu(&old_map->rcu, rps_map_release);
606 free_cpumask_var(mask);
610 static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
611 struct rx_queue_attribute *attr,
614 struct rps_dev_flow_table *flow_table;
615 unsigned int val = 0;
618 flow_table = rcu_dereference(queue->rps_flow_table);
620 val = flow_table->mask + 1;
623 return sprintf(buf, "%u\n", val);
626 static void rps_dev_flow_table_release_work(struct work_struct *work)
628 struct rps_dev_flow_table *table = container_of(work,
629 struct rps_dev_flow_table, free_work);
634 static void rps_dev_flow_table_release(struct rcu_head *rcu)
636 struct rps_dev_flow_table *table = container_of(rcu,
637 struct rps_dev_flow_table, rcu);
639 INIT_WORK(&table->free_work, rps_dev_flow_table_release_work);
640 schedule_work(&table->free_work);
643 static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
644 struct rx_queue_attribute *attr,
645 const char *buf, size_t len)
649 struct rps_dev_flow_table *table, *old_table;
650 static DEFINE_SPINLOCK(rps_dev_flow_lock);
652 if (!capable(CAP_NET_ADMIN))
655 count = simple_strtoul(buf, &endp, 0);
663 /* Enforce a limit to prevent overflow */
666 count = roundup_pow_of_two(count);
667 table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count));
671 table->mask = count - 1;
672 for (i = 0; i < count; i++)
673 table->flows[i].cpu = RPS_NO_CPU;
677 spin_lock(&rps_dev_flow_lock);
678 old_table = queue->rps_flow_table;
679 rcu_assign_pointer(queue->rps_flow_table, table);
680 spin_unlock(&rps_dev_flow_lock);
683 call_rcu(&old_table->rcu, rps_dev_flow_table_release);
688 static struct rx_queue_attribute rps_cpus_attribute =
689 __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map);
692 static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute =
693 __ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR,
694 show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt);
696 static struct attribute *rx_queue_default_attrs[] = {
697 &rps_cpus_attribute.attr,
698 &rps_dev_flow_table_cnt_attribute.attr,
702 static void rx_queue_release(struct kobject *kobj)
704 struct netdev_rx_queue *queue = to_rx_queue(kobj);
705 struct netdev_rx_queue *first = queue->first;
708 call_rcu(&queue->rps_map->rcu, rps_map_release);
710 if (queue->rps_flow_table)
711 call_rcu(&queue->rps_flow_table->rcu,
712 rps_dev_flow_table_release);
714 if (atomic_dec_and_test(&first->count))
718 static struct kobj_type rx_queue_ktype = {
719 .sysfs_ops = &rx_queue_sysfs_ops,
720 .release = rx_queue_release,
721 .default_attrs = rx_queue_default_attrs,
724 static int rx_queue_add_kobject(struct net_device *net, int index)
726 struct netdev_rx_queue *queue = net->_rx + index;
727 struct kobject *kobj = &queue->kobj;
730 kobj->kset = net->queues_kset;
731 error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL,
738 kobject_uevent(kobj, KOBJ_ADD);
743 static int rx_queue_register_kobjects(struct net_device *net)
748 net->queues_kset = kset_create_and_add("queues",
749 NULL, &net->dev.kobj);
750 if (!net->queues_kset)
752 for (i = 0; i < net->num_rx_queues; i++) {
753 error = rx_queue_add_kobject(net, i);
760 kobject_put(&net->_rx[i].kobj);
765 static void rx_queue_remove_kobjects(struct net_device *net)
769 for (i = 0; i < net->num_rx_queues; i++)
770 kobject_put(&net->_rx[i].kobj);
771 kset_unregister(net->queues_kset);
773 #endif /* CONFIG_RPS */
775 static const void *net_current_ns(void)
777 return current->nsproxy->net_ns;
780 static const void *net_initial_ns(void)
785 static const void *net_netlink_ns(struct sock *sk)
790 static struct kobj_ns_type_operations net_ns_type_operations = {
791 .type = KOBJ_NS_TYPE_NET,
792 .current_ns = net_current_ns,
793 .netlink_ns = net_netlink_ns,
794 .initial_ns = net_initial_ns,
797 static void net_kobj_ns_exit(struct net *net)
799 kobj_ns_exit(KOBJ_NS_TYPE_NET, net);
802 static struct pernet_operations kobj_net_ops = {
803 .exit = net_kobj_ns_exit,
807 #ifdef CONFIG_HOTPLUG
808 static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
810 struct net_device *dev = to_net_dev(d);
813 /* pass interface to uevent. */
814 retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
818 /* pass ifindex to uevent.
819 * ifindex is useful as it won't change (interface name may change)
820 * and is what RtNetlink uses natively. */
821 retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex);
829 * netdev_release -- destroy and free a dead device.
830 * Called when last reference to device kobject is gone.
832 static void netdev_release(struct device *d)
834 struct net_device *dev = to_net_dev(d);
836 BUG_ON(dev->reg_state != NETREG_RELEASED);
839 kfree((char *)dev - dev->padded);
842 static const void *net_namespace(struct device *d)
844 struct net_device *dev;
845 dev = container_of(d, struct net_device, dev);
849 static struct class net_class = {
851 .dev_release = netdev_release,
853 .dev_attrs = net_class_attributes,
854 #endif /* CONFIG_SYSFS */
855 #ifdef CONFIG_HOTPLUG
856 .dev_uevent = netdev_uevent,
858 .ns_type = &net_ns_type_operations,
859 .namespace = net_namespace,
862 /* Delete sysfs entries but hold kobject reference until after all
863 * netdev references are gone.
865 void netdev_unregister_kobject(struct net_device * net)
867 struct device *dev = &(net->dev);
869 kobject_get(&dev->kobj);
872 rx_queue_remove_kobjects(net);
878 /* Create sysfs entries for network device. */
879 int netdev_register_kobject(struct net_device *net)
881 struct device *dev = &(net->dev);
882 const struct attribute_group **groups = net->sysfs_groups;
885 device_initialize(dev);
886 dev->class = &net_class;
887 dev->platform_data = net;
888 dev->groups = groups;
890 dev_set_name(dev, "%s", net->name);
893 /* Allow for a device specific group */
897 *groups++ = &netstat_group;
898 #ifdef CONFIG_WIRELESS_EXT_SYSFS
899 if (net->ieee80211_ptr)
900 *groups++ = &wireless_group;
901 #ifdef CONFIG_WIRELESS_EXT
902 else if (net->wireless_handlers)
903 *groups++ = &wireless_group;
906 #endif /* CONFIG_SYSFS */
908 error = device_add(dev);
913 error = rx_queue_register_kobjects(net);
923 int netdev_class_create_file(struct class_attribute *class_attr)
925 return class_create_file(&net_class, class_attr);
928 void netdev_class_remove_file(struct class_attribute *class_attr)
930 class_remove_file(&net_class, class_attr);
933 EXPORT_SYMBOL(netdev_class_create_file);
934 EXPORT_SYMBOL(netdev_class_remove_file);
936 int netdev_kobject_init(void)
938 kobj_ns_type_register(&net_ns_type_operations);
939 register_pernet_subsys(&kobj_net_ops);
940 return class_register(&net_class);