net-sysfs.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338
  1. /*
  2. * net-sysfs.c - network device class and attributes
  3. *
  4. * Copyright (c) 2003 Stephen Hemminger <shemminger@osdl.org>
  5. *
  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.
  10. */
  11. #include <linux/capability.h>
  12. #include <linux/kernel.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/if_arp.h>
  15. #include <linux/slab.h>
  16. #include <linux/nsproxy.h>
  17. #include <net/sock.h>
  18. #include <net/net_namespace.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/wireless.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/export.h>
  23. #include <net/wext.h>
  24. #include "net-sysfs.h"
  25. #ifdef CONFIG_SYSFS
  26. static const char fmt_hex[] = "%#x\n";
  27. static const char fmt_long_hex[] = "%#lx\n";
  28. static const char fmt_dec[] = "%d\n";
  29. static const char fmt_udec[] = "%u\n";
  30. static const char fmt_ulong[] = "%lu\n";
  31. static const char fmt_u64[] = "%llu\n";
  32. static inline int dev_isalive(const struct net_device *dev)
  33. {
  34. return dev->reg_state <= NETREG_REGISTERED;
  35. }
  36. /* use same locking rules as GIF* ioctl's */
  37. static ssize_t netdev_show(const struct device *dev,
  38. struct device_attribute *attr, char *buf,
  39. ssize_t (*format)(const struct net_device *, char *))
  40. {
  41. struct net_device *net = to_net_dev(dev);
  42. ssize_t ret = -EINVAL;
  43. read_lock(&dev_base_lock);
  44. if (dev_isalive(net))
  45. ret = (*format)(net, buf);
  46. read_unlock(&dev_base_lock);
  47. return ret;
  48. }
  49. /* generate a show function for simple field */
  50. #define NETDEVICE_SHOW(field, format_string) \
  51. static ssize_t format_##field(const struct net_device *net, char *buf) \
  52. { \
  53. return sprintf(buf, format_string, net->field); \
  54. } \
  55. static ssize_t show_##field(struct device *dev, \
  56. struct device_attribute *attr, char *buf) \
  57. { \
  58. return netdev_show(dev, attr, buf, format_##field); \
  59. }
  60. /* use same locking and permission rules as SIF* ioctl's */
  61. static ssize_t netdev_store(struct device *dev, struct device_attribute *attr,
  62. const char *buf, size_t len,
  63. int (*set)(struct net_device *, unsigned long))
  64. {
  65. struct net_device *net = to_net_dev(dev);
  66. char *endp;
  67. unsigned long new;
  68. int ret = -EINVAL;
  69. if (!capable(CAP_NET_ADMIN))
  70. return -EPERM;
  71. new = simple_strtoul(buf, &endp, 0);
  72. if (endp == buf)
  73. goto err;
  74. if (!rtnl_trylock())
  75. return restart_syscall();
  76. if (dev_isalive(net)) {
  77. if ((ret = (*set)(net, new)) == 0)
  78. ret = len;
  79. }
  80. rtnl_unlock();
  81. err:
  82. return ret;
  83. }
  84. NETDEVICE_SHOW(dev_id, fmt_hex);
  85. NETDEVICE_SHOW(addr_assign_type, fmt_dec);
  86. NETDEVICE_SHOW(addr_len, fmt_dec);
  87. NETDEVICE_SHOW(iflink, fmt_dec);
  88. NETDEVICE_SHOW(ifindex, fmt_dec);
  89. NETDEVICE_SHOW(type, fmt_dec);
  90. NETDEVICE_SHOW(link_mode, fmt_dec);
  91. /* use same locking rules as GIFHWADDR ioctl's */
  92. static ssize_t show_address(struct device *dev, struct device_attribute *attr,
  93. char *buf)
  94. {
  95. struct net_device *net = to_net_dev(dev);
  96. ssize_t ret = -EINVAL;
  97. read_lock(&dev_base_lock);
  98. if (dev_isalive(net))
  99. ret = sysfs_format_mac(buf, net->dev_addr, net->addr_len);
  100. read_unlock(&dev_base_lock);
  101. return ret;
  102. }
  103. static ssize_t show_broadcast(struct device *dev,
  104. struct device_attribute *attr, char *buf)
  105. {
  106. struct net_device *net = to_net_dev(dev);
  107. if (dev_isalive(net))
  108. return sysfs_format_mac(buf, net->broadcast, net->addr_len);
  109. return -EINVAL;
  110. }
  111. static ssize_t show_carrier(struct device *dev,
  112. struct device_attribute *attr, char *buf)
  113. {
  114. struct net_device *netdev = to_net_dev(dev);
  115. if (netif_running(netdev)) {
  116. return sprintf(buf, fmt_dec, !!netif_carrier_ok(netdev));
  117. }
  118. return -EINVAL;
  119. }
  120. static ssize_t show_speed(struct device *dev,
  121. struct device_attribute *attr, char *buf)
  122. {
  123. struct net_device *netdev = to_net_dev(dev);
  124. int ret = -EINVAL;
  125. if (!rtnl_trylock())
  126. return restart_syscall();
  127. if (netif_running(netdev)) {
  128. struct ethtool_cmd cmd;
  129. if (!__ethtool_get_settings(netdev, &cmd))
  130. ret = sprintf(buf, fmt_udec, ethtool_cmd_speed(&cmd));
  131. }
  132. rtnl_unlock();
  133. return ret;
  134. }
  135. static ssize_t show_duplex(struct device *dev,
  136. struct device_attribute *attr, char *buf)
  137. {
  138. struct net_device *netdev = to_net_dev(dev);
  139. int ret = -EINVAL;
  140. if (!rtnl_trylock())
  141. return restart_syscall();
  142. if (netif_running(netdev)) {
  143. struct ethtool_cmd cmd;
  144. if (!__ethtool_get_settings(netdev, &cmd))
  145. ret = sprintf(buf, "%s\n",
  146. cmd.duplex ? "full" : "half");
  147. }
  148. rtnl_unlock();
  149. return ret;
  150. }
  151. static ssize_t show_dormant(struct device *dev,
  152. struct device_attribute *attr, char *buf)
  153. {
  154. struct net_device *netdev = to_net_dev(dev);
  155. if (netif_running(netdev))
  156. return sprintf(buf, fmt_dec, !!netif_dormant(netdev));
  157. return -EINVAL;
  158. }
  159. static const char *const operstates[] = {
  160. "unknown",
  161. "notpresent", /* currently unused */
  162. "down",
  163. "lowerlayerdown",
  164. "testing", /* currently unused */
  165. "dormant",
  166. "up"
  167. };
  168. static ssize_t show_operstate(struct device *dev,
  169. struct device_attribute *attr, char *buf)
  170. {
  171. const struct net_device *netdev = to_net_dev(dev);
  172. unsigned char operstate;
  173. read_lock(&dev_base_lock);
  174. operstate = netdev->operstate;
  175. if (!netif_running(netdev))
  176. operstate = IF_OPER_DOWN;
  177. read_unlock(&dev_base_lock);
  178. if (operstate >= ARRAY_SIZE(operstates))
  179. return -EINVAL; /* should not happen */
  180. return sprintf(buf, "%s\n", operstates[operstate]);
  181. }
  182. /* read-write attributes */
  183. NETDEVICE_SHOW(mtu, fmt_dec);
  184. static int change_mtu(struct net_device *net, unsigned long new_mtu)
  185. {
  186. return dev_set_mtu(net, (int) new_mtu);
  187. }
  188. static ssize_t store_mtu(struct device *dev, struct device_attribute *attr,
  189. const char *buf, size_t len)
  190. {
  191. return netdev_store(dev, attr, buf, len, change_mtu);
  192. }
  193. NETDEVICE_SHOW(flags, fmt_hex);
  194. static int change_flags(struct net_device *net, unsigned long new_flags)
  195. {
  196. return dev_change_flags(net, (unsigned) new_flags);
  197. }
  198. static ssize_t store_flags(struct device *dev, struct device_attribute *attr,
  199. const char *buf, size_t len)
  200. {
  201. return netdev_store(dev, attr, buf, len, change_flags);
  202. }
  203. NETDEVICE_SHOW(tx_queue_len, fmt_ulong);
  204. static int change_tx_queue_len(struct net_device *net, unsigned long new_len)
  205. {
  206. net->tx_queue_len = new_len;
  207. return 0;
  208. }
  209. static ssize_t store_tx_queue_len(struct device *dev,
  210. struct device_attribute *attr,
  211. const char *buf, size_t len)
  212. {
  213. return netdev_store(dev, attr, buf, len, change_tx_queue_len);
  214. }
  215. static ssize_t store_ifalias(struct device *dev, struct device_attribute *attr,
  216. const char *buf, size_t len)
  217. {
  218. struct net_device *netdev = to_net_dev(dev);
  219. size_t count = len;
  220. ssize_t ret;
  221. if (!capable(CAP_NET_ADMIN))
  222. return -EPERM;
  223. /* ignore trailing newline */
  224. if (len > 0 && buf[len - 1] == '\n')
  225. --count;
  226. if (!rtnl_trylock())
  227. return restart_syscall();
  228. ret = dev_set_alias(netdev, buf, count);
  229. rtnl_unlock();
  230. return ret < 0 ? ret : len;
  231. }
  232. static ssize_t show_ifalias(struct device *dev,
  233. struct device_attribute *attr, char *buf)
  234. {
  235. const struct net_device *netdev = to_net_dev(dev);
  236. ssize_t ret = 0;
  237. if (!rtnl_trylock())
  238. return restart_syscall();
  239. if (netdev->ifalias)
  240. ret = sprintf(buf, "%s\n", netdev->ifalias);
  241. rtnl_unlock();
  242. return ret;
  243. }
  244. NETDEVICE_SHOW(group, fmt_dec);
  245. static int change_group(struct net_device *net, unsigned long new_group)
  246. {
  247. dev_set_group(net, (int) new_group);
  248. return 0;
  249. }
  250. static ssize_t store_group(struct device *dev, struct device_attribute *attr,
  251. const char *buf, size_t len)
  252. {
  253. return netdev_store(dev, attr, buf, len, change_group);
  254. }
  255. static struct device_attribute net_class_attributes[] = {
  256. __ATTR(addr_assign_type, S_IRUGO, show_addr_assign_type, NULL),
  257. __ATTR(addr_len, S_IRUGO, show_addr_len, NULL),
  258. __ATTR(dev_id, S_IRUGO, show_dev_id, NULL),
  259. __ATTR(ifalias, S_IRUGO | S_IWUSR, show_ifalias, store_ifalias),
  260. __ATTR(iflink, S_IRUGO, show_iflink, NULL),
  261. __ATTR(ifindex, S_IRUGO, show_ifindex, NULL),
  262. __ATTR(type, S_IRUGO, show_type, NULL),
  263. __ATTR(link_mode, S_IRUGO, show_link_mode, NULL),
  264. __ATTR(address, S_IRUGO, show_address, NULL),
  265. __ATTR(broadcast, S_IRUGO, show_broadcast, NULL),
  266. __ATTR(carrier, S_IRUGO, show_carrier, NULL),
  267. __ATTR(speed, S_IRUGO, show_speed, NULL),
  268. __ATTR(duplex, S_IRUGO, show_duplex, NULL),
  269. __ATTR(dormant, S_IRUGO, show_dormant, NULL),
  270. __ATTR(operstate, S_IRUGO, show_operstate, NULL),
  271. __ATTR(mtu, S_IRUGO | S_IWUSR, show_mtu, store_mtu),
  272. __ATTR(flags, S_IRUGO | S_IWUSR, show_flags, store_flags),
  273. __ATTR(tx_queue_len, S_IRUGO | S_IWUSR, show_tx_queue_len,
  274. store_tx_queue_len),
  275. __ATTR(netdev_group, S_IRUGO | S_IWUSR, show_group, store_group),
  276. {}
  277. };
  278. /* Show a given an attribute in the statistics group */
  279. static ssize_t netstat_show(const struct device *d,
  280. struct device_attribute *attr, char *buf,
  281. unsigned long offset)
  282. {
  283. struct net_device *dev = to_net_dev(d);
  284. ssize_t ret = -EINVAL;
  285. WARN_ON(offset > sizeof(struct rtnl_link_stats64) ||
  286. offset % sizeof(u64) != 0);
  287. read_lock(&dev_base_lock);
  288. if (dev_isalive(dev)) {
  289. struct rtnl_link_stats64 temp;
  290. const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
  291. ret = sprintf(buf, fmt_u64, *(u64 *)(((u8 *) stats) + offset));
  292. }
  293. read_unlock(&dev_base_lock);
  294. return ret;
  295. }
  296. /* generate a read-only statistics attribute */
  297. #define NETSTAT_ENTRY(name) \
  298. static ssize_t show_##name(struct device *d, \
  299. struct device_attribute *attr, char *buf) \
  300. { \
  301. return netstat_show(d, attr, buf, \
  302. offsetof(struct rtnl_link_stats64, name)); \
  303. } \
  304. static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
  305. NETSTAT_ENTRY(rx_packets);
  306. NETSTAT_ENTRY(tx_packets);
  307. NETSTAT_ENTRY(rx_bytes);
  308. NETSTAT_ENTRY(tx_bytes);
  309. NETSTAT_ENTRY(rx_errors);
  310. NETSTAT_ENTRY(tx_errors);
  311. NETSTAT_ENTRY(rx_dropped);
  312. NETSTAT_ENTRY(tx_dropped);
  313. NETSTAT_ENTRY(multicast);
  314. NETSTAT_ENTRY(collisions);
  315. NETSTAT_ENTRY(rx_length_errors);
  316. NETSTAT_ENTRY(rx_over_errors);
  317. NETSTAT_ENTRY(rx_crc_errors);
  318. NETSTAT_ENTRY(rx_frame_errors);
  319. NETSTAT_ENTRY(rx_fifo_errors);
  320. NETSTAT_ENTRY(rx_missed_errors);
  321. NETSTAT_ENTRY(tx_aborted_errors);
  322. NETSTAT_ENTRY(tx_carrier_errors);
  323. NETSTAT_ENTRY(tx_fifo_errors);
  324. NETSTAT_ENTRY(tx_heartbeat_errors);
  325. NETSTAT_ENTRY(tx_window_errors);
  326. NETSTAT_ENTRY(rx_compressed);
  327. NETSTAT_ENTRY(tx_compressed);
  328. static struct attribute *netstat_attrs[] = {
  329. &dev_attr_rx_packets.attr,
  330. &dev_attr_tx_packets.attr,
  331. &dev_attr_rx_bytes.attr,
  332. &dev_attr_tx_bytes.attr,
  333. &dev_attr_rx_errors.attr,
  334. &dev_attr_tx_errors.attr,
  335. &dev_attr_rx_dropped.attr,
  336. &dev_attr_tx_dropped.attr,
  337. &dev_attr_multicast.attr,
  338. &dev_attr_collisions.attr,
  339. &dev_attr_rx_length_errors.attr,
  340. &dev_attr_rx_over_errors.attr,
  341. &dev_attr_rx_crc_errors.attr,
  342. &dev_attr_rx_frame_errors.attr,
  343. &dev_attr_rx_fifo_errors.attr,
  344. &dev_attr_rx_missed_errors.attr,
  345. &dev_attr_tx_aborted_errors.attr,
  346. &dev_attr_tx_carrier_errors.attr,
  347. &dev_attr_tx_fifo_errors.attr,
  348. &dev_attr_tx_heartbeat_errors.attr,
  349. &dev_attr_tx_window_errors.attr,
  350. &dev_attr_rx_compressed.attr,
  351. &dev_attr_tx_compressed.attr,
  352. NULL
  353. };
  354. static struct attribute_group netstat_group = {
  355. .name = "statistics",
  356. .attrs = netstat_attrs,
  357. };
  358. #ifdef CONFIG_WIRELESS_EXT_SYSFS
  359. /* helper function that does all the locking etc for wireless stats */
  360. static ssize_t wireless_show(struct device *d, char *buf,
  361. ssize_t (*format)(const struct iw_statistics *,
  362. char *))
  363. {
  364. struct net_device *dev = to_net_dev(d);
  365. const struct iw_statistics *iw;
  366. ssize_t ret = -EINVAL;
  367. if (!rtnl_trylock())
  368. return restart_syscall();
  369. if (dev_isalive(dev)) {
  370. iw = get_wireless_stats(dev);
  371. if (iw)
  372. ret = (*format)(iw, buf);
  373. }
  374. rtnl_unlock();
  375. return ret;
  376. }
  377. /* show function template for wireless fields */
  378. #define WIRELESS_SHOW(name, field, format_string) \
  379. static ssize_t format_iw_##name(const struct iw_statistics *iw, char *buf) \
  380. { \
  381. return sprintf(buf, format_string, iw->field); \
  382. } \
  383. static ssize_t show_iw_##name(struct device *d, \
  384. struct device_attribute *attr, char *buf) \
  385. { \
  386. return wireless_show(d, buf, format_iw_##name); \
  387. } \
  388. static DEVICE_ATTR(name, S_IRUGO, show_iw_##name, NULL)
  389. WIRELESS_SHOW(status, status, fmt_hex);
  390. WIRELESS_SHOW(link, qual.qual, fmt_dec);
  391. WIRELESS_SHOW(level, qual.level, fmt_dec);
  392. WIRELESS_SHOW(noise, qual.noise, fmt_dec);
  393. WIRELESS_SHOW(nwid, discard.nwid, fmt_dec);
  394. WIRELESS_SHOW(crypt, discard.code, fmt_dec);
  395. WIRELESS_SHOW(fragment, discard.fragment, fmt_dec);
  396. WIRELESS_SHOW(misc, discard.misc, fmt_dec);
  397. WIRELESS_SHOW(retries, discard.retries, fmt_dec);
  398. WIRELESS_SHOW(beacon, miss.beacon, fmt_dec);
  399. static struct attribute *wireless_attrs[] = {
  400. &dev_attr_status.attr,
  401. &dev_attr_link.attr,
  402. &dev_attr_level.attr,
  403. &dev_attr_noise.attr,
  404. &dev_attr_nwid.attr,
  405. &dev_attr_crypt.attr,
  406. &dev_attr_fragment.attr,
  407. &dev_attr_retries.attr,
  408. &dev_attr_misc.attr,
  409. &dev_attr_beacon.attr,
  410. NULL
  411. };
  412. static struct attribute_group wireless_group = {
  413. .name = "wireless",
  414. .attrs = wireless_attrs,
  415. };
  416. #endif
  417. #endif /* CONFIG_SYSFS */
  418. #ifdef CONFIG_RPS
  419. /*
  420. * RX queue sysfs structures and functions.
  421. */
  422. struct rx_queue_attribute {
  423. struct attribute attr;
  424. ssize_t (*show)(struct netdev_rx_queue *queue,
  425. struct rx_queue_attribute *attr, char *buf);
  426. ssize_t (*store)(struct netdev_rx_queue *queue,
  427. struct rx_queue_attribute *attr, const char *buf, size_t len);
  428. };
  429. #define to_rx_queue_attr(_attr) container_of(_attr, \
  430. struct rx_queue_attribute, attr)
  431. #define to_rx_queue(obj) container_of(obj, struct netdev_rx_queue, kobj)
  432. static ssize_t rx_queue_attr_show(struct kobject *kobj, struct attribute *attr,
  433. char *buf)
  434. {
  435. struct rx_queue_attribute *attribute = to_rx_queue_attr(attr);
  436. struct netdev_rx_queue *queue = to_rx_queue(kobj);
  437. if (!attribute->show)
  438. return -EIO;
  439. return attribute->show(queue, attribute, buf);
  440. }
  441. static ssize_t rx_queue_attr_store(struct kobject *kobj, struct attribute *attr,
  442. const char *buf, size_t count)
  443. {
  444. struct rx_queue_attribute *attribute = to_rx_queue_attr(attr);
  445. struct netdev_rx_queue *queue = to_rx_queue(kobj);
  446. if (!attribute->store)
  447. return -EIO;
  448. return attribute->store(queue, attribute, buf, count);
  449. }
  450. static const struct sysfs_ops rx_queue_sysfs_ops = {
  451. .show = rx_queue_attr_show,
  452. .store = rx_queue_attr_store,
  453. };
  454. static ssize_t show_rps_map(struct netdev_rx_queue *queue,
  455. struct rx_queue_attribute *attribute, char *buf)
  456. {
  457. struct rps_map *map;
  458. cpumask_var_t mask;
  459. size_t len = 0;
  460. int i;
  461. if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
  462. return -ENOMEM;
  463. rcu_read_lock();
  464. map = rcu_dereference(queue->rps_map);
  465. if (map)
  466. for (i = 0; i < map->len; i++)
  467. cpumask_set_cpu(map->cpus[i], mask);
  468. len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
  469. if (PAGE_SIZE - len < 3) {
  470. rcu_read_unlock();
  471. free_cpumask_var(mask);
  472. return -EINVAL;
  473. }
  474. rcu_read_unlock();
  475. free_cpumask_var(mask);
  476. len += sprintf(buf + len, "\n");
  477. return len;
  478. }
  479. static ssize_t store_rps_map(struct netdev_rx_queue *queue,
  480. struct rx_queue_attribute *attribute,
  481. const char *buf, size_t len)
  482. {
  483. struct rps_map *old_map, *map;
  484. cpumask_var_t mask;
  485. int err, cpu, i;
  486. static DEFINE_SPINLOCK(rps_map_lock);
  487. if (!capable(CAP_NET_ADMIN))
  488. return -EPERM;
  489. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  490. return -ENOMEM;
  491. err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
  492. if (err) {
  493. free_cpumask_var(mask);
  494. return err;
  495. }
  496. map = kzalloc(max_t(unsigned,
  497. RPS_MAP_SIZE(cpumask_weight(mask)), L1_CACHE_BYTES),
  498. GFP_KERNEL);
  499. if (!map) {
  500. free_cpumask_var(mask);
  501. return -ENOMEM;
  502. }
  503. i = 0;
  504. for_each_cpu_and(cpu, mask, cpu_online_mask)
  505. map->cpus[i++] = cpu;
  506. if (i)
  507. map->len = i;
  508. else {
  509. kfree(map);
  510. map = NULL;
  511. }
  512. spin_lock(&rps_map_lock);
  513. old_map = rcu_dereference_protected(queue->rps_map,
  514. lockdep_is_held(&rps_map_lock));
  515. rcu_assign_pointer(queue->rps_map, map);
  516. spin_unlock(&rps_map_lock);
  517. if (old_map)
  518. kfree_rcu(old_map, rcu);
  519. free_cpumask_var(mask);
  520. return len;
  521. }
  522. static ssize_t show_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
  523. struct rx_queue_attribute *attr,
  524. char *buf)
  525. {
  526. struct rps_dev_flow_table *flow_table;
  527. unsigned int val = 0;
  528. rcu_read_lock();
  529. flow_table = rcu_dereference(queue->rps_flow_table);
  530. if (flow_table)
  531. val = flow_table->mask + 1;
  532. rcu_read_unlock();
  533. return sprintf(buf, "%u\n", val);
  534. }
  535. static void rps_dev_flow_table_release_work(struct work_struct *work)
  536. {
  537. struct rps_dev_flow_table *table = container_of(work,
  538. struct rps_dev_flow_table, free_work);
  539. vfree(table);
  540. }
  541. static void rps_dev_flow_table_release(struct rcu_head *rcu)
  542. {
  543. struct rps_dev_flow_table *table = container_of(rcu,
  544. struct rps_dev_flow_table, rcu);
  545. INIT_WORK(&table->free_work, rps_dev_flow_table_release_work);
  546. schedule_work(&table->free_work);
  547. }
  548. static ssize_t store_rps_dev_flow_table_cnt(struct netdev_rx_queue *queue,
  549. struct rx_queue_attribute *attr,
  550. const char *buf, size_t len)
  551. {
  552. unsigned int count;
  553. char *endp;
  554. struct rps_dev_flow_table *table, *old_table;
  555. static DEFINE_SPINLOCK(rps_dev_flow_lock);
  556. if (!capable(CAP_NET_ADMIN))
  557. return -EPERM;
  558. count = simple_strtoul(buf, &endp, 0);
  559. if (endp == buf)
  560. return -EINVAL;
  561. if (count) {
  562. int i;
  563. if (count > 1<<30) {
  564. /* Enforce a limit to prevent overflow */
  565. return -EINVAL;
  566. }
  567. count = roundup_pow_of_two(count);
  568. table = vmalloc(RPS_DEV_FLOW_TABLE_SIZE(count));
  569. if (!table)
  570. return -ENOMEM;
  571. table->mask = count - 1;
  572. for (i = 0; i < count; i++)
  573. table->flows[i].cpu = RPS_NO_CPU;
  574. } else
  575. table = NULL;
  576. spin_lock(&rps_dev_flow_lock);
  577. old_table = rcu_dereference_protected(queue->rps_flow_table,
  578. lockdep_is_held(&rps_dev_flow_lock));
  579. rcu_assign_pointer(queue->rps_flow_table, table);
  580. spin_unlock(&rps_dev_flow_lock);
  581. if (old_table)
  582. call_rcu(&old_table->rcu, rps_dev_flow_table_release);
  583. return len;
  584. }
  585. static struct rx_queue_attribute rps_cpus_attribute =
  586. __ATTR(rps_cpus, S_IRUGO | S_IWUSR, show_rps_map, store_rps_map);
  587. static struct rx_queue_attribute rps_dev_flow_table_cnt_attribute =
  588. __ATTR(rps_flow_cnt, S_IRUGO | S_IWUSR,
  589. show_rps_dev_flow_table_cnt, store_rps_dev_flow_table_cnt);
  590. static struct attribute *rx_queue_default_attrs[] = {
  591. &rps_cpus_attribute.attr,
  592. &rps_dev_flow_table_cnt_attribute.attr,
  593. NULL
  594. };
  595. static void rx_queue_release(struct kobject *kobj)
  596. {
  597. struct netdev_rx_queue *queue = to_rx_queue(kobj);
  598. struct rps_map *map;
  599. struct rps_dev_flow_table *flow_table;
  600. map = rcu_dereference_protected(queue->rps_map, 1);
  601. if (map) {
  602. RCU_INIT_POINTER(queue->rps_map, NULL);
  603. kfree_rcu(map, rcu);
  604. }
  605. flow_table = rcu_dereference_protected(queue->rps_flow_table, 1);
  606. if (flow_table) {
  607. RCU_INIT_POINTER(queue->rps_flow_table, NULL);
  608. call_rcu(&flow_table->rcu, rps_dev_flow_table_release);
  609. }
  610. memset(kobj, 0, sizeof(*kobj));
  611. dev_put(queue->dev);
  612. }
  613. static struct kobj_type rx_queue_ktype = {
  614. .sysfs_ops = &rx_queue_sysfs_ops,
  615. .release = rx_queue_release,
  616. .default_attrs = rx_queue_default_attrs,
  617. };
  618. static int rx_queue_add_kobject(struct net_device *net, int index)
  619. {
  620. struct netdev_rx_queue *queue = net->_rx + index;
  621. struct kobject *kobj = &queue->kobj;
  622. int error = 0;
  623. kobj->kset = net->queues_kset;
  624. error = kobject_init_and_add(kobj, &rx_queue_ktype, NULL,
  625. "rx-%u", index);
  626. if (error) {
  627. kobject_put(kobj);
  628. return error;
  629. }
  630. kobject_uevent(kobj, KOBJ_ADD);
  631. dev_hold(queue->dev);
  632. return error;
  633. }
  634. #endif /* CONFIG_RPS */
  635. int
  636. net_rx_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
  637. {
  638. #ifdef CONFIG_RPS
  639. int i;
  640. int error = 0;
  641. for (i = old_num; i < new_num; i++) {
  642. error = rx_queue_add_kobject(net, i);
  643. if (error) {
  644. new_num = old_num;
  645. break;
  646. }
  647. }
  648. while (--i >= new_num)
  649. kobject_put(&net->_rx[i].kobj);
  650. return error;
  651. #else
  652. return 0;
  653. #endif
  654. }
  655. #ifdef CONFIG_XPS
  656. /*
  657. * netdev_queue sysfs structures and functions.
  658. */
  659. struct netdev_queue_attribute {
  660. struct attribute attr;
  661. ssize_t (*show)(struct netdev_queue *queue,
  662. struct netdev_queue_attribute *attr, char *buf);
  663. ssize_t (*store)(struct netdev_queue *queue,
  664. struct netdev_queue_attribute *attr, const char *buf, size_t len);
  665. };
  666. #define to_netdev_queue_attr(_attr) container_of(_attr, \
  667. struct netdev_queue_attribute, attr)
  668. #define to_netdev_queue(obj) container_of(obj, struct netdev_queue, kobj)
  669. static ssize_t netdev_queue_attr_show(struct kobject *kobj,
  670. struct attribute *attr, char *buf)
  671. {
  672. struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr);
  673. struct netdev_queue *queue = to_netdev_queue(kobj);
  674. if (!attribute->show)
  675. return -EIO;
  676. return attribute->show(queue, attribute, buf);
  677. }
  678. static ssize_t netdev_queue_attr_store(struct kobject *kobj,
  679. struct attribute *attr,
  680. const char *buf, size_t count)
  681. {
  682. struct netdev_queue_attribute *attribute = to_netdev_queue_attr(attr);
  683. struct netdev_queue *queue = to_netdev_queue(kobj);
  684. if (!attribute->store)
  685. return -EIO;
  686. return attribute->store(queue, attribute, buf, count);
  687. }
  688. static const struct sysfs_ops netdev_queue_sysfs_ops = {
  689. .show = netdev_queue_attr_show,
  690. .store = netdev_queue_attr_store,
  691. };
  692. static inline unsigned int get_netdev_queue_index(struct netdev_queue *queue)
  693. {
  694. struct net_device *dev = queue->dev;
  695. int i;
  696. for (i = 0; i < dev->num_tx_queues; i++)
  697. if (queue == &dev->_tx[i])
  698. break;
  699. BUG_ON(i >= dev->num_tx_queues);
  700. return i;
  701. }
  702. static ssize_t show_xps_map(struct netdev_queue *queue,
  703. struct netdev_queue_attribute *attribute, char *buf)
  704. {
  705. struct net_device *dev = queue->dev;
  706. struct xps_dev_maps *dev_maps;
  707. cpumask_var_t mask;
  708. unsigned long index;
  709. size_t len = 0;
  710. int i;
  711. if (!zalloc_cpumask_var(&mask, GFP_KERNEL))
  712. return -ENOMEM;
  713. index = get_netdev_queue_index(queue);
  714. rcu_read_lock();
  715. dev_maps = rcu_dereference(dev->xps_maps);
  716. if (dev_maps) {
  717. for_each_possible_cpu(i) {
  718. struct xps_map *map =
  719. rcu_dereference(dev_maps->cpu_map[i]);
  720. if (map) {
  721. int j;
  722. for (j = 0; j < map->len; j++) {
  723. if (map->queues[j] == index) {
  724. cpumask_set_cpu(i, mask);
  725. break;
  726. }
  727. }
  728. }
  729. }
  730. }
  731. rcu_read_unlock();
  732. len += cpumask_scnprintf(buf + len, PAGE_SIZE, mask);
  733. if (PAGE_SIZE - len < 3) {
  734. free_cpumask_var(mask);
  735. return -EINVAL;
  736. }
  737. free_cpumask_var(mask);
  738. len += sprintf(buf + len, "\n");
  739. return len;
  740. }
  741. static DEFINE_MUTEX(xps_map_mutex);
  742. #define xmap_dereference(P) \
  743. rcu_dereference_protected((P), lockdep_is_held(&xps_map_mutex))
  744. static ssize_t store_xps_map(struct netdev_queue *queue,
  745. struct netdev_queue_attribute *attribute,
  746. const char *buf, size_t len)
  747. {
  748. struct net_device *dev = queue->dev;
  749. cpumask_var_t mask;
  750. int err, i, cpu, pos, map_len, alloc_len, need_set;
  751. unsigned long index;
  752. struct xps_map *map, *new_map;
  753. struct xps_dev_maps *dev_maps, *new_dev_maps;
  754. int nonempty = 0;
  755. int numa_node = -2;
  756. if (!capable(CAP_NET_ADMIN))
  757. return -EPERM;
  758. if (!alloc_cpumask_var(&mask, GFP_KERNEL))
  759. return -ENOMEM;
  760. index = get_netdev_queue_index(queue);
  761. err = bitmap_parse(buf, len, cpumask_bits(mask), nr_cpumask_bits);
  762. if (err) {
  763. free_cpumask_var(mask);
  764. return err;
  765. }
  766. new_dev_maps = kzalloc(max_t(unsigned,
  767. XPS_DEV_MAPS_SIZE, L1_CACHE_BYTES), GFP_KERNEL);
  768. if (!new_dev_maps) {
  769. free_cpumask_var(mask);
  770. return -ENOMEM;
  771. }
  772. mutex_lock(&xps_map_mutex);
  773. dev_maps = xmap_dereference(dev->xps_maps);
  774. for_each_possible_cpu(cpu) {
  775. map = dev_maps ?
  776. xmap_dereference(dev_maps->cpu_map[cpu]) : NULL;
  777. new_map = map;
  778. if (map) {
  779. for (pos = 0; pos < map->len; pos++)
  780. if (map->queues[pos] == index)
  781. break;
  782. map_len = map->len;
  783. alloc_len = map->alloc_len;
  784. } else
  785. pos = map_len = alloc_len = 0;
  786. need_set = cpumask_test_cpu(cpu, mask) && cpu_online(cpu);
  787. #ifdef CONFIG_NUMA
  788. if (need_set) {
  789. if (numa_node == -2)
  790. numa_node = cpu_to_node(cpu);
  791. else if (numa_node != cpu_to_node(cpu))
  792. numa_node = -1;
  793. }
  794. #endif
  795. if (need_set && pos >= map_len) {
  796. /* Need to add queue to this CPU's map */
  797. if (map_len >= alloc_len) {
  798. alloc_len = alloc_len ?
  799. 2 * alloc_len : XPS_MIN_MAP_ALLOC;
  800. new_map = kzalloc_node(XPS_MAP_SIZE(alloc_len),
  801. GFP_KERNEL,
  802. cpu_to_node(cpu));
  803. if (!new_map)
  804. goto error;
  805. new_map->alloc_len = alloc_len;
  806. for (i = 0; i < map_len; i++)
  807. new_map->queues[i] = map->queues[i];
  808. new_map->len = map_len;
  809. }
  810. new_map->queues[new_map->len++] = index;
  811. } else if (!need_set && pos < map_len) {
  812. /* Need to remove queue from this CPU's map */
  813. if (map_len > 1)
  814. new_map->queues[pos] =
  815. new_map->queues[--new_map->len];
  816. else
  817. new_map = NULL;
  818. }
  819. RCU_INIT_POINTER(new_dev_maps->cpu_map[cpu], new_map);
  820. }
  821. /* Cleanup old maps */
  822. for_each_possible_cpu(cpu) {
  823. map = dev_maps ?
  824. xmap_dereference(dev_maps->cpu_map[cpu]) : NULL;
  825. if (map && xmap_dereference(new_dev_maps->cpu_map[cpu]) != map)
  826. kfree_rcu(map, rcu);
  827. if (new_dev_maps->cpu_map[cpu])
  828. nonempty = 1;
  829. }
  830. if (nonempty)
  831. RCU_INIT_POINTER(dev->xps_maps, new_dev_maps);
  832. else {
  833. kfree(new_dev_maps);
  834. RCU_INIT_POINTER(dev->xps_maps, NULL);
  835. }
  836. if (dev_maps)
  837. kfree_rcu(dev_maps, rcu);
  838. netdev_queue_numa_node_write(queue, (numa_node >= 0) ? numa_node :
  839. NUMA_NO_NODE);
  840. mutex_unlock(&xps_map_mutex);
  841. free_cpumask_var(mask);
  842. return len;
  843. error:
  844. mutex_unlock(&xps_map_mutex);
  845. if (new_dev_maps)
  846. for_each_possible_cpu(i)
  847. kfree(rcu_dereference_protected(
  848. new_dev_maps->cpu_map[i],
  849. 1));
  850. kfree(new_dev_maps);
  851. free_cpumask_var(mask);
  852. return -ENOMEM;
  853. }
  854. static struct netdev_queue_attribute xps_cpus_attribute =
  855. __ATTR(xps_cpus, S_IRUGO | S_IWUSR, show_xps_map, store_xps_map);
  856. static struct attribute *netdev_queue_default_attrs[] = {
  857. &xps_cpus_attribute.attr,
  858. NULL
  859. };
  860. static void netdev_queue_release(struct kobject *kobj)
  861. {
  862. struct netdev_queue *queue = to_netdev_queue(kobj);
  863. struct net_device *dev = queue->dev;
  864. struct xps_dev_maps *dev_maps;
  865. struct xps_map *map;
  866. unsigned long index;
  867. int i, pos, nonempty = 0;
  868. index = get_netdev_queue_index(queue);
  869. mutex_lock(&xps_map_mutex);
  870. dev_maps = xmap_dereference(dev->xps_maps);
  871. if (dev_maps) {
  872. for_each_possible_cpu(i) {
  873. map = xmap_dereference(dev_maps->cpu_map[i]);
  874. if (!map)
  875. continue;
  876. for (pos = 0; pos < map->len; pos++)
  877. if (map->queues[pos] == index)
  878. break;
  879. if (pos < map->len) {
  880. if (map->len > 1)
  881. map->queues[pos] =
  882. map->queues[--map->len];
  883. else {
  884. RCU_INIT_POINTER(dev_maps->cpu_map[i],
  885. NULL);
  886. kfree_rcu(map, rcu);
  887. map = NULL;
  888. }
  889. }
  890. if (map)
  891. nonempty = 1;
  892. }
  893. if (!nonempty) {
  894. RCU_INIT_POINTER(dev->xps_maps, NULL);
  895. kfree_rcu(dev_maps, rcu);
  896. }
  897. }
  898. mutex_unlock(&xps_map_mutex);
  899. memset(kobj, 0, sizeof(*kobj));
  900. dev_put(queue->dev);
  901. }
  902. static struct kobj_type netdev_queue_ktype = {
  903. .sysfs_ops = &netdev_queue_sysfs_ops,
  904. .release = netdev_queue_release,
  905. .default_attrs = netdev_queue_default_attrs,
  906. };
  907. static int netdev_queue_add_kobject(struct net_device *net, int index)
  908. {
  909. struct netdev_queue *queue = net->_tx + index;
  910. struct kobject *kobj = &queue->kobj;
  911. int error = 0;
  912. kobj->kset = net->queues_kset;
  913. error = kobject_init_and_add(kobj, &netdev_queue_ktype, NULL,
  914. "tx-%u", index);
  915. if (error) {
  916. kobject_put(kobj);
  917. return error;
  918. }
  919. kobject_uevent(kobj, KOBJ_ADD);
  920. dev_hold(queue->dev);
  921. return error;
  922. }
  923. #endif /* CONFIG_XPS */
  924. int
  925. netdev_queue_update_kobjects(struct net_device *net, int old_num, int new_num)
  926. {
  927. #ifdef CONFIG_XPS
  928. int i;
  929. int error = 0;
  930. for (i = old_num; i < new_num; i++) {
  931. error = netdev_queue_add_kobject(net, i);
  932. if (error) {
  933. new_num = old_num;
  934. break;
  935. }
  936. }
  937. while (--i >= new_num)
  938. kobject_put(&net->_tx[i].kobj);
  939. return error;
  940. #else
  941. return 0;
  942. #endif
  943. }
  944. static int register_queue_kobjects(struct net_device *net)
  945. {
  946. int error = 0, txq = 0, rxq = 0, real_rx = 0, real_tx = 0;
  947. #if defined(CONFIG_RPS) || defined(CONFIG_XPS)
  948. net->queues_kset = kset_create_and_add("queues",
  949. NULL, &net->dev.kobj);
  950. if (!net->queues_kset)
  951. return -ENOMEM;
  952. #endif
  953. #ifdef CONFIG_RPS
  954. real_rx = net->real_num_rx_queues;
  955. #endif
  956. real_tx = net->real_num_tx_queues;
  957. error = net_rx_queue_update_kobjects(net, 0, real_rx);
  958. if (error)
  959. goto error;
  960. rxq = real_rx;
  961. error = netdev_queue_update_kobjects(net, 0, real_tx);
  962. if (error)
  963. goto error;
  964. txq = real_tx;
  965. return 0;
  966. error:
  967. netdev_queue_update_kobjects(net, txq, 0);
  968. net_rx_queue_update_kobjects(net, rxq, 0);
  969. return error;
  970. }
  971. static void remove_queue_kobjects(struct net_device *net)
  972. {
  973. int real_rx = 0, real_tx = 0;
  974. #ifdef CONFIG_RPS
  975. real_rx = net->real_num_rx_queues;
  976. #endif
  977. real_tx = net->real_num_tx_queues;
  978. net_rx_queue_update_kobjects(net, real_rx, 0);
  979. netdev_queue_update_kobjects(net, real_tx, 0);
  980. #if defined(CONFIG_RPS) || defined(CONFIG_XPS)
  981. kset_unregister(net->queues_kset);
  982. #endif
  983. }
  984. static void *net_grab_current_ns(void)
  985. {
  986. struct net *ns = current->nsproxy->net_ns;
  987. #ifdef CONFIG_NET_NS
  988. if (ns)
  989. atomic_inc(&ns->passive);
  990. #endif
  991. return ns;
  992. }
  993. static const void *net_initial_ns(void)
  994. {
  995. return &init_net;
  996. }
  997. static const void *net_netlink_ns(struct sock *sk)
  998. {
  999. return sock_net(sk);
  1000. }
  1001. struct kobj_ns_type_operations net_ns_type_operations = {
  1002. .type = KOBJ_NS_TYPE_NET,
  1003. .grab_current_ns = net_grab_current_ns,
  1004. .netlink_ns = net_netlink_ns,
  1005. .initial_ns = net_initial_ns,
  1006. .drop_ns = net_drop_ns,
  1007. };
  1008. EXPORT_SYMBOL_GPL(net_ns_type_operations);
  1009. #ifdef CONFIG_HOTPLUG
  1010. static int netdev_uevent(struct device *d, struct kobj_uevent_env *env)
  1011. {
  1012. struct net_device *dev = to_net_dev(d);
  1013. int retval;
  1014. /* pass interface to uevent. */
  1015. retval = add_uevent_var(env, "INTERFACE=%s", dev->name);
  1016. if (retval)
  1017. goto exit;
  1018. /* pass ifindex to uevent.
  1019. * ifindex is useful as it won't change (interface name may change)
  1020. * and is what RtNetlink uses natively. */
  1021. retval = add_uevent_var(env, "IFINDEX=%d", dev->ifindex);
  1022. exit:
  1023. return retval;
  1024. }
  1025. #endif
  1026. /*
  1027. * netdev_release -- destroy and free a dead device.
  1028. * Called when last reference to device kobject is gone.
  1029. */
  1030. static void netdev_release(struct device *d)
  1031. {
  1032. struct net_device *dev = to_net_dev(d);
  1033. BUG_ON(dev->reg_state != NETREG_RELEASED);
  1034. kfree(dev->ifalias);
  1035. kfree((char *)dev - dev->padded);
  1036. }
  1037. static const void *net_namespace(struct device *d)
  1038. {
  1039. struct net_device *dev;
  1040. dev = container_of(d, struct net_device, dev);
  1041. return dev_net(dev);
  1042. }
  1043. static struct class net_class = {
  1044. .name = "net",
  1045. .dev_release = netdev_release,
  1046. #ifdef CONFIG_SYSFS
  1047. .dev_attrs = net_class_attributes,
  1048. #endif /* CONFIG_SYSFS */
  1049. #ifdef CONFIG_HOTPLUG
  1050. .dev_uevent = netdev_uevent,
  1051. #endif
  1052. .ns_type = &net_ns_type_operations,
  1053. .namespace = net_namespace,
  1054. };
  1055. /* Delete sysfs entries but hold kobject reference until after all
  1056. * netdev references are gone.
  1057. */
  1058. void netdev_unregister_kobject(struct net_device * net)
  1059. {
  1060. struct device *dev = &(net->dev);
  1061. kobject_get(&dev->kobj);
  1062. remove_queue_kobjects(net);
  1063. device_del(dev);
  1064. }
  1065. /* Create sysfs entries for network device. */
  1066. int netdev_register_kobject(struct net_device *net)
  1067. {
  1068. struct device *dev = &(net->dev);
  1069. const struct attribute_group **groups = net->sysfs_groups;
  1070. int error = 0;
  1071. device_initialize(dev);
  1072. dev->class = &net_class;
  1073. dev->platform_data = net;
  1074. dev->groups = groups;
  1075. dev_set_name(dev, "%s", net->name);
  1076. #ifdef CONFIG_SYSFS
  1077. /* Allow for a device specific group */
  1078. if (*groups)
  1079. groups++;
  1080. *groups++ = &netstat_group;
  1081. #ifdef CONFIG_WIRELESS_EXT_SYSFS
  1082. if (net->ieee80211_ptr)
  1083. *groups++ = &wireless_group;
  1084. #ifdef CONFIG_WIRELESS_EXT
  1085. else if (net->wireless_handlers)
  1086. *groups++ = &wireless_group;
  1087. #endif
  1088. #endif
  1089. #endif /* CONFIG_SYSFS */
  1090. error = device_add(dev);
  1091. if (error)
  1092. return error;
  1093. error = register_queue_kobjects(net);
  1094. if (error) {
  1095. device_del(dev);
  1096. return error;
  1097. }
  1098. return error;
  1099. }
  1100. int netdev_class_create_file(struct class_attribute *class_attr)
  1101. {
  1102. return class_create_file(&net_class, class_attr);
  1103. }
  1104. EXPORT_SYMBOL(netdev_class_create_file);
  1105. void netdev_class_remove_file(struct class_attribute *class_attr)
  1106. {
  1107. class_remove_file(&net_class, class_attr);
  1108. }
  1109. EXPORT_SYMBOL(netdev_class_remove_file);
  1110. int netdev_kobject_init(void)
  1111. {
  1112. kobj_ns_type_register(&net_ns_type_operations);
  1113. return class_register(&net_class);
  1114. }