blob: 64e45c97c24447b076c5b8c13474de39fe87fe45 [file] [log] [blame]
Jiri Pirko0a2a78c2013-10-18 17:43:33 +02001/*
2 * drivers/net/bond/bond_netlink.c - Netlink interface for bonding
3 * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us>
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -08004 * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com>
Jiri Pirko0a2a78c2013-10-18 17:43:33 +02005 *
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
sfeldma@cumulusnetworks.com1d3ee882014-01-16 22:57:56 -080024int bond_get_slave(struct net_device *slave_dev, struct sk_buff *skb)
25{
26 struct slave *slave = bond_slave_get_rtnl(slave_dev);
27 const struct aggregator *agg;
28
29 if (nla_put_u8(skb, IFLA_SLAVE_STATE, bond_slave_state(slave)))
30 goto nla_put_failure;
31
32 if (nla_put_u8(skb, IFLA_SLAVE_MII_STATUS, slave->link))
33 goto nla_put_failure;
34
35 if (nla_put_u32(skb, IFLA_SLAVE_LINK_FAILURE_COUNT,
36 slave->link_failure_count))
37 goto nla_put_failure;
38
39 if (nla_put(skb, IFLA_SLAVE_PERM_HWADDR,
40 slave_dev->addr_len, slave->perm_hwaddr))
41 goto nla_put_failure;
42
43 if (nla_put_u16(skb, IFLA_SLAVE_QUEUE_ID, slave->queue_id))
44 goto nla_put_failure;
45
46 if (slave->bond->params.mode == BOND_MODE_8023AD) {
47 agg = SLAVE_AD_INFO(slave).port.aggregator;
48 if (agg)
49 if (nla_put_u16(skb, IFLA_SLAVE_AD_AGGREGATOR_ID,
50 agg->aggregator_identifier))
51 goto nla_put_failure;
52 }
53
54 return 0;
55
56nla_put_failure:
57 return -EMSGSIZE;
58}
59
Jiri Pirko90af2312013-10-18 17:43:38 +020060static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = {
61 [IFLA_BOND_MODE] = { .type = NLA_U8 },
Jiri Pirkoec76aa42013-10-18 17:43:39 +020062 [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -080063 [IFLA_BOND_MIIMON] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -080064 [IFLA_BOND_UPDELAY] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -080065 [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -080066 [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -080067 [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -080068 [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED },
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -080069 [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -080070 [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -080071 [IFLA_BOND_PRIMARY] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -080072 [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -080073 [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -080074 [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -080075 [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -080076 [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -080077 [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -080078 [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -080079 [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -080080 [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 },
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -080081 [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -080082 [IFLA_BOND_AD_SELECT] = { .type = NLA_U8 },
sfeldma@cumulusnetworks.com4ee7ac72014-01-03 14:18:56 -080083 [IFLA_BOND_AD_INFO] = { .type = NLA_NESTED },
Jiri Pirko90af2312013-10-18 17:43:38 +020084};
85
Jiri Pirko0a2a78c2013-10-18 17:43:33 +020086static 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
Jiri Pirko90af2312013-10-18 17:43:38 +020097static int bond_changelink(struct net_device *bond_dev,
98 struct nlattr *tb[], struct nlattr *data[])
99{
100 struct bonding *bond = netdev_priv(bond_dev);
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100101 struct bond_opt_value newval;
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800102 int miimon = 0;
Jiri Pirko90af2312013-10-18 17:43:38 +0200103 int err;
104
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800105 if (!data)
106 return 0;
107
108 if (data[IFLA_BOND_MODE]) {
Jiri Pirko90af2312013-10-18 17:43:38 +0200109 int mode = nla_get_u8(data[IFLA_BOND_MODE]);
110
Nikolay Aleksandrov2b3798d2014-01-22 14:53:17 +0100111 bond_opt_initval(&newval, mode);
112 err = __bond_opt_set(bond, BOND_OPT_MODE, &newval);
Jiri Pirko90af2312013-10-18 17:43:38 +0200113 if (err)
114 return err;
115 }
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800116 if (data[IFLA_BOND_ACTIVE_SLAVE]) {
Jiri Pirkoec76aa42013-10-18 17:43:39 +0200117 int ifindex = nla_get_u32(data[IFLA_BOND_ACTIVE_SLAVE]);
118 struct net_device *slave_dev;
119
120 if (ifindex == 0) {
121 slave_dev = NULL;
122 } else {
123 slave_dev = __dev_get_by_index(dev_net(bond_dev),
124 ifindex);
125 if (!slave_dev)
126 return -ENODEV;
127 }
128 err = bond_option_active_slave_set(bond, slave_dev);
129 if (err)
130 return err;
131 }
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800132 if (data[IFLA_BOND_MIIMON]) {
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800133 miimon = nla_get_u32(data[IFLA_BOND_MIIMON]);
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800134
Nikolay Aleksandrovb98d9c62014-01-22 14:53:31 +0100135 bond_opt_initval(&newval, miimon);
136 err = __bond_opt_set(bond, BOND_OPT_MIIMON, &newval);
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800137 if (err)
138 return err;
139 }
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800140 if (data[IFLA_BOND_UPDELAY]) {
141 int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]);
142
Nikolay Aleksandrove4994612014-01-22 14:53:26 +0100143 bond_opt_initval(&newval, updelay);
144 err = __bond_opt_set(bond, BOND_OPT_UPDELAY, &newval);
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800145 if (err)
146 return err;
147 }
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800148 if (data[IFLA_BOND_DOWNDELAY]) {
149 int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]);
150
Nikolay Aleksandrov25a9b542014-01-22 14:53:25 +0100151 bond_opt_initval(&newval, downdelay);
152 err = __bond_opt_set(bond, BOND_OPT_DOWNDELAY, &newval);
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800153 if (err)
154 return err;
155 }
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800156 if (data[IFLA_BOND_USE_CARRIER]) {
157 int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]);
158
159 err = bond_option_use_carrier_set(bond, use_carrier);
160 if (err)
161 return err;
162 }
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800163 if (data[IFLA_BOND_ARP_INTERVAL]) {
164 int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]);
165
166 if (arp_interval && miimon) {
167 pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n",
168 bond->dev->name);
169 return -EINVAL;
170 }
171
Nikolay Aleksandrov7bdb04e2014-01-22 14:53:23 +0100172 bond_opt_initval(&newval, arp_interval);
173 err = __bond_opt_set(bond, BOND_OPT_ARP_INTERVAL, &newval);
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800174 if (err)
175 return err;
176 }
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800177 if (data[IFLA_BOND_ARP_IP_TARGET]) {
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800178 struct nlattr *attr;
179 int i = 0, rem;
180
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100181 bond_option_arp_ip_targets_clear(bond);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800182 nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) {
Jiri Pirkoe7ef9412013-12-14 12:32:10 +0100183 __be32 target = nla_get_be32(attr);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800184
Nikolay Aleksandrov4fb0ef52014-01-22 14:53:24 +0100185 bond_opt_initval(&newval, target);
186 err = __bond_opt_set(bond, BOND_OPT_ARP_TARGETS,
187 &newval);
188 if (err)
189 break;
190 i++;
191 }
192 if (i == 0 && bond->params.arp_interval)
193 pr_warn("%s: removing last arp target with arp_interval on\n",
194 bond->dev->name);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800195 if (err)
196 return err;
197 }
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800198 if (data[IFLA_BOND_ARP_VALIDATE]) {
199 int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]);
200
201 if (arp_validate && miimon) {
202 pr_err("%s: ARP validating cannot be used with MII monitoring.\n",
203 bond->dev->name);
204 return -EINVAL;
205 }
206
Nikolay Aleksandrov16228882014-01-22 14:53:20 +0100207 bond_opt_initval(&newval, arp_validate);
208 err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval);
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800209 if (err)
210 return err;
211 }
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800212 if (data[IFLA_BOND_ARP_ALL_TARGETS]) {
213 int arp_all_targets =
214 nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]);
215
Nikolay Aleksandrovedf36b22014-01-22 14:53:21 +0100216 bond_opt_initval(&newval, arp_all_targets);
217 err = __bond_opt_set(bond, BOND_OPT_ARP_ALL_TARGETS, &newval);
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800218 if (err)
219 return err;
220 }
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -0800221 if (data[IFLA_BOND_PRIMARY]) {
222 int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]);
223 struct net_device *dev;
224 char *primary = "";
225
226 dev = __dev_get_by_index(dev_net(bond_dev), ifindex);
227 if (dev)
228 primary = dev->name;
229
230 err = bond_option_primary_set(bond, primary);
231 if (err)
232 return err;
233 }
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -0800234 if (data[IFLA_BOND_PRIMARY_RESELECT]) {
235 int primary_reselect =
236 nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]);
237
238 err = bond_option_primary_reselect_set(bond, primary_reselect);
239 if (err)
240 return err;
241 }
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800242 if (data[IFLA_BOND_FAIL_OVER_MAC]) {
243 int fail_over_mac =
244 nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]);
245
Nikolay Aleksandrov1df6b6a2014-01-22 14:53:22 +0100246 bond_opt_initval(&newval, fail_over_mac);
247 err = __bond_opt_set(bond, BOND_OPT_FAIL_OVER_MAC, &newval);
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800248 if (err)
249 return err;
250 }
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800251 if (data[IFLA_BOND_XMIT_HASH_POLICY]) {
252 int xmit_hash_policy =
253 nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]);
254
Nikolay Aleksandrova4b32ce2014-01-22 14:53:19 +0100255 bond_opt_initval(&newval, xmit_hash_policy);
256 err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval);
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800257 if (err)
258 return err;
259 }
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -0800260 if (data[IFLA_BOND_RESEND_IGMP]) {
261 int resend_igmp =
262 nla_get_u32(data[IFLA_BOND_RESEND_IGMP]);
263
264 err = bond_option_resend_igmp_set(bond, resend_igmp);
265 if (err)
266 return err;
267 }
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800268 if (data[IFLA_BOND_NUM_PEER_NOTIF]) {
269 int num_peer_notif =
270 nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]);
271
Nikolay Aleksandrovef56bec2014-01-22 14:53:30 +0100272 bond_opt_initval(&newval, num_peer_notif);
273 err = __bond_opt_set(bond, BOND_OPT_NUM_PEER_NOTIF, &newval);
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800274 if (err)
275 return err;
276 }
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -0800277 if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) {
278 int all_slaves_active =
279 nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]);
280
281 err = bond_option_all_slaves_active_set(bond,
282 all_slaves_active);
283 if (err)
284 return err;
285 }
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -0800286 if (data[IFLA_BOND_MIN_LINKS]) {
287 int min_links =
288 nla_get_u32(data[IFLA_BOND_MIN_LINKS]);
289
Nikolay Aleksandrov633ddc92014-01-22 14:53:28 +0100290 bond_opt_initval(&newval, min_links);
291 err = __bond_opt_set(bond, BOND_OPT_MINLINKS, &newval);
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -0800292 if (err)
293 return err;
294 }
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -0800295 if (data[IFLA_BOND_LP_INTERVAL]) {
296 int lp_interval =
297 nla_get_u32(data[IFLA_BOND_LP_INTERVAL]);
298
299 err = bond_option_lp_interval_set(bond, lp_interval);
300 if (err)
301 return err;
302 }
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -0800303 if (data[IFLA_BOND_PACKETS_PER_SLAVE]) {
304 int packets_per_slave =
305 nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]);
306
Nikolay Aleksandrovaa59d852014-01-22 14:53:18 +0100307 bond_opt_initval(&newval, packets_per_slave);
308 err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval);
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -0800309 if (err)
310 return err;
311 }
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -0800312 if (data[IFLA_BOND_AD_LACP_RATE]) {
313 int lacp_rate =
314 nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]);
315
Nikolay Aleksandrovd3131de2014-01-22 14:53:27 +0100316 bond_opt_initval(&newval, lacp_rate);
317 err = __bond_opt_set(bond, BOND_OPT_LACP_RATE, &newval);
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -0800318 if (err)
319 return err;
320 }
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -0800321 if (data[IFLA_BOND_AD_SELECT]) {
322 int ad_select =
323 nla_get_u8(data[IFLA_BOND_AD_SELECT]);
324
Nikolay Aleksandrov9e5f5ee2014-01-22 14:53:29 +0100325 bond_opt_initval(&newval, ad_select);
326 err = __bond_opt_set(bond, BOND_OPT_AD_SELECT, &newval);
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -0800327 if (err)
328 return err;
329 }
Jiri Pirko90af2312013-10-18 17:43:38 +0200330 return 0;
331}
332
333static int bond_newlink(struct net *src_net, struct net_device *bond_dev,
334 struct nlattr *tb[], struct nlattr *data[])
335{
336 int err;
337
338 err = bond_changelink(bond_dev, tb, data);
339 if (err < 0)
340 return err;
341
342 return register_netdevice(bond_dev);
343}
344
345static size_t bond_get_size(const struct net_device *bond_dev)
346{
Dan Carpentere1398622013-11-01 13:18:44 +0300347 return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800348 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */
349 nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800350 nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800351 nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800352 nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800353 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800354 /* IFLA_BOND_ARP_IP_TARGET */
sfeldma@cumulusnetworks.com288db0a2014-01-03 14:28:11 -0800355 nla_total_size(sizeof(struct nlattr)) +
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800356 nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS +
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800357 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800358 nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -0800359 nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -0800360 nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800361 nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800362 nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -0800363 nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800364 nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -0800365 nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -0800366 nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -0800367 nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -0800368 nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -0800369 nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -0800370 nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */
sfeldma@cumulusnetworks.com4ee7ac72014-01-03 14:18:56 -0800371 nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */
372 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */
373 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */
374 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */
375 nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/
376 nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800377 0;
Jiri Pirko90af2312013-10-18 17:43:38 +0200378}
379
380static int bond_fill_info(struct sk_buff *skb,
381 const struct net_device *bond_dev)
382{
383 struct bonding *bond = netdev_priv(bond_dev);
Jiri Pirkoec76aa42013-10-18 17:43:39 +0200384 struct net_device *slave_dev = bond_option_active_slave_get(bond);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800385 struct nlattr *targets;
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -0800386 unsigned int packets_per_slave;
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800387 int i, targets_added;
Jiri Pirko90af2312013-10-18 17:43:38 +0200388
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800389 if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode))
Jiri Pirko90af2312013-10-18 17:43:38 +0200390 goto nla_put_failure;
sfeldma@cumulusnetworks.comeecdaa62013-12-12 14:09:55 -0800391
392 if (slave_dev &&
393 nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex))
394 goto nla_put_failure;
395
396 if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon))
397 goto nla_put_failure;
398
sfeldma@cumulusnetworks.com25852e22013-12-12 14:10:02 -0800399 if (nla_put_u32(skb, IFLA_BOND_UPDELAY,
400 bond->params.updelay * bond->params.miimon))
401 goto nla_put_failure;
402
sfeldma@cumulusnetworks.comc7461f92013-12-12 14:10:09 -0800403 if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY,
404 bond->params.downdelay * bond->params.miimon))
405 goto nla_put_failure;
406
sfeldma@cumulusnetworks.com9f53e142013-12-12 14:10:16 -0800407 if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier))
408 goto nla_put_failure;
409
sfeldma@cumulusnetworks.com06151db2013-12-12 14:10:24 -0800410 if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval))
411 goto nla_put_failure;
412
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800413 targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET);
414 if (!targets)
415 goto nla_put_failure;
416
417 targets_added = 0;
418 for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) {
419 if (bond->params.arp_targets[i]) {
Jiri Pirkoe7ef9412013-12-14 12:32:10 +0100420 nla_put_be32(skb, i, bond->params.arp_targets[i]);
sfeldma@cumulusnetworks.com7f28fa12013-12-12 14:10:31 -0800421 targets_added = 1;
422 }
423 }
424
425 if (targets_added)
426 nla_nest_end(skb, targets);
427 else
428 nla_nest_cancel(skb, targets);
429
sfeldma@cumulusnetworks.com29c49482013-12-12 14:10:38 -0800430 if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate))
431 goto nla_put_failure;
432
sfeldma@cumulusnetworks.comd5c84252013-12-12 14:10:45 -0800433 if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS,
434 bond->params.arp_all_targets))
435 goto nla_put_failure;
436
sfeldma@cumulusnetworks.com0a98a0d2013-12-15 16:41:51 -0800437 if (bond->primary_slave &&
438 nla_put_u32(skb, IFLA_BOND_PRIMARY,
439 bond->primary_slave->dev->ifindex))
440 goto nla_put_failure;
441
sfeldma@cumulusnetworks.com8a41ae42013-12-15 16:41:58 -0800442 if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT,
443 bond->params.primary_reselect))
444 goto nla_put_failure;
445
sfeldma@cumulusnetworks.com89901972013-12-15 16:42:05 -0800446 if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC,
447 bond->params.fail_over_mac))
448 goto nla_put_failure;
449
sfeldma@cumulusnetworks.comf70161c2013-12-15 16:42:12 -0800450 if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY,
451 bond->params.xmit_policy))
452 goto nla_put_failure;
453
sfeldma@cumulusnetworks.comd8838de72013-12-15 16:42:19 -0800454 if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP,
455 bond->params.resend_igmp))
456 goto nla_put_failure;
457
sfeldma@cumulusnetworks.com2c9839c2013-12-17 21:30:09 -0800458 if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF,
459 bond->params.num_peer_notif))
460 goto nla_put_failure;
461
sfeldma@cumulusnetworks.com1cc0b1e2013-12-17 21:30:16 -0800462 if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE,
463 bond->params.all_slaves_active))
464 goto nla_put_failure;
465
sfeldma@cumulusnetworks.com7d101002013-12-17 21:30:23 -0800466 if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS,
467 bond->params.min_links))
468 goto nla_put_failure;
469
sfeldma@cumulusnetworks.com8d836d02013-12-17 21:30:30 -0800470 if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL,
471 bond->params.lp_interval))
472 goto nla_put_failure;
473
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -0800474 packets_per_slave = bond->params.packets_per_slave;
sfeldma@cumulusnetworks.comc13ab3f2013-12-17 21:30:37 -0800475 if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE,
476 packets_per_slave))
477 goto nla_put_failure;
478
sfeldma@cumulusnetworks.com998e40bb2014-01-03 14:18:41 -0800479 if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE,
480 bond->params.lacp_fast))
481 goto nla_put_failure;
482
sfeldma@cumulusnetworks.comec029fa2014-01-03 14:18:49 -0800483 if (nla_put_u8(skb, IFLA_BOND_AD_SELECT,
484 bond->params.ad_select))
485 goto nla_put_failure;
486
sfeldma@cumulusnetworks.com4ee7ac72014-01-03 14:18:56 -0800487 if (bond->params.mode == BOND_MODE_8023AD) {
488 struct ad_info info;
489
490 if (!bond_3ad_get_active_agg_info(bond, &info)) {
491 struct nlattr *nest;
492
493 nest = nla_nest_start(skb, IFLA_BOND_AD_INFO);
494 if (!nest)
495 goto nla_put_failure;
496
497 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR,
498 info.aggregator_id))
499 goto nla_put_failure;
500 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS,
501 info.ports))
502 goto nla_put_failure;
503 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY,
504 info.actor_key))
505 goto nla_put_failure;
506 if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY,
507 info.partner_key))
508 goto nla_put_failure;
509 if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC,
510 sizeof(info.partner_system),
511 &info.partner_system))
512 goto nla_put_failure;
513
514 nla_nest_end(skb, nest);
515 }
516 }
517
Jiri Pirko90af2312013-10-18 17:43:38 +0200518 return 0;
519
520nla_put_failure:
521 return -EMSGSIZE;
522}
523
Jiri Pirko0a2a78c2013-10-18 17:43:33 +0200524struct rtnl_link_ops bond_link_ops __read_mostly = {
525 .kind = "bond",
526 .priv_size = sizeof(struct bonding),
527 .setup = bond_setup,
Jiri Pirko90af2312013-10-18 17:43:38 +0200528 .maxtype = IFLA_BOND_MAX,
529 .policy = bond_policy,
Jiri Pirko0a2a78c2013-10-18 17:43:33 +0200530 .validate = bond_validate,
Jiri Pirko90af2312013-10-18 17:43:38 +0200531 .newlink = bond_newlink,
532 .changelink = bond_changelink,
533 .get_size = bond_get_size,
534 .fill_info = bond_fill_info,
Jiri Pirko0a2a78c2013-10-18 17:43:33 +0200535 .get_num_tx_queues = bond_get_num_tx_queues,
536 .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number
537 as for TX queues */
538};
539
540int __init bond_netlink_init(void)
541{
542 return rtnl_link_register(&bond_link_ops);
543}
544
David S. Millera729e832013-10-19 19:09:18 -0400545void bond_netlink_fini(void)
Jiri Pirko0a2a78c2013-10-18 17:43:33 +0200546{
547 rtnl_link_unregister(&bond_link_ops);
548}
549
550MODULE_ALIAS_RTNL_LINK("bond");