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