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