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 | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 18 | #include <linux/inet.h> |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 19 | #include "bonding.h" |
| 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 | 0fff0608 | 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 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 189 | static const struct bond_option bond_opts[] = { |
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 | 4fb0ef58 | 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 | 0fff0608 | 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 | d1fbd3ed | 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, |
| 382 | }, |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 383 | { } |
| 384 | }; |
| 385 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 386 | /* Searches for an option by name */ |
| 387 | const struct bond_option *bond_opt_get_by_name(const char *name) |
| 388 | { |
| 389 | const struct bond_option *opt; |
| 390 | int option; |
| 391 | |
| 392 | for (option = 0; option < BOND_OPT_LAST; option++) { |
| 393 | opt = bond_opt_get(option); |
| 394 | if (opt && !strcmp(opt->name, name)) |
| 395 | return opt; |
| 396 | } |
| 397 | |
| 398 | return NULL; |
| 399 | } |
| 400 | |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 401 | /* Searches for a value in opt's values[] table */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 402 | 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] | 403 | { |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 404 | const struct bond_option *opt; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 405 | int i; |
| 406 | |
| 407 | opt = bond_opt_get(option); |
| 408 | if (WARN_ON(!opt)) |
| 409 | return NULL; |
| 410 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 411 | if (opt->values[i].value == val) |
| 412 | return &opt->values[i]; |
| 413 | |
| 414 | return NULL; |
| 415 | } |
| 416 | |
| 417 | /* 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] | 418 | 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] | 419 | u32 flagmask) |
| 420 | { |
| 421 | int i; |
| 422 | |
| 423 | for (i = 0; opt->values && opt->values[i].string; i++) |
| 424 | if (opt->values[i].flags & flagmask) |
| 425 | return &opt->values[i]; |
| 426 | |
| 427 | return NULL; |
| 428 | } |
| 429 | |
| 430 | /* If maxval is missing then there's no range to check. In case minval is |
| 431 | * missing then it's considered to be 0. |
| 432 | */ |
| 433 | static bool bond_opt_check_range(const struct bond_option *opt, u64 val) |
| 434 | { |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 435 | const struct bond_opt_value *minval, *maxval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 436 | |
| 437 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 438 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 439 | if (!maxval || (minval && val < minval->value) || val > maxval->value) |
| 440 | return false; |
| 441 | |
| 442 | return true; |
| 443 | } |
| 444 | |
| 445 | /** |
| 446 | * bond_opt_parse - parse option value |
| 447 | * @opt: the option to parse against |
| 448 | * @val: value to parse |
| 449 | * |
| 450 | * This function tries to extract the value from @val and check if it's |
| 451 | * a possible match for the option and returns NULL if a match isn't found, |
| 452 | * or the struct_opt_value that matched. It also strips the new line from |
| 453 | * @val->string if it's present. |
| 454 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 455 | const struct bond_opt_value *bond_opt_parse(const struct bond_option *opt, |
| 456 | struct bond_opt_value *val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 457 | { |
| 458 | char *p, valstr[BOND_OPT_MAX_NAMELEN + 1] = { 0, }; |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 459 | const struct bond_opt_value *tbl; |
| 460 | const struct bond_opt_value *ret = NULL; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 461 | bool checkval; |
| 462 | int i, rv; |
| 463 | |
| 464 | /* No parsing if the option wants a raw val */ |
| 465 | if (opt->flags & BOND_OPTFLAG_RAWVAL) |
| 466 | return val; |
| 467 | |
| 468 | tbl = opt->values; |
| 469 | if (!tbl) |
| 470 | goto out; |
| 471 | |
| 472 | /* ULLONG_MAX is used to bypass string processing */ |
| 473 | checkval = val->value != ULLONG_MAX; |
| 474 | if (!checkval) { |
| 475 | if (!val->string) |
| 476 | goto out; |
| 477 | p = strchr(val->string, '\n'); |
| 478 | if (p) |
| 479 | *p = '\0'; |
| 480 | for (p = val->string; *p; p++) |
| 481 | if (!(isdigit(*p) || isspace(*p))) |
| 482 | break; |
| 483 | /* The following code extracts the string to match or the value |
| 484 | * and sets checkval appropriately |
| 485 | */ |
| 486 | if (*p) { |
| 487 | rv = sscanf(val->string, "%32s", valstr); |
| 488 | } else { |
| 489 | rv = sscanf(val->string, "%llu", &val->value); |
| 490 | checkval = true; |
| 491 | } |
| 492 | if (!rv) |
| 493 | goto out; |
| 494 | } |
| 495 | |
| 496 | for (i = 0; tbl[i].string; i++) { |
| 497 | /* Check for exact match */ |
| 498 | if (checkval) { |
| 499 | if (val->value == tbl[i].value) |
| 500 | ret = &tbl[i]; |
| 501 | } else { |
| 502 | if (!strcmp(valstr, "default") && |
| 503 | (tbl[i].flags & BOND_VALFLAG_DEFAULT)) |
| 504 | ret = &tbl[i]; |
| 505 | |
| 506 | if (!strcmp(valstr, tbl[i].string)) |
| 507 | ret = &tbl[i]; |
| 508 | } |
| 509 | /* Found an exact match */ |
| 510 | if (ret) |
| 511 | goto out; |
| 512 | } |
| 513 | /* Possible range match */ |
| 514 | if (checkval && bond_opt_check_range(opt, val->value)) |
| 515 | ret = val; |
| 516 | out: |
| 517 | return ret; |
| 518 | } |
| 519 | |
| 520 | /* Check opt's dependencies against bond mode and currently set options */ |
| 521 | static int bond_opt_check_deps(struct bonding *bond, |
| 522 | const struct bond_option *opt) |
| 523 | { |
| 524 | struct bond_params *params = &bond->params; |
| 525 | |
| 526 | if (test_bit(params->mode, &opt->unsuppmodes)) |
| 527 | return -EACCES; |
| 528 | if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) |
| 529 | return -ENOTEMPTY; |
| 530 | if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) |
| 531 | return -EBUSY; |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | static void bond_opt_dep_print(struct bonding *bond, |
| 537 | const struct bond_option *opt) |
| 538 | { |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 539 | const struct bond_opt_value *modeval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 540 | struct bond_params *params; |
| 541 | |
| 542 | params = &bond->params; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 543 | modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 544 | if (test_bit(params->mode, &opt->unsuppmodes)) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 545 | netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n", |
| 546 | opt->name, modeval->string, modeval->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static void bond_opt_error_interpret(struct bonding *bond, |
| 550 | const struct bond_option *opt, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 551 | int error, const struct bond_opt_value *val) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 552 | { |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 553 | const struct bond_opt_value *minval, *maxval; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 554 | char *p; |
| 555 | |
| 556 | switch (error) { |
| 557 | case -EINVAL: |
| 558 | if (val) { |
| 559 | if (val->string) { |
| 560 | /* sometimes RAWVAL opts may have new lines */ |
| 561 | p = strchr(val->string, '\n'); |
| 562 | if (p) |
| 563 | *p = '\0'; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 564 | netdev_err(bond->dev, "option %s: invalid value (%s)\n", |
| 565 | opt->name, val->string); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 566 | } else { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 567 | netdev_err(bond->dev, "option %s: invalid value (%llu)\n", |
| 568 | opt->name, val->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | minval = bond_opt_get_flags(opt, BOND_VALFLAG_MIN); |
| 572 | maxval = bond_opt_get_flags(opt, BOND_VALFLAG_MAX); |
| 573 | if (!maxval) |
| 574 | break; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 575 | netdev_err(bond->dev, "option %s: allowed values %llu - %llu\n", |
| 576 | opt->name, minval ? minval->value : 0, maxval->value); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 577 | break; |
| 578 | case -EACCES: |
| 579 | bond_opt_dep_print(bond, opt); |
| 580 | break; |
| 581 | case -ENOTEMPTY: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 582 | netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n", |
| 583 | opt->name); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 584 | break; |
| 585 | case -EBUSY: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 586 | netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n", |
| 587 | opt->name); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 588 | break; |
| 589 | default: |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * __bond_opt_set - set a bonding option |
| 596 | * @bond: target bond device |
| 597 | * @option: option to set |
| 598 | * @val: value to set it to |
| 599 | * |
| 600 | * This function is used to change the bond's option value, it can be |
| 601 | * used for both enabling/changing an option and for disabling it. RTNL lock |
| 602 | * must be obtained before calling this function. |
| 603 | */ |
| 604 | int __bond_opt_set(struct bonding *bond, |
| 605 | unsigned int option, struct bond_opt_value *val) |
| 606 | { |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 607 | const struct bond_opt_value *retval = NULL; |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 608 | const struct bond_option *opt; |
| 609 | int ret = -ENOENT; |
| 610 | |
| 611 | ASSERT_RTNL(); |
| 612 | |
| 613 | opt = bond_opt_get(option); |
| 614 | if (WARN_ON(!val) || WARN_ON(!opt)) |
| 615 | goto out; |
| 616 | ret = bond_opt_check_deps(bond, opt); |
| 617 | if (ret) |
| 618 | goto out; |
| 619 | retval = bond_opt_parse(opt, val); |
| 620 | if (!retval) { |
| 621 | ret = -EINVAL; |
| 622 | goto out; |
| 623 | } |
| 624 | ret = opt->set(bond, retval); |
| 625 | out: |
| 626 | if (ret) |
| 627 | bond_opt_error_interpret(bond, opt, ret, val); |
Jiri Pirko | d4261e5 | 2014-08-19 16:02:12 +0200 | [diff] [blame] | 628 | else |
| 629 | call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev); |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 630 | |
| 631 | return ret; |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set |
| 636 | * @bond: target bond device |
| 637 | * @option: option to set |
| 638 | * @buf: value to set it to |
| 639 | * |
| 640 | * This function tries to acquire RTNL without blocking and if successful |
| 641 | * calls __bond_opt_set. It is mainly used for sysfs option manipulation. |
| 642 | */ |
| 643 | int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) |
| 644 | { |
| 645 | struct bond_opt_value optval; |
| 646 | int ret; |
| 647 | |
| 648 | if (!rtnl_trylock()) |
| 649 | return restart_syscall(); |
| 650 | bond_opt_initstr(&optval, buf); |
| 651 | ret = __bond_opt_set(bond, option, &optval); |
| 652 | rtnl_unlock(); |
| 653 | |
| 654 | return ret; |
| 655 | } |
| 656 | |
| 657 | /** |
| 658 | * bond_opt_get - get a pointer to an option |
| 659 | * @option: option for which to return a pointer |
| 660 | * |
| 661 | * This function checks if option is valid and if so returns a pointer |
| 662 | * to its entry in the bond_opts[] option array. |
| 663 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 664 | const struct bond_option *bond_opt_get(unsigned int option) |
Nikolay Aleksandrov | 0911736 | 2014-01-22 14:53:16 +0100 | [diff] [blame] | 665 | { |
| 666 | if (!BOND_OPT_VALID(option)) |
| 667 | return NULL; |
| 668 | |
| 669 | return &bond_opts[option]; |
| 670 | } |
| 671 | |
Nikolay Aleksandrov | ff11d8b | 2014-07-15 16:08:57 +0200 | [diff] [blame] | 672 | static int bond_option_mode_set(struct bonding *bond, |
| 673 | const struct bond_opt_value *newval) |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 674 | { |
Veaceslav Falico | 267bed7 | 2014-05-15 21:39:53 +0200 | [diff] [blame] | 675 | if (!bond_mode_uses_arp(newval->value) && bond->params.arp_interval) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 676 | netdev_info(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n", |
| 677 | newval->string); |
dingtianhong | fe9d04a | 2013-11-22 22:28:43 +0800 | [diff] [blame] | 678 | /* disable arp monitoring */ |
| 679 | bond->params.arp_interval = 0; |
| 680 | /* set miimon to default value */ |
| 681 | bond->params.miimon = BOND_DEFAULT_MIIMON; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 682 | netdev_info(bond->dev, "Setting MII monitoring interval to %d\n", |
| 683 | bond->params.miimon); |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /* don't cache arp_validate between modes */ |
| 687 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
Nikolay Aleksandrov | 2b3798d | 2014-01-22 14:53:17 +0100 | [diff] [blame] | 688 | bond->params.mode = newval->value; |
| 689 | |
Jiri Pirko | 72be35f | 2013-10-18 17:43:34 +0200 | [diff] [blame] | 690 | return 0; |
| 691 | } |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 692 | |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 693 | static struct net_device *__bond_option_active_slave_get(struct bonding *bond, |
| 694 | struct slave *slave) |
| 695 | { |
Veaceslav Falico | ec0865a | 2014-05-15 21:39:54 +0200 | [diff] [blame] | 696 | return bond_uses_primary(bond) && slave ? slave->dev : NULL; |
Jiri Pirko | 752d48b | 2013-10-18 17:43:37 +0200 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond) |
| 700 | { |
| 701 | struct slave *slave = rcu_dereference(bond->curr_active_slave); |
| 702 | |
| 703 | return __bond_option_active_slave_get(bond, slave); |
| 704 | } |
| 705 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 706 | static int bond_option_active_slave_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 707 | const struct bond_opt_value *newval) |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 708 | { |
Nikolay Aleksandrov | d1fbd3ed | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 709 | char ifname[IFNAMSIZ] = { 0, }; |
| 710 | struct net_device *slave_dev; |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 711 | int ret = 0; |
| 712 | |
Nikolay Aleksandrov | d1fbd3ed | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 713 | sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */ |
| 714 | if (!strlen(ifname) || newval->string[0] == '\n') { |
| 715 | slave_dev = NULL; |
| 716 | } else { |
| 717 | slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 718 | if (!slave_dev) |
| 719 | return -ENODEV; |
| 720 | } |
| 721 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 722 | if (slave_dev) { |
| 723 | if (!netif_is_bond_slave(slave_dev)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 724 | netdev_err(bond->dev, "Device %s is not bonding slave\n", |
| 725 | slave_dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 726 | return -EINVAL; |
| 727 | } |
| 728 | |
| 729 | if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 730 | netdev_err(bond->dev, "Device %s is not our slave\n", |
| 731 | slave_dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 732 | return -EINVAL; |
| 733 | } |
| 734 | } |
| 735 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 736 | block_netpoll_tx(); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 737 | write_lock_bh(&bond->curr_slave_lock); |
| 738 | |
| 739 | /* check to see if we are clearing active */ |
| 740 | if (!slave_dev) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 741 | netdev_info(bond->dev, "Clearing current active slave\n"); |
Monam Agarwal | 8800a24 | 2014-03-24 00:00:17 +0530 | [diff] [blame] | 742 | RCU_INIT_POINTER(bond->curr_active_slave, NULL); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 743 | bond_select_active_slave(bond); |
| 744 | } else { |
Eric Dumazet | 4740d63 | 2014-07-15 06:56:55 -0700 | [diff] [blame] | 745 | struct slave *old_active = bond_deref_active_protected(bond); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 746 | struct slave *new_active = bond_slave_get_rtnl(slave_dev); |
| 747 | |
| 748 | BUG_ON(!new_active); |
| 749 | |
| 750 | if (new_active == old_active) { |
| 751 | /* do nothing */ |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 752 | netdev_info(bond->dev, "%s is already the current active slave\n", |
| 753 | new_active->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 754 | } else { |
| 755 | if (old_active && (new_active->link == BOND_LINK_UP) && |
Veaceslav Falico | b6adc61 | 2014-05-15 21:39:57 +0200 | [diff] [blame] | 756 | bond_slave_is_up(new_active)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 757 | netdev_info(bond->dev, "Setting %s as active slave\n", |
| 758 | new_active->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 759 | bond_change_active_slave(bond, new_active); |
| 760 | } else { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 761 | netdev_err(bond->dev, "Could not set %s as active slave; either %s is down or the link is down\n", |
| 762 | new_active->dev->name, |
| 763 | new_active->dev->name); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 764 | ret = -EINVAL; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | write_unlock_bh(&bond->curr_slave_lock); |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 770 | unblock_netpoll_tx(); |
Nikolay Aleksandrov | d1fbd3ed | 2014-01-22 14:53:35 +0100 | [diff] [blame] | 771 | |
Jiri Pirko | d9e32b2 | 2013-10-18 17:43:35 +0200 | [diff] [blame] | 772 | return ret; |
| 773 | } |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 774 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 775 | /* There are two tricky bits here. First, if MII monitoring is activated, then |
| 776 | * we must disable ARP monitoring. Second, if the timer isn't running, we must |
| 777 | * start it. |
| 778 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 779 | static int bond_option_miimon_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 780 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 781 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 782 | netdev_info(bond->dev, "Setting MII monitoring interval to %llu\n", |
| 783 | newval->value); |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 784 | bond->params.miimon = newval->value; |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 785 | if (bond->params.updelay) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 786 | 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] | 787 | bond->params.updelay * bond->params.miimon); |
| 788 | if (bond->params.downdelay) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 789 | netdev_info(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value\n", |
| 790 | bond->params.downdelay * bond->params.miimon); |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 791 | if (newval->value && bond->params.arp_interval) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 792 | 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] | 793 | bond->params.arp_interval = 0; |
| 794 | if (bond->params.arp_validate) |
| 795 | bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; |
| 796 | } |
| 797 | if (bond->dev->flags & IFF_UP) { |
| 798 | /* If the interface is up, we may need to fire off |
| 799 | * the MII timer. If the interface is down, the |
| 800 | * timer will get fired off when the open function |
| 801 | * is called. |
| 802 | */ |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 803 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 804 | cancel_delayed_work_sync(&bond->mii_work); |
| 805 | } else { |
| 806 | cancel_delayed_work_sync(&bond->arp_work); |
| 807 | queue_delayed_work(bond->wq, &bond->mii_work, 0); |
| 808 | } |
| 809 | } |
Nikolay Aleksandrov | b98d9c6 | 2014-01-22 14:53:31 +0100 | [diff] [blame] | 810 | |
sfeldma@cumulusnetworks.com | eecdaa6 | 2013-12-12 14:09:55 -0800 | [diff] [blame] | 811 | return 0; |
| 812 | } |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 813 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 814 | /* Set up and down delays. These must be multiples of the |
| 815 | * MII monitoring value, and are stored internally as the multiplier. |
| 816 | * Thus, we must translate to MS for the real world. |
| 817 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 818 | static int bond_option_updelay_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 819 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 820 | { |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 821 | int value = newval->value; |
| 822 | |
Nikolay Aleksandrov | e499461 | 2014-01-22 14:53:26 +0100 | [diff] [blame] | 823 | if (!bond->params.miimon) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 824 | 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] | 825 | return -EPERM; |
| 826 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 827 | if ((value % bond->params.miimon) != 0) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 828 | netdev_warn(bond->dev, "up delay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n", |
| 829 | value, bond->params.miimon, |
| 830 | (value / bond->params.miimon) * |
| 831 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 832 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 833 | bond->params.updelay = value / bond->params.miimon; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 834 | netdev_info(bond->dev, "Setting up delay to %d\n", |
| 835 | bond->params.updelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | 25852e2 | 2013-12-12 14:10:02 -0800 | [diff] [blame] | 836 | |
| 837 | return 0; |
| 838 | } |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 839 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 840 | static int bond_option_downdelay_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 841 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 842 | { |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 843 | int value = newval->value; |
| 844 | |
Nikolay Aleksandrov | 25a9b54 | 2014-01-22 14:53:25 +0100 | [diff] [blame] | 845 | if (!bond->params.miimon) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 846 | 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] | 847 | return -EPERM; |
| 848 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 849 | if ((value % bond->params.miimon) != 0) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 850 | netdev_warn(bond->dev, "down delay (%d) is not a multiple of miimon (%d), delay rounded to %d ms\n", |
| 851 | value, bond->params.miimon, |
| 852 | (value / bond->params.miimon) * |
| 853 | bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 854 | } |
Nikolay Aleksandrov | 0681a28 | 2014-01-23 23:43:43 +0100 | [diff] [blame] | 855 | bond->params.downdelay = value / bond->params.miimon; |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 856 | netdev_info(bond->dev, "Setting down delay to %d\n", |
| 857 | bond->params.downdelay * bond->params.miimon); |
sfeldma@cumulusnetworks.com | c7461f9 | 2013-12-12 14:10:09 -0800 | [diff] [blame] | 858 | |
| 859 | return 0; |
| 860 | } |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 861 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 862 | static int bond_option_use_carrier_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 863 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 864 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 865 | netdev_info(bond->dev, "Setting use_carrier to %llu\n", |
| 866 | newval->value); |
Nikolay Aleksandrov | 0fff0608 | 2014-01-22 14:53:34 +0100 | [diff] [blame] | 867 | bond->params.use_carrier = newval->value; |
sfeldma@cumulusnetworks.com | 9f53e14 | 2013-12-12 14:10:16 -0800 | [diff] [blame] | 868 | |
| 869 | return 0; |
| 870 | } |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 871 | |
Nikolay Aleksandrov | dc3e5d1 | 2014-05-08 14:23:54 +0200 | [diff] [blame] | 872 | /* There are two tricky bits here. First, if ARP monitoring is activated, then |
| 873 | * we must disable MII monitoring. Second, if the ARP timer isn't running, |
| 874 | * we must start it. |
| 875 | */ |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 876 | static int bond_option_arp_interval_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 877 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 878 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 879 | netdev_info(bond->dev, "Setting ARP monitoring interval to %llu\n", |
| 880 | newval->value); |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 881 | bond->params.arp_interval = newval->value; |
| 882 | if (newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 883 | if (bond->params.miimon) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 884 | 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] | 885 | bond->params.miimon = 0; |
| 886 | } |
| 887 | if (!bond->params.arp_targets[0]) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 888 | 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] | 889 | } |
| 890 | if (bond->dev->flags & IFF_UP) { |
| 891 | /* If the interface is up, we may need to fire off |
| 892 | * the ARP timer. If the interface is down, the |
| 893 | * timer will get fired off when the open function |
| 894 | * is called. |
| 895 | */ |
Nikolay Aleksandrov | 7bdb04e | 2014-01-22 14:53:23 +0100 | [diff] [blame] | 896 | if (!newval->value) { |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 897 | if (bond->params.arp_validate) |
| 898 | bond->recv_probe = NULL; |
| 899 | cancel_delayed_work_sync(&bond->arp_work); |
| 900 | } else { |
| 901 | /* arp_validate can be set only in active-backup mode */ |
Veaceslav Falico | 3fe68df | 2014-02-18 07:48:39 +0100 | [diff] [blame] | 902 | bond->recv_probe = bond_arp_rcv; |
sfeldma@cumulusnetworks.com | 06151db | 2013-12-12 14:10:24 -0800 | [diff] [blame] | 903 | cancel_delayed_work_sync(&bond->mii_work); |
| 904 | queue_delayed_work(bond->wq, &bond->arp_work, 0); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | return 0; |
| 909 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 910 | |
| 911 | static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, |
| 912 | __be32 target, |
| 913 | unsigned long last_rx) |
| 914 | { |
| 915 | __be32 *targets = bond->params.arp_targets; |
| 916 | struct list_head *iter; |
| 917 | struct slave *slave; |
| 918 | |
| 919 | if (slot >= 0 && slot < BOND_MAX_ARP_TARGETS) { |
| 920 | bond_for_each_slave(bond, slave, iter) |
| 921 | slave->target_last_arp_rx[slot] = last_rx; |
| 922 | targets[slot] = target; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) |
| 927 | { |
| 928 | __be32 *targets = bond->params.arp_targets; |
| 929 | int ind; |
| 930 | |
Veaceslav Falico | 2807a9f | 2014-05-15 21:39:56 +0200 | [diff] [blame] | 931 | if (!bond_is_ip_target_ok(target)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 932 | netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n", |
| 933 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 934 | return -EINVAL; |
| 935 | } |
| 936 | |
| 937 | if (bond_get_targets_ip(targets, target) != -1) { /* dup */ |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 938 | netdev_err(bond->dev, "ARP target %pI4 is already present\n", |
| 939 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 940 | return -EINVAL; |
| 941 | } |
| 942 | |
| 943 | ind = bond_get_targets_ip(targets, 0); /* first free slot */ |
| 944 | if (ind == -1) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 945 | netdev_err(bond->dev, "ARP target table is full!\n"); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 946 | return -EINVAL; |
| 947 | } |
| 948 | |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 949 | netdev_info(bond->dev, "Adding ARP target %pI4\n", &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 950 | |
| 951 | _bond_options_arp_ip_target_set(bond, ind, target, jiffies); |
| 952 | |
| 953 | return 0; |
| 954 | } |
| 955 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 956 | 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] | 957 | { |
| 958 | int ret; |
| 959 | |
| 960 | /* not to race with bond_arp_rcv */ |
| 961 | write_lock_bh(&bond->lock); |
| 962 | ret = _bond_option_arp_ip_target_add(bond, target); |
| 963 | write_unlock_bh(&bond->lock); |
| 964 | |
| 965 | return ret; |
| 966 | } |
| 967 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 968 | 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] | 969 | { |
| 970 | __be32 *targets = bond->params.arp_targets; |
| 971 | struct list_head *iter; |
| 972 | struct slave *slave; |
| 973 | unsigned long *targets_rx; |
| 974 | int ind, i; |
| 975 | |
Veaceslav Falico | 2807a9f | 2014-05-15 21:39:56 +0200 | [diff] [blame] | 976 | if (!bond_is_ip_target_ok(target)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 977 | netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n", |
| 978 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 979 | return -EINVAL; |
| 980 | } |
| 981 | |
| 982 | ind = bond_get_targets_ip(targets, target); |
| 983 | if (ind == -1) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 984 | netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n", |
| 985 | &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 986 | return -EINVAL; |
| 987 | } |
| 988 | |
| 989 | if (ind == 0 && !targets[1] && bond->params.arp_interval) |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 990 | 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] | 991 | |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 992 | netdev_info(bond->dev, "Removing ARP target %pI4\n", &target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 993 | |
| 994 | /* not to race with bond_arp_rcv */ |
| 995 | write_lock_bh(&bond->lock); |
| 996 | |
| 997 | bond_for_each_slave(bond, slave, iter) { |
| 998 | targets_rx = slave->target_last_arp_rx; |
| 999 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 1000 | targets_rx[i] = targets_rx[i+1]; |
| 1001 | targets_rx[i] = 0; |
| 1002 | } |
| 1003 | for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) |
| 1004 | targets[i] = targets[i+1]; |
| 1005 | targets[i] = 0; |
| 1006 | |
| 1007 | write_unlock_bh(&bond->lock); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1012 | void bond_option_arp_ip_targets_clear(struct bonding *bond) |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1013 | { |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1014 | int i; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1015 | |
| 1016 | /* not to race with bond_arp_rcv */ |
| 1017 | write_lock_bh(&bond->lock); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1018 | for (i = 0; i < BOND_MAX_ARP_TARGETS; i++) |
| 1019 | _bond_options_arp_ip_target_set(bond, i, 0, 0); |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1020 | write_unlock_bh(&bond->lock); |
| 1021 | } |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1022 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1023 | static int bond_option_arp_ip_targets_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1024 | const struct bond_opt_value *newval) |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1025 | { |
| 1026 | int ret = -EPERM; |
| 1027 | __be32 target; |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1028 | |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1029 | if (newval->string) { |
| 1030 | if (!in4_pton(newval->string+1, -1, (u8 *)&target, -1, NULL)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1031 | netdev_err(bond->dev, "invalid ARP target %pI4 specified\n", |
| 1032 | &target); |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1033 | return ret; |
| 1034 | } |
| 1035 | if (newval->string[0] == '+') |
| 1036 | ret = bond_option_arp_ip_target_add(bond, target); |
| 1037 | else if (newval->string[0] == '-') |
| 1038 | ret = bond_option_arp_ip_target_rem(bond, target); |
| 1039 | else |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1040 | netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n"); |
Nikolay Aleksandrov | 4fb0ef58 | 2014-01-22 14:53:24 +0100 | [diff] [blame] | 1041 | } else { |
| 1042 | target = newval->value; |
| 1043 | ret = bond_option_arp_ip_target_add(bond, target); |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1044 | } |
| 1045 | |
sfeldma@cumulusnetworks.com | 7f28fa1 | 2013-12-12 14:10:31 -0800 | [diff] [blame] | 1046 | return ret; |
| 1047 | } |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1048 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1049 | static int bond_option_arp_validate_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1050 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1051 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1052 | netdev_info(bond->dev, "Setting arp_validate to %s (%llu)\n", |
| 1053 | newval->string, newval->value); |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1054 | |
| 1055 | if (bond->dev->flags & IFF_UP) { |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1056 | if (!newval->value) |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1057 | bond->recv_probe = NULL; |
| 1058 | else if (bond->params.arp_interval) |
| 1059 | bond->recv_probe = bond_arp_rcv; |
| 1060 | } |
Nikolay Aleksandrov | 1622888 | 2014-01-22 14:53:20 +0100 | [diff] [blame] | 1061 | bond->params.arp_validate = newval->value; |
sfeldma@cumulusnetworks.com | 29c4948 | 2013-12-12 14:10:38 -0800 | [diff] [blame] | 1062 | |
| 1063 | return 0; |
| 1064 | } |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1065 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1066 | static int bond_option_arp_all_targets_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1067 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1068 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1069 | netdev_info(bond->dev, "Setting arp_all_targets to %s (%llu)\n", |
| 1070 | newval->string, newval->value); |
Nikolay Aleksandrov | edf36b2 | 2014-01-22 14:53:21 +0100 | [diff] [blame] | 1071 | bond->params.arp_all_targets = newval->value; |
sfeldma@cumulusnetworks.com | d5c8425 | 2013-12-12 14:10:45 -0800 | [diff] [blame] | 1072 | |
| 1073 | return 0; |
| 1074 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1075 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1076 | static int bond_option_primary_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1077 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1078 | { |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1079 | char *p, *primary = newval->string; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1080 | struct list_head *iter; |
| 1081 | struct slave *slave; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1082 | |
| 1083 | block_netpoll_tx(); |
| 1084 | read_lock(&bond->lock); |
| 1085 | write_lock_bh(&bond->curr_slave_lock); |
| 1086 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1087 | p = strchr(primary, '\n'); |
| 1088 | if (p) |
| 1089 | *p = '\0'; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1090 | /* check to see if we are clearing primary */ |
| 1091 | if (!strlen(primary)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1092 | netdev_info(bond->dev, "Setting primary slave to None\n"); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame^] | 1093 | RCU_INIT_POINTER(bond->primary_slave, NULL); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1094 | memset(bond->params.primary, 0, sizeof(bond->params.primary)); |
| 1095 | bond_select_active_slave(bond); |
| 1096 | goto out; |
| 1097 | } |
| 1098 | |
| 1099 | bond_for_each_slave(bond, slave, iter) { |
| 1100 | if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1101 | netdev_info(bond->dev, "Setting %s as primary slave\n", |
| 1102 | slave->dev->name); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame^] | 1103 | rcu_assign_pointer(bond->primary_slave, slave); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1104 | strcpy(bond->params.primary, slave->dev->name); |
| 1105 | bond_select_active_slave(bond); |
| 1106 | goto out; |
| 1107 | } |
| 1108 | } |
| 1109 | |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame^] | 1110 | if (rtnl_dereference(bond->primary_slave)) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1111 | netdev_info(bond->dev, "Setting primary slave to None\n"); |
Nikolay Aleksandrov | 059b47e | 2014-09-09 23:17:00 +0200 | [diff] [blame^] | 1112 | RCU_INIT_POINTER(bond->primary_slave, NULL); |
dingtianhong | c59ab67 | 2014-01-18 16:28:52 +0800 | [diff] [blame] | 1113 | bond_select_active_slave(bond); |
| 1114 | } |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1115 | strncpy(bond->params.primary, primary, IFNAMSIZ); |
| 1116 | bond->params.primary[IFNAMSIZ - 1] = 0; |
| 1117 | |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1118 | netdev_info(bond->dev, "Recording %s as primary, but it has not been enslaved to %s yet\n", |
| 1119 | primary, bond->dev->name); |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1120 | |
| 1121 | out: |
| 1122 | write_unlock_bh(&bond->curr_slave_lock); |
| 1123 | read_unlock(&bond->lock); |
| 1124 | unblock_netpoll_tx(); |
| 1125 | |
Nikolay Aleksandrov | 180222f | 2014-01-22 14:53:32 +0100 | [diff] [blame] | 1126 | return 0; |
sfeldma@cumulusnetworks.com | 0a98a0d | 2013-12-15 16:41:51 -0800 | [diff] [blame] | 1127 | } |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1128 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1129 | static int bond_option_primary_reselect_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 | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1131 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1132 | netdev_info(bond->dev, "Setting primary_reselect to %s (%llu)\n", |
| 1133 | newval->string, newval->value); |
Nikolay Aleksandrov | 388d3a6 | 2014-01-22 14:53:33 +0100 | [diff] [blame] | 1134 | bond->params.primary_reselect = newval->value; |
sfeldma@cumulusnetworks.com | 8a41ae4 | 2013-12-15 16:41:58 -0800 | [diff] [blame] | 1135 | |
| 1136 | block_netpoll_tx(); |
| 1137 | write_lock_bh(&bond->curr_slave_lock); |
| 1138 | bond_select_active_slave(bond); |
| 1139 | write_unlock_bh(&bond->curr_slave_lock); |
| 1140 | unblock_netpoll_tx(); |
| 1141 | |
| 1142 | return 0; |
| 1143 | } |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1144 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1145 | static int bond_option_fail_over_mac_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1146 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1147 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1148 | netdev_info(bond->dev, "Setting fail_over_mac to %s (%llu)\n", |
| 1149 | newval->string, newval->value); |
Nikolay Aleksandrov | 1df6b6a | 2014-01-22 14:53:22 +0100 | [diff] [blame] | 1150 | bond->params.fail_over_mac = newval->value; |
sfeldma@cumulusnetworks.com | 8990197 | 2013-12-15 16:42:05 -0800 | [diff] [blame] | 1151 | |
| 1152 | return 0; |
| 1153 | } |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1154 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1155 | static int bond_option_xmit_hash_policy_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1156 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1157 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1158 | netdev_info(bond->dev, "Setting xmit hash policy to %s (%llu)\n", |
| 1159 | newval->string, newval->value); |
Nikolay Aleksandrov | a4b32ce | 2014-01-22 14:53:19 +0100 | [diff] [blame] | 1160 | bond->params.xmit_policy = newval->value; |
sfeldma@cumulusnetworks.com | f70161c | 2013-12-15 16:42:12 -0800 | [diff] [blame] | 1161 | |
| 1162 | return 0; |
| 1163 | } |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1164 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1165 | static int bond_option_resend_igmp_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1166 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1167 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1168 | netdev_info(bond->dev, "Setting resend_igmp to %llu\n", |
| 1169 | newval->value); |
Nikolay Aleksandrov | 105c8fb | 2014-01-22 14:53:38 +0100 | [diff] [blame] | 1170 | bond->params.resend_igmp = newval->value; |
sfeldma@cumulusnetworks.com | d8838de7 | 2013-12-15 16:42:19 -0800 | [diff] [blame] | 1171 | |
| 1172 | return 0; |
| 1173 | } |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1174 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1175 | static int bond_option_num_peer_notif_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1176 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1177 | { |
Nikolay Aleksandrov | ef56bec | 2014-01-22 14:53:30 +0100 | [diff] [blame] | 1178 | bond->params.num_peer_notif = newval->value; |
| 1179 | |
sfeldma@cumulusnetworks.com | 2c9839c | 2013-12-17 21:30:09 -0800 | [diff] [blame] | 1180 | return 0; |
| 1181 | } |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1182 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1183 | static int bond_option_all_slaves_active_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1184 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1185 | { |
| 1186 | struct list_head *iter; |
| 1187 | struct slave *slave; |
| 1188 | |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1189 | if (newval->value == bond->params.all_slaves_active) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1190 | return 0; |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1191 | bond->params.all_slaves_active = newval->value; |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1192 | bond_for_each_slave(bond, slave, iter) { |
| 1193 | if (!bond_is_active_slave(slave)) { |
Nikolay Aleksandrov | 3df0116 | 2014-01-22 14:53:37 +0100 | [diff] [blame] | 1194 | if (newval->value) |
sfeldma@cumulusnetworks.com | 1cc0b1e | 2013-12-17 21:30:16 -0800 | [diff] [blame] | 1195 | slave->inactive = 0; |
| 1196 | else |
| 1197 | slave->inactive = 1; |
| 1198 | } |
| 1199 | } |
| 1200 | |
| 1201 | return 0; |
| 1202 | } |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1203 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1204 | static int bond_option_min_links_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1205 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1206 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1207 | netdev_info(bond->dev, "Setting min links value to %llu\n", |
| 1208 | newval->value); |
Nikolay Aleksandrov | 633ddc9 | 2014-01-22 14:53:28 +0100 | [diff] [blame] | 1209 | bond->params.min_links = newval->value; |
sfeldma@cumulusnetworks.com | 7d10100 | 2013-12-17 21:30:23 -0800 | [diff] [blame] | 1210 | |
| 1211 | return 0; |
| 1212 | } |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1213 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1214 | static int bond_option_lp_interval_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1215 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1216 | { |
Nikolay Aleksandrov | 4325b37 | 2014-01-22 14:53:39 +0100 | [diff] [blame] | 1217 | bond->params.lp_interval = newval->value; |
sfeldma@cumulusnetworks.com | 8d836d09 | 2013-12-17 21:30:30 -0800 | [diff] [blame] | 1218 | |
| 1219 | return 0; |
| 1220 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1221 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1222 | static int bond_option_pps_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1223 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1224 | { |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1225 | bond->params.packets_per_slave = newval->value; |
| 1226 | if (newval->value > 0) { |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1227 | bond->params.reciprocal_packets_per_slave = |
Nikolay Aleksandrov | aa59d85 | 2014-01-22 14:53:18 +0100 | [diff] [blame] | 1228 | reciprocal_value(newval->value); |
Hannes Frederic Sowa | 809fa97 | 2014-01-22 02:29:41 +0100 | [diff] [blame] | 1229 | } else { |
| 1230 | /* reciprocal_packets_per_slave is unused if |
| 1231 | * packets_per_slave is 0 or 1, just initialize it |
| 1232 | */ |
| 1233 | bond->params.reciprocal_packets_per_slave = |
| 1234 | (struct reciprocal_value) { 0 }; |
| 1235 | } |
sfeldma@cumulusnetworks.com | c13ab3f | 2013-12-17 21:30:37 -0800 | [diff] [blame] | 1236 | |
| 1237 | return 0; |
| 1238 | } |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1239 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1240 | static int bond_option_lacp_rate_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1241 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1242 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1243 | netdev_info(bond->dev, "Setting LACP rate to %s (%llu)\n", |
| 1244 | newval->string, newval->value); |
Nikolay Aleksandrov | d3131de | 2014-01-22 14:53:27 +0100 | [diff] [blame] | 1245 | bond->params.lacp_fast = newval->value; |
sfeldma@cumulusnetworks.com | 3243c47 | 2014-01-03 14:28:18 -0800 | [diff] [blame] | 1246 | bond_3ad_update_lacp_rate(bond); |
sfeldma@cumulusnetworks.com | 998e40bb | 2014-01-03 14:18:41 -0800 | [diff] [blame] | 1247 | |
| 1248 | return 0; |
| 1249 | } |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1250 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1251 | static int bond_option_ad_select_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1252 | const struct bond_opt_value *newval) |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1253 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1254 | netdev_info(bond->dev, "Setting ad_select to %s (%llu)\n", |
| 1255 | newval->string, newval->value); |
Nikolay Aleksandrov | 9e5f5ee | 2014-01-22 14:53:29 +0100 | [diff] [blame] | 1256 | bond->params.ad_select = newval->value; |
sfeldma@cumulusnetworks.com | ec029fa | 2014-01-03 14:18:49 -0800 | [diff] [blame] | 1257 | |
| 1258 | return 0; |
| 1259 | } |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1260 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1261 | static int bond_option_queue_id_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1262 | const struct bond_opt_value *newval) |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1263 | { |
| 1264 | struct slave *slave, *update_slave; |
| 1265 | struct net_device *sdev; |
| 1266 | struct list_head *iter; |
| 1267 | char *delim; |
| 1268 | int ret = 0; |
| 1269 | u16 qid; |
| 1270 | |
| 1271 | /* delim will point to queue id if successful */ |
| 1272 | delim = strchr(newval->string, ':'); |
| 1273 | if (!delim) |
| 1274 | goto err_no_cmd; |
| 1275 | |
| 1276 | /* Terminate string that points to device name and bump it |
| 1277 | * up one, so we can read the queue id there. |
| 1278 | */ |
| 1279 | *delim = '\0'; |
| 1280 | if (sscanf(++delim, "%hd\n", &qid) != 1) |
| 1281 | goto err_no_cmd; |
| 1282 | |
| 1283 | /* Check buffer length, valid ifname and queue id */ |
dingtianhong | c313c89 | 2014-02-12 14:58:50 +0800 | [diff] [blame] | 1284 | if (!dev_valid_name(newval->string) || |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1285 | qid > bond->dev->real_num_tx_queues) |
| 1286 | goto err_no_cmd; |
| 1287 | |
| 1288 | /* Get the pointer to that interface if it exists */ |
| 1289 | sdev = __dev_get_by_name(dev_net(bond->dev), newval->string); |
| 1290 | if (!sdev) |
| 1291 | goto err_no_cmd; |
| 1292 | |
| 1293 | /* Search for thes slave and check for duplicate qids */ |
| 1294 | update_slave = NULL; |
| 1295 | bond_for_each_slave(bond, slave, iter) { |
| 1296 | if (sdev == slave->dev) |
| 1297 | /* We don't need to check the matching |
| 1298 | * slave for dups, since we're overwriting it |
| 1299 | */ |
| 1300 | update_slave = slave; |
| 1301 | else if (qid && qid == slave->queue_id) { |
| 1302 | goto err_no_cmd; |
| 1303 | } |
| 1304 | } |
| 1305 | |
| 1306 | if (!update_slave) |
| 1307 | goto err_no_cmd; |
| 1308 | |
| 1309 | /* Actually set the qids for the slave */ |
| 1310 | update_slave->queue_id = qid; |
| 1311 | |
| 1312 | out: |
| 1313 | return ret; |
| 1314 | |
| 1315 | err_no_cmd: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1316 | netdev_info(bond->dev, "invalid input for queue_id set\n"); |
Nikolay Aleksandrov | 24089ba | 2014-01-22 14:53:36 +0100 | [diff] [blame] | 1317 | ret = -EPERM; |
| 1318 | goto out; |
| 1319 | |
| 1320 | } |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1321 | |
stephen hemminger | f325333 | 2014-03-04 16:36:44 -0800 | [diff] [blame] | 1322 | static int bond_option_slaves_set(struct bonding *bond, |
stephen hemminger | 28f084c | 2014-03-06 14:20:17 -0800 | [diff] [blame] | 1323 | const struct bond_opt_value *newval) |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1324 | { |
| 1325 | char command[IFNAMSIZ + 1] = { 0, }; |
| 1326 | struct net_device *dev; |
| 1327 | char *ifname; |
| 1328 | int ret; |
| 1329 | |
| 1330 | sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/ |
| 1331 | ifname = command + 1; |
| 1332 | if ((strlen(command) <= 1) || |
| 1333 | !dev_valid_name(ifname)) |
| 1334 | goto err_no_cmd; |
| 1335 | |
| 1336 | dev = __dev_get_by_name(dev_net(bond->dev), ifname); |
| 1337 | if (!dev) { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1338 | netdev_info(bond->dev, "interface %s does not exist!\n", |
| 1339 | ifname); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1340 | ret = -ENODEV; |
| 1341 | goto out; |
| 1342 | } |
| 1343 | |
| 1344 | switch (command[0]) { |
| 1345 | case '+': |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1346 | netdev_info(bond->dev, "Adding slave %s\n", dev->name); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1347 | ret = bond_enslave(bond->dev, dev); |
| 1348 | break; |
| 1349 | |
| 1350 | case '-': |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1351 | netdev_info(bond->dev, "Removing slave %s\n", dev->name); |
Nikolay Aleksandrov | 0e2e5b6 | 2014-01-22 14:53:40 +0100 | [diff] [blame] | 1352 | ret = bond_release(bond->dev, dev); |
| 1353 | break; |
| 1354 | |
| 1355 | default: |
| 1356 | goto err_no_cmd; |
| 1357 | } |
| 1358 | |
| 1359 | out: |
| 1360 | return ret; |
| 1361 | |
| 1362 | err_no_cmd: |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1363 | 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] | 1364 | ret = -EPERM; |
| 1365 | goto out; |
| 1366 | } |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1367 | |
| 1368 | static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, |
| 1369 | const struct bond_opt_value *newval) |
| 1370 | { |
Veaceslav Falico | 2de390b | 2014-07-15 19:36:08 +0200 | [diff] [blame] | 1371 | netdev_info(bond->dev, "Setting dynamic-lb to %s (%llu)\n", |
| 1372 | newval->string, newval->value); |
Mahesh Bandewar | e9f0fb8 | 2014-04-22 16:30:22 -0700 | [diff] [blame] | 1373 | bond->params.tlb_dynamic_lb = newval->value; |
| 1374 | |
| 1375 | return 0; |
| 1376 | } |