bond_netlink.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  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 <net/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 const struct nla_policy bond_slave_policy[IFLA_BOND_SLAVE_MAX + 1] = {
  86. [IFLA_BOND_SLAVE_QUEUE_ID] = { .type = NLA_U16 },
  87. };
  88. static int bond_validate(struct nlattr *tb[], struct nlattr *data[])
  89. {
  90. if (tb[IFLA_ADDRESS]) {
  91. if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
  92. return -EINVAL;
  93. if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
  94. return -EADDRNOTAVAIL;
  95. }
  96. return 0;
  97. }
  98. static int bond_slave_changelink(struct net_device *bond_dev,
  99. struct net_device *slave_dev,
  100. struct nlattr *tb[], struct nlattr *data[])
  101. {
  102. struct bonding *bond = netdev_priv(bond_dev);
  103. struct bond_opt_value newval;
  104. int err;
  105. if (!data)
  106. return 0;
  107. if (data[IFLA_BOND_SLAVE_QUEUE_ID]) {
  108. u16 queue_id = nla_get_u16(data[IFLA_BOND_SLAVE_QUEUE_ID]);
  109. char queue_id_str[IFNAMSIZ + 7];
  110. /* queue_id option setting expects slave_name:queue_id */
  111. snprintf(queue_id_str, sizeof(queue_id_str), "%s:%u\n",
  112. slave_dev->name, queue_id);
  113. bond_opt_initstr(&newval, queue_id_str);
  114. err = __bond_opt_set(bond, BOND_OPT_QUEUE_ID, &newval);
  115. if (err)
  116. return err;
  117. }
  118. return 0;
  119. }
  120. static int bond_changelink(struct net_device *bond_dev,
  121. struct nlattr *tb[], struct nlattr *data[])
  122. {
  123. struct bonding *bond = netdev_priv(bond_dev);
  124. struct bond_opt_value newval;
  125. int miimon = 0;
  126. int err;
  127. if (!data)
  128. return 0;
  129. if (data[IFLA_BOND_MODE]) {
  130. int mode = nla_get_u8(data[IFLA_BOND_MODE]);
  131. bond_opt_initval(&newval, mode);
  132. err = __bond_opt_set(bond, BOND_OPT_MODE, &newval);
  133. if (err)
  134. return err;
  135. }
  136. if (data[IFLA_BOND_ACTIVE_SLAVE]) {
  137. int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
  138. struct net_device *slave_dev;
  139. char *active_slave = "";
  140. if (ifindex != 0) {
  141. slave_dev = __dev_get_by_index(dev_net(bond_dev),
  142. ifindex);
  143. if (!slave_dev)
  144. return -ENODEV;
  145. active_slave = slave_dev->name;
  146. }
  147. bond_opt_initstr(&newval, active_slave);
  148. err = __bond_opt_set(bond, BOND_OPT_ACTIVE_SLAVE, &newval);
  149. if (err)
  150. return err;
  151. }
  152. if (data[IFLA_BOND_MIIMON]) {
  153. miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
  154. bond_opt_initval(&newval, miimon);
  155. err = __bond_opt_set(bond, BOND_OPT_MIIMON, &newval);
  156. if (err)
  157. return err;
  158. }
  159. if (data[IFLA_BOND_UPDELAY]) {
  160. int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
  161. bond_opt_initval(&newval, updelay);
  162. err = __bond_opt_set(bond, BOND_OPT_UPDELAY, &newval);
  163. if (err)
  164. return err;
  165. }
  166. if (data[IFLA_BOND_DOWNDELAY]) {
  167. int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
  168. bond_opt_initval(&newval, downdelay);
  169. err = __bond_opt_set(bond, BOND_OPT_DOWNDELAY, &newval);
  170. if (err)
  171. return err;
  172. }
  173. if (data[IFLA_BOND_USE_CARRIER]) {
  174. int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]);
  175. bond_opt_initval(&newval, use_carrier);
  176. err = __bond_opt_set(bond, BOND_OPT_USE_CARRIER, &newval);
  177. if (err)
  178. return err;
  179. }
  180. if (data[IFLA_BOND_ARP_INTERVAL]) {
  181. int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
  182. if (arp_interval && miimon) {
  183. netdev_err(bond->dev, "ARP monitoring cannot be used with MII monitoring\n");
  184. return -EINVAL;
  185. }
  186. bond_opt_initval(&newval, arp_interval);
  187. err = __bond_opt_set(bond, BOND_OPT_ARP_INTERVAL, &newval);
  188. if (err)
  189. return err;
  190. }
  191. if (data[IFLA_BOND_ARP_IP_TARGET]) {
  192. struct nlattr *attr;
  193. int i = 0, rem;
  194. bond_option_arp_ip_targets_clear(bond);
  195. nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
  196. __be32 target;
  197. if (nla_len(attr) < sizeof(target))
  198. return -EINVAL;
  199. target = nla_get_be32(attr);
  200. bond_opt_initval(&newval, (__force u64)target);
  201. err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
  202. &newval);
  203. if (err)
  204. break;
  205. i++;
  206. }
  207. if (i == 0 && bond->params.arp_interval)
  208. netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n");
  209. if (err)
  210. return err;
  211. }
  212. if (data[IFLA_BOND_ARP_VALIDATE]) {
  213. int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]);
  214. if (arp_validate && miimon) {
  215. netdev_err(bond->dev, "ARP validating cannot be used with MII monitoring\n");
  216. return -EINVAL;
  217. }
  218. bond_opt_initval(&newval, arp_validate);
  219. err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
  220. if (err)
  221. return err;
  222. }
  223. if (data[IFLA_BOND_ARP_ALL_TARGETS]) {
  224. int arp_all_targets =
  225. nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]);
  226. bond_opt_initval(&newval, arp_all_targets);
  227. err = __bond_opt_set(bond, BOND_OPT_ARP_ALL_TARGETS, &newval);
  228. if (err)
  229. return err;
  230. }
  231. if (data[IFLA_BOND_PRIMARY]) {
  232. int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]);
  233. struct net_device *dev;
  234. char *primary = "";
  235. dev = __dev_get_by_index(dev_net(bond_dev), ifindex);
  236. if (dev)
  237. primary = dev->name;
  238. bond_opt_initstr(&newval, primary);
  239. err = __bond_opt_set(bond, BOND_OPT_PRIMARY, &newval);
  240. if (err)
  241. return err;
  242. }
  243. if (data[IFLA_BOND_PRIMARY_RESELECT]) {
  244. int primary_reselect =
  245. nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
  246. bond_opt_initval(&newval, primary_reselect);
  247. err = __bond_opt_set(bond, BOND_OPT_PRIMARY_RESELECT, &newval);
  248. if (err)
  249. return err;
  250. }
  251. if (data[IFLA_BOND_FAIL_OVER_MAC]) {
  252. int fail_over_mac =
  253. nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
  254. bond_opt_initval(&newval, fail_over_mac);
  255. err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval);
  256. if (err)
  257. return err;
  258. }
  259. if (data[IFLA_BOND_XMIT_HASH_POLICY]) {
  260. int xmit_hash_policy =
  261. nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);
  262. bond_opt_initval(&newval, xmit_hash_policy);
  263. err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval);
  264. if (err)
  265. return err;
  266. }
  267. if (data[IFLA_BOND_RESEND_IGMP]) {
  268. int resend_igmp =
  269. nla_get_u32(data[IFLA_BOND_RESEND_IGMP]);
  270. bond_opt_initval(&newval, resend_igmp);
  271. err = __bond_opt_set(bond, BOND_OPT_RESEND_IGMP, &newval);
  272. if (err)
  273. return err;
  274. }
  275. if (data[IFLA_BOND_NUM_PEER_NOTIF]) {
  276. int num_peer_notif =
  277. nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]);
  278. bond_opt_initval(&newval, num_peer_notif);
  279. err = __bond_opt_set(bond, BOND_OPT_NUM_PEER_NOTIF, &newval);
  280. if (err)
  281. return err;
  282. }
  283. if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) {
  284. int all_slaves_active =
  285. nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
  286. bond_opt_initval(&newval, all_slaves_active);
  287. err = __bond_opt_set(bond, BOND_OPT_ALL_SLAVES_ACTIVE, &newval);
  288. if (err)
  289. return err;
  290. }
  291. if (data[IFLA_BOND_MIN_LINKS]) {
  292. int min_links =
  293. nla_get_u32(data[IFLA_BOND_MIN_LINKS]);
  294. bond_opt_initval(&newval, min_links);
  295. err = __bond_opt_set(bond, BOND_OPT_MINLINKS, &newval);
  296. if (err)
  297. return err;
  298. }
  299. if (data[IFLA_BOND_LP_INTERVAL]) {
  300. int lp_interval =
  301. nla_get_u32(data[IFLA_BOND_LP_INTERVAL]);
  302. bond_opt_initval(&newval, lp_interval);
  303. err = __bond_opt_set(bond, BOND_OPT_LP_INTERVAL, &newval);
  304. if (err)
  305. return err;
  306. }
  307. if (data[IFLA_BOND_PACKETS_PER_SLAVE]) {
  308. int packets_per_slave =
  309. nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
  310. bond_opt_initval(&newval, packets_per_slave);
  311. err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
  312. if (err)
  313. return err;
  314. }
  315. if (data[IFLA_BOND_AD_LACP_RATE]) {
  316. int lacp_rate =
  317. nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
  318. bond_opt_initval(&newval, lacp_rate);
  319. err = __bond_opt_set(bond, BOND_OPT_LACP_RATE, &newval);
  320. if (err)
  321. return err;
  322. }
  323. if (data[IFLA_BOND_AD_SELECT]) {
  324. int ad_select =
  325. nla_get_u8(data[IFLA_BOND_AD_SELECT]);
  326. bond_opt_initval(&newval, ad_select);
  327. err = __bond_opt_set(bond, BOND_OPT_AD_SELECT, &newval);
  328. if (err)
  329. return err;
  330. }
  331. return 0;
  332. }
  333. static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
  334. struct nlattr *tb[], struct nlattr *data[])
  335. {
  336. int err;
  337. err = bond_changelink(bond_dev, tb, data);
  338. if (err < 0)
  339. return err;
  340. return register_netdevice(bond_dev);
  341. }
  342. static size_t bond_get_size(const struct net_device *bond_dev)
  343. {
  344. return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */
  345. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */
  346. nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
  347. nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
  348. nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
  349. nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
  350. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
  351. /* IFLA_BOND_ARP_IP_TARGET */
  352. nla_total_size(sizeof(struct nlattr)) +
  353. nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
  354. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */
  355. nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */
  356. nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */
  357. nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
  358. nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
  359. nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */
  360. nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */
  361. nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */
  362. nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */
  363. nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */
  364. nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */
  365. nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */
  366. nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */
  367. nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */
  368. nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */
  369. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */
  370. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */
  371. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */
  372. nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/
  373. nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/
  374. 0;
  375. }
  376. static int bond_option_active_slave_get_ifindex(struct bonding *bond)
  377. {
  378. const struct net_device *slave;
  379. int ifindex;
  380. rcu_read_lock();
  381. slave = bond_option_active_slave_get_rcu(bond);
  382. ifindex = slave ? slave->ifindex : 0;
  383. rcu_read_unlock();
  384. return ifindex;
  385. }
  386. static int bond_fill_info(struct sk_buff *skb,
  387. const struct net_device *bond_dev)
  388. {
  389. struct bonding *bond = netdev_priv(bond_dev);
  390. unsigned int packets_per_slave;
  391. int ifindex, i, targets_added;
  392. struct nlattr *targets;
  393. struct slave *primary;
  394. if (nla_put_u8(skb, IFLA_BOND_MODE, BOND_MODE(bond)))
  395. goto nla_put_failure;
  396. ifindex = bond_option_active_slave_get_ifindex(bond);
  397. if (ifindex && nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, ifindex))
  398. goto nla_put_failure;
  399. if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
  400. goto nla_put_failure;
  401. if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
  402. bond->params.updelay * bond->params.miimon))
  403. goto nla_put_failure;
  404. if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
  405. bond->params.downdelay * bond->params.miimon))
  406. goto nla_put_failure;
  407. if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
  408. goto nla_put_failure;
  409. if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
  410. goto nla_put_failure;
  411. targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
  412. if (!targets)
  413. goto nla_put_failure;
  414. targets_added = 0;
  415. for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
  416. if (bond->params.arp_targets[i]) {
  417. nla_put_be32(skb, i, bond->params.arp_targets[i]);
  418. targets_added = 1;
  419. }
  420. }
  421. if (targets_added)
  422. nla_nest_end(skb, targets);
  423. else
  424. nla_nest_cancel(skb, targets);
  425. if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate))
  426. goto nla_put_failure;
  427. if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS,
  428. bond->params.arp_all_targets))
  429. goto nla_put_failure;
  430. primary = rtnl_dereference(bond->primary_slave);
  431. if (primary &&
  432. nla_put_u32(skb, IFLA_BOND_PRIMARY, primary->dev->ifindex))
  433. goto nla_put_failure;
  434. if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
  435. bond->params.primary_reselect))
  436. goto nla_put_failure;
  437. if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
  438. bond->params.fail_over_mac))
  439. goto nla_put_failure;
  440. if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY,
  441. bond->params.xmit_policy))
  442. goto nla_put_failure;
  443. if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP,
  444. bond->params.resend_igmp))
  445. goto nla_put_failure;
  446. if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF,
  447. bond->params.num_peer_notif))
  448. goto nla_put_failure;
  449. if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE,
  450. bond->params.all_slaves_active))
  451. goto nla_put_failure;
  452. if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS,
  453. bond->params.min_links))
  454. goto nla_put_failure;
  455. if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL,
  456. bond->params.lp_interval))
  457. goto nla_put_failure;
  458. packets_per_slave = bond->params.packets_per_slave;
  459. if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE,
  460. packets_per_slave))
  461. goto nla_put_failure;
  462. if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
  463. bond->params.lacp_fast))
  464. goto nla_put_failure;
  465. if (nla_put_u8(skb, IFLA_BOND_AD_SELECT,
  466. bond->params.ad_select))
  467. goto nla_put_failure;
  468. if (BOND_MODE(bond) == BOND_MODE_8023AD) {
  469. struct ad_info info;
  470. if (!bond_3ad_get_active_agg_info(bond, &info)) {
  471. struct nlattr *nest;
  472. nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
  473. if (!nest)
  474. goto nla_put_failure;
  475. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR,
  476. info.aggregator_id))
  477. goto nla_put_failure;
  478. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS,
  479. info.ports))
  480. goto nla_put_failure;
  481. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY,
  482. info.actor_key))
  483. goto nla_put_failure;
  484. if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY,
  485. info.partner_key))
  486. goto nla_put_failure;
  487. if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC,
  488. sizeof(info.partner_system),
  489. &info.partner_system))
  490. goto nla_put_failure;
  491. nla_nest_end(skb, nest);
  492. }
  493. }
  494. return 0;
  495. nla_put_failure:
  496. return -EMSGSIZE;
  497. }
  498. struct rtnl_link_ops bond_link_ops __read_mostly = {
  499. .kind = "bond",
  500. .priv_size = sizeof(struct bonding),
  501. .setup = bond_setup,
  502. .maxtype = IFLA_BOND_MAX,
  503. .policy = bond_policy,
  504. .validate = bond_validate,
  505. .newlink = bond_newlink,
  506. .changelink = bond_changelink,
  507. .get_size = bond_get_size,
  508. .fill_info = bond_fill_info,
  509. .get_num_tx_queues = bond_get_num_tx_queues,
  510. .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
  511. as for TX queues */
  512. .slave_maxtype = IFLA_BOND_SLAVE_MAX,
  513. .slave_policy = bond_slave_policy,
  514. .slave_changelink = bond_slave_changelink,
  515. .get_slave_size = bond_get_slave_size,
  516. .fill_slave_info = bond_fill_slave_info,
  517. };
  518. int __init bond_netlink_init(void)
  519. {
  520. return rtnl_link_register(&bond_link_ops);
  521. }
  522. void bond_netlink_fini(void)
  523. {
  524. rtnl_link_unregister(&bond_link_ops);
  525. }
  526. MODULE_ALIAS_RTNL_LINK("bond");