bond_netlink.c 20 KB

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