bond_sysfs.c 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. /*
  2. * Copyright(c) 2004-2005 Intel Corporation. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. */
  22. #include <linux/config.h>
  23. #include <linux/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/sched.h>
  26. #include <linux/device.h>
  27. #include <linux/sysdev.h>
  28. #include <linux/fs.h>
  29. #include <linux/types.h>
  30. #include <linux/string.h>
  31. #include <linux/netdevice.h>
  32. #include <linux/inetdevice.h>
  33. #include <linux/in.h>
  34. #include <linux/sysfs.h>
  35. #include <linux/string.h>
  36. #include <linux/ctype.h>
  37. #include <linux/inet.h>
  38. #include <linux/rtnetlink.h>
  39. /* #define BONDING_DEBUG 1 */
  40. #include "bonding.h"
  41. #define to_class_dev(obj) container_of(obj,struct class_device,kobj)
  42. #define to_net_dev(class) container_of(class, struct net_device, class_dev)
  43. #define to_bond(cd) ((struct bonding *)(to_net_dev(cd)->priv))
  44. /*---------------------------- Declarations -------------------------------*/
  45. extern struct list_head bond_dev_list;
  46. extern struct bond_params bonding_defaults;
  47. extern struct bond_parm_tbl bond_mode_tbl[];
  48. extern struct bond_parm_tbl bond_lacp_tbl[];
  49. extern struct bond_parm_tbl xmit_hashtype_tbl[];
  50. static int expected_refcount = -1;
  51. static struct class *netdev_class;
  52. /*--------------------------- Data Structures -----------------------------*/
  53. /* Bonding sysfs lock. Why can't we just use the subsytem lock?
  54. * Because kobject_register tries to acquire the subsystem lock. If
  55. * we already hold the lock (which we would if the user was creating
  56. * a new bond through the sysfs interface), we deadlock.
  57. * This lock is only needed when deleting a bond - we need to make sure
  58. * that we don't collide with an ongoing ioctl.
  59. */
  60. struct rw_semaphore bonding_rwsem;
  61. /*------------------------------ Functions --------------------------------*/
  62. /*
  63. * "show" function for the bond_masters attribute.
  64. * The class parameter is ignored.
  65. */
  66. static ssize_t bonding_show_bonds(struct class *cls, char *buffer)
  67. {
  68. int res = 0;
  69. struct bonding *bond;
  70. down_read(&(bonding_rwsem));
  71. list_for_each_entry(bond, &bond_dev_list, bond_list) {
  72. if (res > (PAGE_SIZE - IFNAMSIZ)) {
  73. /* not enough space for another interface name */
  74. if ((PAGE_SIZE - res) > 10)
  75. res = PAGE_SIZE - 10;
  76. res += sprintf(buffer + res, "++more++");
  77. break;
  78. }
  79. res += sprintf(buffer + res, "%s ",
  80. bond->dev->name);
  81. }
  82. res += sprintf(buffer + res, "\n");
  83. res++;
  84. up_read(&(bonding_rwsem));
  85. return res;
  86. }
  87. /*
  88. * "store" function for the bond_masters attribute. This is what
  89. * creates and deletes entire bonds.
  90. *
  91. * The class parameter is ignored.
  92. *
  93. */
  94. static ssize_t bonding_store_bonds(struct class *cls, const char *buffer, size_t count)
  95. {
  96. char command[IFNAMSIZ + 1] = {0, };
  97. char *ifname;
  98. int res = count;
  99. struct bonding *bond;
  100. struct bonding *nxt;
  101. down_write(&(bonding_rwsem));
  102. sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
  103. ifname = command + 1;
  104. if ((strlen(command) <= 1) ||
  105. !dev_valid_name(ifname))
  106. goto err_no_cmd;
  107. if (command[0] == '+') {
  108. /* Check to see if the bond already exists. */
  109. list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
  110. if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
  111. printk(KERN_ERR DRV_NAME
  112. ": cannot add bond %s; it already exists\n",
  113. ifname);
  114. res = -EPERM;
  115. goto out;
  116. }
  117. printk(KERN_INFO DRV_NAME
  118. ": %s is being created...\n", ifname);
  119. if (bond_create(ifname, &bonding_defaults, &bond)) {
  120. printk(KERN_INFO DRV_NAME
  121. ": %s interface already exists. Bond creation failed.\n",
  122. ifname);
  123. res = -EPERM;
  124. }
  125. goto out;
  126. }
  127. if (command[0] == '-') {
  128. list_for_each_entry_safe(bond, nxt, &bond_dev_list, bond_list)
  129. if (strnicmp(bond->dev->name, ifname, IFNAMSIZ) == 0) {
  130. rtnl_lock();
  131. /* check the ref count on the bond's kobject.
  132. * If it's > expected, then there's a file open,
  133. * and we have to fail.
  134. */
  135. if (atomic_read(&bond->dev->class_dev.kobj.kref.refcount)
  136. > expected_refcount){
  137. rtnl_unlock();
  138. printk(KERN_INFO DRV_NAME
  139. ": Unable remove bond %s due to open references.\n",
  140. ifname);
  141. res = -EPERM;
  142. goto out;
  143. }
  144. printk(KERN_INFO DRV_NAME
  145. ": %s is being deleted...\n",
  146. bond->dev->name);
  147. unregister_netdevice(bond->dev);
  148. bond_deinit(bond->dev);
  149. bond_destroy_sysfs_entry(bond);
  150. rtnl_unlock();
  151. goto out;
  152. }
  153. printk(KERN_ERR DRV_NAME
  154. ": unable to delete non-existent bond %s\n", ifname);
  155. res = -ENODEV;
  156. goto out;
  157. }
  158. err_no_cmd:
  159. printk(KERN_ERR DRV_NAME
  160. ": no command found in bonding_masters. Use +ifname or -ifname.\n");
  161. res = -EPERM;
  162. /* Always return either count or an error. If you return 0, you'll
  163. * get called forever, which is bad.
  164. */
  165. out:
  166. up_write(&(bonding_rwsem));
  167. return res;
  168. }
  169. /* class attribute for bond_masters file. This ends up in /sys/class/net */
  170. static CLASS_ATTR(bonding_masters, S_IWUSR | S_IRUGO,
  171. bonding_show_bonds, bonding_store_bonds);
  172. int bond_create_slave_symlinks(struct net_device *master, struct net_device *slave)
  173. {
  174. char linkname[IFNAMSIZ+7];
  175. int ret = 0;
  176. /* first, create a link from the slave back to the master */
  177. ret = sysfs_create_link(&(slave->class_dev.kobj), &(master->class_dev.kobj),
  178. "master");
  179. if (ret)
  180. return ret;
  181. /* next, create a link from the master to the slave */
  182. sprintf(linkname,"slave_%s",slave->name);
  183. ret = sysfs_create_link(&(master->class_dev.kobj), &(slave->class_dev.kobj),
  184. linkname);
  185. return ret;
  186. }
  187. void bond_destroy_slave_symlinks(struct net_device *master, struct net_device *slave)
  188. {
  189. char linkname[IFNAMSIZ+7];
  190. sysfs_remove_link(&(slave->class_dev.kobj), "master");
  191. sprintf(linkname,"slave_%s",slave->name);
  192. sysfs_remove_link(&(master->class_dev.kobj), linkname);
  193. }
  194. /*
  195. * Show the slaves in the current bond.
  196. */
  197. static ssize_t bonding_show_slaves(struct class_device *cd, char *buf)
  198. {
  199. struct slave *slave;
  200. int i, res = 0;
  201. struct bonding *bond = to_bond(cd);
  202. read_lock_bh(&bond->lock);
  203. bond_for_each_slave(bond, slave, i) {
  204. if (res > (PAGE_SIZE - IFNAMSIZ)) {
  205. /* not enough space for another interface name */
  206. if ((PAGE_SIZE - res) > 10)
  207. res = PAGE_SIZE - 10;
  208. res += sprintf(buf + res, "++more++");
  209. break;
  210. }
  211. res += sprintf(buf + res, "%s ", slave->dev->name);
  212. }
  213. read_unlock_bh(&bond->lock);
  214. res += sprintf(buf + res, "\n");
  215. res++;
  216. return res;
  217. }
  218. /*
  219. * Set the slaves in the current bond. The bond interface must be
  220. * up for this to succeed.
  221. * This function is largely the same flow as bonding_update_bonds().
  222. */
  223. static ssize_t bonding_store_slaves(struct class_device *cd, const char *buffer, size_t count)
  224. {
  225. char command[IFNAMSIZ + 1] = { 0, };
  226. char *ifname;
  227. int i, res, found, ret = count;
  228. struct slave *slave;
  229. struct net_device *dev = 0;
  230. struct bonding *bond = to_bond(cd);
  231. /* Quick sanity check -- is the bond interface up? */
  232. if (!(bond->dev->flags & IFF_UP)) {
  233. printk(KERN_ERR DRV_NAME
  234. ": %s: Unable to update slaves because interface is down.\n",
  235. bond->dev->name);
  236. ret = -EPERM;
  237. goto out;
  238. }
  239. /* Note: We can't hold bond->lock here, as bond_create grabs it. */
  240. sscanf(buffer, "%16s", command); /* IFNAMSIZ*/
  241. ifname = command + 1;
  242. if ((strlen(command) <= 1) ||
  243. !dev_valid_name(ifname))
  244. goto err_no_cmd;
  245. if (command[0] == '+') {
  246. /* Got a slave name in ifname. Is it already in the list? */
  247. found = 0;
  248. read_lock_bh(&bond->lock);
  249. bond_for_each_slave(bond, slave, i)
  250. if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
  251. printk(KERN_ERR DRV_NAME
  252. ": %s: Interface %s is already enslaved!\n",
  253. bond->dev->name, ifname);
  254. ret = -EPERM;
  255. read_unlock_bh(&bond->lock);
  256. goto out;
  257. }
  258. read_unlock_bh(&bond->lock);
  259. printk(KERN_INFO DRV_NAME ": %s: Adding slave %s.\n",
  260. bond->dev->name, ifname);
  261. dev = dev_get_by_name(ifname);
  262. if (!dev) {
  263. printk(KERN_INFO DRV_NAME
  264. ": %s: Interface %s does not exist!\n",
  265. bond->dev->name, ifname);
  266. ret = -EPERM;
  267. goto out;
  268. }
  269. else
  270. dev_put(dev);
  271. if (dev->flags & IFF_UP) {
  272. printk(KERN_ERR DRV_NAME
  273. ": %s: Error: Unable to enslave %s "
  274. "because it is already up.\n",
  275. bond->dev->name, dev->name);
  276. ret = -EPERM;
  277. goto out;
  278. }
  279. /* If this is the first slave, then we need to set
  280. the master's hardware address to be the same as the
  281. slave's. */
  282. if (!(*((u32 *) & (bond->dev->dev_addr[0])))) {
  283. memcpy(bond->dev->dev_addr, dev->dev_addr,
  284. dev->addr_len);
  285. }
  286. /* Set the slave's MTU to match the bond */
  287. if (dev->mtu != bond->dev->mtu) {
  288. if (dev->change_mtu) {
  289. res = dev->change_mtu(dev,
  290. bond->dev->mtu);
  291. if (res) {
  292. ret = res;
  293. goto out;
  294. }
  295. } else {
  296. dev->mtu = bond->dev->mtu;
  297. }
  298. }
  299. rtnl_lock();
  300. res = bond_enslave(bond->dev, dev);
  301. rtnl_unlock();
  302. if (res) {
  303. ret = res;
  304. }
  305. goto out;
  306. }
  307. if (command[0] == '-') {
  308. dev = NULL;
  309. bond_for_each_slave(bond, slave, i)
  310. if (strnicmp(slave->dev->name, ifname, IFNAMSIZ) == 0) {
  311. dev = slave->dev;
  312. break;
  313. }
  314. if (dev) {
  315. printk(KERN_INFO DRV_NAME ": %s: Removing slave %s\n",
  316. bond->dev->name, dev->name);
  317. rtnl_lock();
  318. res = bond_release(bond->dev, dev);
  319. rtnl_unlock();
  320. if (res) {
  321. ret = res;
  322. goto out;
  323. }
  324. /* set the slave MTU to the default */
  325. if (dev->change_mtu) {
  326. dev->change_mtu(dev, 1500);
  327. } else {
  328. dev->mtu = 1500;
  329. }
  330. }
  331. else {
  332. printk(KERN_ERR DRV_NAME ": unable to remove non-existent slave %s for bond %s.\n",
  333. ifname, bond->dev->name);
  334. ret = -ENODEV;
  335. }
  336. goto out;
  337. }
  338. err_no_cmd:
  339. printk(KERN_ERR DRV_NAME ": no command found in slaves file for bond %s. Use +ifname or -ifname.\n", bond->dev->name);
  340. ret = -EPERM;
  341. out:
  342. return ret;
  343. }
  344. static CLASS_DEVICE_ATTR(slaves, S_IRUGO | S_IWUSR, bonding_show_slaves, bonding_store_slaves);
  345. /*
  346. * Show and set the bonding mode. The bond interface must be down to
  347. * change the mode.
  348. */
  349. static ssize_t bonding_show_mode(struct class_device *cd, char *buf)
  350. {
  351. struct bonding *bond = to_bond(cd);
  352. return sprintf(buf, "%s %d\n",
  353. bond_mode_tbl[bond->params.mode].modename,
  354. bond->params.mode) + 1;
  355. }
  356. static ssize_t bonding_store_mode(struct class_device *cd, const char *buf, size_t count)
  357. {
  358. int new_value, ret = count;
  359. struct bonding *bond = to_bond(cd);
  360. if (bond->dev->flags & IFF_UP) {
  361. printk(KERN_ERR DRV_NAME
  362. ": unable to update mode of %s because interface is up.\n",
  363. bond->dev->name);
  364. ret = -EPERM;
  365. goto out;
  366. }
  367. new_value = bond_parse_parm((char *)buf, bond_mode_tbl);
  368. if (new_value < 0) {
  369. printk(KERN_ERR DRV_NAME
  370. ": %s: Ignoring invalid mode value %.*s.\n",
  371. bond->dev->name,
  372. (int)strlen(buf) - 1, buf);
  373. ret = -EINVAL;
  374. goto out;
  375. } else {
  376. bond->params.mode = new_value;
  377. bond_set_mode_ops(bond, bond->params.mode);
  378. printk(KERN_INFO DRV_NAME ": %s: setting mode to %s (%d).\n",
  379. bond->dev->name, bond_mode_tbl[new_value].modename, new_value);
  380. }
  381. out:
  382. return ret;
  383. }
  384. static CLASS_DEVICE_ATTR(mode, S_IRUGO | S_IWUSR, bonding_show_mode, bonding_store_mode);
  385. /*
  386. * Show and set the bonding transmit hash method. The bond interface must be down to
  387. * change the xmit hash policy.
  388. */
  389. static ssize_t bonding_show_xmit_hash(struct class_device *cd, char *buf)
  390. {
  391. int count;
  392. struct bonding *bond = to_bond(cd);
  393. if ((bond->params.mode != BOND_MODE_XOR) &&
  394. (bond->params.mode != BOND_MODE_8023AD)) {
  395. // Not Applicable
  396. count = sprintf(buf, "NA\n") + 1;
  397. } else {
  398. count = sprintf(buf, "%s %d\n",
  399. xmit_hashtype_tbl[bond->params.xmit_policy].modename,
  400. bond->params.xmit_policy) + 1;
  401. }
  402. return count;
  403. }
  404. static ssize_t bonding_store_xmit_hash(struct class_device *cd, const char *buf, size_t count)
  405. {
  406. int new_value, ret = count;
  407. struct bonding *bond = to_bond(cd);
  408. if (bond->dev->flags & IFF_UP) {
  409. printk(KERN_ERR DRV_NAME
  410. "%s: Interface is up. Unable to update xmit policy.\n",
  411. bond->dev->name);
  412. ret = -EPERM;
  413. goto out;
  414. }
  415. if ((bond->params.mode != BOND_MODE_XOR) &&
  416. (bond->params.mode != BOND_MODE_8023AD)) {
  417. printk(KERN_ERR DRV_NAME
  418. "%s: Transmit hash policy is irrelevant in this mode.\n",
  419. bond->dev->name);
  420. ret = -EPERM;
  421. goto out;
  422. }
  423. new_value = bond_parse_parm((char *)buf, xmit_hashtype_tbl);
  424. if (new_value < 0) {
  425. printk(KERN_ERR DRV_NAME
  426. ": %s: Ignoring invalid xmit hash policy value %.*s.\n",
  427. bond->dev->name,
  428. (int)strlen(buf) - 1, buf);
  429. ret = -EINVAL;
  430. goto out;
  431. } else {
  432. bond->params.xmit_policy = new_value;
  433. bond_set_mode_ops(bond, bond->params.mode);
  434. printk(KERN_INFO DRV_NAME ": %s: setting xmit hash policy to %s (%d).\n",
  435. bond->dev->name, xmit_hashtype_tbl[new_value].modename, new_value);
  436. }
  437. out:
  438. return ret;
  439. }
  440. static CLASS_DEVICE_ATTR(xmit_hash_policy, S_IRUGO | S_IWUSR, bonding_show_xmit_hash, bonding_store_xmit_hash);
  441. /*
  442. * Show and set the arp timer interval. There are two tricky bits
  443. * here. First, if ARP monitoring is activated, then we must disable
  444. * MII monitoring. Second, if the ARP timer isn't running, we must
  445. * start it.
  446. */
  447. static ssize_t bonding_show_arp_interval(struct class_device *cd, char *buf)
  448. {
  449. struct bonding *bond = to_bond(cd);
  450. return sprintf(buf, "%d\n", bond->params.arp_interval) + 1;
  451. }
  452. static ssize_t bonding_store_arp_interval(struct class_device *cd, const char *buf, size_t count)
  453. {
  454. int new_value, ret = count;
  455. struct bonding *bond = to_bond(cd);
  456. if (sscanf(buf, "%d", &new_value) != 1) {
  457. printk(KERN_ERR DRV_NAME
  458. ": %s: no arp_interval value specified.\n",
  459. bond->dev->name);
  460. ret = -EINVAL;
  461. goto out;
  462. }
  463. if (new_value < 0) {
  464. printk(KERN_ERR DRV_NAME
  465. ": %s: Invalid arp_interval value %d not in range 1-%d; rejected.\n",
  466. bond->dev->name, new_value, INT_MAX);
  467. ret = -EINVAL;
  468. goto out;
  469. }
  470. printk(KERN_INFO DRV_NAME
  471. ": %s: Setting ARP monitoring interval to %d.\n",
  472. bond->dev->name, new_value);
  473. bond->params.arp_interval = new_value;
  474. if (bond->params.miimon) {
  475. printk(KERN_INFO DRV_NAME
  476. ": %s: ARP monitoring cannot be used with MII monitoring. "
  477. "%s Disabling MII monitoring.\n",
  478. bond->dev->name, bond->dev->name);
  479. bond->params.miimon = 0;
  480. /* Kill MII timer, else it brings bond's link down */
  481. if (bond->arp_timer.function) {
  482. printk(KERN_INFO DRV_NAME
  483. ": %s: Kill MII timer, else it brings bond's link down...\n",
  484. bond->dev->name);
  485. del_timer_sync(&bond->mii_timer);
  486. }
  487. }
  488. if (!bond->params.arp_targets[0]) {
  489. printk(KERN_INFO DRV_NAME
  490. ": %s: ARP monitoring has been set up, "
  491. "but no ARP targets have been specified.\n",
  492. bond->dev->name);
  493. }
  494. if (bond->dev->flags & IFF_UP) {
  495. /* If the interface is up, we may need to fire off
  496. * the ARP timer. If the interface is down, the
  497. * timer will get fired off when the open function
  498. * is called.
  499. */
  500. if (bond->arp_timer.function) {
  501. /* The timer's already set up, so fire it off */
  502. mod_timer(&bond->arp_timer, jiffies + 1);
  503. } else {
  504. /* Set up the timer. */
  505. init_timer(&bond->arp_timer);
  506. bond->arp_timer.expires = jiffies + 1;
  507. bond->arp_timer.data =
  508. (unsigned long) bond->dev;
  509. if (bond->params.mode == BOND_MODE_ACTIVEBACKUP) {
  510. bond->arp_timer.function =
  511. (void *)
  512. &bond_activebackup_arp_mon;
  513. } else {
  514. bond->arp_timer.function =
  515. (void *)
  516. &bond_loadbalance_arp_mon;
  517. }
  518. add_timer(&bond->arp_timer);
  519. }
  520. }
  521. out:
  522. return ret;
  523. }
  524. static CLASS_DEVICE_ATTR(arp_interval, S_IRUGO | S_IWUSR , bonding_show_arp_interval, bonding_store_arp_interval);
  525. /*
  526. * Show and set the arp targets.
  527. */
  528. static ssize_t bonding_show_arp_targets(struct class_device *cd, char *buf)
  529. {
  530. int i, res = 0;
  531. struct bonding *bond = to_bond(cd);
  532. for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
  533. if (bond->params.arp_targets[i])
  534. res += sprintf(buf + res, "%u.%u.%u.%u ",
  535. NIPQUAD(bond->params.arp_targets[i]));
  536. }
  537. if (res)
  538. res--; /* eat the leftover space */
  539. res += sprintf(buf + res, "\n");
  540. res++;
  541. return res;
  542. }
  543. static ssize_t bonding_store_arp_targets(struct class_device *cd, const char *buf, size_t count)
  544. {
  545. u32 newtarget;
  546. int i = 0, done = 0, ret = count;
  547. struct bonding *bond = to_bond(cd);
  548. u32 *targets;
  549. targets = bond->params.arp_targets;
  550. newtarget = in_aton(buf + 1);
  551. /* look for adds */
  552. if (buf[0] == '+') {
  553. if ((newtarget == 0) || (newtarget == INADDR_BROADCAST)) {
  554. printk(KERN_ERR DRV_NAME
  555. ": %s: invalid ARP target %u.%u.%u.%u specified for addition\n",
  556. bond->dev->name, NIPQUAD(newtarget));
  557. ret = -EINVAL;
  558. goto out;
  559. }
  560. /* look for an empty slot to put the target in, and check for dupes */
  561. for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
  562. if (targets[i] == newtarget) { /* duplicate */
  563. printk(KERN_ERR DRV_NAME
  564. ": %s: ARP target %u.%u.%u.%u is already present\n",
  565. bond->dev->name, NIPQUAD(newtarget));
  566. if (done)
  567. targets[i] = 0;
  568. ret = -EINVAL;
  569. goto out;
  570. }
  571. if (targets[i] == 0 && !done) {
  572. printk(KERN_INFO DRV_NAME
  573. ": %s: adding ARP target %d.%d.%d.%d.\n",
  574. bond->dev->name, NIPQUAD(newtarget));
  575. done = 1;
  576. targets[i] = newtarget;
  577. }
  578. }
  579. if (!done) {
  580. printk(KERN_ERR DRV_NAME
  581. ": %s: ARP target table is full!\n",
  582. bond->dev->name);
  583. ret = -EINVAL;
  584. goto out;
  585. }
  586. }
  587. else if (buf[0] == '-') {
  588. if ((newtarget == 0) || (newtarget == INADDR_BROADCAST)) {
  589. printk(KERN_ERR DRV_NAME
  590. ": %s: invalid ARP target %d.%d.%d.%d specified for removal\n",
  591. bond->dev->name, NIPQUAD(newtarget));
  592. ret = -EINVAL;
  593. goto out;
  594. }
  595. for (i = 0; (i < BOND_MAX_ARP_TARGETS); i++) {
  596. if (targets[i] == newtarget) {
  597. printk(KERN_INFO DRV_NAME
  598. ": %s: removing ARP target %d.%d.%d.%d.\n",
  599. bond->dev->name, NIPQUAD(newtarget));
  600. targets[i] = 0;
  601. done = 1;
  602. }
  603. }
  604. if (!done) {
  605. printk(KERN_INFO DRV_NAME
  606. ": %s: unable to remove nonexistent ARP target %d.%d.%d.%d.\n",
  607. bond->dev->name, NIPQUAD(newtarget));
  608. ret = -EINVAL;
  609. goto out;
  610. }
  611. }
  612. else {
  613. printk(KERN_ERR DRV_NAME ": no command found in arp_ip_targets file for bond %s. Use +<addr> or -<addr>.\n",
  614. bond->dev->name);
  615. ret = -EPERM;
  616. goto out;
  617. }
  618. out:
  619. return ret;
  620. }
  621. static CLASS_DEVICE_ATTR(arp_ip_target, S_IRUGO | S_IWUSR , bonding_show_arp_targets, bonding_store_arp_targets);
  622. /*
  623. * Show and set the up and down delays. These must be multiples of the
  624. * MII monitoring value, and are stored internally as the multiplier.
  625. * Thus, we must translate to MS for the real world.
  626. */
  627. static ssize_t bonding_show_downdelay(struct class_device *cd, char *buf)
  628. {
  629. struct bonding *bond = to_bond(cd);
  630. return sprintf(buf, "%d\n", bond->params.downdelay * bond->params.miimon) + 1;
  631. }
  632. static ssize_t bonding_store_downdelay(struct class_device *cd, const char *buf, size_t count)
  633. {
  634. int new_value, ret = count;
  635. struct bonding *bond = to_bond(cd);
  636. if (!(bond->params.miimon)) {
  637. printk(KERN_ERR DRV_NAME
  638. ": %s: Unable to set down delay as MII monitoring is disabled\n",
  639. bond->dev->name);
  640. ret = -EPERM;
  641. goto out;
  642. }
  643. if (sscanf(buf, "%d", &new_value) != 1) {
  644. printk(KERN_ERR DRV_NAME
  645. ": %s: no down delay value specified.\n",
  646. bond->dev->name);
  647. ret = -EINVAL;
  648. goto out;
  649. }
  650. if (new_value < 0) {
  651. printk(KERN_ERR DRV_NAME
  652. ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
  653. bond->dev->name, new_value, 1, INT_MAX);
  654. ret = -EINVAL;
  655. goto out;
  656. } else {
  657. if ((new_value % bond->params.miimon) != 0) {
  658. printk(KERN_WARNING DRV_NAME
  659. ": %s: Warning: down delay (%d) is not a multiple "
  660. "of miimon (%d), delay rounded to %d ms\n",
  661. bond->dev->name, new_value, bond->params.miimon,
  662. (new_value / bond->params.miimon) *
  663. bond->params.miimon);
  664. }
  665. bond->params.downdelay = new_value / bond->params.miimon;
  666. printk(KERN_INFO DRV_NAME ": %s: Setting down delay to %d.\n",
  667. bond->dev->name, bond->params.downdelay * bond->params.miimon);
  668. }
  669. out:
  670. return ret;
  671. }
  672. static CLASS_DEVICE_ATTR(downdelay, S_IRUGO | S_IWUSR , bonding_show_downdelay, bonding_store_downdelay);
  673. static ssize_t bonding_show_updelay(struct class_device *cd, char *buf)
  674. {
  675. struct bonding *bond = to_bond(cd);
  676. return sprintf(buf, "%d\n", bond->params.updelay * bond->params.miimon) + 1;
  677. }
  678. static ssize_t bonding_store_updelay(struct class_device *cd, const char *buf, size_t count)
  679. {
  680. int new_value, ret = count;
  681. struct bonding *bond = to_bond(cd);
  682. if (!(bond->params.miimon)) {
  683. printk(KERN_ERR DRV_NAME
  684. ": %s: Unable to set up delay as MII monitoring is disabled\n",
  685. bond->dev->name);
  686. ret = -EPERM;
  687. goto out;
  688. }
  689. if (sscanf(buf, "%d", &new_value) != 1) {
  690. printk(KERN_ERR DRV_NAME
  691. ": %s: no up delay value specified.\n",
  692. bond->dev->name);
  693. ret = -EINVAL;
  694. goto out;
  695. }
  696. if (new_value < 0) {
  697. printk(KERN_ERR DRV_NAME
  698. ": %s: Invalid down delay value %d not in range %d-%d; rejected.\n",
  699. bond->dev->name, new_value, 1, INT_MAX);
  700. ret = -EINVAL;
  701. goto out;
  702. } else {
  703. if ((new_value % bond->params.miimon) != 0) {
  704. printk(KERN_WARNING DRV_NAME
  705. ": %s: Warning: up delay (%d) is not a multiple "
  706. "of miimon (%d), updelay rounded to %d ms\n",
  707. bond->dev->name, new_value, bond->params.miimon,
  708. (new_value / bond->params.miimon) *
  709. bond->params.miimon);
  710. }
  711. bond->params.updelay = new_value / bond->params.miimon;
  712. printk(KERN_INFO DRV_NAME ": %s: Setting up delay to %d.\n",
  713. bond->dev->name, bond->params.updelay * bond->params.miimon);
  714. }
  715. out:
  716. return ret;
  717. }
  718. static CLASS_DEVICE_ATTR(updelay, S_IRUGO | S_IWUSR , bonding_show_updelay, bonding_store_updelay);
  719. /*
  720. * Show and set the LACP interval. Interface must be down, and the mode
  721. * must be set to 802.3ad mode.
  722. */
  723. static ssize_t bonding_show_lacp(struct class_device *cd, char *buf)
  724. {
  725. struct bonding *bond = to_bond(cd);
  726. return sprintf(buf, "%s %d\n",
  727. bond_lacp_tbl[bond->params.lacp_fast].modename,
  728. bond->params.lacp_fast) + 1;
  729. }
  730. static ssize_t bonding_store_lacp(struct class_device *cd, const char *buf, size_t count)
  731. {
  732. int new_value, ret = count;
  733. struct bonding *bond = to_bond(cd);
  734. if (bond->dev->flags & IFF_UP) {
  735. printk(KERN_ERR DRV_NAME
  736. ": %s: Unable to update LACP rate because interface is up.\n",
  737. bond->dev->name);
  738. ret = -EPERM;
  739. goto out;
  740. }
  741. if (bond->params.mode != BOND_MODE_8023AD) {
  742. printk(KERN_ERR DRV_NAME
  743. ": %s: Unable to update LACP rate because bond is not in 802.3ad mode.\n",
  744. bond->dev->name);
  745. ret = -EPERM;
  746. goto out;
  747. }
  748. new_value = bond_parse_parm((char *)buf, bond_lacp_tbl);
  749. if ((new_value == 1) || (new_value == 0)) {
  750. bond->params.lacp_fast = new_value;
  751. printk(KERN_INFO DRV_NAME
  752. ": %s: Setting LACP rate to %s (%d).\n",
  753. bond->dev->name, bond_lacp_tbl[new_value].modename, new_value);
  754. } else {
  755. printk(KERN_ERR DRV_NAME
  756. ": %s: Ignoring invalid LACP rate value %.*s.\n",
  757. bond->dev->name, (int)strlen(buf) - 1, buf);
  758. ret = -EINVAL;
  759. }
  760. out:
  761. return ret;
  762. }
  763. static CLASS_DEVICE_ATTR(lacp_rate, S_IRUGO | S_IWUSR, bonding_show_lacp, bonding_store_lacp);
  764. /*
  765. * Show and set the MII monitor interval. There are two tricky bits
  766. * here. First, if MII monitoring is activated, then we must disable
  767. * ARP monitoring. Second, if the timer isn't running, we must
  768. * start it.
  769. */
  770. static ssize_t bonding_show_miimon(struct class_device *cd, char *buf)
  771. {
  772. struct bonding *bond = to_bond(cd);
  773. return sprintf(buf, "%d\n", bond->params.miimon) + 1;
  774. }
  775. static ssize_t bonding_store_miimon(struct class_device *cd, const char *buf, size_t count)
  776. {
  777. int new_value, ret = count;
  778. struct bonding *bond = to_bond(cd);
  779. if (sscanf(buf, "%d", &new_value) != 1) {
  780. printk(KERN_ERR DRV_NAME
  781. ": %s: no miimon value specified.\n",
  782. bond->dev->name);
  783. ret = -EINVAL;
  784. goto out;
  785. }
  786. if (new_value < 0) {
  787. printk(KERN_ERR DRV_NAME
  788. ": %s: Invalid miimon value %d not in range %d-%d; rejected.\n",
  789. bond->dev->name, new_value, 1, INT_MAX);
  790. ret = -EINVAL;
  791. goto out;
  792. } else {
  793. printk(KERN_INFO DRV_NAME
  794. ": %s: Setting MII monitoring interval to %d.\n",
  795. bond->dev->name, new_value);
  796. bond->params.miimon = new_value;
  797. if(bond->params.updelay)
  798. printk(KERN_INFO DRV_NAME
  799. ": %s: Note: Updating updelay (to %d) "
  800. "since it is a multiple of the miimon value.\n",
  801. bond->dev->name,
  802. bond->params.updelay * bond->params.miimon);
  803. if(bond->params.downdelay)
  804. printk(KERN_INFO DRV_NAME
  805. ": %s: Note: Updating downdelay (to %d) "
  806. "since it is a multiple of the miimon value.\n",
  807. bond->dev->name,
  808. bond->params.downdelay * bond->params.miimon);
  809. if (bond->params.arp_interval) {
  810. printk(KERN_INFO DRV_NAME
  811. ": %s: MII monitoring cannot be used with "
  812. "ARP monitoring. Disabling ARP monitoring...\n",
  813. bond->dev->name);
  814. bond->params.arp_interval = 0;
  815. /* Kill ARP timer, else it brings bond's link down */
  816. if (bond->mii_timer.function) {
  817. printk(KERN_INFO DRV_NAME
  818. ": %s: Kill ARP timer, else it brings bond's link down...\n",
  819. bond->dev->name);
  820. del_timer_sync(&bond->arp_timer);
  821. }
  822. }
  823. if (bond->dev->flags & IFF_UP) {
  824. /* If the interface is up, we may need to fire off
  825. * the MII timer. If the interface is down, the
  826. * timer will get fired off when the open function
  827. * is called.
  828. */
  829. if (bond->mii_timer.function) {
  830. /* The timer's already set up, so fire it off */
  831. mod_timer(&bond->mii_timer, jiffies + 1);
  832. } else {
  833. /* Set up the timer. */
  834. init_timer(&bond->mii_timer);
  835. bond->mii_timer.expires = jiffies + 1;
  836. bond->mii_timer.data =
  837. (unsigned long) bond->dev;
  838. bond->mii_timer.function =
  839. (void *) &bond_mii_monitor;
  840. add_timer(&bond->mii_timer);
  841. }
  842. }
  843. }
  844. out:
  845. return ret;
  846. }
  847. static CLASS_DEVICE_ATTR(miimon, S_IRUGO | S_IWUSR, bonding_show_miimon, bonding_store_miimon);
  848. /*
  849. * Show and set the primary slave. The store function is much
  850. * simpler than bonding_store_slaves function because it only needs to
  851. * handle one interface name.
  852. * The bond must be a mode that supports a primary for this be
  853. * set.
  854. */
  855. static ssize_t bonding_show_primary(struct class_device *cd, char *buf)
  856. {
  857. int count = 0;
  858. struct bonding *bond = to_bond(cd);
  859. if (bond->primary_slave)
  860. count = sprintf(buf, "%s\n", bond->primary_slave->dev->name) + 1;
  861. else
  862. count = sprintf(buf, "\n") + 1;
  863. return count;
  864. }
  865. static ssize_t bonding_store_primary(struct class_device *cd, const char *buf, size_t count)
  866. {
  867. int i;
  868. struct slave *slave;
  869. struct bonding *bond = to_bond(cd);
  870. write_lock_bh(&bond->lock);
  871. if (!USES_PRIMARY(bond->params.mode)) {
  872. printk(KERN_INFO DRV_NAME
  873. ": %s: Unable to set primary slave; %s is in mode %d\n",
  874. bond->dev->name, bond->dev->name, bond->params.mode);
  875. } else {
  876. bond_for_each_slave(bond, slave, i) {
  877. if (strnicmp
  878. (slave->dev->name, buf,
  879. strlen(slave->dev->name)) == 0) {
  880. printk(KERN_INFO DRV_NAME
  881. ": %s: Setting %s as primary slave.\n",
  882. bond->dev->name, slave->dev->name);
  883. bond->primary_slave = slave;
  884. bond_select_active_slave(bond);
  885. goto out;
  886. }
  887. }
  888. /* if we got here, then we didn't match the name of any slave */
  889. if (strlen(buf) == 0 || buf[0] == '\n') {
  890. printk(KERN_INFO DRV_NAME
  891. ": %s: Setting primary slave to None.\n",
  892. bond->dev->name);
  893. bond->primary_slave = 0;
  894. bond_select_active_slave(bond);
  895. } else {
  896. printk(KERN_INFO DRV_NAME
  897. ": %s: Unable to set %.*s as primary slave as it is not a slave.\n",
  898. bond->dev->name, (int)strlen(buf) - 1, buf);
  899. }
  900. }
  901. out:
  902. write_unlock_bh(&bond->lock);
  903. return count;
  904. }
  905. static CLASS_DEVICE_ATTR(primary, S_IRUGO | S_IWUSR, bonding_show_primary, bonding_store_primary);
  906. /*
  907. * Show and set the use_carrier flag.
  908. */
  909. static ssize_t bonding_show_carrier(struct class_device *cd, char *buf)
  910. {
  911. struct bonding *bond = to_bond(cd);
  912. return sprintf(buf, "%d\n", bond->params.use_carrier) + 1;
  913. }
  914. static ssize_t bonding_store_carrier(struct class_device *cd, const char *buf, size_t count)
  915. {
  916. int new_value, ret = count;
  917. struct bonding *bond = to_bond(cd);
  918. if (sscanf(buf, "%d", &new_value) != 1) {
  919. printk(KERN_ERR DRV_NAME
  920. ": %s: no use_carrier value specified.\n",
  921. bond->dev->name);
  922. ret = -EINVAL;
  923. goto out;
  924. }
  925. if ((new_value == 0) || (new_value == 1)) {
  926. bond->params.use_carrier = new_value;
  927. printk(KERN_INFO DRV_NAME ": %s: Setting use_carrier to %d.\n",
  928. bond->dev->name, new_value);
  929. } else {
  930. printk(KERN_INFO DRV_NAME
  931. ": %s: Ignoring invalid use_carrier value %d.\n",
  932. bond->dev->name, new_value);
  933. }
  934. out:
  935. return count;
  936. }
  937. static CLASS_DEVICE_ATTR(use_carrier, S_IRUGO | S_IWUSR, bonding_show_carrier, bonding_store_carrier);
  938. /*
  939. * Show and set currently active_slave.
  940. */
  941. static ssize_t bonding_show_active_slave(struct class_device *cd, char *buf)
  942. {
  943. struct slave *curr;
  944. struct bonding *bond = to_bond(cd);
  945. int count;
  946. read_lock(&bond->curr_slave_lock);
  947. curr = bond->curr_active_slave;
  948. read_unlock(&bond->curr_slave_lock);
  949. if (USES_PRIMARY(bond->params.mode) && curr)
  950. count = sprintf(buf, "%s\n", curr->dev->name) + 1;
  951. else
  952. count = sprintf(buf, "\n") + 1;
  953. return count;
  954. }
  955. static ssize_t bonding_store_active_slave(struct class_device *cd, const char *buf, size_t count)
  956. {
  957. int i;
  958. struct slave *slave;
  959. struct slave *old_active = NULL;
  960. struct slave *new_active = NULL;
  961. struct bonding *bond = to_bond(cd);
  962. write_lock_bh(&bond->lock);
  963. if (!USES_PRIMARY(bond->params.mode)) {
  964. printk(KERN_INFO DRV_NAME
  965. ": %s: Unable to change active slave; %s is in mode %d\n",
  966. bond->dev->name, bond->dev->name, bond->params.mode);
  967. } else {
  968. bond_for_each_slave(bond, slave, i) {
  969. if (strnicmp
  970. (slave->dev->name, buf,
  971. strlen(slave->dev->name)) == 0) {
  972. old_active = bond->curr_active_slave;
  973. new_active = slave;
  974. if (new_active && (new_active == old_active)) {
  975. /* do nothing */
  976. printk(KERN_INFO DRV_NAME
  977. ": %s: %s is already the current active slave.\n",
  978. bond->dev->name, slave->dev->name);
  979. goto out;
  980. }
  981. else {
  982. if ((new_active) &&
  983. (old_active) &&
  984. (new_active->link == BOND_LINK_UP) &&
  985. IS_UP(new_active->dev)) {
  986. printk(KERN_INFO DRV_NAME
  987. ": %s: Setting %s as active slave.\n",
  988. bond->dev->name, slave->dev->name);
  989. bond_change_active_slave(bond, new_active);
  990. }
  991. else {
  992. printk(KERN_INFO DRV_NAME
  993. ": %s: Could not set %s as active slave; "
  994. "either %s is down or the link is down.\n",
  995. bond->dev->name, slave->dev->name,
  996. slave->dev->name);
  997. }
  998. goto out;
  999. }
  1000. }
  1001. }
  1002. /* if we got here, then we didn't match the name of any slave */
  1003. if (strlen(buf) == 0 || buf[0] == '\n') {
  1004. printk(KERN_INFO DRV_NAME
  1005. ": %s: Setting active slave to None.\n",
  1006. bond->dev->name);
  1007. bond->primary_slave = 0;
  1008. bond_select_active_slave(bond);
  1009. } else {
  1010. printk(KERN_INFO DRV_NAME
  1011. ": %s: Unable to set %.*s as active slave as it is not a slave.\n",
  1012. bond->dev->name, (int)strlen(buf) - 1, buf);
  1013. }
  1014. }
  1015. out:
  1016. write_unlock_bh(&bond->lock);
  1017. return count;
  1018. }
  1019. static CLASS_DEVICE_ATTR(active_slave, S_IRUGO | S_IWUSR, bonding_show_active_slave, bonding_store_active_slave);
  1020. /*
  1021. * Show link status of the bond interface.
  1022. */
  1023. static ssize_t bonding_show_mii_status(struct class_device *cd, char *buf)
  1024. {
  1025. struct slave *curr;
  1026. struct bonding *bond = to_bond(cd);
  1027. read_lock(&bond->curr_slave_lock);
  1028. curr = bond->curr_active_slave;
  1029. read_unlock(&bond->curr_slave_lock);
  1030. return sprintf(buf, "%s\n", (curr) ? "up" : "down") + 1;
  1031. }
  1032. static CLASS_DEVICE_ATTR(mii_status, S_IRUGO, bonding_show_mii_status, NULL);
  1033. /*
  1034. * Show current 802.3ad aggregator ID.
  1035. */
  1036. static ssize_t bonding_show_ad_aggregator(struct class_device *cd, char *buf)
  1037. {
  1038. int count = 0;
  1039. struct bonding *bond = to_bond(cd);
  1040. if (bond->params.mode == BOND_MODE_8023AD) {
  1041. struct ad_info ad_info;
  1042. count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.aggregator_id) + 1;
  1043. }
  1044. else
  1045. count = sprintf(buf, "\n") + 1;
  1046. return count;
  1047. }
  1048. static CLASS_DEVICE_ATTR(ad_aggregator, S_IRUGO, bonding_show_ad_aggregator, NULL);
  1049. /*
  1050. * Show number of active 802.3ad ports.
  1051. */
  1052. static ssize_t bonding_show_ad_num_ports(struct class_device *cd, char *buf)
  1053. {
  1054. int count = 0;
  1055. struct bonding *bond = to_bond(cd);
  1056. if (bond->params.mode == BOND_MODE_8023AD) {
  1057. struct ad_info ad_info;
  1058. count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0: ad_info.ports) + 1;
  1059. }
  1060. else
  1061. count = sprintf(buf, "\n") + 1;
  1062. return count;
  1063. }
  1064. static CLASS_DEVICE_ATTR(ad_num_ports, S_IRUGO, bonding_show_ad_num_ports, NULL);
  1065. /*
  1066. * Show current 802.3ad actor key.
  1067. */
  1068. static ssize_t bonding_show_ad_actor_key(struct class_device *cd, char *buf)
  1069. {
  1070. int count = 0;
  1071. struct bonding *bond = to_bond(cd);
  1072. if (bond->params.mode == BOND_MODE_8023AD) {
  1073. struct ad_info ad_info;
  1074. count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.actor_key) + 1;
  1075. }
  1076. else
  1077. count = sprintf(buf, "\n") + 1;
  1078. return count;
  1079. }
  1080. static CLASS_DEVICE_ATTR(ad_actor_key, S_IRUGO, bonding_show_ad_actor_key, NULL);
  1081. /*
  1082. * Show current 802.3ad partner key.
  1083. */
  1084. static ssize_t bonding_show_ad_partner_key(struct class_device *cd, char *buf)
  1085. {
  1086. int count = 0;
  1087. struct bonding *bond = to_bond(cd);
  1088. if (bond->params.mode == BOND_MODE_8023AD) {
  1089. struct ad_info ad_info;
  1090. count = sprintf(buf, "%d\n", (bond_3ad_get_active_agg_info(bond, &ad_info)) ? 0 : ad_info.partner_key) + 1;
  1091. }
  1092. else
  1093. count = sprintf(buf, "\n") + 1;
  1094. return count;
  1095. }
  1096. static CLASS_DEVICE_ATTR(ad_partner_key, S_IRUGO, bonding_show_ad_partner_key, NULL);
  1097. /*
  1098. * Show current 802.3ad partner mac.
  1099. */
  1100. static ssize_t bonding_show_ad_partner_mac(struct class_device *cd, char *buf)
  1101. {
  1102. int count = 0;
  1103. struct bonding *bond = to_bond(cd);
  1104. if (bond->params.mode == BOND_MODE_8023AD) {
  1105. struct ad_info ad_info;
  1106. if (!bond_3ad_get_active_agg_info(bond, &ad_info)) {
  1107. count = sprintf(buf,"%02x:%02x:%02x:%02x:%02x:%02x\n",
  1108. ad_info.partner_system[0],
  1109. ad_info.partner_system[1],
  1110. ad_info.partner_system[2],
  1111. ad_info.partner_system[3],
  1112. ad_info.partner_system[4],
  1113. ad_info.partner_system[5]) + 1;
  1114. }
  1115. }
  1116. else
  1117. count = sprintf(buf, "\n") + 1;
  1118. return count;
  1119. }
  1120. static CLASS_DEVICE_ATTR(ad_partner_mac, S_IRUGO, bonding_show_ad_partner_mac, NULL);
  1121. static struct attribute *per_bond_attrs[] = {
  1122. &class_device_attr_slaves.attr,
  1123. &class_device_attr_mode.attr,
  1124. &class_device_attr_arp_interval.attr,
  1125. &class_device_attr_arp_ip_target.attr,
  1126. &class_device_attr_downdelay.attr,
  1127. &class_device_attr_updelay.attr,
  1128. &class_device_attr_lacp_rate.attr,
  1129. &class_device_attr_xmit_hash_policy.attr,
  1130. &class_device_attr_miimon.attr,
  1131. &class_device_attr_primary.attr,
  1132. &class_device_attr_use_carrier.attr,
  1133. &class_device_attr_active_slave.attr,
  1134. &class_device_attr_mii_status.attr,
  1135. &class_device_attr_ad_aggregator.attr,
  1136. &class_device_attr_ad_num_ports.attr,
  1137. &class_device_attr_ad_actor_key.attr,
  1138. &class_device_attr_ad_partner_key.attr,
  1139. &class_device_attr_ad_partner_mac.attr,
  1140. NULL,
  1141. };
  1142. static struct attribute_group bonding_group = {
  1143. .name = "bonding",
  1144. .attrs = per_bond_attrs,
  1145. };
  1146. /*
  1147. * Initialize sysfs. This sets up the bonding_masters file in
  1148. * /sys/class/net.
  1149. */
  1150. int bond_create_sysfs(void)
  1151. {
  1152. int ret = 0;
  1153. struct bonding *firstbond;
  1154. init_rwsem(&bonding_rwsem);
  1155. /* get the netdev class pointer */
  1156. firstbond = container_of(bond_dev_list.next, struct bonding, bond_list);
  1157. if (!firstbond)
  1158. return -ENODEV;
  1159. netdev_class = firstbond->dev->class_dev.class;
  1160. if (!netdev_class)
  1161. return -ENODEV;
  1162. ret = class_create_file(netdev_class, &class_attr_bonding_masters);
  1163. return ret;
  1164. }
  1165. /*
  1166. * Remove /sys/class/net/bonding_masters.
  1167. */
  1168. void bond_destroy_sysfs(void)
  1169. {
  1170. if (netdev_class)
  1171. class_remove_file(netdev_class, &class_attr_bonding_masters);
  1172. }
  1173. /*
  1174. * Initialize sysfs for each bond. This sets up and registers
  1175. * the 'bondctl' directory for each individual bond under /sys/class/net.
  1176. */
  1177. int bond_create_sysfs_entry(struct bonding *bond)
  1178. {
  1179. struct net_device *dev = bond->dev;
  1180. int err;
  1181. err = sysfs_create_group(&(dev->class_dev.kobj), &bonding_group);
  1182. if (err) {
  1183. printk(KERN_EMERG "eek! didn't create group!\n");
  1184. }
  1185. if (expected_refcount < 1)
  1186. expected_refcount = atomic_read(&bond->dev->class_dev.kobj.kref.refcount);
  1187. return err;
  1188. }
  1189. /*
  1190. * Remove sysfs entries for each bond.
  1191. */
  1192. void bond_destroy_sysfs_entry(struct bonding *bond)
  1193. {
  1194. struct net_device *dev = bond->dev;
  1195. sysfs_remove_group(&(dev->class_dev.kobj), &bonding_group);
  1196. }