bond_netlink.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /*
  2. * drivers/net/bond/bond_netlink.c - Netlink interface for bonding
  3. * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
  4. * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/errno.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/etherdevice.h>
  15. #include <linux/if_link.h>
  16. #include <linux/if_ether.h>
  17. #include <net/netlink.h>
  18. #include <net/rtnetlink.h>
  19. #include "bonding.h"
  20. static size_t bond_get_slave_size(const struct net_device *bond_dev,
  21. const struct net_device *slave_dev)
  22. {
  23. return nla_total_size(sizeof(u8)) + /* IFLA_BOND_SLAVE_STATE */
  24. nla_total_size(sizeof(u8)) + /* IFLA_BOND_SLAVE_MII_STATUS */
  25. nla_total_size(sizeof(u32)) + /* IFLA_BOND_SLAVE_LINK_FAILURE_COUNT */
  26. nla_total_size(MAX_ADDR_LEN) + /* IFLA_BOND_SLAVE_PERM_HWADDR */
  27. nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_QUEUE_ID */
  28. nla_total_size(sizeof(u16)) + /* IFLA_BOND_SLAVE_AD_AGGREGATOR_ID */
  29. 0;
  30. }
  31. static int bond_fill_slave_info(struct sk_buff *skb,
  32. const struct net_device *bond_dev,
  33. const struct net_device *slave_dev)
  34. {
  35. struct slave *slave = bond_slave_get_rtnl(slave_dev);
  36. if (nla_put_u8(skb, IFLA_BOND_SLAVE_STATE, bond_slave_state(slave)))
  37. goto nla_put_failure;
  38. if (nla_put_u8(skb, IFLA_BOND_SLAVE_MII_STATUS, slave->link))
  39. goto nla_put_failure;
  40. if (nla_put_u32(skb, IFLA_BOND_SLAVE_LINK_FAILURE_COUNT,
  41. slave->link_failure_count))
  42. goto nla_put_failure;
  43. if (nla_put(skb, IFLA_BOND_SLAVE_PERM_HWADDR,
  44. slave_dev->addr_len, slave->perm_hwaddr))
  45. goto nla_put_failure;
  46. if (nla_put_u16(skb, IFLA_BOND_SLAVE_QUEUE_ID, slave->queue_id))
  47. goto nla_put_failure;
  48. if (BOND_MODE(slave->bond) == BOND_MODE_8023AD) {
  49. const struct aggregator *agg;
  50. agg = SLAVE_AD_INFO(slave)->port.aggregator;
  51. if (agg)
  52. if (nla_put_u16(skb, IFLA_BOND_SLAVE_AD_AGGREGATOR_ID,
  53. agg->aggregator_identifier))
  54. goto nla_put_failure;
  55. }
  56. return 0;
  57. nla_put_failure:
  58. return -EMSGSIZE;
  59. }
  60. static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
  61. [IFLA_BOND_MODE] = { .type = NLA_U8 },
  62. [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
  63. [IFLA_BOND_MIIMON] = { .type = NLA_U32 },
  64. [IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
  65. [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
  66. [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
  67. [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 },
  68. [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED },
  69. [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 },
  70. [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 },
  71. [IFLA_BOND_PRIMARY] = { .type = NLA_U32 },
  72. [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 },
  73. [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 },
  74. [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 },
  75. [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 },
  76. [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 },
  77. [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 },
  78. [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 },
  79. [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 },
  80. [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 },
  81. [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 },
  82. [IFLA_BOND_AD_SELECT] = { .type = NLA_U8 },
  83. [IFLA_BOND_AD_INFO] = { .type = NLA_NESTED },
  84. };
  85. static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
  86. {
  87. if (tb[IFLA_ADDRESS]) {
  88. if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
  89. return -EINVAL;
  90. if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
  91. return -EADDRNOTAVAIL;
  92. }
  93. return 0;
  94. }
  95. static int bond_changelink(struct net_device *bond_dev,
  96. struct nlattr *tb[], struct nlattr *data[])
  97. {
  98. struct bonding *bond = netdev_priv(bond_dev);
  99. struct bond_opt_value newval;
  100. int miimon = 0;
  101. int err;
  102. if (!data)
  103. return 0;
  104. if (data[IFLA_BOND_MODE]) {
  105. int mode = nla_get_u8(data[IFLA_BOND_MODE]);
  106. bond_opt_initval(&newval, mode);
  107. err = __bond_opt_set(bond, BOND_OPT_MODE, &newval);
  108. if (err)
  109. return err;
  110. }
  111. if (data[IFLA_BOND_ACTIVE_SLAVE]) {
  112. int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
  113. struct net_device *slave_dev;
  114. char *active_slave = "";
  115. if (ifindex != 0) {
  116. slave_dev = __dev_get_by_index(dev_net(bond_dev),
  117. ifindex);
  118. if (!slave_dev)
  119. return -ENODEV;
  120. active_slave = slave_dev->name;
  121. }
  122. bond_opt_initstr(&newval, active_slave);
  123. err = __bond_opt_set(bond, BOND_OPT_ACTIVE_SLAVE, &newval);
  124. if (err)
  125. return err;
  126. }
  127. if (data[IFLA_BOND_MIIMON]) {
  128. miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
  129. bond_opt_initval(&newval, miimon);
  130. err = __bond_opt_set(bond, BOND_OPT_MIIMON, &newval);
  131. if (err)
  132. return err;
  133. }
  134. if (data[IFLA_BOND_UPDELAY]) {
  135. int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
  136. bond_opt_initval(&newval, updelay);
  137. err = __bond_opt_set(bond, BOND_OPT_UPDELAY, &newval);
  138. if (err)
  139. return err;
  140. }
  141. if (data[IFLA_BOND_DOWNDELAY]) {
  142. int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
  143. bond_opt_initval(&newval, downdelay);
  144. err = __bond_opt_set(bond, BOND_OPT_DOWNDELAY, &newval);
  145. if (err)
  146. return err;
  147. }
  148. if (data[IFLA_BOND_USE_CARRIER]) {
  149. int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]);
  150. bond_opt_initval(&newval, use_carrier);
  151. err = __bond_opt_set(bond, BOND_OPT_USE_CARRIER, &newval);
  152. if (err)
  153. return err;
  154. }
  155. if (data[IFLA_BOND_ARP_INTERVAL]) {
  156. int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
  157. if (arp_interval && miimon) {
  158. netdev_err(bond->dev, "ARP monitoring cannot be used with MII monitoring\n");
  159. return -EINVAL;
  160. }
  161. bond_opt_initval(&newval, arp_interval);
  162. err = __bond_opt_set(bond, BOND_OPT_ARP_INTERVAL, &newval);
  163. if (err)
  164. return err;
  165. }
  166. if (data[IFLA_BOND_ARP_IP_TARGET]) {
  167. struct nlattr *attr;
  168. int i = 0, rem;
  169. bond_option_arp_ip_targets_clear(bond);
  170. nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
  171. __be32 target = nla_get_be32(attr);
  172. bond_opt_initval(&newval, (__force u64)target);
  173. err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
  174. &newval);
  175. if (err)
  176. break;
  177. i++;
  178. }
  179. if (i == 0 && bond->params.arp_interval)
  180. netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n");
  181. if (err)
  182. return err;
  183. }
  184. if (data[IFLA_BOND_ARP_VALIDATE]) {
  185. int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]);
  186. if (arp_validate && miimon) {
  187. netdev_err(bond->dev, "ARP validating cannot be used with MII monitoring\n");
  188. return -EINVAL;
  189. }
  190. bond_opt_initval(&newval, arp_validate);
  191. err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
  192. if (err)
  193. return err;
  194. }
  195. if (data[IFLA_BOND_ARP_ALL_TARGETS]) {
  196. int arp_all_targets =
  197. nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]);
  198. bond_opt_initval(&newval, arp_all_targets);
  199. err = __bond_opt_set(bond, BOND_OPT_ARP_ALL_TARGETS, &newval);
  200. if (err)
  201. return err;
  202. }
  203. if (data[IFLA_BOND_PRIMARY]) {
  204. int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]);
  205. struct net_device *dev;
  206. char *primary = "";
  207. dev = __dev_get_by_index(dev_net(bond_dev), ifindex);
  208. if (dev)
  209. primary = dev->name;
  210. bond_opt_initstr(&newval, primary);
  211. err = __bond_opt_set(bond, BOND_OPT_PRIMARY, &newval);
  212. if (err)
  213. return err;
  214. }
  215. if (data[IFLA_BOND_PRIMARY_RESELECT]) {
  216. int primary_reselect =
  217. nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
  218. bond_opt_initval(&newval, primary_reselect);
  219. err = __bond_opt_set(bond, BOND_OPT_PRIMARY_RESELECT, &newval);
  220. if (err)
  221. return err;
  222. }
  223. if (data[IFLA_BOND_FAIL_OVER_MAC]) {
  224. int fail_over_mac =
  225. nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
  226. bond_opt_initval(&newval, fail_over_mac);
  227. err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval);
  228. if (err)
  229. return err;
  230. }
  231. if (data[IFLA_BOND_XMIT_HASH_POLICY]) {
  232. int xmit_hash_policy =
  233. nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);
  234. bond_opt_initval(&newval, xmit_hash_policy);
  235. err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval);
  236. if (err)
  237. return err;
  238. }
  239. if (data[IFLA_BOND_RESEND_IGMP]) {
  240. int resend_igmp =
  241. nla_get_u32(data[IFLA_BOND_RESEND_IGMP]);
  242. bond_opt_initval(&newval, resend_igmp);
  243. err = __bond_opt_set(bond, BOND_OPT_RESEND_IGMP, &newval);
  244. if (err)
  245. return err;
  246. }
  247. if (data[IFLA_BOND_NUM_PEER_NOTIF]) {
  248. int num_peer_notif =
  249. nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]);
  250. bond_opt_initval(&newval, num_peer_notif);
  251. err = __bond_opt_set(bond, BOND_OPT_NUM_PEER_NOTIF, &newval);
  252. if (err)
  253. return err;
  254. }
  255. if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) {
  256. int all_slaves_active =
  257. nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
  258. bond_opt_initval(&newval, all_slaves_active);
  259. err = __bond_opt_set(bond, BOND_OPT_ALL_SLAVES_ACTIVE, &newval);
  260. if (err)
  261. return err;
  262. }
  263. if (data[IFLA_BOND_MIN_LINKS]) {
  264. int min_links =
  265. nla_get_u32(data[IFLA_BOND_MIN_LINKS]);
  266. bond_opt_initval(&newval, min_links);
  267. err = __bond_opt_set(bond, BOND_OPT_MINLINKS, &newval);
  268. if (err)
  269. return err;
  270. }
  271. if (data[IFLA_BOND_LP_INTERVAL]) {
  272. int lp_interval =
  273. nla_get_u32(data[IFLA_BOND_LP_INTERVAL]);
  274. bond_opt_initval(&newval, lp_interval);
  275. err = __bond_opt_set(bond, BOND_OPT_LP_INTERVAL, &newval);
  276. if (err)
  277. return err;
  278. }
  279. if (data[IFLA_BOND_PACKETS_PER_SLAVE]) {
  280. int packets_per_slave =
  281. nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
  282. bond_opt_initval(&newval, packets_per_slave);
  283. err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
  284. if (err)
  285. return err;
  286. }
  287. if (data[IFLA_BOND_AD_LACP_RATE]) {
  288. int lacp_rate =
  289. nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
  290. bond_opt_initval(&newval, lacp_rate);
  291. err = __bond_opt_set(bond, BOND_OPT_LACP_RATE, &newval);
  292. if (err)
  293. return err;
  294. }
  295. if (data[IFLA_BOND_AD_SELECT]) {
  296. int ad_select =
  297. nla_get_u8(data[IFLA_BOND_AD_SELECT]);
  298. bond_opt_initval(&newval, ad_select);
  299. err = __bond_opt_set(bond, BOND_OPT_AD_SELECT, &newval);
  300. if (err)
  301. return err;
  302. }
  303. return 0;
  304. }
  305. static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
  306. struct nlattr *tb[], struct nlattr *data[])
  307. {
  308. int err;
  309. err = bond_changelink(bond_dev, tb, data);
  310. if (err < 0)
  311. return err;
  312. return register_netdevice(bond_dev);
  313. }
  314. static size_t bond_get_size(const struct net_device *bond_dev)
  315. {
  316. return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */
  317. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */
  318. nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
  319. nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
  320. nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
  321. nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
  322. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
  323. /* IFLA_BOND_ARP_IP_TARGET */
  324. nla_total_size(sizeof(struct nlattr)) +
  325. nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
  326. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */
  327. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */
  328. nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */
  329. nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
  330. nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
  331. nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */
  332. nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */
  333. nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */
  334. nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */
  335. nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */
  336. nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */
  337. nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */
  338. nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */
  339. nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */
  340. nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */
  341. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */
  342. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */
  343. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */
  344. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/
  345. nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/
  346. 0;
  347. }
  348. static int bond_option_active_slave_get_ifindex(struct bonding *bond)
  349. {
  350. const struct net_device *slave;
  351. int ifindex;
  352. rcu_read_lock();
  353. slave = bond_option_active_slave_get_rcu(bond);
  354. ifindex = slave ? slave->ifindex : 0;
  355. rcu_read_unlock();
  356. return ifindex;
  357. }
  358. static int bond_fill_info(struct sk_buff *skb,
  359. const struct net_device *bond_dev)
  360. {
  361. struct bonding *bond = netdev_priv(bond_dev);
  362. unsigned int packets_per_slave;
  363. int ifindex, i, targets_added;
  364. struct nlattr *targets;
  365. if (nla_put_u8(skb, IFLA_BOND_MODE, BOND_MODE(bond)))
  366. goto nla_put_failure;
  367. ifindex = bond_option_active_slave_get_ifindex(bond);
  368. if (ifindex && nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, ifindex))
  369. goto nla_put_failure;
  370. if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
  371. goto nla_put_failure;
  372. if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
  373. bond->params.updelay * bond->params.miimon))
  374. goto nla_put_failure;
  375. if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
  376. bond->params.downdelay * bond->params.miimon))
  377. goto nla_put_failure;
  378. if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
  379. goto nla_put_failure;
  380. if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
  381. goto nla_put_failure;
  382. targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
  383. if (!targets)
  384. goto nla_put_failure;
  385. targets_added = 0;
  386. for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
  387. if (bond->params.arp_targets[i]) {
  388. nla_put_be32(skb, i, bond->params.arp_targets[i]);
  389. targets_added = 1;
  390. }
  391. }
  392. if (targets_added)
  393. nla_nest_end(skb, targets);
  394. else
  395. nla_nest_cancel(skb, targets);
  396. if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate))
  397. goto nla_put_failure;
  398. if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS,
  399. bond->params.arp_all_targets))
  400. goto nla_put_failure;
  401. if (bond->primary_slave &&
  402. nla_put_u32(skb, IFLA_BOND_PRIMARY,
  403. bond->primary_slave->dev->ifindex))
  404. goto nla_put_failure;
  405. if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
  406. bond->params.primary_reselect))
  407. goto nla_put_failure;
  408. if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
  409. bond->params.fail_over_mac))
  410. goto nla_put_failure;
  411. if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY,
  412. bond->params.xmit_policy))
  413. goto nla_put_failure;
  414. if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP,
  415. bond->params.resend_igmp))
  416. goto nla_put_failure;
  417. if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF,
  418. bond->params.num_peer_notif))
  419. goto nla_put_failure;
  420. if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE,
  421. bond->params.all_slaves_active))
  422. goto nla_put_failure;
  423. if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS,
  424. bond->params.min_links))
  425. goto nla_put_failure;
  426. if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL,
  427. bond->params.lp_interval))
  428. goto nla_put_failure;
  429. packets_per_slave = bond->params.packets_per_slave;
  430. if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE,
  431. packets_per_slave))
  432. goto nla_put_failure;
  433. if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
  434. bond->params.lacp_fast))
  435. goto nla_put_failure;
  436. if (nla_put_u8(skb, IFLA_BOND_AD_SELECT,
  437. bond->params.ad_select))
  438. goto nla_put_failure;
  439. if (BOND_MODE(bond) == BOND_MODE_8023AD) {
  440. struct ad_info info;
  441. if (!bond_3ad_get_active_agg_info(bond, &info)) {
  442. struct nlattr *nest;
  443. nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
  444. if (!nest)
  445. goto nla_put_failure;
  446. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR,
  447. info.aggregator_id))
  448. goto nla_put_failure;
  449. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS,
  450. info.ports))
  451. goto nla_put_failure;
  452. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY,
  453. info.actor_key))
  454. goto nla_put_failure;
  455. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY,
  456. info.partner_key))
  457. goto nla_put_failure;
  458. if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC,
  459. sizeof(info.partner_system),
  460. &info.partner_system))
  461. goto nla_put_failure;
  462. nla_nest_end(skb, nest);
  463. }
  464. }
  465. return 0;
  466. nla_put_failure:
  467. return -EMSGSIZE;
  468. }
  469. struct rtnl_link_ops bond_link_ops __read_mostly = {
  470. .kind = "bond",
  471. .priv_size = sizeof(struct bonding),
  472. .setup = bond_setup,
  473. .maxtype = IFLA_BOND_MAX,
  474. .policy = bond_policy,
  475. .validate = bond_validate,
  476. .newlink = bond_newlink,
  477. .changelink = bond_changelink,
  478. .get_size = bond_get_size,
  479. .fill_info = bond_fill_info,
  480. .get_num_tx_queues = bond_get_num_tx_queues,
  481. .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
  482. as for TX queues */
  483. .get_slave_size = bond_get_slave_size,
  484. .fill_slave_info = bond_fill_slave_info,
  485. };
  486. int __init bond_netlink_init(void)
  487. {
  488. return rtnl_link_register(&bond_link_ops);
  489. }
  490. void bond_netlink_fini(void)
  491. {
  492. rtnl_link_unregister(&bond_link_ops);
  493. }
  494. MODULE_ALIAS_RTNL_LINK("bond");