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