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