bond_netlink.c 16 KB

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