Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 1 | /* |
| 2 | * drivers/net/bond/bond_options.c - bonding options |
| 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 | 72be35f | 2013-10-18 17:43:34 +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 | |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 12 | #include <linux/errno.h> |
| 13 | #include <linux/if.h> |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 14 | #include <linux/netdevice.h> |
Mike Galbraith | eb2d4c6 | 2014-02-14 08:21:04 +0100 | [diff] [blame] | 15 | #include <linux/spinlock.h> |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 16 | #include <linux/rcupdate.h> |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 17 | #include <linux/ctype.h> |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 18 | #include <linux/inet.h> |
David S. Miller | 1ef8019 | 2014-11-10 13:27:49 -0500 | [diff] [blame] | 19 | #include <net/bonding.h> |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 20 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 21 | static int bond_option_active_slave_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 22 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 23 | static int bond_option_miimon_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 24 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 25 | static int bond_option_updelay_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 26 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 27 | static int bond_option_downdelay_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 28 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 29 | static int bond_option_use_carrier_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 30 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 31 | static int bond_option_arp_interval_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 32 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 33 | static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target); |
| 34 | static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target); |
| 35 | static int bond_option_arp_ip_targets_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 36 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 37 | static int bond_option_arp_validate_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 38 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 39 | static int bond_option_arp_all_targets_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 40 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 41 | static int bond_option_primary_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 42 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 43 | static int bond_option_primary_reselect_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 44 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 45 | static int bond_option_fail_over_mac_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 46 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 47 | static int bond_option_xmit_hash_policy_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 48 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 49 | static int bond_option_resend_igmp_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 50 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 51 | static int bond_option_num_peer_notif_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 52 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 53 | static int bond_option_all_slaves_active_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 54 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 55 | static int bond_option_min_links_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 56 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 57 | static int bond_option_lp_interval_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 58 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 59 | static int bond_option_pps_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 60 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 61 | static int bond_option_lacp_rate_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 62 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 63 | static int bond_option_ad_select_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 64 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 65 | static int bond_option_queue_id_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 66 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 67 | static int bond_option_mode_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 68 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 69 | static int bond_option_slaves_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 70 | const struct bond_opt_value *newval); |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 71 | static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, |
| 72 | const struct bond_opt_value *newval); |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 73 | |
| 74 | |
| 75 | static const struct bond_opt_value bond_mode_tbl[] = { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 76 | { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT}, |
| 77 | { "active-backup", BOND_MODE_ACTIVEBACKUP, 0}, |
| 78 | { "balance-xor", BOND_MODE_XOR, 0}, |
| 79 | { "broadcast", BOND_MODE_BROADCAST, 0}, |
| 80 | { "802.3ad", BOND_MODE_8023AD, 0}, |
| 81 | { "balance-tlb", BOND_MODE_TLB, 0}, |
| 82 | { "balance-alb", BOND_MODE_ALB, 0}, |
| 83 | { NULL, -1, 0}, |
| 84 | }; |
| 85 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 86 | static const struct bond_opt_value bond_pps_tbl[] = { |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 87 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 88 | { "maxval", USHRT_MAX, BOND_VALFLAG_MAX}, |
| 89 | { NULL, -1, 0}, |
| 90 | }; |
| 91 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 92 | static const struct bond_opt_value bond_xmit_hashtype_tbl[] = { |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 93 | { "layer2", BOND_XMIT_POLICY_LAYER2, BOND_VALFLAG_DEFAULT}, |
| 94 | { "layer3+4", BOND_XMIT_POLICY_LAYER34, 0}, |
| 95 | { "layer2+3", BOND_XMIT_POLICY_LAYER23, 0}, |
| 96 | { "encap2+3", BOND_XMIT_POLICY_ENCAP23, 0}, |
| 97 | { "encap3+4", BOND_XMIT_POLICY_ENCAP34, 0}, |
| 98 | { NULL, -1, 0}, |
| 99 | }; |
| 100 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 101 | static const struct bond_opt_value bond_arp_validate_tbl[] = { |
Veaceslav Falico | 896149f | 2014-02-18 07:48:40 +0100 | [diff] [blame] | 102 | { "none", BOND_ARP_VALIDATE_NONE, BOND_VALFLAG_DEFAULT}, |
| 103 | { "active", BOND_ARP_VALIDATE_ACTIVE, 0}, |
| 104 | { "backup", BOND_ARP_VALIDATE_BACKUP, 0}, |
| 105 | { "all", BOND_ARP_VALIDATE_ALL, 0}, |
| 106 | { "filter", BOND_ARP_FILTER, 0}, |
| 107 | { "filter_active", BOND_ARP_FILTER_ACTIVE, 0}, |
| 108 | { "filter_backup", BOND_ARP_FILTER_BACKUP, 0}, |
| 109 | { NULL, -1, 0}, |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 112 | static const struct bond_opt_value bond_arp_all_targets_tbl[] = { |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 113 | { "any", BOND_ARP_TARGETS_ANY, BOND_VALFLAG_DEFAULT}, |
| 114 | { "all", BOND_ARP_TARGETS_ALL, 0}, |
| 115 | { NULL, -1, 0}, |
| 116 | }; |
| 117 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 118 | static const struct bond_opt_value bond_fail_over_mac_tbl[] = { |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 119 | { "none", BOND_FOM_NONE, BOND_VALFLAG_DEFAULT}, |
| 120 | { "active", BOND_FOM_ACTIVE, 0}, |
| 121 | { "follow", BOND_FOM_FOLLOW, 0}, |
| 122 | { NULL, -1, 0}, |
| 123 | }; |
| 124 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 125 | static const struct bond_opt_value bond_intmax_tbl[] = { |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 126 | { "off", 0, BOND_VALFLAG_DEFAULT}, |
| 127 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, |
Nikolay Aleksandrov | 81c7080 | 2014-05-15 13:35:23 +0200 | [diff] [blame] | 128 | { NULL, -1, 0} |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 131 | static const struct bond_opt_value bond_lacp_rate_tbl[] = { |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 132 | { "slow", AD_LACP_SLOW, 0}, |
| 133 | { "fast", AD_LACP_FAST, 0}, |
| 134 | { NULL, -1, 0}, |
| 135 | }; |
| 136 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 137 | static const struct bond_opt_value bond_ad_select_tbl[] = { |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 138 | { "stable", BOND_AD_STABLE, BOND_VALFLAG_DEFAULT}, |
| 139 | { "bandwidth", BOND_AD_BANDWIDTH, 0}, |
| 140 | { "count", BOND_AD_COUNT, 0}, |
| 141 | { NULL, -1, 0}, |
| 142 | }; |
| 143 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 144 | static const struct bond_opt_value bond_num_peer_notif_tbl[] = { |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 145 | { "off", 0, 0}, |
| 146 | { "maxval", 255, BOND_VALFLAG_MAX}, |
| 147 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 148 | { NULL, -1, 0} |
| 149 | }; |
| 150 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 151 | static const struct bond_opt_value bond_primary_reselect_tbl[] = { |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 152 | { "always", BOND_PRI_RESELECT_ALWAYS, BOND_VALFLAG_DEFAULT}, |
| 153 | { "better", BOND_PRI_RESELECT_BETTER, 0}, |
| 154 | { "failure", BOND_PRI_RESELECT_FAILURE, 0}, |
| 155 | { NULL, -1}, |
| 156 | }; |
| 157 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 158 | static const struct bond_opt_value bond_use_carrier_tbl[] = { |
Nikolay Aleksandrov | 0fff060 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 159 | { "off", 0, 0}, |
| 160 | { "on", 1, BOND_VALFLAG_DEFAULT}, |
| 161 | { NULL, -1, 0} |
| 162 | }; |
| 163 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 164 | static const struct bond_opt_value bond_all_slaves_active_tbl[] = { |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 165 | { "off", 0, BOND_VALFLAG_DEFAULT}, |
| 166 | { "on", 1, 0}, |
| 167 | { NULL, -1, 0} |
| 168 | }; |
| 169 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 170 | static const struct bond_opt_value bond_resend_igmp_tbl[] = { |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 171 | { "off", 0, 0}, |
| 172 | { "maxval", 255, BOND_VALFLAG_MAX}, |
| 173 | { "default", 1, BOND_VALFLAG_DEFAULT}, |
| 174 | { NULL, -1, 0} |
| 175 | }; |
| 176 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 177 | static const struct bond_opt_value bond_lp_interval_tbl[] = { |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 178 | { "minval", 1, BOND_VALFLAG_MIN | BOND_VALFLAG_DEFAULT}, |
| 179 | { "maxval", INT_MAX, BOND_VALFLAG_MAX}, |
Sasha Levin | 5bd4e4c | 2014-03-06 16:53:11 -0500 | [diff] [blame] | 180 | { NULL, -1, 0}, |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 181 | }; |
| 182 | |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 183 | static const struct bond_opt_value bond_tlb_dynamic_lb_tbl[] = { |
| 184 | { "off", 0, 0}, |
| 185 | { "on", 1, BOND_VALFLAG_DEFAULT}, |
| 186 | { NULL, -1, 0} |
| 187 | }; |
| 188 | |
Jonathan Toppins | 7bfa014 | 2015-01-09 13:31:08 -0500 | [diff] [blame] | 189 | static const struct bond_option bond_opts[BOND_OPT_LAST] = { |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 190 | [BOND_OPT_MODE] = { |
| 191 | .id = BOND_OPT_MODE, |
| 192 | .name = "mode", |
| 193 | .desc = "bond device mode", |
| 194 | .flags = BOND_OPTFLAG_NOSLAVES | BOND_OPTFLAG_IFDOWN, |
| 195 | .values = bond_mode_tbl, |
| 196 | .set = bond_option_mode_set |
| 197 | }, |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 198 | [BOND_OPT_PACKETS_PER_SLAVE] = { |
| 199 | .id = BOND_OPT_PACKETS_PER_SLAVE, |
| 200 | .name = "packets_per_slave", |
| 201 | .desc = "Packets to send per slave in RR mode", |
| 202 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ROUNDROBIN)), |
| 203 | .values = bond_pps_tbl, |
| 204 | .set = bond_option_pps_set |
| 205 | }, |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 206 | [BOND_OPT_XMIT_HASH] = { |
| 207 | .id = BOND_OPT_XMIT_HASH, |
| 208 | .name = "xmit_hash_policy", |
Mahesh Bandewar | f05b42e | 2014-04-22 16:30:20 -0700 | [diff] [blame] | 209 | .desc = "balance-xor, 802.3ad, and tlb hashing method", |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 210 | .values = bond_xmit_hashtype_tbl, |
| 211 | .set = bond_option_xmit_hash_policy_set |
| 212 | }, |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 213 | [BOND_OPT_ARP_VALIDATE] = { |
| 214 | .id = BOND_OPT_ARP_VALIDATE, |
| 215 | .name = "arp_validate", |
| 216 | .desc = "validate src/dst of ARP probes", |
Veaceslav Falico | 13ac34a | 2014-02-18 07:48:37 +0100 | [diff] [blame] | 217 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | |
| 218 | BIT(BOND_MODE_ALB), |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 219 | .values = bond_arp_validate_tbl, |
| 220 | .set = bond_option_arp_validate_set |
| 221 | }, |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 222 | [BOND_OPT_ARP_ALL_TARGETS] = { |
| 223 | .id = BOND_OPT_ARP_ALL_TARGETS, |
| 224 | .name = "arp_all_targets", |
| 225 | .desc = "fail on any/all arp targets timeout", |
| 226 | .values = bond_arp_all_targets_tbl, |
| 227 | .set = bond_option_arp_all_targets_set |
| 228 | }, |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 229 | [BOND_OPT_FAIL_OVER_MAC] = { |
| 230 | .id = BOND_OPT_FAIL_OVER_MAC, |
| 231 | .name = "fail_over_mac", |
| 232 | .desc = "For active-backup, do not set all slaves to the same MAC", |
| 233 | .flags = BOND_OPTFLAG_NOSLAVES, |
| 234 | .values = bond_fail_over_mac_tbl, |
| 235 | .set = bond_option_fail_over_mac_set |
| 236 | }, |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 237 | [BOND_OPT_ARP_INTERVAL] = { |
| 238 | .id = BOND_OPT_ARP_INTERVAL, |
| 239 | .name = "arp_interval", |
| 240 | .desc = "arp interval in milliseconds", |
| 241 | .unsuppmodes = BIT(BOND_MODE_8023AD) | BIT(BOND_MODE_TLB) | |
| 242 | BIT(BOND_MODE_ALB), |
| 243 | .values = bond_intmax_tbl, |
| 244 | .set = bond_option_arp_interval_set |
| 245 | }, |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 246 | [BOND_OPT_ARP_TARGETS] = { |
| 247 | .id = BOND_OPT_ARP_TARGETS, |
| 248 | .name = "arp_ip_target", |
| 249 | .desc = "arp targets in n.n.n.n form", |
| 250 | .flags = BOND_OPTFLAG_RAWVAL, |
| 251 | .set = bond_option_arp_ip_targets_set |
| 252 | }, |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 253 | [BOND_OPT_DOWNDELAY] = { |
| 254 | .id = BOND_OPT_DOWNDELAY, |
| 255 | .name = "downdelay", |
| 256 | .desc = "Delay before considering link down, in milliseconds", |
| 257 | .values = bond_intmax_tbl, |
| 258 | .set = bond_option_downdelay_set |
| 259 | }, |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 260 | [BOND_OPT_UPDELAY] = { |
| 261 | .id = BOND_OPT_UPDELAY, |
| 262 | .name = "updelay", |
| 263 | .desc = "Delay before considering link up, in milliseconds", |
| 264 | .values = bond_intmax_tbl, |
| 265 | .set = bond_option_updelay_set |
| 266 | }, |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 267 | [BOND_OPT_LACP_RATE] = { |
| 268 | .id = BOND_OPT_LACP_RATE, |
| 269 | .name = "lacp_rate", |
| 270 | .desc = "LACPDU tx rate to request from 802.3ad partner", |
| 271 | .flags = BOND_OPTFLAG_IFDOWN, |
| 272 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_8023AD)), |
| 273 | .values = bond_lacp_rate_tbl, |
| 274 | .set = bond_option_lacp_rate_set |
| 275 | }, |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 276 | [BOND_OPT_MINLINKS] = { |
| 277 | .id = BOND_OPT_MINLINKS, |
| 278 | .name = "min_links", |
| 279 | .desc = "Minimum number of available links before turning on carrier", |
| 280 | .values = bond_intmax_tbl, |
| 281 | .set = bond_option_min_links_set |
| 282 | }, |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 283 | [BOND_OPT_AD_SELECT] = { |
| 284 | .id = BOND_OPT_AD_SELECT, |
| 285 | .name = "ad_select", |
| 286 | .desc = "803.ad aggregation selection logic", |
| 287 | .flags = BOND_OPTFLAG_IFDOWN, |
| 288 | .values = bond_ad_select_tbl, |
| 289 | .set = bond_option_ad_select_set |
| 290 | }, |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 291 | [BOND_OPT_NUM_PEER_NOTIF] = { |
| 292 | .id = BOND_OPT_NUM_PEER_NOTIF, |
| 293 | .name = "num_unsol_na", |
| 294 | .desc = "Number of peer notifications to send on failover event", |
| 295 | .values = bond_num_peer_notif_tbl, |
| 296 | .set = bond_option_num_peer_notif_set |
| 297 | }, |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 298 | [BOND_OPT_MIIMON] = { |
| 299 | .id = BOND_OPT_MIIMON, |
| 300 | .name = "miimon", |
| 301 | .desc = "Link check interval in milliseconds", |
| 302 | .values = bond_intmax_tbl, |
| 303 | .set = bond_option_miimon_set |
| 304 | }, |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 305 | [BOND_OPT_PRIMARY] = { |
| 306 | .id = BOND_OPT_PRIMARY, |
| 307 | .name = "primary", |
| 308 | .desc = "Primary network device to use", |
| 309 | .flags = BOND_OPTFLAG_RAWVAL, |
| 310 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | |
| 311 | BIT(BOND_MODE_TLB) | |
| 312 | BIT(BOND_MODE_ALB)), |
| 313 | .set = bond_option_primary_set |
| 314 | }, |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 315 | [BOND_OPT_PRIMARY_RESELECT] = { |
| 316 | .id = BOND_OPT_PRIMARY_RESELECT, |
| 317 | .name = "primary_reselect", |
| 318 | .desc = "Reselect primary slave once it comes up", |
| 319 | .values = bond_primary_reselect_tbl, |
| 320 | .set = bond_option_primary_reselect_set |
| 321 | }, |
Nikolay Aleksandrov | 0fff060 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 322 | [BOND_OPT_USE_CARRIER] = { |
| 323 | .id = BOND_OPT_USE_CARRIER, |
| 324 | .name = "use_carrier", |
| 325 | .desc = "Use netif_carrier_ok (vs MII ioctls) in miimon", |
| 326 | .values = bond_use_carrier_tbl, |
| 327 | .set = bond_option_use_carrier_set |
| 328 | }, |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 329 | [BOND_OPT_ACTIVE_SLAVE] = { |
| 330 | .id = BOND_OPT_ACTIVE_SLAVE, |
| 331 | .name = "active_slave", |
| 332 | .desc = "Currently active slave", |
| 333 | .flags = BOND_OPTFLAG_RAWVAL, |
| 334 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_ACTIVEBACKUP) | |
| 335 | BIT(BOND_MODE_TLB) | |
| 336 | BIT(BOND_MODE_ALB)), |
| 337 | .set = bond_option_active_slave_set |
| 338 | }, |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 339 | [BOND_OPT_QUEUE_ID] = { |
| 340 | .id = BOND_OPT_QUEUE_ID, |
| 341 | .name = "queue_id", |
| 342 | .desc = "Set queue id of a slave", |
| 343 | .flags = BOND_OPTFLAG_RAWVAL, |
| 344 | .set = bond_option_queue_id_set |
| 345 | }, |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 346 | [BOND_OPT_ALL_SLAVES_ACTIVE] = { |
| 347 | .id = BOND_OPT_ALL_SLAVES_ACTIVE, |
| 348 | .name = "all_slaves_active", |
| 349 | .desc = "Keep all frames received on an interface by setting active flag for all slaves", |
| 350 | .values = bond_all_slaves_active_tbl, |
| 351 | .set = bond_option_all_slaves_active_set |
| 352 | }, |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 353 | [BOND_OPT_RESEND_IGMP] = { |
| 354 | .id = BOND_OPT_RESEND_IGMP, |
| 355 | .name = "resend_igmp", |
| 356 | .desc = "Number of IGMP membership reports to send on link failure", |
| 357 | .values = bond_resend_igmp_tbl, |
| 358 | .set = bond_option_resend_igmp_set |
| 359 | }, |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 360 | [BOND_OPT_LP_INTERVAL] = { |
| 361 | .id = BOND_OPT_LP_INTERVAL, |
| 362 | .name = "lp_interval", |
| 363 | .desc = "The number of seconds between instances where the bonding driver sends learning packets to each slave's peer switch", |
| 364 | .values = bond_lp_interval_tbl, |
| 365 | .set = bond_option_lp_interval_set |
| 366 | }, |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 367 | [BOND_OPT_SLAVES] = { |
| 368 | .id = BOND_OPT_SLAVES, |
| 369 | .name = "slaves", |
| 370 | .desc = "Slave membership management", |
| 371 | .flags = BOND_OPTFLAG_RAWVAL, |
| 372 | .set = bond_option_slaves_set |
| 373 | }, |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 374 | [BOND_OPT_TLB_DYNAMIC_LB] = { |
| 375 | .id = BOND_OPT_TLB_DYNAMIC_LB, |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 376 | .name = "tlb_dynamic_lb", |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 377 | .desc = "Enable dynamic flow shuffling", |
| 378 | .unsuppmodes = BOND_MODE_ALL_EX(BIT(BOND_MODE_TLB)), |
| 379 | .values = bond_tlb_dynamic_lb_tbl, |
| 380 | .flags = BOND_OPTFLAG_IFDOWN, |
| 381 | .set = bond_option_tlb_dynamic_lb_set, |
Jonathan Toppins | 7bfa014 | 2015-01-09 13:31:08 -0500 | [diff] [blame] | 382 | } |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 383 | }; |
| 384 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 385 | /* Searches for an option by name */ |
| 386 | const struct bond_option *bond_opt_get_by_name(const char *name) |
| 387 | { |
| 388 | const struct bond_option *opt; |
| 389 | int option; |
| 390 | |
| 391 | for (option = 0; option < BOND_OPT_LAST; option++) { |
| 392 | opt = bond_opt_get(option); |
| 393 | if (opt && !strcmp(opt->name, name)) |
| 394 | return opt; |
| 395 | } |
| 396 | |
| 397 | return NULL; |
| 398 | } |
| 399 | |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 400 | /* Searches for a value in opt's values[] table */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 401 | const struct bond_opt_value *bond_opt_get_val(unsigned int option, u64 val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 402 | { |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 403 | const struct bond_option *opt; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 404 | int i; |
| 405 | |
| 406 | opt = bond_opt_get(option); |
| 407 | if (WARN_ON(!opt)) |
| 408 | return NULL; |
| 409 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 410 | if (opt->values[i].value == val) |
| 411 | return &opt->values[i]; |
| 412 | |
| 413 | return NULL; |
| 414 | } |
| 415 | |
| 416 | /* Searches for a value in opt's values[] table which matches the flagmask */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 417 | static const struct bond_opt_value *bond_opt_get_flags(const struct bond_option *opt, |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 418 | u32 flagmask) |
| 419 | { |
| 420 | int i; |
| 421 | |
| 422 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 423 | if (opt->values[i].flags & flagmask) |
| 424 | return &opt->values[i]; |
| 425 | |
| 426 | return NULL; |
| 427 | } |
| 428 | |
| 429 | /* If maxval is missing then there's no range to check. In case minval is |
| 430 | * missing then it's considered to be 0. |
| 431 | */ |
| 432 | static bool bond_opt_check_range(const struct bond_option *opt, u64 val) |
| 433 | { |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 434 | const struct bond_opt_value *minval, *maxval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 435 | |
| 436 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 437 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 438 | if (!maxval || (minval && val < minval->value) || val > maxval->value) |
| 439 | return false; |
| 440 | |
| 441 | return true; |
| 442 | } |
| 443 | |
| 444 | /** |
| 445 | * bond_opt_parse - parse option value |
| 446 | * @opt: the option to parse against |
| 447 | * @val: value to parse |
| 448 | * |
| 449 | * This function tries to extract the value from @val and check if it's |
| 450 | * a possible match for the option and returns NULL if a match isn't found, |
| 451 | * or the struct_opt_value that matched. It also strips the new line from |
| 452 | * @val->string if it's present. |
| 453 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 454 | const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, |
| 455 | struct bond_opt_value *val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 456 | { |
| 457 | char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 458 | const struct bond_opt_value *tbl; |
| 459 | const struct bond_opt_value *ret = NULL; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 460 | bool checkval; |
| 461 | int i, rv; |
| 462 | |
| 463 | /* No parsing if the option wants a raw val */ |
| 464 | if (opt->flags & BOND_OPTFLAG_RAWVAL) |
| 465 | return val; |
| 466 | |
| 467 | tbl = opt->values; |
| 468 | if (!tbl) |
| 469 | goto out; |
| 470 | |
| 471 | /* ULLONG_MAX is used to bypass string processing */ |
| 472 | checkval = val->value != ULLONG_MAX; |
| 473 | if (!checkval) { |
| 474 | if (!val->string) |
| 475 | goto out; |
| 476 | p = strchr(val->string, '\n'); |
| 477 | if (p) |
| 478 | *p = '\0'; |
| 479 | for (p = val->string; *p; p++) |
| 480 | if (!(isdigit(*p) || isspace(*p))) |
| 481 | break; |
| 482 | /* The following code extracts the string to match or the value |
| 483 | * and sets checkval appropriately |
| 484 | */ |
| 485 | if (*p) { |
| 486 | rv = sscanf(val->string, "%32s", valstr); |
| 487 | } else { |
| 488 | rv = sscanf(val->string, "%llu", &val->value); |
| 489 | checkval = true; |
| 490 | } |
| 491 | if (!rv) |
| 492 | goto out; |
| 493 | } |
| 494 | |
| 495 | for (i = 0; tbl[i].string; i++) { |
| 496 | /* Check for exact match */ |
| 497 | if (checkval) { |
| 498 | if (val->value == tbl[i].value) |
| 499 | ret = &tbl[i]; |
| 500 | } else { |
| 501 | if (!strcmp(valstr, "default") && |
| 502 | (tbl[i].flags & BOND_VALFLAG_DEFAULT)) |
| 503 | ret = &tbl[i]; |
| 504 | |
| 505 | if (!strcmp(valstr, tbl[i].string)) |
| 506 | ret = &tbl[i]; |
| 507 | } |
| 508 | /* Found an exact match */ |
| 509 | if (ret) |
| 510 | goto out; |
| 511 | } |
| 512 | /* Possible range match */ |
| 513 | if (checkval && bond_opt_check_range(opt, val->value)) |
| 514 | ret = val; |
| 515 | out: |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | /* Check opt's dependencies against bond mode and currently set options */ |
| 520 | static int bond_opt_check_deps(struct bonding *bond, |
| 521 | const struct bond_option *opt) |
| 522 | { |
| 523 | struct bond_params *params = &bond->params; |
| 524 | |
| 525 | if (test_bit(params->mode, &opt->unsuppmodes)) |
| 526 | return -EACCES; |
| 527 | if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) |
| 528 | return -ENOTEMPTY; |
| 529 | if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) |
| 530 | return -EBUSY; |
| 531 | |
| 532 | return 0; |
| 533 | } |
| 534 | |
| 535 | static void bond_opt_dep_print(struct bonding *bond, |
| 536 | const struct bond_option *opt) |
| 537 | { |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 538 | const struct bond_opt_value *modeval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 539 | struct bond_params *params; |
| 540 | |
| 541 | params = &bond->params; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 542 | modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 543 | if (test_bit(params->mode, &opt->unsuppmodes)) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 544 | netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n", |
| 545 | opt->name, modeval->string, modeval->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | static void bond_opt_error_interpret(struct bonding *bond, |
| 549 | const struct bond_option *opt, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 550 | int error, const struct bond_opt_value *val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 551 | { |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 552 | const struct bond_opt_value *minval, *maxval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 553 | char *p; |
| 554 | |
| 555 | switch (error) { |
| 556 | case -EINVAL: |
| 557 | if (val) { |
| 558 | if (val->string) { |
| 559 | /* sometimes RAWVAL opts may have new lines */ |
| 560 | p = strchr(val->string, '\n'); |
| 561 | if (p) |
| 562 | *p = '\0'; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 563 | netdev_err(bond->dev, "option %s: invalid value (%s)\n", |
| 564 | opt->name, val->string); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 565 | } else { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 566 | netdev_err(bond->dev, "option %s: invalid value (%llu)\n", |
| 567 | opt->name, val->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 571 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 572 | if (!maxval) |
| 573 | break; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 574 | netdev_err(bond->dev, "option %s: allowed values %llu - %llu\n", |
| 575 | opt->name, minval ? minval->value : 0, maxval->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 576 | break; |
| 577 | case -EACCES: |
| 578 | bond_opt_dep_print(bond, opt); |
| 579 | break; |
| 580 | case -ENOTEMPTY: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 581 | netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n", |
| 582 | opt->name); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 583 | break; |
| 584 | case -EBUSY: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 585 | netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n", |
| 586 | opt->name); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 587 | break; |
| 588 | default: |
| 589 | break; |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | /** |
| 594 | * __bond_opt_set - set a bonding option |
| 595 | * @bond: target bond device |
| 596 | * @option: option to set |
| 597 | * @val: value to set it to |
| 598 | * |
| 599 | * This function is used to change the bond's option value, it can be |
| 600 | * used for both enabling/changing an option and for disabling it. RTNL lock |
| 601 | * must be obtained before calling this function. |
| 602 | */ |
| 603 | int __bond_opt_set(struct bonding *bond, |
| 604 | unsigned int option, struct bond_opt_value *val) |
| 605 | { |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 606 | const struct bond_opt_value *retval = NULL; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 607 | const struct bond_option *opt; |
| 608 | int ret = -ENOENT; |
| 609 | |
| 610 | ASSERT_RTNL(); |
| 611 | |
| 612 | opt = bond_opt_get(option); |
| 613 | if (WARN_ON(!val) || WARN_ON(!opt)) |
| 614 | goto out; |
| 615 | ret = bond_opt_check_deps(bond, opt); |
| 616 | if (ret) |
| 617 | goto out; |
| 618 | retval = bond_opt_parse(opt, val); |
| 619 | if (!retval) { |
| 620 | ret = -EINVAL; |
| 621 | goto out; |
| 622 | } |
| 623 | ret = opt->set(bond, retval); |
| 624 | out: |
| 625 | if (ret) |
| 626 | bond_opt_error_interpret(bond, opt, ret, val); |
Nicolas Dichtel | ed2a80a | 2015-05-13 14:19:42 +0200 | [diff] [blame] | 627 | else if (bond->dev->reg_state == NETREG_REGISTERED) |
Jiri Pirko | d4261e5 | 2014-08-19 16:02:12 +0200 | [diff] [blame] | 628 | call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 629 | |
| 630 | return ret; |
| 631 | } |
| 632 | |
| 633 | /** |
| 634 | * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set |
| 635 | * @bond: target bond device |
| 636 | * @option: option to set |
| 637 | * @buf: value to set it to |
| 638 | * |
| 639 | * This function tries to acquire RTNL without blocking and if successful |
| 640 | * calls __bond_opt_set. It is mainly used for sysfs option manipulation. |
| 641 | */ |
| 642 | int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) |
| 643 | { |
| 644 | struct bond_opt_value optval; |
| 645 | int ret; |
| 646 | |
| 647 | if (!rtnl_trylock()) |
| 648 | return restart_syscall(); |
| 649 | bond_opt_initstr(&optval, buf); |
| 650 | ret = __bond_opt_set(bond, option, &optval); |
| 651 | rtnl_unlock(); |
| 652 | |
| 653 | return ret; |
| 654 | } |
| 655 | |
| 656 | /** |
| 657 | * bond_opt_get - get a pointer to an option |
| 658 | * @option: option for which to return a pointer |
| 659 | * |
| 660 | * This function checks if option is valid and if so returns a pointer |
| 661 | * to its entry in the bond_opts[] option array. |
| 662 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 663 | const struct bond_option *bond_opt_get(unsigned int option) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 664 | { |
| 665 | if (!BOND_OPT_VALID(option)) |
| 666 | return NULL; |
| 667 | |
| 668 | return &bond_opts[option]; |
| 669 | } |
| 670 | |
Nikolay Aleksandrov | ff11d8b | 2014-07-15 16:08:57 +0200 | [diff] [blame] | 671 | static int bond_option_mode_set(struct bonding *bond, |
| 672 | const struct bond_opt_value *newval) |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 673 | { |
Veaceslav Falico | 267bed7 | 2014-05-15 21:39:53 +0200 | [diff] [blame] | 674 | if (!bond_mode_uses_arp(newval->value) && bond->params.arp_interval) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 675 | netdev_info(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n", |
| 676 | newval->string); |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 677 | /* disable arp monitoring */ |
| 678 | bond->params.arp_interval = 0; |
| 679 | /* set miimon to default value */ |
| 680 | bond->params.miimon = BOND_DEFAULT_MIIMON; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 681 | netdev_info(bond->dev, "Setting MII monitoring interval to %d\n", |
| 682 | bond->params.miimon); |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | /* don't cache arp_validate between modes */ |
| 686 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 687 | bond->params.mode = newval->value; |
| 688 | |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 689 | return 0; |
| 690 | } |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 691 | |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 692 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
| 693 | struct slave *slave) |
| 694 | { |
Veaceslav Falico | ec0865a | 2014-05-15 21:39:54 +0200 | [diff] [blame] | 695 | return bond_uses_primary(bond) && slave ? slave->dev : NULL; |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) |
| 699 | { |
| 700 | struct slave *slave = rcu_dereference(bond->curr_active_slave); |
| 701 | |
| 702 | return __bond_option_active_slave_get(bond, slave); |
| 703 | } |
| 704 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 705 | static int bond_option_active_slave_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 706 | const struct bond_opt_value *newval) |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 707 | { |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 708 | char ifname[IFNAMSIZ] = { 0, }; |
| 709 | struct net_device *slave_dev; |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 710 | int ret = 0; |
| 711 | |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 712 | sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */ |
| 713 | if (!strlen(ifname) || newval->string[0] == '\n') { |
| 714 | slave_dev = NULL; |
| 715 | } else { |
| 716 | slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 717 | if (!slave_dev) |
| 718 | return -ENODEV; |
| 719 | } |
| 720 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 721 | if (slave_dev) { |
| 722 | if (!netif_is_bond_slave(slave_dev)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 723 | netdev_err(bond->dev, "Device %s is not bonding slave\n", |
| 724 | slave_dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 725 | return -EINVAL; |
| 726 | } |
| 727 | |
| 728 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 729 | netdev_err(bond->dev, "Device %s is not our slave\n", |
| 730 | slave_dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 731 | return -EINVAL; |
| 732 | } |
| 733 | } |
| 734 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 735 | block_netpoll_tx(); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 736 | /* check to see if we are clearing active */ |
| 737 | if (!slave_dev) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 738 | netdev_info(bond->dev, "Clearing current active slave\n"); |
Monam Agarwal | 8800a24 | 2014-03-24 00:00:17 +0530 | [diff] [blame] | 739 | RCU_INIT_POINTER(bond->curr_active_slave, NULL); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 740 | bond_select_active_slave(bond); |
| 741 | } else { |
Nikolay Aleksandrov | 1c72cfdc9 | 2014-09-11 22:49:24 +0200 | [diff] [blame] | 742 | struct slave *old_active = rtnl_dereference(bond->curr_active_slave); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 743 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); |
| 744 | |
| 745 | BUG_ON(!new_active); |
| 746 | |
| 747 | if (new_active == old_active) { |
| 748 | /* do nothing */ |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 749 | netdev_info(bond->dev, "%s is already the current active slave\n", |
| 750 | new_active->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 751 | } else { |
| 752 | if (old_active && (new_active->link == BOND_LINK_UP) && |
Veaceslav Falico | b6adc61 | 2014-05-15 21:39:57 +0200 | [diff] [blame] | 753 | bond_slave_is_up(new_active)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 754 | netdev_info(bond->dev, "Setting %s as active slave\n", |
| 755 | new_active->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 756 | bond_change_active_slave(bond, new_active); |
| 757 | } else { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 758 | netdev_err(bond->dev, "Could not set %s as active slave; either %s is down or the link is down\n", |
| 759 | new_active->dev->name, |
| 760 | new_active->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 761 | ret = -EINVAL; |
| 762 | } |
| 763 | } |
| 764 | } |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 765 | unblock_netpoll_tx(); |
Nikolay Aleksandrov | d1fbd3e | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 766 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 767 | return ret; |
| 768 | } |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 769 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 770 | /* There are two tricky bits here. First, if MII monitoring is activated, then |
| 771 | * we must disable ARP monitoring. Second, if the timer isn't running, we must |
| 772 | * start it. |
| 773 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 774 | static int bond_option_miimon_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 775 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 776 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 777 | netdev_info(bond->dev, "Setting MII monitoring interval to %llu\n", |
| 778 | newval->value); |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 779 | bond->params.miimon = newval->value; |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 780 | if (bond->params.updelay) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 781 | netdev_info(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n", |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 782 | bond->params.updelay * bond->params.miimon); |
| 783 | if (bond->params.downdelay) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 784 | netdev_info(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n", |
| 785 | bond->params.downdelay * bond->params.miimon); |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 786 | if (newval->value && bond->params.arp_interval) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 787 | netdev_info(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitoring...\n"); |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 788 | bond->params.arp_interval = 0; |
| 789 | if (bond->params.arp_validate) |
| 790 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 791 | } |
| 792 | if (bond->dev->flags & IFF_UP) { |
| 793 | /* If the interface is up, we may need to fire off |
| 794 | * the MII timer. If the interface is down, the |
| 795 | * timer will get fired off when the open function |
| 796 | * is called. |
| 797 | */ |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 798 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 799 | cancel_delayed_work_sync(&bond->mii_work); |
| 800 | } else { |
| 801 | cancel_delayed_work_sync(&bond->arp_work); |
| 802 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
| 803 | } |
| 804 | } |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 805 | |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 806 | return 0; |
| 807 | } |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 808 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 809 | /* Set up and down delays. These must be multiples of the |
| 810 | * MII monitoring value, and are stored internally as the multiplier. |
| 811 | * Thus, we must translate to MS for the real world. |
| 812 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 813 | static int bond_option_updelay_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 814 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 815 | { |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 816 | int value = newval->value; |
| 817 | |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 818 | if (!bond->params.miimon) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 819 | netdev_err(bond->dev, "Unable to set up delay as MII monitoring is disabled\n"); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 820 | return -EPERM; |
| 821 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 822 | if ((value % bond->params.miimon) != 0) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 823 | netdev_warn(bond->dev, "up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
| 824 | value, bond->params.miimon, |
| 825 | (value / bond->params.miimon) * |
| 826 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 827 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 828 | bond->params.updelay = value / bond->params.miimon; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 829 | netdev_info(bond->dev, "Setting up delay to %d\n", |
| 830 | bond->params.updelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 831 | |
| 832 | return 0; |
| 833 | } |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 834 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 835 | static int bond_option_downdelay_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 836 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 837 | { |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 838 | int value = newval->value; |
| 839 | |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 840 | if (!bond->params.miimon) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 841 | netdev_err(bond->dev, "Unable to set down delay as MII monitoring is disabled\n"); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 842 | return -EPERM; |
| 843 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 844 | if ((value % bond->params.miimon) != 0) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 845 | netdev_warn(bond->dev, "down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
| 846 | value, bond->params.miimon, |
| 847 | (value / bond->params.miimon) * |
| 848 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 849 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 850 | bond->params.downdelay = value / bond->params.miimon; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 851 | netdev_info(bond->dev, "Setting down delay to %d\n", |
| 852 | bond->params.downdelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 853 | |
| 854 | return 0; |
| 855 | } |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 856 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 857 | static int bond_option_use_carrier_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 858 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 859 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 860 | netdev_info(bond->dev, "Setting use_carrier to %llu\n", |
| 861 | newval->value); |
Nikolay Aleksandrov | 0fff060 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 862 | bond->params.use_carrier = newval->value; |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 863 | |
| 864 | return 0; |
| 865 | } |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 866 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 867 | /* There are two tricky bits here. First, if ARP monitoring is activated, then |
| 868 | * we must disable MII monitoring. Second, if the ARP timer isn't running, |
| 869 | * we must start it. |
| 870 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 871 | static int bond_option_arp_interval_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 872 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 873 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 874 | netdev_info(bond->dev, "Setting ARP monitoring interval to %llu\n", |
| 875 | newval->value); |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 876 | bond->params.arp_interval = newval->value; |
| 877 | if (newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 878 | if (bond->params.miimon) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 879 | netdev_info(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring\n"); |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 880 | bond->params.miimon = 0; |
| 881 | } |
| 882 | if (!bond->params.arp_targets[0]) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 883 | netdev_info(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n"); |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 884 | } |
| 885 | if (bond->dev->flags & IFF_UP) { |
| 886 | /* If the interface is up, we may need to fire off |
| 887 | * the ARP timer. If the interface is down, the |
| 888 | * timer will get fired off when the open function |
| 889 | * is called. |
| 890 | */ |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 891 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 892 | if (bond->params.arp_validate) |
| 893 | bond->recv_probe = NULL; |
| 894 | cancel_delayed_work_sync(&bond->arp_work); |
| 895 | } else { |
| 896 | /* arp_validate can be set only in active-backup mode */ |
Veaceslav Falico | 3fe68df | 2014-02-18 07:48:39 +0100 | [diff] [blame] | 897 | bond->recv_probe = bond_arp_rcv; |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 898 | cancel_delayed_work_sync(&bond->mii_work); |
| 899 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | return 0; |
| 904 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 905 | |
| 906 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, |
| 907 | __be32 target, |
| 908 | unsigned long last_rx) |
| 909 | { |
| 910 | __be32 *targets = bond->params.arp_targets; |
| 911 | struct list_head *iter; |
| 912 | struct slave *slave; |
| 913 | |
| 914 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { |
| 915 | bond_for_each_slave(bond, slave, iter) |
| 916 | slave->target_last_arp_rx[slot] = last_rx; |
| 917 | targets[slot] = target; |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
| 922 | { |
| 923 | __be32 *targets = bond->params.arp_targets; |
| 924 | int ind; |
| 925 | |
Veaceslav Falico | 2807a9f | 2014-05-15 21:39:56 +0200 | [diff] [blame] | 926 | if (!bond_is_ip_target_ok(target)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 927 | netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n", |
| 928 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 929 | return -EINVAL; |
| 930 | } |
| 931 | |
| 932 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 933 | netdev_err(bond->dev, "ARP target %pI4 is already present\n", |
| 934 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 935 | return -EINVAL; |
| 936 | } |
| 937 | |
| 938 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 939 | if (ind == -1) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 940 | netdev_err(bond->dev, "ARP target table is full!\n"); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 941 | return -EINVAL; |
| 942 | } |
| 943 | |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 944 | netdev_info(bond->dev, "Adding ARP target %pI4\n", &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 945 | |
| 946 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); |
| 947 | |
| 948 | return 0; |
| 949 | } |
| 950 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 951 | static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 952 | { |
Nikolay Aleksandrov | 246df7b | 2014-09-09 23:17:02 +0200 | [diff] [blame] | 953 | return _bond_option_arp_ip_target_add(bond, target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 954 | } |
| 955 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 956 | static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 957 | { |
| 958 | __be32 *targets = bond->params.arp_targets; |
| 959 | struct list_head *iter; |
| 960 | struct slave *slave; |
| 961 | unsigned long *targets_rx; |
| 962 | int ind, i; |
| 963 | |
Veaceslav Falico | 2807a9f | 2014-05-15 21:39:56 +0200 | [diff] [blame] | 964 | if (!bond_is_ip_target_ok(target)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 965 | netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n", |
| 966 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 967 | return -EINVAL; |
| 968 | } |
| 969 | |
| 970 | ind = bond_get_targets_ip(targets, target); |
| 971 | if (ind == -1) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 972 | netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n", |
| 973 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 974 | return -EINVAL; |
| 975 | } |
| 976 | |
| 977 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 978 | netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n"); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 979 | |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 980 | netdev_info(bond->dev, "Removing ARP target %pI4\n", &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 981 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 982 | bond_for_each_slave(bond, slave, iter) { |
| 983 | targets_rx = slave->target_last_arp_rx; |
| 984 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 985 | targets_rx[i] = targets_rx[i+1]; |
| 986 | targets_rx[i] = 0; |
| 987 | } |
| 988 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 989 | targets[i] = targets[i+1]; |
| 990 | targets[i] = 0; |
| 991 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 992 | return 0; |
| 993 | } |
| 994 | |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 995 | void bond_option_arp_ip_targets_clear(struct bonding *bond) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 996 | { |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 997 | int i; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 998 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 999 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) |
| 1000 | _bond_options_arp_ip_target_set(bond, i, 0, 0); |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1001 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1002 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1003 | static int bond_option_arp_ip_targets_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1004 | const struct bond_opt_value *newval) |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1005 | { |
| 1006 | int ret = -EPERM; |
| 1007 | __be32 target; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1008 | |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1009 | if (newval->string) { |
| 1010 | if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1011 | netdev_err(bond->dev, "invalid ARP target %pI4 specified\n", |
| 1012 | &target); |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1013 | return ret; |
| 1014 | } |
| 1015 | if (newval->string[0] == '+') |
| 1016 | ret = bond_option_arp_ip_target_add(bond, target); |
| 1017 | else if (newval->string[0] == '-') |
| 1018 | ret = bond_option_arp_ip_target_rem(bond, target); |
| 1019 | else |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1020 | netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n"); |
Nikolay Aleksandrov | 4fb0ef5 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1021 | } else { |
| 1022 | target = newval->value; |
| 1023 | ret = bond_option_arp_ip_target_add(bond, target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1024 | } |
| 1025 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1026 | return ret; |
| 1027 | } |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1028 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1029 | static int bond_option_arp_validate_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1030 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1031 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1032 | netdev_info(bond->dev, "Setting arp_validate to %s (%llu)\n", |
| 1033 | newval->string, newval->value); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1034 | |
| 1035 | if (bond->dev->flags & IFF_UP) { |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1036 | if (!newval->value) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1037 | bond->recv_probe = NULL; |
| 1038 | else if (bond->params.arp_interval) |
| 1039 | bond->recv_probe = bond_arp_rcv; |
| 1040 | } |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1041 | bond->params.arp_validate = newval->value; |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1042 | |
| 1043 | return 0; |
| 1044 | } |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1045 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1046 | static int bond_option_arp_all_targets_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1047 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1048 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1049 | netdev_info(bond->dev, "Setting arp_all_targets to %s (%llu)\n", |
| 1050 | newval->string, newval->value); |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 1051 | bond->params.arp_all_targets = newval->value; |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1052 | |
| 1053 | return 0; |
| 1054 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1055 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1056 | static int bond_option_primary_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1057 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1058 | { |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1059 | char *p, *primary = newval->string; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1060 | struct list_head *iter; |
| 1061 | struct slave *slave; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1062 | |
| 1063 | block_netpoll_tx(); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1064 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1065 | p = strchr(primary, '\n'); |
| 1066 | if (p) |
| 1067 | *p = '\0'; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1068 | /* check to see if we are clearing primary */ |
| 1069 | if (!strlen(primary)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1070 | netdev_info(bond->dev, "Setting primary slave to None\n"); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame] | 1071 | RCU_INIT_POINTER(bond->primary_slave, NULL); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1072 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
| 1073 | bond_select_active_slave(bond); |
| 1074 | goto out; |
| 1075 | } |
| 1076 | |
| 1077 | bond_for_each_slave(bond, slave, iter) { |
| 1078 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1079 | netdev_info(bond->dev, "Setting %s as primary slave\n", |
| 1080 | slave->dev->name); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame] | 1081 | rcu_assign_pointer(bond->primary_slave, slave); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1082 | strcpy(bond->params.primary, slave->dev->name); |
| 1083 | bond_select_active_slave(bond); |
| 1084 | goto out; |
| 1085 | } |
| 1086 | } |
| 1087 | |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame] | 1088 | if (rtnl_dereference(bond->primary_slave)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1089 | netdev_info(bond->dev, "Setting primary slave to None\n"); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame] | 1090 | RCU_INIT_POINTER(bond->primary_slave, NULL); |
dingtianhong | c59ab67 | 2014-01-18 16:28:52 +0800 | [diff] [blame] | 1091 | bond_select_active_slave(bond); |
| 1092 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1093 | strncpy(bond->params.primary, primary, IFNAMSIZ); |
| 1094 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 1095 | |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1096 | netdev_info(bond->dev, "Recording %s as primary, but it has not been enslaved to %s yet\n", |
| 1097 | primary, bond->dev->name); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1098 | |
| 1099 | out: |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1100 | unblock_netpoll_tx(); |
| 1101 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1102 | return 0; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1103 | } |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1104 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1105 | static int bond_option_primary_reselect_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1106 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1107 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1108 | netdev_info(bond->dev, "Setting primary_reselect to %s (%llu)\n", |
| 1109 | newval->string, newval->value); |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 1110 | bond->params.primary_reselect = newval->value; |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1111 | |
| 1112 | block_netpoll_tx(); |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1113 | bond_select_active_slave(bond); |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1114 | unblock_netpoll_tx(); |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1118 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1119 | static int bond_option_fail_over_mac_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1120 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1121 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1122 | netdev_info(bond->dev, "Setting fail_over_mac to %s (%llu)\n", |
| 1123 | newval->string, newval->value); |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 1124 | bond->params.fail_over_mac = newval->value; |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1125 | |
| 1126 | return 0; |
| 1127 | } |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1128 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1129 | static int bond_option_xmit_hash_policy_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1130 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1131 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1132 | netdev_info(bond->dev, "Setting xmit hash policy to %s (%llu)\n", |
| 1133 | newval->string, newval->value); |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 1134 | bond->params.xmit_policy = newval->value; |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1135 | |
| 1136 | return 0; |
| 1137 | } |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1138 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1139 | static int bond_option_resend_igmp_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1140 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1141 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1142 | netdev_info(bond->dev, "Setting resend_igmp to %llu\n", |
| 1143 | newval->value); |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 1144 | bond->params.resend_igmp = newval->value; |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1145 | |
| 1146 | return 0; |
| 1147 | } |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1148 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1149 | static int bond_option_num_peer_notif_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1150 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1151 | { |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 1152 | bond->params.num_peer_notif = newval->value; |
| 1153 | |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1154 | return 0; |
| 1155 | } |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1156 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1157 | static int bond_option_all_slaves_active_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1158 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1159 | { |
| 1160 | struct list_head *iter; |
| 1161 | struct slave *slave; |
| 1162 | |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1163 | if (newval->value == bond->params.all_slaves_active) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1164 | return 0; |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1165 | bond->params.all_slaves_active = newval->value; |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1166 | bond_for_each_slave(bond, slave, iter) { |
| 1167 | if (!bond_is_active_slave(slave)) { |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1168 | if (newval->value) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1169 | slave->inactive = 0; |
| 1170 | else |
| 1171 | slave->inactive = 1; |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1177 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1178 | static int bond_option_min_links_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1179 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1180 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1181 | netdev_info(bond->dev, "Setting min links value to %llu\n", |
| 1182 | newval->value); |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 1183 | bond->params.min_links = newval->value; |
Jonathan Toppins | 2477bc9 | 2015-01-26 01:16:57 -0500 | [diff] [blame] | 1184 | bond_set_carrier(bond); |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1185 | |
| 1186 | return 0; |
| 1187 | } |
sfeldma@cumulusnetworks.com | 8d836d0 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1188 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1189 | static int bond_option_lp_interval_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1190 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8d836d0 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1191 | { |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 1192 | bond->params.lp_interval = newval->value; |
sfeldma@cumulusnetworks.com | 8d836d0 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1193 | |
| 1194 | return 0; |
| 1195 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1196 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1197 | static int bond_option_pps_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1198 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1199 | { |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1200 | bond->params.packets_per_slave = newval->value; |
| 1201 | if (newval->value > 0) { |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1202 | bond->params.reciprocal_packets_per_slave = |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1203 | reciprocal_value(newval->value); |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1204 | } else { |
| 1205 | /* reciprocal_packets_per_slave is unused if |
| 1206 | * packets_per_slave is 0 or 1, just initialize it |
| 1207 | */ |
| 1208 | bond->params.reciprocal_packets_per_slave = |
| 1209 | (struct reciprocal_value) { 0 }; |
| 1210 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1211 | |
| 1212 | return 0; |
| 1213 | } |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1214 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1215 | static int bond_option_lacp_rate_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1216 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1217 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1218 | netdev_info(bond->dev, "Setting LACP rate to %s (%llu)\n", |
| 1219 | newval->string, newval->value); |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 1220 | bond->params.lacp_fast = newval->value; |
sfeldma@cumulusnetworks.com | 3243c47 | 2014-01-03 14:28:18 -0800 | [diff] [blame] | 1221 | bond_3ad_update_lacp_rate(bond); |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1222 | |
| 1223 | return 0; |
| 1224 | } |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1225 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1226 | static int bond_option_ad_select_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1227 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1228 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1229 | netdev_info(bond->dev, "Setting ad_select to %s (%llu)\n", |
| 1230 | newval->string, newval->value); |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 1231 | bond->params.ad_select = newval->value; |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1232 | |
| 1233 | return 0; |
| 1234 | } |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1235 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1236 | static int bond_option_queue_id_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1237 | const struct bond_opt_value *newval) |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1238 | { |
| 1239 | struct slave *slave, *update_slave; |
| 1240 | struct net_device *sdev; |
| 1241 | struct list_head *iter; |
| 1242 | char *delim; |
| 1243 | int ret = 0; |
| 1244 | u16 qid; |
| 1245 | |
| 1246 | /* delim will point to queue id if successful */ |
| 1247 | delim = strchr(newval->string, ':'); |
| 1248 | if (!delim) |
| 1249 | goto err_no_cmd; |
| 1250 | |
| 1251 | /* Terminate string that points to device name and bump it |
| 1252 | * up one, so we can read the queue id there. |
| 1253 | */ |
| 1254 | *delim = '\0'; |
| 1255 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1256 | goto err_no_cmd; |
| 1257 | |
| 1258 | /* Check buffer length, valid ifname and queue id */ |
dingtianhong | c313c89 | 2014-02-12 14:58:50 +0800 | [diff] [blame] | 1259 | if (!dev_valid_name(newval->string) || |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1260 | qid > bond->dev->real_num_tx_queues) |
| 1261 | goto err_no_cmd; |
| 1262 | |
| 1263 | /* Get the pointer to that interface if it exists */ |
| 1264 | sdev = __dev_get_by_name(dev_net(bond->dev), newval->string); |
| 1265 | if (!sdev) |
| 1266 | goto err_no_cmd; |
| 1267 | |
| 1268 | /* Search for thes slave and check for duplicate qids */ |
| 1269 | update_slave = NULL; |
| 1270 | bond_for_each_slave(bond, slave, iter) { |
| 1271 | if (sdev == slave->dev) |
| 1272 | /* We don't need to check the matching |
| 1273 | * slave for dups, since we're overwriting it |
| 1274 | */ |
| 1275 | update_slave = slave; |
| 1276 | else if (qid && qid == slave->queue_id) { |
| 1277 | goto err_no_cmd; |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | if (!update_slave) |
| 1282 | goto err_no_cmd; |
| 1283 | |
| 1284 | /* Actually set the qids for the slave */ |
| 1285 | update_slave->queue_id = qid; |
| 1286 | |
| 1287 | out: |
| 1288 | return ret; |
| 1289 | |
| 1290 | err_no_cmd: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1291 | netdev_info(bond->dev, "invalid input for queue_id set\n"); |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1292 | ret = -EPERM; |
| 1293 | goto out; |
| 1294 | |
| 1295 | } |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1296 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1297 | static int bond_option_slaves_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1298 | const struct bond_opt_value *newval) |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1299 | { |
| 1300 | char command[IFNAMSIZ + 1] = { 0, }; |
| 1301 | struct net_device *dev; |
| 1302 | char *ifname; |
| 1303 | int ret; |
| 1304 | |
| 1305 | sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/ |
| 1306 | ifname = command + 1; |
| 1307 | if ((strlen(command) <= 1) || |
| 1308 | !dev_valid_name(ifname)) |
| 1309 | goto err_no_cmd; |
| 1310 | |
| 1311 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 1312 | if (!dev) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1313 | netdev_info(bond->dev, "interface %s does not exist!\n", |
| 1314 | ifname); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1315 | ret = -ENODEV; |
| 1316 | goto out; |
| 1317 | } |
| 1318 | |
| 1319 | switch (command[0]) { |
| 1320 | case '+': |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1321 | netdev_info(bond->dev, "Adding slave %s\n", dev->name); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1322 | ret = bond_enslave(bond->dev, dev); |
| 1323 | break; |
| 1324 | |
| 1325 | case '-': |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1326 | netdev_info(bond->dev, "Removing slave %s\n", dev->name); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1327 | ret = bond_release(bond->dev, dev); |
| 1328 | break; |
| 1329 | |
| 1330 | default: |
| 1331 | goto err_no_cmd; |
| 1332 | } |
| 1333 | |
| 1334 | out: |
| 1335 | return ret; |
| 1336 | |
| 1337 | err_no_cmd: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1338 | netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n"); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1339 | ret = -EPERM; |
| 1340 | goto out; |
| 1341 | } |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1342 | |
| 1343 | static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, |
| 1344 | const struct bond_opt_value *newval) |
| 1345 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1346 | netdev_info(bond->dev, "Setting dynamic-lb to %s (%llu)\n", |
| 1347 | newval->string, newval->value); |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1348 | bond->params.tlb_dynamic_lb = newval->value; |
| 1349 | |
| 1350 | return 0; |
| 1351 | } |