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.c41
1 files changed, 30 insertions, 11 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index bcf02f608cbf..28c5f5aa7ca7 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -18,11 +18,9 @@
18#include <net/sock.h> 18#include <net/sock.h>
19#include <net/net_namespace.h> 19#include <net/net_namespace.h>
20#include <linux/rtnetlink.h> 20#include <linux/rtnetlink.h>
21#include <linux/wireless.h>
22#include <linux/vmalloc.h> 21#include <linux/vmalloc.h>
23#include <linux/export.h> 22#include <linux/export.h>
24#include <linux/jiffies.h> 23#include <linux/jiffies.h>
25#include <net/wext.h>
26 24
27#include "net-sysfs.h" 25#include "net-sysfs.h"
28 26
@@ -73,11 +71,12 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
73 const char *buf, size_t len, 71 const char *buf, size_t len,
74 int (*set)(struct net_device *, unsigned long)) 72 int (*set)(struct net_device *, unsigned long))
75{ 73{
76 struct net_device *net = to_net_dev(dev); 74 struct net_device *netdev = to_net_dev(dev);
75 struct net *net = dev_net(netdev);
77 unsigned long new; 76 unsigned long new;
78 int ret = -EINVAL; 77 int ret = -EINVAL;
79 78
80 if (!capable(CAP_NET_ADMIN)) 79 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
81 return -EPERM; 80 return -EPERM;
82 81
83 ret = kstrtoul(buf, 0, &new); 82 ret = kstrtoul(buf, 0, &new);
@@ -87,8 +86,8 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
87 if (!rtnl_trylock()) 86 if (!rtnl_trylock())
88 return restart_syscall(); 87 return restart_syscall();
89 88
90 if (dev_isalive(net)) { 89 if (dev_isalive(netdev)) {
91 if ((ret = (*set)(net, new)) == 0) 90 if ((ret = (*set)(netdev, new)) == 0)
92 ret = len; 91 ret = len;
93 } 92 }
94 rtnl_unlock(); 93 rtnl_unlock();
@@ -264,6 +263,9 @@ static ssize_t store_tx_queue_len(struct device *dev,
264 struct device_attribute *attr, 263 struct device_attribute *attr,
265 const char *buf, size_t len) 264 const char *buf, size_t len)
266{ 265{
266 if (!capable(CAP_NET_ADMIN))
267 return -EPERM;
268
267 return netdev_store(dev, attr, buf, len, change_tx_queue_len); 269 return netdev_store(dev, attr, buf, len, change_tx_queue_len);
268} 270}
269 271
@@ -271,10 +273,11 @@ static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr,
271 const char *buf, size_t len) 273 const char *buf, size_t len)
272{ 274{
273 struct net_device *netdev = to_net_dev(dev); 275 struct net_device *netdev = to_net_dev(dev);
276 struct net *net = dev_net(netdev);
274 size_t count = len; 277 size_t count = len;
275 ssize_t ret; 278 ssize_t ret;
276 279
277 if (!capable(CAP_NET_ADMIN)) 280 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
278 return -EPERM; 281 return -EPERM;
279 282
280 /* ignore trailing newline */ 283 /* ignore trailing newline */
@@ -429,6 +432,17 @@ static struct attribute_group netstat_group = {
429 .name = "statistics", 432 .name = "statistics",
430 .attrs = netstat_attrs, 433 .attrs = netstat_attrs,
431}; 434};
435
436#if IS_ENABLED(CONFIG_WIRELESS_EXT) || IS_ENABLED(CONFIG_CFG80211)
437static struct attribute *wireless_attrs[] = {
438 NULL
439};
440
441static struct attribute_group wireless_group = {
442 .name = "wireless",
443 .attrs = wireless_attrs,
444};
445#endif
432#endif /* CONFIG_SYSFS */ 446#endif /* CONFIG_SYSFS */
433 447
434#ifdef CONFIG_RPS 448#ifdef CONFIG_RPS
@@ -1320,7 +1334,6 @@ struct kobj_ns_type_operations net_ns_type_operations = {
1320}; 1334};
1321EXPORT_SYMBOL_GPL(net_ns_type_operations); 1335EXPORT_SYMBOL_GPL(net_ns_type_operations);
1322 1336
1323#ifdef CONFIG_HOTPLUG
1324static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) 1337static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
1325{ 1338{
1326 struct net_device *dev = to_net_dev(d); 1339 struct net_device *dev = to_net_dev(d);
@@ -1339,7 +1352,6 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
1339exit: 1352exit:
1340 return retval; 1353 return retval;
1341} 1354}
1342#endif
1343 1355
1344/* 1356/*
1345 * netdev_release -- destroy and free a dead device. 1357 * netdev_release -- destroy and free a dead device.
@@ -1368,9 +1380,7 @@ static struct class net_class = {
1368#ifdef CONFIG_SYSFS 1380#ifdef CONFIG_SYSFS
1369 .dev_attrs = net_class_attributes, 1381 .dev_attrs = net_class_attributes,
1370#endif /* CONFIG_SYSFS */ 1382#endif /* CONFIG_SYSFS */
1371#ifdef CONFIG_HOTPLUG
1372 .dev_uevent = netdev_uevent, 1383 .dev_uevent = netdev_uevent,
1373#endif
1374 .ns_type = &net_ns_type_operations, 1384 .ns_type = &net_ns_type_operations,
1375 .namespace = net_namespace, 1385 .namespace = net_namespace,
1376}; 1386};
@@ -1409,6 +1419,15 @@ int netdev_register_kobject(struct net_device *net)
1409 groups++; 1419 groups++;
1410 1420
1411 *groups++ = &netstat_group; 1421 *groups++ = &netstat_group;
1422
1423#if IS_ENABLED(CONFIG_WIRELESS_EXT) || IS_ENABLED(CONFIG_CFG80211)
1424 if (net->ieee80211_ptr)
1425 *groups++ = &wireless_group;
1426#if IS_ENABLED(CONFIG_WIRELESS_EXT)
1427 else if (net->wireless_handlers)
1428 *groups++ = &wireless_group;
1429#endif
1430#endif
1412#endif /* CONFIG_SYSFS */ 1431#endif /* CONFIG_SYSFS */
1413 1432
1414 error = device_add(dev); 1433 error = device_add(dev);