net-sysfs.c 32 KB

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