rtnetlink: provide api for getting and setting slave info
[deliverable/linux.git] / drivers / net / bonding / bond_netlink.c
CommitLineData
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 24int 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
df7dbcbb 29 if (nla_put_u8(skb, IFLA_BOND_SLAVE_STATE, bond_slave_state(slave)))
1d3ee88a 30 goto nla_put_failure;
31
df7dbcbb 32 if (nla_put_u8(skb, IFLA_BOND_SLAVE_MII_STATUS, slave->link))
1d3ee88a 33 goto nla_put_failure;
34
df7dbcbb 35 if (nla_put_u32(skb, IFLA_BOND_SLAVE_LINK_FAILURE_COUNT,
1d3ee88a 36 slave->link_failure_count))
37 goto nla_put_failure;
38
df7dbcbb 39 if (nla_put(skb, IFLA_BOND_SLAVE_PERM_HWADDR,
1d3ee88a 40 slave_dev->addr_len, slave->perm_hwaddr))
41 goto nla_put_failure;
42
df7dbcbb 43 if (nla_put_u16(skb, IFLA_BOND_SLAVE_QUEUE_ID, slave->queue_id))
1d3ee88a 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)
df7dbcbb 49 if (nla_put_u16(skb, IFLA_BOND_SLAVE_AD_AGGREGATOR_ID,
1d3ee88a 50 agg->aggregator_identifier))
51 goto nla_put_failure;
52 }
53
54 return 0;
55
56nla_put_failure:
57 return -EMSGSIZE;
58}
59
90af2311
JP
60static 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
86static 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
97static 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;
d1fbd3ed 119 char *active_slave = "";
ec76aa49 120
d1fbd3ed 121 if (ifindex != 0) {
ec76aa49
JP
122 slave_dev = __dev_get_by_index(dev_net(bond_dev),
123 ifindex);
124 if (!slave_dev)
125 return -ENODEV;
d1fbd3ed 126 active_slave = slave_dev->name;
ec76aa49 127 }
d1fbd3ed
NA
128 bond_opt_initstr(&newval, active_slave);
129 err = __bond_opt_set(bond, BOND_OPT_ACTIVE_SLAVE, &newval);
ec76aa49
JP
130 if (err)
131 return err;
132 }
eecdaa6e 133 if (data[IFLA_BOND_MIIMON]) {
06151dbc 134 miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
eecdaa6e 135
b98d9c66
NA
136 bond_opt_initval(&newval, miimon);
137 err = __bond_opt_set(bond, BOND_OPT_MIIMON, &newval);
eecdaa6e 138 if (err)
139 return err;
140 }
25852e29 141 if (data[IFLA_BOND_UPDELAY]) {
142 int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
143
e4994612
NA
144 bond_opt_initval(&newval, updelay);
145 err = __bond_opt_set(bond, BOND_OPT_UPDELAY, &newval);
25852e29 146 if (err)
147 return err;
148 }
c7461f9b 149 if (data[IFLA_BOND_DOWNDELAY]) {
150 int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
151
25a9b54a
NA
152 bond_opt_initval(&newval, downdelay);
153 err = __bond_opt_set(bond, BOND_OPT_DOWNDELAY, &newval);
c7461f9b 154 if (err)
155 return err;
156 }
9f53e14e 157 if (data[IFLA_BOND_USE_CARRIER]) {
158 int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]);
159
0fff0608
NA
160 bond_opt_initval(&newval, use_carrier);
161 err = __bond_opt_set(bond, BOND_OPT_USE_CARRIER, &newval);
9f53e14e 162 if (err)
163 return err;
164 }
06151dbc 165 if (data[IFLA_BOND_ARP_INTERVAL]) {
166 int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
167
168 if (arp_interval && miimon) {
169 pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n",
170 bond->dev->name);
171 return -EINVAL;
172 }
173
7bdb04ed
NA
174 bond_opt_initval(&newval, arp_interval);
175 err = __bond_opt_set(bond, BOND_OPT_ARP_INTERVAL, &newval);
06151dbc 176 if (err)
177 return err;
178 }
7f28fa10 179 if (data[IFLA_BOND_ARP_IP_TARGET]) {
7f28fa10 180 struct nlattr *attr;
181 int i = 0, rem;
182
4fb0ef58 183 bond_option_arp_ip_targets_clear(bond);
7f28fa10 184 nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
e7ef941d 185 __be32 target = nla_get_be32(attr);
7f28fa10 186
4fb0ef58
NA
187 bond_opt_initval(&newval, target);
188 err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
189 &newval);
190 if (err)
191 break;
192 i++;
193 }
194 if (i == 0 && bond->params.arp_interval)
195 pr_warn("%s: removing last arp target with arp_interval on\n",
196 bond->dev->name);
7f28fa10 197 if (err)
198 return err;
199 }
29c49482 200 if (data[IFLA_BOND_ARP_VALIDATE]) {
201 int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]);
202
203 if (arp_validate && miimon) {
204 pr_err("%s: ARP validating cannot be used with MII monitoring.\n",
205 bond->dev->name);
206 return -EINVAL;
207 }
208
16228881
NA
209 bond_opt_initval(&newval, arp_validate);
210 err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
29c49482 211 if (err)
212 return err;
213 }
d5c84254 214 if (data[IFLA_BOND_ARP_ALL_TARGETS]) {
215 int arp_all_targets =
216 nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]);
217
edf36b24
NA
218 bond_opt_initval(&newval, arp_all_targets);
219 err = __bond_opt_set(bond, BOND_OPT_ARP_ALL_TARGETS, &newval);
d5c84254 220 if (err)
221 return err;
222 }
0a98a0d1 223 if (data[IFLA_BOND_PRIMARY]) {
224 int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]);
225 struct net_device *dev;
226 char *primary = "";
227
228 dev = __dev_get_by_index(dev_net(bond_dev), ifindex);
229 if (dev)
230 primary = dev->name;
231
180222f0
NA
232 bond_opt_initstr(&newval, primary);
233 err = __bond_opt_set(bond, BOND_OPT_PRIMARY, &newval);
0a98a0d1 234 if (err)
235 return err;
236 }
8a41ae44 237 if (data[IFLA_BOND_PRIMARY_RESELECT]) {
238 int primary_reselect =
239 nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
240
388d3a6d
NA
241 bond_opt_initval(&newval, primary_reselect);
242 err = __bond_opt_set(bond, BOND_OPT_PRIMARY_RESELECT, &newval);
8a41ae44 243 if (err)
244 return err;
245 }
89901972 246 if (data[IFLA_BOND_FAIL_OVER_MAC]) {
247 int fail_over_mac =
248 nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
249
1df6b6aa
NA
250 bond_opt_initval(&newval, fail_over_mac);
251 err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval);
89901972 252 if (err)
253 return err;
254 }
f70161c6 255 if (data[IFLA_BOND_XMIT_HASH_POLICY]) {
256 int xmit_hash_policy =
257 nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);
258
a4b32ce7
NA
259 bond_opt_initval(&newval, xmit_hash_policy);
260 err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval);
f70161c6 261 if (err)
262 return err;
263 }
d8838de7 264 if (data[IFLA_BOND_RESEND_IGMP]) {
265 int resend_igmp =
266 nla_get_u32(data[IFLA_BOND_RESEND_IGMP]);
267
105c8fb6
NA
268 bond_opt_initval(&newval, resend_igmp);
269 err = __bond_opt_set(bond, BOND_OPT_RESEND_IGMP, &newval);
d8838de7 270 if (err)
271 return err;
272 }
2c9839c1 273 if (data[IFLA_BOND_NUM_PEER_NOTIF]) {
274 int num_peer_notif =
275 nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]);
276
ef56becb
NA
277 bond_opt_initval(&newval, num_peer_notif);
278 err = __bond_opt_set(bond, BOND_OPT_NUM_PEER_NOTIF, &newval);
2c9839c1 279 if (err)
280 return err;
281 }
1cc0b1e3 282 if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) {
283 int all_slaves_active =
284 nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
285
3df01162
NA
286 bond_opt_initval(&newval, all_slaves_active);
287 err = __bond_opt_set(bond, BOND_OPT_ALL_SLAVES_ACTIVE, &newval);
1cc0b1e3 288 if (err)
289 return err;
290 }
7d101008 291 if (data[IFLA_BOND_MIN_LINKS]) {
292 int min_links =
293 nla_get_u32(data[IFLA_BOND_MIN_LINKS]);
294
633ddc9e
NA
295 bond_opt_initval(&newval, min_links);
296 err = __bond_opt_set(bond, BOND_OPT_MINLINKS, &newval);
7d101008 297 if (err)
298 return err;
299 }
8d836d09 300 if (data[IFLA_BOND_LP_INTERVAL]) {
301 int lp_interval =
302 nla_get_u32(data[IFLA_BOND_LP_INTERVAL]);
303
4325b374
NA
304 bond_opt_initval(&newval, lp_interval);
305 err = __bond_opt_set(bond, BOND_OPT_LP_INTERVAL, &newval);
8d836d09 306 if (err)
307 return err;
308 }
c13ab3ff 309 if (data[IFLA_BOND_PACKETS_PER_SLAVE]) {
310 int packets_per_slave =
311 nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
312
aa59d851
NA
313 bond_opt_initval(&newval, packets_per_slave);
314 err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
c13ab3ff 315 if (err)
316 return err;
317 }
998e40bb 318 if (data[IFLA_BOND_AD_LACP_RATE]) {
319 int lacp_rate =
320 nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
321
d3131de7
NA
322 bond_opt_initval(&newval, lacp_rate);
323 err = __bond_opt_set(bond, BOND_OPT_LACP_RATE, &newval);
998e40bb 324 if (err)
325 return err;
326 }
ec029fac 327 if (data[IFLA_BOND_AD_SELECT]) {
328 int ad_select =
329 nla_get_u8(data[IFLA_BOND_AD_SELECT]);
330
9e5f5eeb
NA
331 bond_opt_initval(&newval, ad_select);
332 err = __bond_opt_set(bond, BOND_OPT_AD_SELECT, &newval);
ec029fac 333 if (err)
334 return err;
335 }
90af2311
JP
336 return 0;
337}
338
339static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
340 struct nlattr *tb[], struct nlattr *data[])
341{
342 int err;
343
344 err = bond_changelink(bond_dev, tb, data);
345 if (err < 0)
346 return err;
347
348 return register_netdevice(bond_dev);
349}
350
351static size_t bond_get_size(const struct net_device *bond_dev)
352{
e139862e 353 return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */
eecdaa6e 354 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */
355 nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
25852e29 356 nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
c7461f9b 357 nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
9f53e14e 358 nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
06151dbc 359 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
7f28fa10 360 /* IFLA_BOND_ARP_IP_TARGET */
288db0aa 361 nla_total_size(sizeof(struct nlattr)) +
7f28fa10 362 nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
29c49482 363 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */
d5c84254 364 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */
0a98a0d1 365 nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */
8a41ae44 366 nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
89901972 367 nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
f70161c6 368 nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */
d8838de7 369 nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */
2c9839c1 370 nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */
1cc0b1e3 371 nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */
7d101008 372 nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */
8d836d09 373 nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */
c13ab3ff 374 nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */
998e40bb 375 nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */
ec029fac 376 nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */
4ee7ac75 377 nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */
378 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */
379 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */
380 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */
381 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/
382 nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/
eecdaa6e 383 0;
90af2311
JP
384}
385
386static int bond_fill_info(struct sk_buff *skb,
387 const struct net_device *bond_dev)
388{
389 struct bonding *bond = netdev_priv(bond_dev);
ec76aa49 390 struct net_device *slave_dev = bond_option_active_slave_get(bond);
7f28fa10 391 struct nlattr *targets;
c13ab3ff 392 unsigned int packets_per_slave;
7f28fa10 393 int i, targets_added;
90af2311 394
eecdaa6e 395 if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
90af2311 396 goto nla_put_failure;
eecdaa6e 397
398 if (slave_dev &&
399 nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex))
400 goto nla_put_failure;
401
402 if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
403 goto nla_put_failure;
404
25852e29 405 if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
406 bond->params.updelay * bond->params.miimon))
407 goto nla_put_failure;
408
c7461f9b 409 if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
410 bond->params.downdelay * bond->params.miimon))
411 goto nla_put_failure;
412
9f53e14e 413 if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
414 goto nla_put_failure;
415
06151dbc 416 if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
417 goto nla_put_failure;
418
7f28fa10 419 targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
420 if (!targets)
421 goto nla_put_failure;
422
423 targets_added = 0;
424 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
425 if (bond->params.arp_targets[i]) {
e7ef941d 426 nla_put_be32(skb, i, bond->params.arp_targets[i]);
7f28fa10 427 targets_added = 1;
428 }
429 }
430
431 if (targets_added)
432 nla_nest_end(skb, targets);
433 else
434 nla_nest_cancel(skb, targets);
435
29c49482 436 if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate))
437 goto nla_put_failure;
438
d5c84254 439 if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS,
440 bond->params.arp_all_targets))
441 goto nla_put_failure;
442
0a98a0d1 443 if (bond->primary_slave &&
444 nla_put_u32(skb, IFLA_BOND_PRIMARY,
445 bond->primary_slave->dev->ifindex))
446 goto nla_put_failure;
447
8a41ae44 448 if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
449 bond->params.primary_reselect))
450 goto nla_put_failure;
451
89901972 452 if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
453 bond->params.fail_over_mac))
454 goto nla_put_failure;
455
f70161c6 456 if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY,
457 bond->params.xmit_policy))
458 goto nla_put_failure;
459
d8838de7 460 if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP,
461 bond->params.resend_igmp))
462 goto nla_put_failure;
463
2c9839c1 464 if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF,
465 bond->params.num_peer_notif))
466 goto nla_put_failure;
467
1cc0b1e3 468 if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE,
469 bond->params.all_slaves_active))
470 goto nla_put_failure;
471
7d101008 472 if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS,
473 bond->params.min_links))
474 goto nla_put_failure;
475
8d836d09 476 if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL,
477 bond->params.lp_interval))
478 goto nla_put_failure;
479
c13ab3ff 480 packets_per_slave = bond->params.packets_per_slave;
c13ab3ff 481 if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE,
482 packets_per_slave))
483 goto nla_put_failure;
484
998e40bb 485 if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
486 bond->params.lacp_fast))
487 goto nla_put_failure;
488
ec029fac 489 if (nla_put_u8(skb, IFLA_BOND_AD_SELECT,
490 bond->params.ad_select))
491 goto nla_put_failure;
492
4ee7ac75 493 if (bond->params.mode == BOND_MODE_8023AD) {
494 struct ad_info info;
495
496 if (!bond_3ad_get_active_agg_info(bond, &info)) {
497 struct nlattr *nest;
498
499 nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
500 if (!nest)
501 goto nla_put_failure;
502
503 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR,
504 info.aggregator_id))
505 goto nla_put_failure;
506 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS,
507 info.ports))
508 goto nla_put_failure;
509 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY,
510 info.actor_key))
511 goto nla_put_failure;
512 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY,
513 info.partner_key))
514 goto nla_put_failure;
515 if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC,
516 sizeof(info.partner_system),
517 &info.partner_system))
518 goto nla_put_failure;
519
520 nla_nest_end(skb, nest);
521 }
522 }
523
90af2311
JP
524 return 0;
525
526nla_put_failure:
527 return -EMSGSIZE;
528}
529
0a2a78c4
JP
530struct rtnl_link_ops bond_link_ops __read_mostly = {
531 .kind = "bond",
532 .priv_size = sizeof(struct bonding),
533 .setup = bond_setup,
90af2311
JP
534 .maxtype = IFLA_BOND_MAX,
535 .policy = bond_policy,
0a2a78c4 536 .validate = bond_validate,
90af2311
JP
537 .newlink = bond_newlink,
538 .changelink = bond_changelink,
539 .get_size = bond_get_size,
540 .fill_info = bond_fill_info,
0a2a78c4
JP
541 .get_num_tx_queues = bond_get_num_tx_queues,
542 .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
543 as for TX queues */
544};
545
546int __init bond_netlink_init(void)
547{
548 return rtnl_link_register(&bond_link_ops);
549}
550
a729e83a 551void bond_netlink_fini(void)
0a2a78c4
JP
552{
553 rtnl_link_unregister(&bond_link_ops);
554}
555
556MODULE_ALIAS_RTNL_LINK("bond");
This page took 0.075623 seconds and 5 git commands to generate.