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