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