net-sysfs.c 31 KB

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