aboutsummaryrefslogtreecommitdiffstats
path: root/net/core/net-sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/core/net-sysfs.c')
-rw-r--r--net/core/net-sysfs.c76
1 files changed, 25 insertions, 51 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index e2137f3e489d..e1da81d261d1 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -84,16 +84,11 @@ static ssize_t netdev_store(struct class_device *dev,
84 return ret; 84 return ret;
85} 85}
86 86
87/* generate a read-only network device class attribute */ 87NETDEVICE_SHOW(addr_len, fmt_dec);
88#define NETDEVICE_ATTR(field, format_string) \ 88NETDEVICE_SHOW(iflink, fmt_dec);
89NETDEVICE_SHOW(field, format_string) \ 89NETDEVICE_SHOW(ifindex, fmt_dec);
90static CLASS_DEVICE_ATTR(field, S_IRUGO, show_##field, NULL) \ 90NETDEVICE_SHOW(features, fmt_long_hex);
91 91NETDEVICE_SHOW(type, fmt_dec);
92NETDEVICE_ATTR(addr_len, fmt_dec);
93NETDEVICE_ATTR(iflink, fmt_dec);
94NETDEVICE_ATTR(ifindex, fmt_dec);
95NETDEVICE_ATTR(features, fmt_long_hex);
96NETDEVICE_ATTR(type, fmt_dec);
97 92
98/* use same locking rules as GIFHWADDR ioctl's */ 93/* use same locking rules as GIFHWADDR ioctl's */
99static ssize_t format_addr(char *buf, const unsigned char *addr, int len) 94static ssize_t format_addr(char *buf, const unsigned char *addr, int len)
@@ -136,10 +131,6 @@ static ssize_t show_carrier(struct class_device *dev, char *buf)
136 return -EINVAL; 131 return -EINVAL;
137} 132}
138 133
139static CLASS_DEVICE_ATTR(address, S_IRUGO, show_address, NULL);
140static CLASS_DEVICE_ATTR(broadcast, S_IRUGO, show_broadcast, NULL);
141static CLASS_DEVICE_ATTR(carrier, S_IRUGO, show_carrier, NULL);
142
143/* read-write attributes */ 134/* read-write attributes */
144NETDEVICE_SHOW(mtu, fmt_dec); 135NETDEVICE_SHOW(mtu, fmt_dec);
145 136
@@ -153,8 +144,6 @@ static ssize_t store_mtu(struct class_device *dev, const char *buf, size_t len)
153 return netdev_store(dev, buf, len, change_mtu); 144 return netdev_store(dev, buf, len, change_mtu);
154} 145}
155 146
156static CLASS_DEVICE_ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu);
157
158NETDEVICE_SHOW(flags, fmt_hex); 147NETDEVICE_SHOW(flags, fmt_hex);
159 148
160static int change_flags(struct net_device *net, unsigned long new_flags) 149static int change_flags(struct net_device *net, unsigned long new_flags)
@@ -167,8 +156,6 @@ static ssize_t store_flags(struct class_device *dev, const char *buf, size_t len
167 return netdev_store(dev, buf, len, change_flags); 156 return netdev_store(dev, buf, len, change_flags);
168} 157}
169 158
170static CLASS_DEVICE_ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags);
171
172NETDEVICE_SHOW(tx_queue_len, fmt_ulong); 159NETDEVICE_SHOW(tx_queue_len, fmt_ulong);
173 160
174static int change_tx_queue_len(struct net_device *net, unsigned long new_len) 161static int change_tx_queue_len(struct net_device *net, unsigned long new_len)
@@ -182,9 +169,6 @@ static ssize_t store_tx_queue_len(struct class_device *dev, const char *buf, siz
182 return netdev_store(dev, buf, len, change_tx_queue_len); 169 return netdev_store(dev, buf, len, change_tx_queue_len);
183} 170}
184 171
185static CLASS_DEVICE_ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
186 store_tx_queue_len);
187
188NETDEVICE_SHOW(weight, fmt_dec); 172NETDEVICE_SHOW(weight, fmt_dec);
189 173
190static int change_weight(struct net_device *net, unsigned long new_weight) 174static int change_weight(struct net_device *net, unsigned long new_weight)
@@ -198,24 +182,21 @@ static ssize_t store_weight(struct class_device *dev, const char *buf, size_t le
198 return netdev_store(dev, buf, len, change_weight); 182 return netdev_store(dev, buf, len, change_weight);
199} 183}
200 184
201static CLASS_DEVICE_ATTR(weight, S_IRUGO | S_IWUSR, show_weight, 185static struct class_device_attribute net_class_attributes[] = {
202 store_weight); 186 __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
203 187 __ATTR(iflink, S_IRUGO, show_iflink, NULL),
204 188 __ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
205static struct class_device_attribute *net_class_attributes[] = { 189 __ATTR(features, S_IRUGO, show_features, NULL),
206 &class_device_attr_ifindex, 190 __ATTR(type, S_IRUGO, show_type, NULL),
207 &class_device_attr_iflink, 191 __ATTR(address, S_IRUGO, show_address, NULL),
208 &class_device_attr_addr_len, 192 __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
209 &class_device_attr_tx_queue_len, 193 __ATTR(carrier, S_IRUGO, show_carrier, NULL),
210 &class_device_attr_features, 194 __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
211 &class_device_attr_mtu, 195 __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags),
212 &class_device_attr_flags, 196 __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
213 &class_device_attr_weight, 197 store_tx_queue_len),
214 &class_device_attr_type, 198 __ATTR(weight, S_IRUGO | S_IWUSR, show_weight, store_weight),
215 &class_device_attr_address, 199 {}
216 &class_device_attr_broadcast,
217 &class_device_attr_carrier,
218 NULL
219}; 200};
220 201
221/* Show a given an attribute in the statistics group */ 202/* Show a given an attribute in the statistics group */
@@ -369,14 +350,14 @@ static struct attribute_group wireless_group = {
369#endif 350#endif
370 351
371#ifdef CONFIG_HOTPLUG 352#ifdef CONFIG_HOTPLUG
372static int netdev_hotplug(struct class_device *cd, char **envp, 353static int netdev_uevent(struct class_device *cd, char **envp,
373 int num_envp, char *buf, int size) 354 int num_envp, char *buf, int size)
374{ 355{
375 struct net_device *dev = to_net_dev(cd); 356 struct net_device *dev = to_net_dev(cd);
376 int i = 0; 357 int i = 0;
377 int n; 358 int n;
378 359
379 /* pass interface in env to hotplug. */ 360 /* pass interface to uevent. */
380 envp[i++] = buf; 361 envp[i++] = buf;
381 n = snprintf(buf, size, "INTERFACE=%s", dev->name) + 1; 362 n = snprintf(buf, size, "INTERFACE=%s", dev->name) + 1;
382 buf += n; 363 buf += n;
@@ -407,8 +388,9 @@ static void netdev_release(struct class_device *cd)
407static struct class net_class = { 388static struct class net_class = {
408 .name = "net", 389 .name = "net",
409 .release = netdev_release, 390 .release = netdev_release,
391 .class_dev_attrs = net_class_attributes,
410#ifdef CONFIG_HOTPLUG 392#ifdef CONFIG_HOTPLUG
411 .hotplug = netdev_hotplug, 393 .uevent = netdev_uevent,
412#endif 394#endif
413}; 395};
414 396
@@ -431,8 +413,6 @@ void netdev_unregister_sysfs(struct net_device * net)
431int netdev_register_sysfs(struct net_device *net) 413int netdev_register_sysfs(struct net_device *net)
432{ 414{
433 struct class_device *class_dev = &(net->class_dev); 415 struct class_device *class_dev = &(net->class_dev);
434 int i;
435 struct class_device_attribute *attr;
436 int ret; 416 int ret;
437 417
438 class_dev->class = &net_class; 418 class_dev->class = &net_class;
@@ -442,12 +422,6 @@ int netdev_register_sysfs(struct net_device *net)
442 if ((ret = class_device_register(class_dev))) 422 if ((ret = class_device_register(class_dev)))
443 goto out; 423 goto out;
444 424
445 for (i = 0; (attr = net_class_attributes[i]) != NULL; i++) {
446 if ((ret = class_device_create_file(class_dev, attr)))
447 goto out_unreg;
448 }
449
450
451 if (net->get_stats && 425 if (net->get_stats &&
452 (ret = sysfs_create_group(&class_dev->kobj, &netstat_group))) 426 (ret = sysfs_create_group(&class_dev->kobj, &netstat_group)))
453 goto out_unreg; 427 goto out_unreg;