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