Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/bond/bond_netlink.c - Netlink interface for bonding |
| 3 | * Copyright (c) 2013 Jiri Pirko <jiri@resnulli.us> |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 4 | * Copyright (c) 2013 Scott Feldman <sfeldma@cumulusnetworks.com> |
Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | */ |
| 11 | |
| 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/netdevice.h> |
| 17 | #include <linux/etherdevice.h> |
| 18 | #include <linux/if_link.h> |
| 19 | #include <linux/if_ether.h> |
| 20 | #include <net/netlink.h> |
| 21 | #include <net/rtnetlink.h> |
| 22 | #include "bonding.h" |
| 23 | |
sfeldma@cumulusnetworks.com | 1d3ee88 | 2014-01-16 22:57:56 -0800 | [diff] [blame] | 24 | int 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 | |
| 56 | nla_put_failure: |
| 57 | return -EMSGSIZE; |
| 58 | } |
| 59 | |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 60 | static const struct nla_policy bond_policy[IFLA_BOND_MAX + 1] = { |
| 61 | [IFLA_BOND_MODE] = { .type = NLA_U8 }, |
Jiri Pirko | ec76aa4 | 2013-10-18 17:43:39 +0200 | [diff] [blame] | 62 | [IFLA_BOND_ACTIVE_SLAVE] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 63 | [IFLA_BOND_MIIMON] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 64 | [IFLA_BOND_UPDELAY] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 65 | [IFLA_BOND_DOWNDELAY] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 66 | [IFLA_BOND_USE_CARRIER] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 67 | [IFLA_BOND_ARP_INTERVAL] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 68 | [IFLA_BOND_ARP_IP_TARGET] = { .type = NLA_NESTED }, |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 69 | [IFLA_BOND_ARP_VALIDATE] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 70 | [IFLA_BOND_ARP_ALL_TARGETS] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 71 | [IFLA_BOND_PRIMARY] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 72 | [IFLA_BOND_PRIMARY_RESELECT] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 73 | [IFLA_BOND_FAIL_OVER_MAC] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 74 | [IFLA_BOND_XMIT_HASH_POLICY] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 75 | [IFLA_BOND_RESEND_IGMP] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 76 | [IFLA_BOND_NUM_PEER_NOTIF] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 77 | [IFLA_BOND_ALL_SLAVES_ACTIVE] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 78 | [IFLA_BOND_MIN_LINKS] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 79 | [IFLA_BOND_LP_INTERVAL] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 80 | [IFLA_BOND_PACKETS_PER_SLAVE] = { .type = NLA_U32 }, |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 81 | [IFLA_BOND_AD_LACP_RATE] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 82 | [IFLA_BOND_AD_SELECT] = { .type = NLA_U8 }, |
sfeldma@cumulusnetworks.com | 4ee7ac7 | 2014-01-03 14:18:56 -0800 | [diff] [blame] | 83 | [IFLA_BOND_AD_INFO] = { .type = NLA_NESTED }, |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 84 | }; |
| 85 | |
Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 86 | static 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 Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 97 | static 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 Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 101 | struct bond_opt_value newval; |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 102 | int miimon = 0; |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 103 | int err; |
| 104 | |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 105 | if (!data) |
| 106 | return 0; |
| 107 | |
| 108 | if (data[IFLA_BOND_MODE]) { |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 109 | int mode = nla_get_u8(data[IFLA_BOND_MODE]); |
| 110 | |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 111 | bond_opt_initval(&newval, mode); |
| 112 | err = __bond_opt_set(bond, BOND_OPT_MODE, &newval); |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 113 | if (err) |
| 114 | return err; |
| 115 | } |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 116 | if (data[IFLA_BOND_ACTIVE_SLAVE]) { |
Jiri Pirko | ec76aa4 | 2013-10-18 17:43:39 +0200 | [diff] [blame] | 117 | 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.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 132 | if (data[IFLA_BOND_MIIMON]) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 133 | miimon = nla_get_u32(data[IFLA_BOND_MIIMON]); |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 134 | |
| 135 | err = bond_option_miimon_set(bond, miimon); |
| 136 | if (err) |
| 137 | return err; |
| 138 | } |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 139 | if (data[IFLA_BOND_UPDELAY]) { |
| 140 | int updelay = nla_get_u32(data[IFLA_BOND_UPDELAY]); |
| 141 | |
| 142 | err = bond_option_updelay_set(bond, updelay); |
| 143 | if (err) |
| 144 | return err; |
| 145 | } |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 146 | if (data[IFLA_BOND_DOWNDELAY]) { |
| 147 | int downdelay = nla_get_u32(data[IFLA_BOND_DOWNDELAY]); |
| 148 | |
| 149 | err = bond_option_downdelay_set(bond, downdelay); |
| 150 | if (err) |
| 151 | return err; |
| 152 | } |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 153 | if (data[IFLA_BOND_USE_CARRIER]) { |
| 154 | int use_carrier = nla_get_u8(data[IFLA_BOND_USE_CARRIER]); |
| 155 | |
| 156 | err = bond_option_use_carrier_set(bond, use_carrier); |
| 157 | if (err) |
| 158 | return err; |
| 159 | } |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 160 | if (data[IFLA_BOND_ARP_INTERVAL]) { |
| 161 | int arp_interval = nla_get_u32(data[IFLA_BOND_ARP_INTERVAL]); |
| 162 | |
| 163 | if (arp_interval && miimon) { |
| 164 | pr_err("%s: ARP monitoring cannot be used with MII monitoring.\n", |
| 165 | bond->dev->name); |
| 166 | return -EINVAL; |
| 167 | } |
| 168 | |
| 169 | err = bond_option_arp_interval_set(bond, arp_interval); |
| 170 | if (err) |
| 171 | return err; |
| 172 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 173 | if (data[IFLA_BOND_ARP_IP_TARGET]) { |
| 174 | __be32 targets[BOND_MAX_ARP_TARGETS] = { 0, }; |
| 175 | struct nlattr *attr; |
| 176 | int i = 0, rem; |
| 177 | |
| 178 | nla_for_each_nested(attr, data[IFLA_BOND_ARP_IP_TARGET], rem) { |
Jiri Pirko | e7ef941 | 2013-12-14 12:32:10 +0100 | [diff] [blame] | 179 | __be32 target = nla_get_be32(attr); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 180 | targets[i++] = target; |
| 181 | } |
| 182 | |
| 183 | err = bond_option_arp_ip_targets_set(bond, targets, i); |
| 184 | if (err) |
| 185 | return err; |
| 186 | } |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 187 | if (data[IFLA_BOND_ARP_VALIDATE]) { |
| 188 | int arp_validate = nla_get_u32(data[IFLA_BOND_ARP_VALIDATE]); |
| 189 | |
| 190 | if (arp_validate && miimon) { |
| 191 | pr_err("%s: ARP validating cannot be used with MII monitoring.\n", |
| 192 | bond->dev->name); |
| 193 | return -EINVAL; |
| 194 | } |
| 195 | |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame^] | 196 | bond_opt_initval(&newval, arp_validate); |
| 197 | err = __bond_opt_set(bond, BOND_OPT_ARP_VALIDATE, &newval); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 198 | if (err) |
| 199 | return err; |
| 200 | } |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 201 | if (data[IFLA_BOND_ARP_ALL_TARGETS]) { |
| 202 | int arp_all_targets = |
| 203 | nla_get_u32(data[IFLA_BOND_ARP_ALL_TARGETS]); |
| 204 | |
| 205 | err = bond_option_arp_all_targets_set(bond, arp_all_targets); |
| 206 | if (err) |
| 207 | return err; |
| 208 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 209 | if (data[IFLA_BOND_PRIMARY]) { |
| 210 | int ifindex = nla_get_u32(data[IFLA_BOND_PRIMARY]); |
| 211 | struct net_device *dev; |
| 212 | char *primary = ""; |
| 213 | |
| 214 | dev = __dev_get_by_index(dev_net(bond_dev), ifindex); |
| 215 | if (dev) |
| 216 | primary = dev->name; |
| 217 | |
| 218 | err = bond_option_primary_set(bond, primary); |
| 219 | if (err) |
| 220 | return err; |
| 221 | } |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 222 | if (data[IFLA_BOND_PRIMARY_RESELECT]) { |
| 223 | int primary_reselect = |
| 224 | nla_get_u8(data[IFLA_BOND_PRIMARY_RESELECT]); |
| 225 | |
| 226 | err = bond_option_primary_reselect_set(bond, primary_reselect); |
| 227 | if (err) |
| 228 | return err; |
| 229 | } |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 230 | if (data[IFLA_BOND_FAIL_OVER_MAC]) { |
| 231 | int fail_over_mac = |
| 232 | nla_get_u8(data[IFLA_BOND_FAIL_OVER_MAC]); |
| 233 | |
| 234 | err = bond_option_fail_over_mac_set(bond, fail_over_mac); |
| 235 | if (err) |
| 236 | return err; |
| 237 | } |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 238 | if (data[IFLA_BOND_XMIT_HASH_POLICY]) { |
| 239 | int xmit_hash_policy = |
| 240 | nla_get_u8(data[IFLA_BOND_XMIT_HASH_POLICY]); |
| 241 | |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 242 | bond_opt_initval(&newval, xmit_hash_policy); |
| 243 | err = __bond_opt_set(bond, BOND_OPT_XMIT_HASH, &newval); |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 244 | if (err) |
| 245 | return err; |
| 246 | } |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 247 | if (data[IFLA_BOND_RESEND_IGMP]) { |
| 248 | int resend_igmp = |
| 249 | nla_get_u32(data[IFLA_BOND_RESEND_IGMP]); |
| 250 | |
| 251 | err = bond_option_resend_igmp_set(bond, resend_igmp); |
| 252 | if (err) |
| 253 | return err; |
| 254 | } |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 255 | if (data[IFLA_BOND_NUM_PEER_NOTIF]) { |
| 256 | int num_peer_notif = |
| 257 | nla_get_u8(data[IFLA_BOND_NUM_PEER_NOTIF]); |
| 258 | |
| 259 | err = bond_option_num_peer_notif_set(bond, num_peer_notif); |
| 260 | if (err) |
| 261 | return err; |
| 262 | } |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 263 | if (data[IFLA_BOND_ALL_SLAVES_ACTIVE]) { |
| 264 | int all_slaves_active = |
| 265 | nla_get_u8(data[IFLA_BOND_ALL_SLAVES_ACTIVE]); |
| 266 | |
| 267 | err = bond_option_all_slaves_active_set(bond, |
| 268 | all_slaves_active); |
| 269 | if (err) |
| 270 | return err; |
| 271 | } |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 272 | if (data[IFLA_BOND_MIN_LINKS]) { |
| 273 | int min_links = |
| 274 | nla_get_u32(data[IFLA_BOND_MIN_LINKS]); |
| 275 | |
| 276 | err = bond_option_min_links_set(bond, min_links); |
| 277 | if (err) |
| 278 | return err; |
| 279 | } |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 280 | if (data[IFLA_BOND_LP_INTERVAL]) { |
| 281 | int lp_interval = |
| 282 | nla_get_u32(data[IFLA_BOND_LP_INTERVAL]); |
| 283 | |
| 284 | err = bond_option_lp_interval_set(bond, lp_interval); |
| 285 | if (err) |
| 286 | return err; |
| 287 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 288 | if (data[IFLA_BOND_PACKETS_PER_SLAVE]) { |
| 289 | int packets_per_slave = |
| 290 | nla_get_u32(data[IFLA_BOND_PACKETS_PER_SLAVE]); |
| 291 | |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 292 | bond_opt_initval(&newval, packets_per_slave); |
| 293 | err = __bond_opt_set(bond, BOND_OPT_PACKETS_PER_SLAVE, &newval); |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 294 | if (err) |
| 295 | return err; |
| 296 | } |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 297 | if (data[IFLA_BOND_AD_LACP_RATE]) { |
| 298 | int lacp_rate = |
| 299 | nla_get_u8(data[IFLA_BOND_AD_LACP_RATE]); |
| 300 | |
| 301 | err = bond_option_lacp_rate_set(bond, lacp_rate); |
| 302 | if (err) |
| 303 | return err; |
| 304 | } |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 305 | if (data[IFLA_BOND_AD_SELECT]) { |
| 306 | int ad_select = |
| 307 | nla_get_u8(data[IFLA_BOND_AD_SELECT]); |
| 308 | |
| 309 | err = bond_option_ad_select_set(bond, ad_select); |
| 310 | if (err) |
| 311 | return err; |
| 312 | } |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 313 | return 0; |
| 314 | } |
| 315 | |
| 316 | static int bond_newlink(struct net *src_net, struct net_device *bond_dev, |
| 317 | struct nlattr *tb[], struct nlattr *data[]) |
| 318 | { |
| 319 | int err; |
| 320 | |
| 321 | err = bond_changelink(bond_dev, tb, data); |
| 322 | if (err < 0) |
| 323 | return err; |
| 324 | |
| 325 | return register_netdevice(bond_dev); |
| 326 | } |
| 327 | |
| 328 | static size_t bond_get_size(const struct net_device *bond_dev) |
| 329 | { |
Dan Carpenter | e139862 | 2013-11-01 13:18:44 +0300 | [diff] [blame] | 330 | return nla_total_size(sizeof(u8)) + /* IFLA_BOND_MODE */ |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 331 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ACTIVE_SLAVE */ |
| 332 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIIMON */ |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 333 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_UPDELAY */ |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 334 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_DOWNDELAY */ |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 335 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_USE_CARRIER */ |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 336 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_INTERVAL */ |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 337 | /* IFLA_BOND_ARP_IP_TARGET */ |
sfeldma@cumulusnetworks.com | 288db0a | 2014-01-03 14:28:11 -0800 | [diff] [blame] | 338 | nla_total_size(sizeof(struct nlattr)) + |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 339 | nla_total_size(sizeof(u32)) * BOND_MAX_ARP_TARGETS + |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 340 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_VALIDATE */ |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 341 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_ARP_ALL_TARGETS */ |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 342 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_PRIMARY */ |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 343 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_PRIMARY_RESELECT */ |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 344 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_FAIL_OVER_MAC */ |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 345 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_XMIT_HASH_POLICY */ |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 346 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_RESEND_IGMP */ |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 347 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_NUM_PEER_NOTIF */ |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 348 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_ALL_SLAVES_ACTIVE */ |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 349 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_MIN_LINKS */ |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 350 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_LP_INTERVAL */ |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 351 | nla_total_size(sizeof(u32)) + /* IFLA_BOND_PACKETS_PER_SLAVE */ |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 352 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_LACP_RATE */ |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 353 | nla_total_size(sizeof(u8)) + /* IFLA_BOND_AD_SELECT */ |
sfeldma@cumulusnetworks.com | 4ee7ac7 | 2014-01-03 14:18:56 -0800 | [diff] [blame] | 354 | nla_total_size(sizeof(struct nlattr)) + /* IFLA_BOND_AD_INFO */ |
| 355 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_AGGREGATOR */ |
| 356 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_NUM_PORTS */ |
| 357 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_ACTOR_KEY */ |
| 358 | nla_total_size(sizeof(u16)) + /* IFLA_BOND_AD_INFO_PARTNER_KEY*/ |
| 359 | nla_total_size(ETH_ALEN) + /* IFLA_BOND_AD_INFO_PARTNER_MAC*/ |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 360 | 0; |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static int bond_fill_info(struct sk_buff *skb, |
| 364 | const struct net_device *bond_dev) |
| 365 | { |
| 366 | struct bonding *bond = netdev_priv(bond_dev); |
Jiri Pirko | ec76aa4 | 2013-10-18 17:43:39 +0200 | [diff] [blame] | 367 | struct net_device *slave_dev = bond_option_active_slave_get(bond); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 368 | struct nlattr *targets; |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 369 | unsigned int packets_per_slave; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 370 | int i, targets_added; |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 371 | |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 372 | if (nla_put_u8(skb, IFLA_BOND_MODE, bond->params.mode)) |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 373 | goto nla_put_failure; |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 374 | |
| 375 | if (slave_dev && |
| 376 | nla_put_u32(skb, IFLA_BOND_ACTIVE_SLAVE, slave_dev->ifindex)) |
| 377 | goto nla_put_failure; |
| 378 | |
| 379 | if (nla_put_u32(skb, IFLA_BOND_MIIMON, bond->params.miimon)) |
| 380 | goto nla_put_failure; |
| 381 | |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 382 | if (nla_put_u32(skb, IFLA_BOND_UPDELAY, |
| 383 | bond->params.updelay * bond->params.miimon)) |
| 384 | goto nla_put_failure; |
| 385 | |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 386 | if (nla_put_u32(skb, IFLA_BOND_DOWNDELAY, |
| 387 | bond->params.downdelay * bond->params.miimon)) |
| 388 | goto nla_put_failure; |
| 389 | |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 390 | if (nla_put_u8(skb, IFLA_BOND_USE_CARRIER, bond->params.use_carrier)) |
| 391 | goto nla_put_failure; |
| 392 | |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 393 | if (nla_put_u32(skb, IFLA_BOND_ARP_INTERVAL, bond->params.arp_interval)) |
| 394 | goto nla_put_failure; |
| 395 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 396 | targets = nla_nest_start(skb, IFLA_BOND_ARP_IP_TARGET); |
| 397 | if (!targets) |
| 398 | goto nla_put_failure; |
| 399 | |
| 400 | targets_added = 0; |
| 401 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) { |
| 402 | if (bond->params.arp_targets[i]) { |
Jiri Pirko | e7ef941 | 2013-12-14 12:32:10 +0100 | [diff] [blame] | 403 | nla_put_be32(skb, i, bond->params.arp_targets[i]); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 404 | targets_added = 1; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | if (targets_added) |
| 409 | nla_nest_end(skb, targets); |
| 410 | else |
| 411 | nla_nest_cancel(skb, targets); |
| 412 | |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 413 | if (nla_put_u32(skb, IFLA_BOND_ARP_VALIDATE, bond->params.arp_validate)) |
| 414 | goto nla_put_failure; |
| 415 | |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 416 | if (nla_put_u32(skb, IFLA_BOND_ARP_ALL_TARGETS, |
| 417 | bond->params.arp_all_targets)) |
| 418 | goto nla_put_failure; |
| 419 | |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 420 | if (bond->primary_slave && |
| 421 | nla_put_u32(skb, IFLA_BOND_PRIMARY, |
| 422 | bond->primary_slave->dev->ifindex)) |
| 423 | goto nla_put_failure; |
| 424 | |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 425 | if (nla_put_u8(skb, IFLA_BOND_PRIMARY_RESELECT, |
| 426 | bond->params.primary_reselect)) |
| 427 | goto nla_put_failure; |
| 428 | |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 429 | if (nla_put_u8(skb, IFLA_BOND_FAIL_OVER_MAC, |
| 430 | bond->params.fail_over_mac)) |
| 431 | goto nla_put_failure; |
| 432 | |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 433 | if (nla_put_u8(skb, IFLA_BOND_XMIT_HASH_POLICY, |
| 434 | bond->params.xmit_policy)) |
| 435 | goto nla_put_failure; |
| 436 | |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 437 | if (nla_put_u32(skb, IFLA_BOND_RESEND_IGMP, |
| 438 | bond->params.resend_igmp)) |
| 439 | goto nla_put_failure; |
| 440 | |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 441 | if (nla_put_u8(skb, IFLA_BOND_NUM_PEER_NOTIF, |
| 442 | bond->params.num_peer_notif)) |
| 443 | goto nla_put_failure; |
| 444 | |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 445 | if (nla_put_u8(skb, IFLA_BOND_ALL_SLAVES_ACTIVE, |
| 446 | bond->params.all_slaves_active)) |
| 447 | goto nla_put_failure; |
| 448 | |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 449 | if (nla_put_u32(skb, IFLA_BOND_MIN_LINKS, |
| 450 | bond->params.min_links)) |
| 451 | goto nla_put_failure; |
| 452 | |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 453 | if (nla_put_u32(skb, IFLA_BOND_LP_INTERVAL, |
| 454 | bond->params.lp_interval)) |
| 455 | goto nla_put_failure; |
| 456 | |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 457 | packets_per_slave = bond->params.packets_per_slave; |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 458 | if (nla_put_u32(skb, IFLA_BOND_PACKETS_PER_SLAVE, |
| 459 | packets_per_slave)) |
| 460 | goto nla_put_failure; |
| 461 | |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 462 | if (nla_put_u8(skb, IFLA_BOND_AD_LACP_RATE, |
| 463 | bond->params.lacp_fast)) |
| 464 | goto nla_put_failure; |
| 465 | |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 466 | if (nla_put_u8(skb, IFLA_BOND_AD_SELECT, |
| 467 | bond->params.ad_select)) |
| 468 | goto nla_put_failure; |
| 469 | |
sfeldma@cumulusnetworks.com | 4ee7ac7 | 2014-01-03 14:18:56 -0800 | [diff] [blame] | 470 | if (bond->params.mode == BOND_MODE_8023AD) { |
| 471 | struct ad_info info; |
| 472 | |
| 473 | if (!bond_3ad_get_active_agg_info(bond, &info)) { |
| 474 | struct nlattr *nest; |
| 475 | |
| 476 | nest = nla_nest_start(skb, IFLA_BOND_AD_INFO); |
| 477 | if (!nest) |
| 478 | goto nla_put_failure; |
| 479 | |
| 480 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_AGGREGATOR, |
| 481 | info.aggregator_id)) |
| 482 | goto nla_put_failure; |
| 483 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_NUM_PORTS, |
| 484 | info.ports)) |
| 485 | goto nla_put_failure; |
| 486 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_ACTOR_KEY, |
| 487 | info.actor_key)) |
| 488 | goto nla_put_failure; |
| 489 | if (nla_put_u16(skb, IFLA_BOND_AD_INFO_PARTNER_KEY, |
| 490 | info.partner_key)) |
| 491 | goto nla_put_failure; |
| 492 | if (nla_put(skb, IFLA_BOND_AD_INFO_PARTNER_MAC, |
| 493 | sizeof(info.partner_system), |
| 494 | &info.partner_system)) |
| 495 | goto nla_put_failure; |
| 496 | |
| 497 | nla_nest_end(skb, nest); |
| 498 | } |
| 499 | } |
| 500 | |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 501 | return 0; |
| 502 | |
| 503 | nla_put_failure: |
| 504 | return -EMSGSIZE; |
| 505 | } |
| 506 | |
Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 507 | struct rtnl_link_ops bond_link_ops __read_mostly = { |
| 508 | .kind = "bond", |
| 509 | .priv_size = sizeof(struct bonding), |
| 510 | .setup = bond_setup, |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 511 | .maxtype = IFLA_BOND_MAX, |
| 512 | .policy = bond_policy, |
Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 513 | .validate = bond_validate, |
Jiri Pirko | 90af231 | 2013-10-18 17:43:38 +0200 | [diff] [blame] | 514 | .newlink = bond_newlink, |
| 515 | .changelink = bond_changelink, |
| 516 | .get_size = bond_get_size, |
| 517 | .fill_info = bond_fill_info, |
Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 518 | .get_num_tx_queues = bond_get_num_tx_queues, |
| 519 | .get_num_rx_queues = bond_get_num_tx_queues, /* Use the same number |
| 520 | as for TX queues */ |
| 521 | }; |
| 522 | |
| 523 | int __init bond_netlink_init(void) |
| 524 | { |
| 525 | return rtnl_link_register(&bond_link_ops); |
| 526 | } |
| 527 | |
David S. Miller | a729e83 | 2013-10-19 19:09:18 -0400 | [diff] [blame] | 528 | void bond_netlink_fini(void) |
Jiri Pirko | 0a2a78c | 2013-10-18 17:43:33 +0200 | [diff] [blame] | 529 | { |
| 530 | rtnl_link_unregister(&bond_link_ops); |
| 531 | } |
| 532 | |
| 533 | MODULE_ALIAS_RTNL_LINK("bond"); |