Commit | Line | Data |
---|---|---|
0a2a78c4 JP |
1 | /* |
2 | * drivers/net/bond/bond_netlink.c - Netlink interface for bonding | |
3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> | |
eecdaa6e | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
0a2a78c4 JP |
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 | ||
12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | |
13 | ||
14 | #include <linux/module.h> | |
15 | #include <linux/errno.h> | |
16 | #include <linux/netdevice.h> | |
17 | #include <linux/etherdevice.h> | |
18 | #include <linux/if_link.h> | |
19 | #include <linux/if_ether.h> | |
20 | #include <net/netlink.h> | |
21 | #include <net/rtnetlink.h> | |
22 | #include "bonding.h" | |
23 | ||
1d3ee88a | 24 | int bond_get_slave(struct net_device *slave_dev, struct sk_buff *skb) |
25 | { | |
26 | struct slave *slave = bond_slave_get_rtnl(slave_dev); | |
27 | const struct aggregator *agg; | |
28 | ||
29 | if (nla_put_u8(skb, IFLA_SLAVE_STATE, bond_slave_state(slave))) | |
30 | goto nla_put_failure; | |
31 | ||
32 | if (nla_put_u8(skb, IFLA_SLAVE_MII_STATUS, slave->link)) | |
33 | goto nla_put_failure; | |
34 | ||
35 | if (nla_put_u32(skb, IFLA_SLAVE_LINK_FAILURE_COUNT, | |
36 | slave->link_failure_count)) | |
37 | goto nla_put_failure; | |
38 | ||
39 | if (nla_put(skb, IFLA_SLAVE_PERM_HWADDR, | |
40 | slave_dev->addr_len, slave->perm_hwaddr)) | |
41 | goto nla_put_failure; | |
42 | ||
43 | if (nla_put_u16(skb, IFLA_SLAVE_QUEUE_ID, slave->queue_id)) | |
44 | goto nla_put_failure; | |
45 | ||
46 | if (slave->bond->params.mode == BOND_MODE_8023AD) { | |
47 | agg = SLAVE_AD_INFO(slave).port.aggregator; | |
48 | if (agg) | |
49 | if (nla_put_u16(skb, IFLA_SLAVE_AD_AGGREGATOR_ID, | |
50 | agg->aggregator_identifier)) | |
51 | goto nla_put_failure; | |
52 | } | |
53 | ||
54 | return 0; | |
55 | ||
56 | nla_put_failure: | |
57 | return -EMSGSIZE; | |
58 | } | |
59 | ||
90af2311 JP |
60 | static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { |
61 | [IFLA_BOND_MODE] = { .type = NLA_U8 }, | |
ec76aa49 | 62 | [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 }, |
eecdaa6e | 63 | [IFLA_BOND_MIIMON] = { .type = NLA_U32 }, |
25852e29 | 64 | [IFLA_BOND_UPDELAY] = { .type = NLA_U32 }, |
c7461f9b | 65 | [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 }, |
9f53e14e | 66 | [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 }, |
06151dbc | 67 | [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 }, |
7f28fa10 | 68 | [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED }, |
29c49482 | 69 | [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 }, |
d5c84254 | 70 | [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 }, |
0a98a0d1 | 71 | [IFLA_BOND_PRIMARY] = { .type = NLA_U32 }, |
8a41ae44 | 72 | [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 }, |
89901972 | 73 | [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 }, |
f70161c6 | 74 | [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 }, |
d8838de7 | 75 | [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 }, |
2c9839c1 | 76 | [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 }, |
1cc0b1e3 | 77 | [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 }, |
7d101008 | 78 | [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 }, |
8d836d09 | 79 | [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 }, |
c13ab3ff | 80 | [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 }, |
998e40bb | 81 | [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 }, |
ec029fac | 82 | [IFLA_BOND_AD_SELECT] = { .type = NLA_U8 }, |
4ee7ac75 | 83 | [IFLA_BOND_AD_INFO] = { .type = NLA_NESTED }, |
90af2311 JP |
84 | }; |
85 | ||
0a2a78c4 JP |
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 | ||
90af2311 JP |
97 | static int bond_changelink(struct net_device *bond_dev, |
98 | struct nlattr *tb[], struct nlattr *data[]) | |
99 | { | |
100 | struct bonding *bond = netdev_priv(bond_dev); | |
2b3798d5 | 101 | struct bond_opt_value newval; |
06151dbc | 102 | int miimon = 0; |
90af2311 JP |
103 | int err; |
104 | ||
eecdaa6e | 105 | if (!data) |
106 | return 0; | |
107 | ||
108 | if (data[IFLA_BOND_MODE]) { | |
90af2311 JP |
109 | int mode = nla_get_u8(data[IFLA_BOND_MODE]); |
110 | ||
2b3798d5 NA |
111 | bond_opt_initval(&newval, mode); |
112 | err = __bond_opt_set(bond, BOND_OPT_MODE, &newval); | |
90af2311 JP |
113 | if (err) |
114 | return err; | |
115 | } | |
eecdaa6e | 116 | if (data[IFLA_BOND_ACTIVE_SLAVE]) { |
ec76aa49 JP |
117 | int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]); |
118 | struct net_device *slave_dev; | |
119 | ||
120 | if (ifindex == 0) { | |
121 | slave_dev = NULL; | |
122 | } else { | |
123 | slave_dev = __dev_get_by_index(dev_net(bond_dev), | |
124 | ifindex); | |
125 | if (!slave_dev) | |
126 | return -ENODEV; | |
127 | } | |
128 | err = bond_option_active_slave_set(bond, slave_dev); | |
129 | if (err) | |
130 | return err; | |
131 | } | |
eecdaa6e | 132 | if (data[IFLA_BOND_MIIMON]) { |
06151dbc | 133 | miimon = nla_get_u32(data[IFLA_BOND_MIIMON]); |
eecdaa6e | 134 | |
135 | err = bond_option_miimon_set(bond, miimon); | |
136 | if (err) | |
137 | return err; | |
138 | } | |
25852e29 | 139 | if (data[IFLA_BOND_UPDELAY]) { |
140 | int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]); | |
141 | ||
142 | err = bond_option_updelay_set(bond, updelay); | |
143 | if (err) | |
144 | return err; | |
145 | } | |
c7461f9b | 146 | if (data[IFLA_BOND_DOWNDELAY]) { |
147 | int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]); | |
148 | ||
149 | err = bond_option_downdelay_set(bond, downdelay); | |
150 | if (err) | |
151 | return err; | |
152 | } | |
9f53e14e | 153 | if (data[IFLA_BOND_USE_CARRIER]) { |
154 | int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]); | |
155 | ||
156 | err = bond_option_use_carrier_set(bond, use_carrier); | |
157 | if (err) | |
158 | return err; | |
159 | } | |
06151dbc | 160 | if (data[IFLA_BOND_ARP_INTERVAL]) { |
161 | int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]); | |
162 | ||
163 | if (arp_interval && miimon) { | |
164 | pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n", | |
165 | bond->dev->name); | |
166 | return -EINVAL; | |
167 | } | |
168 | ||
7bdb04ed NA |
169 | bond_opt_initval(&newval, arp_interval); |
170 | err = __bond_opt_set(bond, BOND_OPT_ARP_INTERVAL, &newval); | |
06151dbc | 171 | if (err) |
172 | return err; | |
173 | } | |
7f28fa10 | 174 | if (data[IFLA_BOND_ARP_IP_TARGET]) { |
7f28fa10 | 175 | struct nlattr *attr; |
176 | int i = 0, rem; | |
177 | ||
4fb0ef58 | 178 | bond_option_arp_ip_targets_clear(bond); |
7f28fa10 | 179 | nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) { |
e7ef941d | 180 | __be32 target = nla_get_be32(attr); |
7f28fa10 | 181 | |
4fb0ef58 NA |
182 | bond_opt_initval(&newval, target); |
183 | err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS, | |
184 | &newval); | |
185 | if (err) | |
186 | break; | |
187 | i++; | |
188 | } | |
189 | if (i == 0 && bond->params.arp_interval) | |
190 | pr_warn("%s: removing last arp target with arp_interval on\n", | |
191 | bond->dev->name); | |
7f28fa10 | 192 | if (err) |
193 | return err; | |
194 | } | |
29c49482 | 195 | if (data[IFLA_BOND_ARP_VALIDATE]) { |
196 | int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]); | |
197 | ||
198 | if (arp_validate && miimon) { | |
199 | pr_err("%s: ARP validating cannot be used with MII monitoring.\n", | |
200 | bond->dev->name); | |
201 | return -EINVAL; | |
202 | } | |
203 | ||
16228881 NA |
204 | bond_opt_initval(&newval, arp_validate); |
205 | err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval); | |
29c49482 | 206 | if (err) |
207 | return err; | |
208 | } | |
d5c84254 | 209 | if (data[IFLA_BOND_ARP_ALL_TARGETS]) { |
210 | int arp_all_targets = | |
211 | nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]); | |
212 | ||
edf36b24 NA |
213 | bond_opt_initval(&newval, arp_all_targets); |
214 | err = __bond_opt_set(bond, BOND_OPT_ARP_ALL_TARGETS, &newval); | |
d5c84254 | 215 | if (err) |
216 | return err; | |
217 | } | |
0a98a0d1 | 218 | if (data[IFLA_BOND_PRIMARY]) { |
219 | int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]); | |
220 | struct net_device *dev; | |
221 | char *primary = ""; | |
222 | ||
223 | dev = __dev_get_by_index(dev_net(bond_dev), ifindex); | |
224 | if (dev) | |
225 | primary = dev->name; | |
226 | ||
227 | err = bond_option_primary_set(bond, primary); | |
228 | if (err) | |
229 | return err; | |
230 | } | |
8a41ae44 | 231 | if (data[IFLA_BOND_PRIMARY_RESELECT]) { |
232 | int primary_reselect = | |
233 | nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]); | |
234 | ||
235 | err = bond_option_primary_reselect_set(bond, primary_reselect); | |
236 | if (err) | |
237 | return err; | |
238 | } | |
89901972 | 239 | if (data[IFLA_BOND_FAIL_OVER_MAC]) { |
240 | int fail_over_mac = | |
241 | nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]); | |
242 | ||
1df6b6aa NA |
243 | bond_opt_initval(&newval, fail_over_mac); |
244 | err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval); | |
89901972 | 245 | if (err) |
246 | return err; | |
247 | } | |
f70161c6 | 248 | if (data[IFLA_BOND_XMIT_HASH_POLICY]) { |
249 | int xmit_hash_policy = | |
250 | nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]); | |
251 | ||
a4b32ce7 NA |
252 | bond_opt_initval(&newval, xmit_hash_policy); |
253 | err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval); | |
f70161c6 | 254 | if (err) |
255 | return err; | |
256 | } | |
d8838de7 | 257 | if (data[IFLA_BOND_RESEND_IGMP]) { |
258 | int resend_igmp = | |
259 | nla_get_u32(data[IFLA_BOND_RESEND_IGMP]); | |
260 | ||
261 | err = bond_option_resend_igmp_set(bond, resend_igmp); | |
262 | if (err) | |
263 | return err; | |
264 | } | |
2c9839c1 | 265 | if (data[IFLA_BOND_NUM_PEER_NOTIF]) { |
266 | int num_peer_notif = | |
267 | nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]); | |
268 | ||
269 | err = bond_option_num_peer_notif_set(bond, num_peer_notif); | |
270 | if (err) | |
271 | return err; | |
272 | } | |
1cc0b1e3 | 273 | if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) { |
274 | int all_slaves_active = | |
275 | nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]); | |
276 | ||
277 | err = bond_option_all_slaves_active_set(bond, | |
278 | all_slaves_active); | |
279 | if (err) | |
280 | return err; | |
281 | } | |
7d101008 | 282 | if (data[IFLA_BOND_MIN_LINKS]) { |
283 | int min_links = | |
284 | nla_get_u32(data[IFLA_BOND_MIN_LINKS]); | |
285 | ||
286 | err = bond_option_min_links_set(bond, min_links); | |
287 | if (err) | |
288 | return err; | |
289 | } | |
8d836d09 | 290 | if (data[IFLA_BOND_LP_INTERVAL]) { |
291 | int lp_interval = | |
292 | nla_get_u32(data[IFLA_BOND_LP_INTERVAL]); | |
293 | ||
294 | err = bond_option_lp_interval_set(bond, lp_interval); | |
295 | if (err) | |
296 | return err; | |
297 | } | |
c13ab3ff | 298 | if (data[IFLA_BOND_PACKETS_PER_SLAVE]) { |
299 | int packets_per_slave = | |
300 | nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]); | |
301 | ||
aa59d851 NA |
302 | bond_opt_initval(&newval, packets_per_slave); |
303 | err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval); | |
c13ab3ff | 304 | if (err) |
305 | return err; | |
306 | } | |
998e40bb | 307 | if (data[IFLA_BOND_AD_LACP_RATE]) { |
308 | int lacp_rate = | |
309 | nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]); | |
310 | ||
311 | err = bond_option_lacp_rate_set(bond, lacp_rate); | |
312 | if (err) | |
313 | return err; | |
314 | } | |
ec029fac | 315 | if (data[IFLA_BOND_AD_SELECT]) { |
316 | int ad_select = | |
317 | nla_get_u8(data[IFLA_BOND_AD_SELECT]); | |
318 | ||
319 | err = bond_option_ad_select_set(bond, ad_select); | |
320 | if (err) | |
321 | return err; | |
322 | } | |
90af2311 JP |
323 | return 0; |
324 | } | |
325 | ||
326 | static int bond_newlink(struct net *src_net, struct net_device *bond_dev, | |
327 | struct nlattr *tb[], struct nlattr *data[]) | |
328 | { | |
329 | int err; | |
330 | ||
331 | err = bond_changelink(bond_dev, tb, data); | |
332 | if (err < 0) | |
333 | return err; | |
334 | ||
335 | return register_netdevice(bond_dev); | |
336 | } | |
337 | ||
338 | static size_t bond_get_size(const struct net_device *bond_dev) | |
339 | { | |
e139862e | 340 | return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */ |
eecdaa6e | 341 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */ |
342 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */ | |
25852e29 | 343 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */ |
c7461f9b | 344 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */ |
9f53e14e | 345 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */ |
06151dbc | 346 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */ |
7f28fa10 | 347 | /* IFLA_BOND_ARP_IP_TARGET */ |
288db0aa | 348 | nla_total_size(sizeof(struct nlattr)) + |
7f28fa10 | 349 | nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS + |
29c49482 | 350 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */ |
d5c84254 | 351 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */ |
0a98a0d1 | 352 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */ |
8a41ae44 | 353 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */ |
89901972 | 354 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */ |
f70161c6 | 355 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */ |
d8838de7 | 356 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */ |
2c9839c1 | 357 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */ |
1cc0b1e3 | 358 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */ |
7d101008 | 359 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */ |
8d836d09 | 360 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */ |
c13ab3ff | 361 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */ |
998e40bb | 362 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */ |
ec029fac | 363 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */ |
4ee7ac75 | 364 | nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */ |
365 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */ | |
366 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */ | |
367 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */ | |
368 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/ | |
369 | nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/ | |
eecdaa6e | 370 | 0; |
90af2311 JP |
371 | } |
372 | ||
373 | static int bond_fill_info(struct sk_buff *skb, | |
374 | const struct net_device *bond_dev) | |
375 | { | |
376 | struct bonding *bond = netdev_priv(bond_dev); | |
ec76aa49 | 377 | struct net_device *slave_dev = bond_option_active_slave_get(bond); |
7f28fa10 | 378 | struct nlattr *targets; |
c13ab3ff | 379 | unsigned int packets_per_slave; |
7f28fa10 | 380 | int i, targets_added; |
90af2311 | 381 | |
eecdaa6e | 382 | if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode)) |
90af2311 | 383 | goto nla_put_failure; |
eecdaa6e | 384 | |
385 | if (slave_dev && | |
386 | nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)) | |
387 | goto nla_put_failure; | |
388 | ||
389 | if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon)) | |
390 | goto nla_put_failure; | |
391 | ||
25852e29 | 392 | if (nla_put_u32(skb, IFLA_BOND_UPDELAY, |
393 | bond->params.updelay * bond->params.miimon)) | |
394 | goto nla_put_failure; | |
395 | ||
c7461f9b | 396 | if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY, |
397 | bond->params.downdelay * bond->params.miimon)) | |
398 | goto nla_put_failure; | |
399 | ||
9f53e14e | 400 | if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier)) |
401 | goto nla_put_failure; | |
402 | ||
06151dbc | 403 | if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval)) |
404 | goto nla_put_failure; | |
405 | ||
7f28fa10 | 406 | targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET); |
407 | if (!targets) | |
408 | goto nla_put_failure; | |
409 | ||
410 | targets_added = 0; | |
411 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { | |
412 | if (bond->params.arp_targets[i]) { | |
e7ef941d | 413 | nla_put_be32(skb, i, bond->params.arp_targets[i]); |
7f28fa10 | 414 | targets_added = 1; |
415 | } | |
416 | } | |
417 | ||
418 | if (targets_added) | |
419 | nla_nest_end(skb, targets); | |
420 | else | |
421 | nla_nest_cancel(skb, targets); | |
422 | ||
29c49482 | 423 | if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate)) |
424 | goto nla_put_failure; | |
425 | ||
d5c84254 | 426 | if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS, |
427 | bond->params.arp_all_targets)) | |
428 | goto nla_put_failure; | |
429 | ||
0a98a0d1 | 430 | if (bond->primary_slave && |
431 | nla_put_u32(skb, IFLA_BOND_PRIMARY, | |
432 | bond->primary_slave->dev->ifindex)) | |
433 | goto nla_put_failure; | |
434 | ||
8a41ae44 | 435 | if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT, |
436 | bond->params.primary_reselect)) | |
437 | goto nla_put_failure; | |
438 | ||
89901972 | 439 | if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC, |
440 | bond->params.fail_over_mac)) | |
441 | goto nla_put_failure; | |
442 | ||
f70161c6 | 443 | if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY, |
444 | bond->params.xmit_policy)) | |
445 | goto nla_put_failure; | |
446 | ||
d8838de7 | 447 | if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP, |
448 | bond->params.resend_igmp)) | |
449 | goto nla_put_failure; | |
450 | ||
2c9839c1 | 451 | if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF, |
452 | bond->params.num_peer_notif)) | |
453 | goto nla_put_failure; | |
454 | ||
1cc0b1e3 | 455 | if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE, |
456 | bond->params.all_slaves_active)) | |
457 | goto nla_put_failure; | |
458 | ||
7d101008 | 459 | if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS, |
460 | bond->params.min_links)) | |
461 | goto nla_put_failure; | |
462 | ||
8d836d09 | 463 | if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL, |
464 | bond->params.lp_interval)) | |
465 | goto nla_put_failure; | |
466 | ||
c13ab3ff | 467 | packets_per_slave = bond->params.packets_per_slave; |
c13ab3ff | 468 | if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE, |
469 | packets_per_slave)) | |
470 | goto nla_put_failure; | |
471 | ||
998e40bb | 472 | if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE, |
473 | bond->params.lacp_fast)) | |
474 | goto nla_put_failure; | |
475 | ||
ec029fac | 476 | if (nla_put_u8(skb, IFLA_BOND_AD_SELECT, |
477 | bond->params.ad_select)) | |
478 | goto nla_put_failure; | |
479 | ||
4ee7ac75 | 480 | if (bond->params.mode == BOND_MODE_8023AD) { |
481 | struct ad_info info; | |
482 | ||
483 | if (!bond_3ad_get_active_agg_info(bond, &info)) { | |
484 | struct nlattr *nest; | |
485 | ||
486 | nest = nla_nest_start(skb, IFLA_BOND_AD_INFO); | |
487 | if (!nest) | |
488 | goto nla_put_failure; | |
489 | ||
490 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR, | |
491 | info.aggregator_id)) | |
492 | goto nla_put_failure; | |
493 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS, | |
494 | info.ports)) | |
495 | goto nla_put_failure; | |
496 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY, | |
497 | info.actor_key)) | |
498 | goto nla_put_failure; | |
499 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY, | |
500 | info.partner_key)) | |
501 | goto nla_put_failure; | |
502 | if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC, | |
503 | sizeof(info.partner_system), | |
504 | &info.partner_system)) | |
505 | goto nla_put_failure; | |
506 | ||
507 | nla_nest_end(skb, nest); | |
508 | } | |
509 | } | |
510 | ||
90af2311 JP |
511 | return 0; |
512 | ||
513 | nla_put_failure: | |
514 | return -EMSGSIZE; | |
515 | } | |
516 | ||
0a2a78c4 JP |
517 | struct rtnl_link_ops bond_link_ops __read_mostly = { |
518 | .kind = "bond", | |
519 | .priv_size = sizeof(struct bonding), | |
520 | .setup = bond_setup, | |
90af2311 JP |
521 | .maxtype = IFLA_BOND_MAX, |
522 | .policy = bond_policy, | |
0a2a78c4 | 523 | .validate = bond_validate, |
90af2311 JP |
524 | .newlink = bond_newlink, |
525 | .changelink = bond_changelink, | |
526 | .get_size = bond_get_size, | |
527 | .fill_info = bond_fill_info, | |
0a2a78c4 JP |
528 | .get_num_tx_queues = bond_get_num_tx_queues, |
529 | .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number | |
530 | as for TX queues */ | |
531 | }; | |
532 | ||
533 | int __init bond_netlink_init(void) | |
534 | { | |
535 | return rtnl_link_register(&bond_link_ops); | |
536 | } | |
537 | ||
a729e83a | 538 | void bond_netlink_fini(void) |
0a2a78c4 JP |
539 | { |
540 | rtnl_link_unregister(&bond_link_ops); | |
541 | } | |
542 | ||
543 | MODULE_ALIAS_RTNL_LINK("bond"); |