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