br_sysfs_br.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819
  1. /*
  2. * Sysfs attributes of bridge ports
  3. * Linux ethernet bridge
  4. *
  5. * Authors:
  6. * Stephen Hemminger <shemminger@osdl.org>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version
  11. * 2 of the License, or (at your option) any later version.
  12. */
  13. #include <linux/capability.h>
  14. #include <linux/kernel.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/if_bridge.h>
  17. #include <linux/rtnetlink.h>
  18. #include <linux/spinlock.h>
  19. #include <linux/times.h>
  20. #include "br_private.h"
  21. #define to_dev(obj) container_of(obj, struct device, kobj)
  22. #define to_bridge(cd) ((struct net_bridge *)netdev_priv(to_net_dev(cd)))
  23. /*
  24. * Common code for storing bridge parameters.
  25. */
  26. static ssize_t store_bridge_parm(struct device *d,
  27. const char *buf, size_t len,
  28. int (*set)(struct net_bridge *, unsigned long))
  29. {
  30. struct net_bridge *br = to_bridge(d);
  31. char *endp;
  32. unsigned long val;
  33. int err;
  34. if (!capable(CAP_NET_ADMIN))
  35. return -EPERM;
  36. val = simple_strtoul(buf, &endp, 0);
  37. if (endp == buf)
  38. return -EINVAL;
  39. err = (*set)(br, val);
  40. return err ? err : len;
  41. }
  42. static ssize_t show_forward_delay(struct device *d,
  43. struct device_attribute *attr, char *buf)
  44. {
  45. struct net_bridge *br = to_bridge(d);
  46. return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->forward_delay));
  47. }
  48. static ssize_t store_forward_delay(struct device *d,
  49. struct device_attribute *attr,
  50. const char *buf, size_t len)
  51. {
  52. return store_bridge_parm(d, buf, len, br_set_forward_delay);
  53. }
  54. static DEVICE_ATTR(forward_delay, S_IRUGO | S_IWUSR,
  55. show_forward_delay, store_forward_delay);
  56. static ssize_t show_hello_time(struct device *d, struct device_attribute *attr,
  57. char *buf)
  58. {
  59. return sprintf(buf, "%lu\n",
  60. jiffies_to_clock_t(to_bridge(d)->hello_time));
  61. }
  62. static ssize_t store_hello_time(struct device *d,
  63. struct device_attribute *attr, const char *buf,
  64. size_t len)
  65. {
  66. return store_bridge_parm(d, buf, len, br_set_hello_time);
  67. }
  68. static DEVICE_ATTR(hello_time, S_IRUGO | S_IWUSR, show_hello_time,
  69. store_hello_time);
  70. static ssize_t show_max_age(struct device *d, struct device_attribute *attr,
  71. char *buf)
  72. {
  73. return sprintf(buf, "%lu\n",
  74. jiffies_to_clock_t(to_bridge(d)->max_age));
  75. }
  76. static ssize_t store_max_age(struct device *d, struct device_attribute *attr,
  77. const char *buf, size_t len)
  78. {
  79. return store_bridge_parm(d, buf, len, br_set_max_age);
  80. }
  81. static DEVICE_ATTR(max_age, S_IRUGO | S_IWUSR, show_max_age, store_max_age);
  82. static ssize_t show_ageing_time(struct device *d,
  83. struct device_attribute *attr, char *buf)
  84. {
  85. struct net_bridge *br = to_bridge(d);
  86. return sprintf(buf, "%lu\n", jiffies_to_clock_t(br->ageing_time));
  87. }
  88. static int set_ageing_time(struct net_bridge *br, unsigned long val)
  89. {
  90. br->ageing_time = clock_t_to_jiffies(val);
  91. return 0;
  92. }
  93. static ssize_t store_ageing_time(struct device *d,
  94. struct device_attribute *attr,
  95. const char *buf, size_t len)
  96. {
  97. return store_bridge_parm(d, buf, len, set_ageing_time);
  98. }
  99. static DEVICE_ATTR(ageing_time, S_IRUGO | S_IWUSR, show_ageing_time,
  100. store_ageing_time);
  101. static ssize_t show_stp_state(struct device *d,
  102. struct device_attribute *attr, char *buf)
  103. {
  104. struct net_bridge *br = to_bridge(d);
  105. return sprintf(buf, "%d\n", br->stp_enabled);
  106. }
  107. static ssize_t store_stp_state(struct device *d,
  108. struct device_attribute *attr, const char *buf,
  109. size_t len)
  110. {
  111. struct net_bridge *br = to_bridge(d);
  112. char *endp;
  113. unsigned long val;
  114. if (!capable(CAP_NET_ADMIN))
  115. return -EPERM;
  116. val = simple_strtoul(buf, &endp, 0);
  117. if (endp == buf)
  118. return -EINVAL;
  119. if (!rtnl_trylock())
  120. return restart_syscall();
  121. br_stp_set_enabled(br, val);
  122. rtnl_unlock();
  123. return len;
  124. }
  125. static DEVICE_ATTR(stp_state, S_IRUGO | S_IWUSR, show_stp_state,
  126. store_stp_state);
  127. static ssize_t show_group_fwd_mask(struct device *d,
  128. struct device_attribute *attr, char *buf)
  129. {
  130. struct net_bridge *br = to_bridge(d);
  131. return sprintf(buf, "%#x\n", br->group_fwd_mask);
  132. }
  133. static ssize_t store_group_fwd_mask(struct device *d,
  134. struct device_attribute *attr, const char *buf,
  135. size_t len)
  136. {
  137. struct net_bridge *br = to_bridge(d);
  138. char *endp;
  139. unsigned long val;
  140. if (!capable(CAP_NET_ADMIN))
  141. return -EPERM;
  142. val = simple_strtoul(buf, &endp, 0);
  143. if (endp == buf)
  144. return -EINVAL;
  145. if (val & BR_GROUPFWD_RESTRICTED)
  146. return -EINVAL;
  147. br->group_fwd_mask = val;
  148. return len;
  149. }
  150. static DEVICE_ATTR(group_fwd_mask, S_IRUGO | S_IWUSR, show_group_fwd_mask,
  151. store_group_fwd_mask);
  152. static ssize_t show_priority(struct device *d, struct device_attribute *attr,
  153. char *buf)
  154. {
  155. struct net_bridge *br = to_bridge(d);
  156. return sprintf(buf, "%d\n",
  157. (br->bridge_id.prio[0] << 8) | br->bridge_id.prio[1]);
  158. }
  159. static int set_priority(struct net_bridge *br, unsigned long val)
  160. {
  161. br_stp_set_bridge_priority(br, (u16) val);
  162. return 0;
  163. }
  164. static ssize_t store_priority(struct device *d, struct device_attribute *attr,
  165. const char *buf, size_t len)
  166. {
  167. return store_bridge_parm(d, buf, len, set_priority);
  168. }
  169. static DEVICE_ATTR(priority, S_IRUGO | S_IWUSR, show_priority, store_priority);
  170. static ssize_t show_root_id(struct device *d, struct device_attribute *attr,
  171. char *buf)
  172. {
  173. return br_show_bridge_id(buf, &to_bridge(d)->designated_root);
  174. }
  175. static DEVICE_ATTR(root_id, S_IRUGO, show_root_id, NULL);
  176. static ssize_t show_bridge_id(struct device *d, struct device_attribute *attr,
  177. char *buf)
  178. {
  179. return br_show_bridge_id(buf, &to_bridge(d)->bridge_id);
  180. }
  181. static DEVICE_ATTR(bridge_id, S_IRUGO, show_bridge_id, NULL);
  182. static ssize_t show_root_port(struct device *d, struct device_attribute *attr,
  183. char *buf)
  184. {
  185. return sprintf(buf, "%d\n", to_bridge(d)->root_port);
  186. }
  187. static DEVICE_ATTR(root_port, S_IRUGO, show_root_port, NULL);
  188. static ssize_t show_root_path_cost(struct device *d,
  189. struct device_attribute *attr, char *buf)
  190. {
  191. return sprintf(buf, "%d\n", to_bridge(d)->root_path_cost);
  192. }
  193. static DEVICE_ATTR(root_path_cost, S_IRUGO, show_root_path_cost, NULL);
  194. static ssize_t show_topology_change(struct device *d,
  195. struct device_attribute *attr, char *buf)
  196. {
  197. return sprintf(buf, "%d\n", to_bridge(d)->topology_change);
  198. }
  199. static DEVICE_ATTR(topology_change, S_IRUGO, show_topology_change, NULL);
  200. static ssize_t show_topology_change_detected(struct device *d,
  201. struct device_attribute *attr,
  202. char *buf)
  203. {
  204. struct net_bridge *br = to_bridge(d);
  205. return sprintf(buf, "%d\n", br->topology_change_detected);
  206. }
  207. static DEVICE_ATTR(topology_change_detected, S_IRUGO,
  208. show_topology_change_detected, NULL);
  209. static ssize_t show_hello_timer(struct device *d,
  210. struct device_attribute *attr, char *buf)
  211. {
  212. struct net_bridge *br = to_bridge(d);
  213. return sprintf(buf, "%ld\n", br_timer_value(&br->hello_timer));
  214. }
  215. static DEVICE_ATTR(hello_timer, S_IRUGO, show_hello_timer, NULL);
  216. static ssize_t show_tcn_timer(struct device *d, struct device_attribute *attr,
  217. char *buf)
  218. {
  219. struct net_bridge *br = to_bridge(d);
  220. return sprintf(buf, "%ld\n", br_timer_value(&br->tcn_timer));
  221. }
  222. static DEVICE_ATTR(tcn_timer, S_IRUGO, show_tcn_timer, NULL);
  223. static ssize_t show_topology_change_timer(struct device *d,
  224. struct device_attribute *attr,
  225. char *buf)
  226. {
  227. struct net_bridge *br = to_bridge(d);
  228. return sprintf(buf, "%ld\n", br_timer_value(&br->topology_change_timer));
  229. }
  230. static DEVICE_ATTR(topology_change_timer, S_IRUGO, show_topology_change_timer,
  231. NULL);
  232. static ssize_t show_gc_timer(struct device *d, struct device_attribute *attr,
  233. char *buf)
  234. {
  235. struct net_bridge *br = to_bridge(d);
  236. return sprintf(buf, "%ld\n", br_timer_value(&br->gc_timer));
  237. }
  238. static DEVICE_ATTR(gc_timer, S_IRUGO, show_gc_timer, NULL);
  239. static ssize_t show_group_addr(struct device *d,
  240. struct device_attribute *attr, char *buf)
  241. {
  242. struct net_bridge *br = to_bridge(d);
  243. return sprintf(buf, "%x:%x:%x:%x:%x:%x\n",
  244. br->group_addr[0], br->group_addr[1],
  245. br->group_addr[2], br->group_addr[3],
  246. br->group_addr[4], br->group_addr[5]);
  247. }
  248. static ssize_t store_group_addr(struct device *d,
  249. struct device_attribute *attr,
  250. const char *buf, size_t len)
  251. {
  252. struct net_bridge *br = to_bridge(d);
  253. unsigned int new_addr[6];
  254. int i;
  255. if (!capable(CAP_NET_ADMIN))
  256. return -EPERM;
  257. if (sscanf(buf, "%x:%x:%x:%x:%x:%x",
  258. &new_addr[0], &new_addr[1], &new_addr[2],
  259. &new_addr[3], &new_addr[4], &new_addr[5]) != 6)
  260. return -EINVAL;
  261. /* Must be 01:80:c2:00:00:0X */
  262. for (i = 0; i < 5; i++)
  263. if (new_addr[i] != br_group_address[i])
  264. return -EINVAL;
  265. if (new_addr[5] & ~0xf)
  266. return -EINVAL;
  267. if (new_addr[5] == 1 || /* 802.3x Pause address */
  268. new_addr[5] == 2 || /* 802.3ad Slow protocols */
  269. new_addr[5] == 3) /* 802.1X PAE address */
  270. return -EINVAL;
  271. spin_lock_bh(&br->lock);
  272. for (i = 0; i < 6; i++)
  273. br->group_addr[i] = new_addr[i];
  274. spin_unlock_bh(&br->lock);
  275. return len;
  276. }
  277. static DEVICE_ATTR(group_addr, S_IRUGO | S_IWUSR,
  278. show_group_addr, store_group_addr);
  279. static ssize_t store_flush(struct device *d,
  280. struct device_attribute *attr,
  281. const char *buf, size_t len)
  282. {
  283. struct net_bridge *br = to_bridge(d);
  284. if (!capable(CAP_NET_ADMIN))
  285. return -EPERM;
  286. br_fdb_flush(br);
  287. return len;
  288. }
  289. static DEVICE_ATTR(flush, S_IWUSR, NULL, store_flush);
  290. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  291. static ssize_t show_multicast_router(struct device *d,
  292. struct device_attribute *attr, char *buf)
  293. {
  294. struct net_bridge *br = to_bridge(d);
  295. return sprintf(buf, "%d\n", br->multicast_router);
  296. }
  297. static ssize_t store_multicast_router(struct device *d,
  298. struct device_attribute *attr,
  299. const char *buf, size_t len)
  300. {
  301. return store_bridge_parm(d, buf, len, br_multicast_set_router);
  302. }
  303. static DEVICE_ATTR(multicast_router, S_IRUGO | S_IWUSR, show_multicast_router,
  304. store_multicast_router);
  305. static ssize_t show_multicast_snooping(struct device *d,
  306. struct device_attribute *attr,
  307. char *buf)
  308. {
  309. struct net_bridge *br = to_bridge(d);
  310. return sprintf(buf, "%d\n", !br->multicast_disabled);
  311. }
  312. static ssize_t store_multicast_snooping(struct device *d,
  313. struct device_attribute *attr,
  314. const char *buf, size_t len)
  315. {
  316. return store_bridge_parm(d, buf, len, br_multicast_toggle);
  317. }
  318. static DEVICE_ATTR(multicast_snooping, S_IRUGO | S_IWUSR,
  319. show_multicast_snooping, store_multicast_snooping);
  320. static ssize_t show_hash_elasticity(struct device *d,
  321. struct device_attribute *attr, char *buf)
  322. {
  323. struct net_bridge *br = to_bridge(d);
  324. return sprintf(buf, "%u\n", br->hash_elasticity);
  325. }
  326. static int set_elasticity(struct net_bridge *br, unsigned long val)
  327. {
  328. br->hash_elasticity = val;
  329. return 0;
  330. }
  331. static ssize_t store_hash_elasticity(struct device *d,
  332. struct device_attribute *attr,
  333. const char *buf, size_t len)
  334. {
  335. return store_bridge_parm(d, buf, len, set_elasticity);
  336. }
  337. static DEVICE_ATTR(hash_elasticity, S_IRUGO | S_IWUSR, show_hash_elasticity,
  338. store_hash_elasticity);
  339. static ssize_t show_hash_max(struct device *d, struct device_attribute *attr,
  340. char *buf)
  341. {
  342. struct net_bridge *br = to_bridge(d);
  343. return sprintf(buf, "%u\n", br->hash_max);
  344. }
  345. static ssize_t store_hash_max(struct device *d, struct device_attribute *attr,
  346. const char *buf, size_t len)
  347. {
  348. return store_bridge_parm(d, buf, len, br_multicast_set_hash_max);
  349. }
  350. static DEVICE_ATTR(hash_max, S_IRUGO | S_IWUSR, show_hash_max,
  351. store_hash_max);
  352. static ssize_t show_multicast_last_member_count(struct device *d,
  353. struct device_attribute *attr,
  354. char *buf)
  355. {
  356. struct net_bridge *br = to_bridge(d);
  357. return sprintf(buf, "%u\n", br->multicast_last_member_count);
  358. }
  359. static int set_last_member_count(struct net_bridge *br, unsigned long val)
  360. {
  361. br->multicast_last_member_count = val;
  362. return 0;
  363. }
  364. static ssize_t store_multicast_last_member_count(struct device *d,
  365. struct device_attribute *attr,
  366. const char *buf, size_t len)
  367. {
  368. return store_bridge_parm(d, buf, len, set_last_member_count);
  369. }
  370. static DEVICE_ATTR(multicast_last_member_count, S_IRUGO | S_IWUSR,
  371. show_multicast_last_member_count,
  372. store_multicast_last_member_count);
  373. static ssize_t show_multicast_startup_query_count(
  374. struct device *d, struct device_attribute *attr, char *buf)
  375. {
  376. struct net_bridge *br = to_bridge(d);
  377. return sprintf(buf, "%u\n", br->multicast_startup_query_count);
  378. }
  379. static int set_startup_query_count(struct net_bridge *br, unsigned long val)
  380. {
  381. br->multicast_startup_query_count = val;
  382. return 0;
  383. }
  384. static ssize_t store_multicast_startup_query_count(
  385. struct device *d, struct device_attribute *attr, const char *buf,
  386. size_t len)
  387. {
  388. return store_bridge_parm(d, buf, len, set_startup_query_count);
  389. }
  390. static DEVICE_ATTR(multicast_startup_query_count, S_IRUGO | S_IWUSR,
  391. show_multicast_startup_query_count,
  392. store_multicast_startup_query_count);
  393. static ssize_t show_multicast_last_member_interval(
  394. struct device *d, struct device_attribute *attr, char *buf)
  395. {
  396. struct net_bridge *br = to_bridge(d);
  397. return sprintf(buf, "%lu\n",
  398. jiffies_to_clock_t(br->multicast_last_member_interval));
  399. }
  400. static int set_last_member_interval(struct net_bridge *br, unsigned long val)
  401. {
  402. br->multicast_last_member_interval = clock_t_to_jiffies(val);
  403. return 0;
  404. }
  405. static ssize_t store_multicast_last_member_interval(
  406. struct device *d, struct device_attribute *attr, const char *buf,
  407. size_t len)
  408. {
  409. return store_bridge_parm(d, buf, len, set_last_member_interval);
  410. }
  411. static DEVICE_ATTR(multicast_last_member_interval, S_IRUGO | S_IWUSR,
  412. show_multicast_last_member_interval,
  413. store_multicast_last_member_interval);
  414. static ssize_t show_multicast_membership_interval(
  415. struct device *d, struct device_attribute *attr, char *buf)
  416. {
  417. struct net_bridge *br = to_bridge(d);
  418. return sprintf(buf, "%lu\n",
  419. jiffies_to_clock_t(br->multicast_membership_interval));
  420. }
  421. static int set_membership_interval(struct net_bridge *br, unsigned long val)
  422. {
  423. br->multicast_membership_interval = clock_t_to_jiffies(val);
  424. return 0;
  425. }
  426. static ssize_t store_multicast_membership_interval(
  427. struct device *d, struct device_attribute *attr, const char *buf,
  428. size_t len)
  429. {
  430. return store_bridge_parm(d, buf, len, set_membership_interval);
  431. }
  432. static DEVICE_ATTR(multicast_membership_interval, S_IRUGO | S_IWUSR,
  433. show_multicast_membership_interval,
  434. store_multicast_membership_interval);
  435. static ssize_t show_multicast_querier_interval(struct device *d,
  436. struct device_attribute *attr,
  437. char *buf)
  438. {
  439. struct net_bridge *br = to_bridge(d);
  440. return sprintf(buf, "%lu\n",
  441. jiffies_to_clock_t(br->multicast_querier_interval));
  442. }
  443. static int set_querier_interval(struct net_bridge *br, unsigned long val)
  444. {
  445. br->multicast_querier_interval = clock_t_to_jiffies(val);
  446. return 0;
  447. }
  448. static ssize_t store_multicast_querier_interval(struct device *d,
  449. struct device_attribute *attr,
  450. const char *buf, size_t len)
  451. {
  452. return store_bridge_parm(d, buf, len, set_querier_interval);
  453. }
  454. static DEVICE_ATTR(multicast_querier_interval, S_IRUGO | S_IWUSR,
  455. show_multicast_querier_interval,
  456. store_multicast_querier_interval);
  457. static ssize_t show_multicast_query_interval(struct device *d,
  458. struct device_attribute *attr,
  459. char *buf)
  460. {
  461. struct net_bridge *br = to_bridge(d);
  462. return sprintf(buf, "%lu\n",
  463. jiffies_to_clock_t(br->multicast_query_interval));
  464. }
  465. static int set_query_interval(struct net_bridge *br, unsigned long val)
  466. {
  467. br->multicast_query_interval = clock_t_to_jiffies(val);
  468. return 0;
  469. }
  470. static ssize_t store_multicast_query_interval(struct device *d,
  471. struct device_attribute *attr,
  472. const char *buf, size_t len)
  473. {
  474. return store_bridge_parm(d, buf, len, set_query_interval);
  475. }
  476. static DEVICE_ATTR(multicast_query_interval, S_IRUGO | S_IWUSR,
  477. show_multicast_query_interval,
  478. store_multicast_query_interval);
  479. static ssize_t show_multicast_query_response_interval(
  480. struct device *d, struct device_attribute *attr, char *buf)
  481. {
  482. struct net_bridge *br = to_bridge(d);
  483. return sprintf(
  484. buf, "%lu\n",
  485. jiffies_to_clock_t(br->multicast_query_response_interval));
  486. }
  487. static int set_query_response_interval(struct net_bridge *br, unsigned long val)
  488. {
  489. br->multicast_query_response_interval = clock_t_to_jiffies(val);
  490. return 0;
  491. }
  492. static ssize_t store_multicast_query_response_interval(
  493. struct device *d, struct device_attribute *attr, const char *buf,
  494. size_t len)
  495. {
  496. return store_bridge_parm(d, buf, len, set_query_response_interval);
  497. }
  498. static DEVICE_ATTR(multicast_query_response_interval, S_IRUGO | S_IWUSR,
  499. show_multicast_query_response_interval,
  500. store_multicast_query_response_interval);
  501. static ssize_t show_multicast_startup_query_interval(
  502. struct device *d, struct device_attribute *attr, char *buf)
  503. {
  504. struct net_bridge *br = to_bridge(d);
  505. return sprintf(
  506. buf, "%lu\n",
  507. jiffies_to_clock_t(br->multicast_startup_query_interval));
  508. }
  509. static int set_startup_query_interval(struct net_bridge *br, unsigned long val)
  510. {
  511. br->multicast_startup_query_interval = clock_t_to_jiffies(val);
  512. return 0;
  513. }
  514. static ssize_t store_multicast_startup_query_interval(
  515. struct device *d, struct device_attribute *attr, const char *buf,
  516. size_t len)
  517. {
  518. return store_bridge_parm(d, buf, len, set_startup_query_interval);
  519. }
  520. static DEVICE_ATTR(multicast_startup_query_interval, S_IRUGO | S_IWUSR,
  521. show_multicast_startup_query_interval,
  522. store_multicast_startup_query_interval);
  523. #endif
  524. #ifdef CONFIG_BRIDGE_NETFILTER
  525. static ssize_t show_nf_call_iptables(
  526. struct device *d, struct device_attribute *attr, char *buf)
  527. {
  528. struct net_bridge *br = to_bridge(d);
  529. return sprintf(buf, "%u\n", br->nf_call_iptables);
  530. }
  531. static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
  532. {
  533. br->nf_call_iptables = val ? true : false;
  534. return 0;
  535. }
  536. static ssize_t store_nf_call_iptables(
  537. struct device *d, struct device_attribute *attr, const char *buf,
  538. size_t len)
  539. {
  540. return store_bridge_parm(d, buf, len, set_nf_call_iptables);
  541. }
  542. static DEVICE_ATTR(nf_call_iptables, S_IRUGO | S_IWUSR,
  543. show_nf_call_iptables, store_nf_call_iptables);
  544. static ssize_t show_nf_call_ip6tables(
  545. struct device *d, struct device_attribute *attr, char *buf)
  546. {
  547. struct net_bridge *br = to_bridge(d);
  548. return sprintf(buf, "%u\n", br->nf_call_ip6tables);
  549. }
  550. static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
  551. {
  552. br->nf_call_ip6tables = val ? true : false;
  553. return 0;
  554. }
  555. static ssize_t store_nf_call_ip6tables(
  556. struct device *d, struct device_attribute *attr, const char *buf,
  557. size_t len)
  558. {
  559. return store_bridge_parm(d, buf, len, set_nf_call_ip6tables);
  560. }
  561. static DEVICE_ATTR(nf_call_ip6tables, S_IRUGO | S_IWUSR,
  562. show_nf_call_ip6tables, store_nf_call_ip6tables);
  563. static ssize_t show_nf_call_arptables(
  564. struct device *d, struct device_attribute *attr, char *buf)
  565. {
  566. struct net_bridge *br = to_bridge(d);
  567. return sprintf(buf, "%u\n", br->nf_call_arptables);
  568. }
  569. static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
  570. {
  571. br->nf_call_arptables = val ? true : false;
  572. return 0;
  573. }
  574. static ssize_t store_nf_call_arptables(
  575. struct device *d, struct device_attribute *attr, const char *buf,
  576. size_t len)
  577. {
  578. return store_bridge_parm(d, buf, len, set_nf_call_arptables);
  579. }
  580. static DEVICE_ATTR(nf_call_arptables, S_IRUGO | S_IWUSR,
  581. show_nf_call_arptables, store_nf_call_arptables);
  582. #endif
  583. static struct attribute *bridge_attrs[] = {
  584. &dev_attr_forward_delay.attr,
  585. &dev_attr_hello_time.attr,
  586. &dev_attr_max_age.attr,
  587. &dev_attr_ageing_time.attr,
  588. &dev_attr_stp_state.attr,
  589. &dev_attr_group_fwd_mask.attr,
  590. &dev_attr_priority.attr,
  591. &dev_attr_bridge_id.attr,
  592. &dev_attr_root_id.attr,
  593. &dev_attr_root_path_cost.attr,
  594. &dev_attr_root_port.attr,
  595. &dev_attr_topology_change.attr,
  596. &dev_attr_topology_change_detected.attr,
  597. &dev_attr_hello_timer.attr,
  598. &dev_attr_tcn_timer.attr,
  599. &dev_attr_topology_change_timer.attr,
  600. &dev_attr_gc_timer.attr,
  601. &dev_attr_group_addr.attr,
  602. &dev_attr_flush.attr,
  603. #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
  604. &dev_attr_multicast_router.attr,
  605. &dev_attr_multicast_snooping.attr,
  606. &dev_attr_hash_elasticity.attr,
  607. &dev_attr_hash_max.attr,
  608. &dev_attr_multicast_last_member_count.attr,
  609. &dev_attr_multicast_startup_query_count.attr,
  610. &dev_attr_multicast_last_member_interval.attr,
  611. &dev_attr_multicast_membership_interval.attr,
  612. &dev_attr_multicast_querier_interval.attr,
  613. &dev_attr_multicast_query_interval.attr,
  614. &dev_attr_multicast_query_response_interval.attr,
  615. &dev_attr_multicast_startup_query_interval.attr,
  616. #endif
  617. #ifdef CONFIG_BRIDGE_NETFILTER
  618. &dev_attr_nf_call_iptables.attr,
  619. &dev_attr_nf_call_ip6tables.attr,
  620. &dev_attr_nf_call_arptables.attr,
  621. #endif
  622. NULL
  623. };
  624. static struct attribute_group bridge_group = {
  625. .name = SYSFS_BRIDGE_ATTR,
  626. .attrs = bridge_attrs,
  627. };
  628. /*
  629. * Export the forwarding information table as a binary file
  630. * The records are struct __fdb_entry.
  631. *
  632. * Returns the number of bytes read.
  633. */
  634. static ssize_t brforward_read(struct file *filp, struct kobject *kobj,
  635. struct bin_attribute *bin_attr,
  636. char *buf, loff_t off, size_t count)
  637. {
  638. struct device *dev = to_dev(kobj);
  639. struct net_bridge *br = to_bridge(dev);
  640. int n;
  641. /* must read whole records */
  642. if (off % sizeof(struct __fdb_entry) != 0)
  643. return -EINVAL;
  644. n = br_fdb_fillbuf(br, buf,
  645. count / sizeof(struct __fdb_entry),
  646. off / sizeof(struct __fdb_entry));
  647. if (n > 0)
  648. n *= sizeof(struct __fdb_entry);
  649. return n;
  650. }
  651. static struct bin_attribute bridge_forward = {
  652. .attr = { .name = SYSFS_BRIDGE_FDB,
  653. .mode = S_IRUGO, },
  654. .read = brforward_read,
  655. };
  656. /*
  657. * Add entries in sysfs onto the existing network class device
  658. * for the bridge.
  659. * Adds a attribute group "bridge" containing tuning parameters.
  660. * Binary attribute containing the forward table
  661. * Sub directory to hold links to interfaces.
  662. *
  663. * Note: the ifobj exists only to be a subdirectory
  664. * to hold links. The ifobj exists in same data structure
  665. * as it's parent the bridge so reference counting works.
  666. */
  667. int br_sysfs_addbr(struct net_device *dev)
  668. {
  669. struct kobject *brobj = &dev->dev.kobj;
  670. struct net_bridge *br = netdev_priv(dev);
  671. int err;
  672. err = sysfs_create_group(brobj, &bridge_group);
  673. if (err) {
  674. pr_info("%s: can't create group %s/%s\n",
  675. __func__, dev->name, bridge_group.name);
  676. goto out1;
  677. }
  678. err = sysfs_create_bin_file(brobj, &bridge_forward);
  679. if (err) {
  680. pr_info("%s: can't create attribute file %s/%s\n",
  681. __func__, dev->name, bridge_forward.attr.name);
  682. goto out2;
  683. }
  684. br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, brobj);
  685. if (!br->ifobj) {
  686. pr_info("%s: can't add kobject (directory) %s/%s\n",
  687. __func__, dev->name, SYSFS_BRIDGE_PORT_SUBDIR);
  688. goto out3;
  689. }
  690. return 0;
  691. out3:
  692. sysfs_remove_bin_file(&dev->dev.kobj, &bridge_forward);
  693. out2:
  694. sysfs_remove_group(&dev->dev.kobj, &bridge_group);
  695. out1:
  696. return err;
  697. }
  698. void br_sysfs_delbr(struct net_device *dev)
  699. {
  700. struct kobject *kobj = &dev->dev.kobj;
  701. struct net_bridge *br = netdev_priv(dev);
  702. kobject_put(br->ifobj);
  703. sysfs_remove_bin_file(kobj, &bridge_forward);
  704. sysfs_remove_group(kobj, &bridge_group);
  705. }