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