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