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