Lines Matching +full:primary +full:- +full:bond

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/net/bond/bond_options.c - bonding options
20 static int bond_option_active_slave_set(struct bonding *bond,
22 static int bond_option_miimon_set(struct bonding *bond,
24 static int bond_option_updelay_set(struct bonding *bond,
26 static int bond_option_downdelay_set(struct bonding *bond,
28 static int bond_option_peer_notif_delay_set(struct bonding *bond,
30 static int bond_option_use_carrier_set(struct bonding *bond,
32 static int bond_option_arp_interval_set(struct bonding *bond,
34 static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target);
35 static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target);
36 static int bond_option_arp_ip_targets_set(struct bonding *bond,
38 static int bond_option_ns_ip6_targets_set(struct bonding *bond,
40 static int bond_option_arp_validate_set(struct bonding *bond,
42 static int bond_option_arp_all_targets_set(struct bonding *bond,
44 static int bond_option_prio_set(struct bonding *bond,
46 static int bond_option_primary_set(struct bonding *bond,
48 static int bond_option_primary_reselect_set(struct bonding *bond,
50 static int bond_option_fail_over_mac_set(struct bonding *bond,
52 static int bond_option_xmit_hash_policy_set(struct bonding *bond,
54 static int bond_option_resend_igmp_set(struct bonding *bond,
56 static int bond_option_num_peer_notif_set(struct bonding *bond,
58 static int bond_option_all_slaves_active_set(struct bonding *bond,
60 static int bond_option_min_links_set(struct bonding *bond,
62 static int bond_option_lp_interval_set(struct bonding *bond,
64 static int bond_option_pps_set(struct bonding *bond,
66 static int bond_option_lacp_active_set(struct bonding *bond,
68 static int bond_option_lacp_rate_set(struct bonding *bond,
70 static int bond_option_ad_select_set(struct bonding *bond,
72 static int bond_option_queue_id_set(struct bonding *bond,
74 static int bond_option_mode_set(struct bonding *bond,
76 static int bond_option_slaves_set(struct bonding *bond,
78 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond,
80 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond,
82 static int bond_option_ad_actor_system_set(struct bonding *bond,
84 static int bond_option_ad_user_port_key_set(struct bonding *bond,
86 static int bond_option_missed_max_set(struct bonding *bond,
88 static int bond_option_coupled_control_set(struct bonding *bond,
90 static int bond_option_broadcast_neigh_set(struct bonding *bond,
94 { "balance-rr", BOND_MODE_ROUNDROBIN, BOND_VALFLAG_DEFAULT},
95 { "active-backup", BOND_MODE_ACTIVEBACKUP, 0},
96 { "balance-xor", BOND_MODE_XOR, 0},
99 { "balance-tlb", BOND_MODE_TLB, 0},
100 { "balance-alb", BOND_MODE_ALB, 0},
101 { NULL, -1, 0},
107 { NULL, -1, 0},
117 { NULL, -1, 0},
128 { NULL, -1, 0},
134 { NULL, -1, 0},
141 { NULL, -1, 0},
147 { NULL, -1, 0}
153 { NULL, -1, 0}
159 { NULL, -1, 0},
166 { NULL, -1, 0},
173 { NULL, -1, 0}
179 { NULL, -1, 0}
186 { NULL, -1},
192 { NULL, -1, 0}
198 { NULL, -1, 0}
205 { NULL, -1, 0}
211 { NULL, -1, 0},
217 { NULL, -1, 0}
223 { NULL, -1, 0},
229 { NULL, -1, 0},
236 { NULL, -1, 0},
242 { NULL, -1, 0},
248 { NULL, -1, 0}
255 .desc = "bond device mode",
271 .desc = "balance-xor, 802.3ad, and tlb hashing method",
294 .desc = "For active-backup, do not set all slaves to the same MAC",
395 .desc = "Link priority for failover re-selection",
404 .name = "primary",
405 .desc = "Primary network device to use",
415 .desc = "Reselect primary slave once it comes up",
543 if (opt && !strcmp(opt->name, name)) in bond_opt_get_by_name()
559 for (i = 0; opt->values && opt->values[i].string; i++) in bond_opt_get_val()
560 if (opt->values[i].value == val) in bond_opt_get_val()
561 return &opt->values[i]; in bond_opt_get_val()
572 for (i = 0; opt->values && opt->values[i].string; i++) in bond_opt_get_flags()
573 if (opt->values[i].flags & flagmask) in bond_opt_get_flags()
574 return &opt->values[i]; in bond_opt_get_flags()
588 if (!maxval || (minval && val < minval->value) || val > maxval->value) in bond_opt_check_range()
595 * bond_opt_parse - parse option value
602 * @val->string if it's present.
614 if (opt->flags & BOND_OPTFLAG_RAWVAL) in bond_opt_parse()
617 tbl = opt->values; in bond_opt_parse()
622 checkval = val->value != ULLONG_MAX; in bond_opt_parse()
624 if (!val->string) in bond_opt_parse()
626 p = strchr(val->string, '\n'); in bond_opt_parse()
629 for (p = val->string; *p; p++) in bond_opt_parse()
636 rv = sscanf(val->string, "%32s", valstr); in bond_opt_parse()
638 rv = sscanf(val->string, "%llu", &val->value); in bond_opt_parse()
648 if (val->value == tbl[i].value) in bond_opt_parse()
663 if (checkval && bond_opt_check_range(opt, val->value)) in bond_opt_parse()
669 /* Check opt's dependencies against bond mode and currently set options */
670 static int bond_opt_check_deps(struct bonding *bond, in bond_opt_check_deps() argument
673 struct bond_params *params = &bond->params; in bond_opt_check_deps()
675 if (test_bit(params->mode, &opt->unsuppmodes)) in bond_opt_check_deps()
676 return -EACCES; in bond_opt_check_deps()
677 if ((opt->flags & BOND_OPTFLAG_NOSLAVES) && bond_has_slaves(bond)) in bond_opt_check_deps()
678 return -ENOTEMPTY; in bond_opt_check_deps()
679 if ((opt->flags & BOND_OPTFLAG_IFDOWN) && (bond->dev->flags & IFF_UP)) in bond_opt_check_deps()
680 return -EBUSY; in bond_opt_check_deps()
685 static void bond_opt_dep_print(struct bonding *bond, in bond_opt_dep_print() argument
693 params = &bond->params; in bond_opt_dep_print()
694 modeval = bond_opt_get_val(BOND_OPT_MODE, params->mode); in bond_opt_dep_print()
695 if (test_bit(params->mode, &opt->unsuppmodes)) { in bond_opt_dep_print()
696 netdev_err(bond->dev, "option %s: mode dependency failed, not supported in mode %s(%llu)\n", in bond_opt_dep_print()
697 opt->name, modeval->string, modeval->value); in bond_opt_dep_print()
703 static void bond_opt_error_interpret(struct bonding *bond, in bond_opt_error_interpret() argument
713 case -EINVAL: in bond_opt_error_interpret()
716 if (val->string) { in bond_opt_error_interpret()
718 p = strchr(val->string, '\n'); in bond_opt_error_interpret()
721 netdev_err(bond->dev, "option %s: invalid value (%s)\n", in bond_opt_error_interpret()
722 opt->name, val->string); in bond_opt_error_interpret()
724 netdev_err(bond->dev, "option %s: invalid value (%llu)\n", in bond_opt_error_interpret()
725 opt->name, val->value); in bond_opt_error_interpret()
732 netdev_err(bond->dev, "option %s: allowed values %llu - %llu\n", in bond_opt_error_interpret()
733 opt->name, minval ? minval->value : 0, maxval->value); in bond_opt_error_interpret()
735 case -EACCES: in bond_opt_error_interpret()
736 bond_opt_dep_print(bond, opt, bad_attr, extack); in bond_opt_error_interpret()
738 case -ENOTEMPTY: in bond_opt_error_interpret()
740 "unable to set option because the bond device has slaves"); in bond_opt_error_interpret()
741 netdev_err(bond->dev, "option %s: unable to set because the bond device has slaves\n", in bond_opt_error_interpret()
742 opt->name); in bond_opt_error_interpret()
744 case -EBUSY: in bond_opt_error_interpret()
746 "unable to set option because the bond is up"); in bond_opt_error_interpret()
747 netdev_err(bond->dev, "option %s: unable to set because the bond device is up\n", in bond_opt_error_interpret()
748 opt->name); in bond_opt_error_interpret()
750 case -ENODEV: in bond_opt_error_interpret()
751 if (val && val->string) { in bond_opt_error_interpret()
752 p = strchr(val->string, '\n'); in bond_opt_error_interpret()
755 netdev_err(bond->dev, "option %s: interface %s does not exist!\n", in bond_opt_error_interpret()
756 opt->name, val->string); in bond_opt_error_interpret()
767 * __bond_opt_set - set a bonding option
768 * @bond: target bond device
775 * This function is used to change the bond's option value, it can be
779 int __bond_opt_set(struct bonding *bond, in __bond_opt_set() argument
785 int ret = -ENOENT; in __bond_opt_set()
792 ret = bond_opt_check_deps(bond, opt); in __bond_opt_set()
797 ret = -EINVAL; in __bond_opt_set()
800 ret = opt->set(bond, retval); in __bond_opt_set()
803 bond_opt_error_interpret(bond, opt, ret, val, bad_attr, extack); in __bond_opt_set()
808 * __bond_opt_set_notify - set a bonding option
809 * @bond: target bond device
813 * This function is used to change the bond's option value and trigger
818 int __bond_opt_set_notify(struct bonding *bond, in __bond_opt_set_notify() argument
825 ret = __bond_opt_set(bond, option, val, NULL, NULL); in __bond_opt_set_notify()
827 if (!ret && (bond->dev->reg_state == NETREG_REGISTERED)) in __bond_opt_set_notify()
828 call_netdevice_notifiers(NETDEV_CHANGEINFODATA, bond->dev); in __bond_opt_set_notify()
834 * bond_opt_tryset_rtnl - try to acquire rtnl and call __bond_opt_set
835 * @bond: target bond device
842 int bond_opt_tryset_rtnl(struct bonding *bond, unsigned int option, char *buf) in bond_opt_tryset_rtnl() argument
850 ret = __bond_opt_set_notify(bond, option, &optval); in bond_opt_tryset_rtnl()
857 * bond_opt_get - get a pointer to an option
871 static bool bond_set_xfrm_features(struct bonding *bond) in bond_set_xfrm_features() argument
876 if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) in bond_set_xfrm_features()
877 bond->dev->wanted_features |= BOND_XFRM_FEATURES; in bond_set_xfrm_features()
879 bond->dev->wanted_features &= ~BOND_XFRM_FEATURES; in bond_set_xfrm_features()
884 static int bond_option_mode_set(struct bonding *bond, in bond_option_mode_set() argument
887 if (bond->xdp_prog && !bond_xdp_check(bond, newval->value)) in bond_option_mode_set()
888 return -EOPNOTSUPP; in bond_option_mode_set()
890 if (!bond_mode_uses_arp(newval->value)) { in bond_option_mode_set()
891 if (bond->params.arp_interval) { in bond_option_mode_set()
892 netdev_dbg(bond->dev, "%s mode is incompatible with arp monitoring, start mii monitoring\n", in bond_option_mode_set()
893 newval->string); in bond_option_mode_set()
895 bond->params.arp_interval = 0; in bond_option_mode_set()
898 if (!bond->params.miimon) { in bond_option_mode_set()
900 bond->params.miimon = BOND_DEFAULT_MIIMON; in bond_option_mode_set()
901 netdev_dbg(bond->dev, "Setting MII monitoring interval to %d\n", in bond_option_mode_set()
902 bond->params.miimon); in bond_option_mode_set()
906 if (newval->value == BOND_MODE_ALB) in bond_option_mode_set()
907 bond->params.tlb_dynamic_lb = 1; in bond_option_mode_set()
910 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; in bond_option_mode_set()
911 bond->params.mode = newval->value; in bond_option_mode_set()
913 /* When changing mode, the bond device is down, we may reduce in bond_option_mode_set()
918 bond->params.broadcast_neighbor = 0; in bond_option_mode_set()
920 if (bond->dev->reg_state == NETREG_REGISTERED) { in bond_option_mode_set()
923 update |= bond_set_xfrm_features(bond); in bond_option_mode_set()
926 netdev_update_features(bond->dev); in bond_option_mode_set()
929 bond_xdp_set_features(bond->dev); in bond_option_mode_set()
934 static int bond_option_active_slave_set(struct bonding *bond, in bond_option_active_slave_set() argument
941 sscanf(newval->string, "%15s", ifname); /* IFNAMSIZ */ in bond_option_active_slave_set()
942 if (!strlen(ifname) || newval->string[0] == '\n') { in bond_option_active_slave_set()
945 slave_dev = __dev_get_by_name(dev_net(bond->dev), ifname); in bond_option_active_slave_set()
947 return -ENODEV; in bond_option_active_slave_set()
952 slave_err(bond->dev, slave_dev, "Device is not bonding slave\n"); in bond_option_active_slave_set()
953 return -EINVAL; in bond_option_active_slave_set()
956 if (bond->dev != netdev_master_upper_dev_get(slave_dev)) { in bond_option_active_slave_set()
957 slave_err(bond->dev, slave_dev, "Device is not our slave\n"); in bond_option_active_slave_set()
958 return -EINVAL; in bond_option_active_slave_set()
965 netdev_dbg(bond->dev, "Clearing current active slave\n"); in bond_option_active_slave_set()
966 bond_change_active_slave(bond, NULL); in bond_option_active_slave_set()
967 bond_select_active_slave(bond); in bond_option_active_slave_set()
969 struct slave *old_active = rtnl_dereference(bond->curr_active_slave); in bond_option_active_slave_set()
976 slave_dbg(bond->dev, new_active->dev, "is already the current active slave\n"); in bond_option_active_slave_set()
978 if (old_active && (new_active->link == BOND_LINK_UP) && in bond_option_active_slave_set()
980 slave_dbg(bond->dev, new_active->dev, "Setting as active slave\n"); in bond_option_active_slave_set()
981 bond_change_active_slave(bond, new_active); in bond_option_active_slave_set()
983 …slave_err(bond->dev, new_active->dev, "Could not set as active slave; either %s is down or the lin… in bond_option_active_slave_set()
984 new_active->dev->name); in bond_option_active_slave_set()
985 ret = -EINVAL; in bond_option_active_slave_set()
998 static int bond_option_miimon_set(struct bonding *bond, in bond_option_miimon_set() argument
1001 netdev_dbg(bond->dev, "Setting MII monitoring interval to %llu\n", in bond_option_miimon_set()
1002 newval->value); in bond_option_miimon_set()
1003 bond->params.miimon = newval->value; in bond_option_miimon_set()
1004 if (bond->params.updelay) in bond_option_miimon_set()
1005 …netdev_dbg(bond->dev, "Note: Updating updelay (to %d) since it is a multiple of the miimon value\n… in bond_option_miimon_set()
1006 bond->params.updelay * bond->params.miimon); in bond_option_miimon_set()
1007 if (bond->params.downdelay) in bond_option_miimon_set()
1008 …netdev_dbg(bond->dev, "Note: Updating downdelay (to %d) since it is a multiple of the miimon value… in bond_option_miimon_set()
1009 bond->params.downdelay * bond->params.miimon); in bond_option_miimon_set()
1010 if (bond->params.peer_notif_delay) in bond_option_miimon_set()
1011 …netdev_dbg(bond->dev, "Note: Updating peer_notif_delay (to %d) since it is a multiple of the miimo… in bond_option_miimon_set()
1012 bond->params.peer_notif_delay * bond->params.miimon); in bond_option_miimon_set()
1013 if (newval->value && bond->params.arp_interval) { in bond_option_miimon_set()
1014 …netdev_dbg(bond->dev, "MII monitoring cannot be used with ARP monitoring - disabling ARP monitorin… in bond_option_miimon_set()
1015 bond->params.arp_interval = 0; in bond_option_miimon_set()
1016 if (bond->params.arp_validate) in bond_option_miimon_set()
1017 bond->params.arp_validate = BOND_ARP_VALIDATE_NONE; in bond_option_miimon_set()
1019 if (bond->dev->flags & IFF_UP) { in bond_option_miimon_set()
1025 if (!newval->value) { in bond_option_miimon_set()
1026 cancel_delayed_work_sync(&bond->mii_work); in bond_option_miimon_set()
1028 cancel_delayed_work_sync(&bond->arp_work); in bond_option_miimon_set()
1029 queue_delayed_work(bond->wq, &bond->mii_work, 0); in bond_option_miimon_set()
1040 static int _bond_option_delay_set(struct bonding *bond, in _bond_option_delay_set() argument
1045 int value = newval->value; in _bond_option_delay_set()
1047 if (!bond->params.miimon) { in _bond_option_delay_set()
1048 netdev_err(bond->dev, "Unable to set %s as MII monitoring is disabled\n", in _bond_option_delay_set()
1050 return -EPERM; in _bond_option_delay_set()
1052 if ((value % bond->params.miimon) != 0) { in _bond_option_delay_set()
1053 netdev_warn(bond->dev, in _bond_option_delay_set()
1056 value, bond->params.miimon, in _bond_option_delay_set()
1057 (value / bond->params.miimon) * in _bond_option_delay_set()
1058 bond->params.miimon); in _bond_option_delay_set()
1060 *target = value / bond->params.miimon; in _bond_option_delay_set()
1061 netdev_dbg(bond->dev, "Setting %s to %d\n", in _bond_option_delay_set()
1063 *target * bond->params.miimon); in _bond_option_delay_set()
1068 static int bond_option_updelay_set(struct bonding *bond, in bond_option_updelay_set() argument
1071 return _bond_option_delay_set(bond, newval, "up delay", in bond_option_updelay_set()
1072 &bond->params.updelay); in bond_option_updelay_set()
1075 static int bond_option_downdelay_set(struct bonding *bond, in bond_option_downdelay_set() argument
1078 return _bond_option_delay_set(bond, newval, "down delay", in bond_option_downdelay_set()
1079 &bond->params.downdelay); in bond_option_downdelay_set()
1082 static int bond_option_peer_notif_delay_set(struct bonding *bond, in bond_option_peer_notif_delay_set() argument
1085 int ret = _bond_option_delay_set(bond, newval, in bond_option_peer_notif_delay_set()
1087 &bond->params.peer_notif_delay); in bond_option_peer_notif_delay_set()
1091 static int bond_option_use_carrier_set(struct bonding *bond, in bond_option_use_carrier_set() argument
1094 netdev_dbg(bond->dev, "Setting use_carrier to %llu\n", in bond_option_use_carrier_set()
1095 newval->value); in bond_option_use_carrier_set()
1096 bond->params.use_carrier = newval->value; in bond_option_use_carrier_set()
1105 static int bond_option_arp_interval_set(struct bonding *bond, in bond_option_arp_interval_set() argument
1108 netdev_dbg(bond->dev, "Setting ARP monitoring interval to %llu\n", in bond_option_arp_interval_set()
1109 newval->value); in bond_option_arp_interval_set()
1110 bond->params.arp_interval = newval->value; in bond_option_arp_interval_set()
1111 if (newval->value) { in bond_option_arp_interval_set()
1112 if (bond->params.miimon) { in bond_option_arp_interval_set()
1113 …netdev_dbg(bond->dev, "ARP monitoring cannot be used with MII monitoring. Disabling MII monitoring… in bond_option_arp_interval_set()
1114 bond->params.miimon = 0; in bond_option_arp_interval_set()
1116 if (!bond->params.arp_targets[0]) in bond_option_arp_interval_set()
1117 … netdev_dbg(bond->dev, "ARP monitoring has been set up, but no ARP targets have been specified\n"); in bond_option_arp_interval_set()
1119 if (bond->dev->flags & IFF_UP) { in bond_option_arp_interval_set()
1125 if (!newval->value) { in bond_option_arp_interval_set()
1126 if (bond->params.arp_validate) in bond_option_arp_interval_set()
1127 bond->recv_probe = NULL; in bond_option_arp_interval_set()
1128 cancel_delayed_work_sync(&bond->arp_work); in bond_option_arp_interval_set()
1130 /* arp_validate can be set only in active-backup mode */ in bond_option_arp_interval_set()
1131 bond->recv_probe = bond_rcv_validate; in bond_option_arp_interval_set()
1132 cancel_delayed_work_sync(&bond->mii_work); in bond_option_arp_interval_set()
1133 queue_delayed_work(bond->wq, &bond->arp_work, 0); in bond_option_arp_interval_set()
1140 static void _bond_options_arp_ip_target_set(struct bonding *bond, int slot, in _bond_options_arp_ip_target_set() argument
1144 __be32 *targets = bond->params.arp_targets; in _bond_options_arp_ip_target_set()
1149 bond_for_each_slave(bond, slave, iter) in _bond_options_arp_ip_target_set()
1150 slave->target_last_arp_rx[slot] = last_rx; in _bond_options_arp_ip_target_set()
1155 static int _bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) in _bond_option_arp_ip_target_add() argument
1157 __be32 *targets = bond->params.arp_targets; in _bond_option_arp_ip_target_add()
1161 netdev_err(bond->dev, "invalid ARP target %pI4 specified for addition\n", in _bond_option_arp_ip_target_add()
1163 return -EINVAL; in _bond_option_arp_ip_target_add()
1166 if (bond_get_targets_ip(targets, target) != -1) { /* dup */ in _bond_option_arp_ip_target_add()
1167 netdev_err(bond->dev, "ARP target %pI4 is already present\n", in _bond_option_arp_ip_target_add()
1169 return -EINVAL; in _bond_option_arp_ip_target_add()
1173 if (ind == -1) { in _bond_option_arp_ip_target_add()
1174 netdev_err(bond->dev, "ARP target table is full!\n"); in _bond_option_arp_ip_target_add()
1175 return -EINVAL; in _bond_option_arp_ip_target_add()
1178 netdev_dbg(bond->dev, "Adding ARP target %pI4\n", &target); in _bond_option_arp_ip_target_add()
1180 _bond_options_arp_ip_target_set(bond, ind, target, jiffies); in _bond_option_arp_ip_target_add()
1185 static int bond_option_arp_ip_target_add(struct bonding *bond, __be32 target) in bond_option_arp_ip_target_add() argument
1187 return _bond_option_arp_ip_target_add(bond, target); in bond_option_arp_ip_target_add()
1190 static int bond_option_arp_ip_target_rem(struct bonding *bond, __be32 target) in bond_option_arp_ip_target_rem() argument
1192 __be32 *targets = bond->params.arp_targets; in bond_option_arp_ip_target_rem()
1199 netdev_err(bond->dev, "invalid ARP target %pI4 specified for removal\n", in bond_option_arp_ip_target_rem()
1201 return -EINVAL; in bond_option_arp_ip_target_rem()
1205 if (ind == -1) { in bond_option_arp_ip_target_rem()
1206 netdev_err(bond->dev, "unable to remove nonexistent ARP target %pI4\n", in bond_option_arp_ip_target_rem()
1208 return -EINVAL; in bond_option_arp_ip_target_rem()
1211 if (ind == 0 && !targets[1] && bond->params.arp_interval) in bond_option_arp_ip_target_rem()
1212 netdev_warn(bond->dev, "Removing last arp target with arp_interval on\n"); in bond_option_arp_ip_target_rem()
1214 netdev_dbg(bond->dev, "Removing ARP target %pI4\n", &target); in bond_option_arp_ip_target_rem()
1216 bond_for_each_slave(bond, slave, iter) { in bond_option_arp_ip_target_rem()
1217 targets_rx = slave->target_last_arp_rx; in bond_option_arp_ip_target_rem()
1218 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) in bond_option_arp_ip_target_rem()
1222 for (i = ind; (i < BOND_MAX_ARP_TARGETS-1) && targets[i+1]; i++) in bond_option_arp_ip_target_rem()
1229 void bond_option_arp_ip_targets_clear(struct bonding *bond) in bond_option_arp_ip_targets_clear() argument
1234 _bond_options_arp_ip_target_set(bond, i, 0, 0); in bond_option_arp_ip_targets_clear()
1237 static int bond_option_arp_ip_targets_set(struct bonding *bond, in bond_option_arp_ip_targets_set() argument
1240 int ret = -EPERM; in bond_option_arp_ip_targets_set()
1243 if (newval->string) { in bond_option_arp_ip_targets_set()
1244 if (strlen(newval->string) < 1 || in bond_option_arp_ip_targets_set()
1245 !in4_pton(newval->string + 1, -1, (u8 *)&target, -1, NULL)) { in bond_option_arp_ip_targets_set()
1246 netdev_err(bond->dev, "invalid ARP target specified\n"); in bond_option_arp_ip_targets_set()
1249 if (newval->string[0] == '+') in bond_option_arp_ip_targets_set()
1250 ret = bond_option_arp_ip_target_add(bond, target); in bond_option_arp_ip_targets_set()
1251 else if (newval->string[0] == '-') in bond_option_arp_ip_targets_set()
1252 ret = bond_option_arp_ip_target_rem(bond, target); in bond_option_arp_ip_targets_set()
1254 netdev_err(bond->dev, "no command found in arp_ip_targets file - use +<addr> or -<addr>\n"); in bond_option_arp_ip_targets_set()
1256 target = newval->value; in bond_option_arp_ip_targets_set()
1257 ret = bond_option_arp_ip_target_add(bond, target); in bond_option_arp_ip_targets_set()
1264 static bool slave_can_set_ns_maddr(const struct bonding *bond, struct slave *slave) in slave_can_set_ns_maddr() argument
1266 return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP && in slave_can_set_ns_maddr()
1268 slave->dev->flags & IFF_MULTICAST; in slave_can_set_ns_maddr()
1272 * slave_set_ns_maddrs - add/del all NS mac addresses for slave
1273 * @bond: bond device
1281 * solicited-node multicast address of the target. The dest mac of NS message
1282 * is converted from the solicited-node multicast address.
1288 static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add) in slave_set_ns_maddrs() argument
1290 struct in6_addr *targets = bond->params.ns_targets; in slave_set_ns_maddrs()
1295 if (!slave_can_set_ns_maddr(bond, slave)) in slave_set_ns_maddrs()
1303 if (!ndisc_mc_map(&mcaddr, slot_maddr, slave->dev, 0)) { in slave_set_ns_maddrs()
1305 dev_mc_add(slave->dev, slot_maddr); in slave_set_ns_maddrs()
1307 dev_mc_del(slave->dev, slot_maddr); in slave_set_ns_maddrs()
1312 void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave) in bond_slave_ns_maddrs_add() argument
1314 if (!bond->params.arp_validate) in bond_slave_ns_maddrs_add()
1316 slave_set_ns_maddrs(bond, slave, true); in bond_slave_ns_maddrs_add()
1319 void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave) in bond_slave_ns_maddrs_del() argument
1321 if (!bond->params.arp_validate) in bond_slave_ns_maddrs_del()
1323 slave_set_ns_maddrs(bond, slave, false); in bond_slave_ns_maddrs_del()
1327 * slave_set_ns_maddr - set new NS mac address for slave
1328 * @bond: bond device
1337 * solicited-node multicast address of the target. The dest mac of NS message
1338 * is converted from the solicited-node multicast address.
1343 static void slave_set_ns_maddr(struct bonding *bond, struct slave *slave, in slave_set_ns_maddr() argument
1349 if (!bond->params.arp_validate || !slave_can_set_ns_maddr(bond, slave)) in slave_set_ns_maddr()
1355 !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0)) in slave_set_ns_maddr()
1356 dev_mc_del(slave->dev, mac_addr); in slave_set_ns_maddr()
1361 !ndisc_mc_map(&mcast_addr, mac_addr, slave->dev, 0)) in slave_set_ns_maddr()
1362 dev_mc_add(slave->dev, mac_addr); in slave_set_ns_maddr()
1365 static void _bond_options_ns_ip6_target_set(struct bonding *bond, int slot, in _bond_options_ns_ip6_target_set() argument
1369 struct in6_addr *targets = bond->params.ns_targets; in _bond_options_ns_ip6_target_set()
1374 bond_for_each_slave(bond, slave, iter) { in _bond_options_ns_ip6_target_set()
1375 slave->target_last_arp_rx[slot] = last_rx; in _bond_options_ns_ip6_target_set()
1376 slave_set_ns_maddr(bond, slave, target, &targets[slot]); in _bond_options_ns_ip6_target_set()
1382 void bond_option_ns_ip6_targets_clear(struct bonding *bond) in bond_option_ns_ip6_targets_clear() argument
1388 _bond_options_ns_ip6_target_set(bond, i, &addr_any, 0); in bond_option_ns_ip6_targets_clear()
1391 static int bond_option_ns_ip6_targets_set(struct bonding *bond, in bond_option_ns_ip6_targets_set() argument
1394 struct in6_addr *target = (struct in6_addr *)newval->extra; in bond_option_ns_ip6_targets_set()
1395 struct in6_addr *targets = bond->params.ns_targets; in bond_option_ns_ip6_targets_set()
1400 netdev_err(bond->dev, "invalid NS target %pI6c specified for addition\n", in bond_option_ns_ip6_targets_set()
1402 return -EINVAL; in bond_option_ns_ip6_targets_set()
1405 if (bond_get_targets_ip6(targets, target) != -1) { /* dup */ in bond_option_ns_ip6_targets_set()
1406 netdev_err(bond->dev, "NS target %pI6c is already present\n", in bond_option_ns_ip6_targets_set()
1408 return -EINVAL; in bond_option_ns_ip6_targets_set()
1412 if (index == -1) { in bond_option_ns_ip6_targets_set()
1413 netdev_err(bond->dev, "NS target table is full!\n"); in bond_option_ns_ip6_targets_set()
1414 return -EINVAL; in bond_option_ns_ip6_targets_set()
1417 netdev_dbg(bond->dev, "Adding NS target %pI6c\n", target); in bond_option_ns_ip6_targets_set()
1419 _bond_options_ns_ip6_target_set(bond, index, target, jiffies); in bond_option_ns_ip6_targets_set()
1424 static int bond_option_ns_ip6_targets_set(struct bonding *bond, in bond_option_ns_ip6_targets_set() argument
1427 return -EPERM; in bond_option_ns_ip6_targets_set()
1430 static void slave_set_ns_maddrs(struct bonding *bond, struct slave *slave, bool add) {} in slave_set_ns_maddrs() argument
1432 void bond_slave_ns_maddrs_add(struct bonding *bond, struct slave *slave) {} in bond_slave_ns_maddrs_add() argument
1434 void bond_slave_ns_maddrs_del(struct bonding *bond, struct slave *slave) {} in bond_slave_ns_maddrs_del() argument
1437 static int bond_option_arp_validate_set(struct bonding *bond, in bond_option_arp_validate_set() argument
1440 bool changed = !!bond->params.arp_validate != !!newval->value; in bond_option_arp_validate_set()
1444 netdev_dbg(bond->dev, "Setting arp_validate to %s (%llu)\n", in bond_option_arp_validate_set()
1445 newval->string, newval->value); in bond_option_arp_validate_set()
1446 bond->params.arp_validate = newval->value; in bond_option_arp_validate_set()
1449 bond_for_each_slave(bond, slave, iter) in bond_option_arp_validate_set()
1450 slave_set_ns_maddrs(bond, slave, !!bond->params.arp_validate); in bond_option_arp_validate_set()
1456 static int bond_option_arp_all_targets_set(struct bonding *bond, in bond_option_arp_all_targets_set() argument
1459 netdev_dbg(bond->dev, "Setting arp_all_targets to %s (%llu)\n", in bond_option_arp_all_targets_set()
1460 newval->string, newval->value); in bond_option_arp_all_targets_set()
1461 bond->params.arp_all_targets = newval->value; in bond_option_arp_all_targets_set()
1466 static int bond_option_missed_max_set(struct bonding *bond, in bond_option_missed_max_set() argument
1469 netdev_dbg(bond->dev, "Setting missed max to %s (%llu)\n", in bond_option_missed_max_set()
1470 newval->string, newval->value); in bond_option_missed_max_set()
1471 bond->params.missed_max = newval->value; in bond_option_missed_max_set()
1476 static int bond_option_prio_set(struct bonding *bond, in bond_option_prio_set() argument
1481 slave = bond_slave_get_rtnl(newval->slave_dev); in bond_option_prio_set()
1483 netdev_dbg(newval->slave_dev, "%s called on NULL slave\n", __func__); in bond_option_prio_set()
1484 return -ENODEV; in bond_option_prio_set()
1486 slave->prio = newval->value; in bond_option_prio_set()
1488 if (rtnl_dereference(bond->primary_slave)) in bond_option_prio_set()
1489 slave_warn(bond->dev, slave->dev, in bond_option_prio_set()
1490 "prio updated, but will not affect failover re-selection as primary slave have been set\n"); in bond_option_prio_set()
1492 bond_select_active_slave(bond); in bond_option_prio_set()
1497 static int bond_option_primary_set(struct bonding *bond, in bond_option_primary_set() argument
1500 char *p, *primary = newval->string; in bond_option_primary_set() local
1506 p = strchr(primary, '\n'); in bond_option_primary_set()
1509 /* check to see if we are clearing primary */ in bond_option_primary_set()
1510 if (!strlen(primary)) { in bond_option_primary_set()
1511 netdev_dbg(bond->dev, "Setting primary slave to None\n"); in bond_option_primary_set()
1512 RCU_INIT_POINTER(bond->primary_slave, NULL); in bond_option_primary_set()
1513 memset(bond->params.primary, 0, sizeof(bond->params.primary)); in bond_option_primary_set()
1514 bond_select_active_slave(bond); in bond_option_primary_set()
1518 bond_for_each_slave(bond, slave, iter) { in bond_option_primary_set()
1519 if (strncmp(slave->dev->name, primary, IFNAMSIZ) == 0) { in bond_option_primary_set()
1520 slave_dbg(bond->dev, slave->dev, "Setting as primary slave\n"); in bond_option_primary_set()
1521 rcu_assign_pointer(bond->primary_slave, slave); in bond_option_primary_set()
1522 strcpy(bond->params.primary, slave->dev->name); in bond_option_primary_set()
1523 bond->force_primary = true; in bond_option_primary_set()
1524 bond_select_active_slave(bond); in bond_option_primary_set()
1529 if (rtnl_dereference(bond->primary_slave)) { in bond_option_primary_set()
1530 netdev_dbg(bond->dev, "Setting primary slave to None\n"); in bond_option_primary_set()
1531 RCU_INIT_POINTER(bond->primary_slave, NULL); in bond_option_primary_set()
1532 bond_select_active_slave(bond); in bond_option_primary_set()
1534 strscpy_pad(bond->params.primary, primary, IFNAMSIZ); in bond_option_primary_set()
1536 netdev_dbg(bond->dev, "Recording %s as primary, but it has not been enslaved yet\n", in bond_option_primary_set()
1537 primary); in bond_option_primary_set()
1545 static int bond_option_primary_reselect_set(struct bonding *bond, in bond_option_primary_reselect_set() argument
1548 netdev_dbg(bond->dev, "Setting primary_reselect to %s (%llu)\n", in bond_option_primary_reselect_set()
1549 newval->string, newval->value); in bond_option_primary_reselect_set()
1550 bond->params.primary_reselect = newval->value; in bond_option_primary_reselect_set()
1553 bond_select_active_slave(bond); in bond_option_primary_reselect_set()
1559 static int bond_option_fail_over_mac_set(struct bonding *bond, in bond_option_fail_over_mac_set() argument
1562 netdev_dbg(bond->dev, "Setting fail_over_mac to %s (%llu)\n", in bond_option_fail_over_mac_set()
1563 newval->string, newval->value); in bond_option_fail_over_mac_set()
1564 bond->params.fail_over_mac = newval->value; in bond_option_fail_over_mac_set()
1569 static int bond_option_xmit_hash_policy_set(struct bonding *bond, in bond_option_xmit_hash_policy_set() argument
1572 netdev_dbg(bond->dev, "Setting xmit hash policy to %s (%llu)\n", in bond_option_xmit_hash_policy_set()
1573 newval->string, newval->value); in bond_option_xmit_hash_policy_set()
1574 bond->params.xmit_policy = newval->value; in bond_option_xmit_hash_policy_set()
1579 static int bond_option_resend_igmp_set(struct bonding *bond, in bond_option_resend_igmp_set() argument
1582 netdev_dbg(bond->dev, "Setting resend_igmp to %llu\n", in bond_option_resend_igmp_set()
1583 newval->value); in bond_option_resend_igmp_set()
1584 bond->params.resend_igmp = newval->value; in bond_option_resend_igmp_set()
1589 static int bond_option_num_peer_notif_set(struct bonding *bond, in bond_option_num_peer_notif_set() argument
1592 bond->params.num_peer_notif = newval->value; in bond_option_num_peer_notif_set()
1597 static int bond_option_all_slaves_active_set(struct bonding *bond, in bond_option_all_slaves_active_set() argument
1603 if (newval->value == bond->params.all_slaves_active) in bond_option_all_slaves_active_set()
1605 bond->params.all_slaves_active = newval->value; in bond_option_all_slaves_active_set()
1606 bond_for_each_slave(bond, slave, iter) { in bond_option_all_slaves_active_set()
1608 if (newval->value) in bond_option_all_slaves_active_set()
1609 slave->inactive = 0; in bond_option_all_slaves_active_set()
1611 slave->inactive = 1; in bond_option_all_slaves_active_set()
1618 static int bond_option_min_links_set(struct bonding *bond, in bond_option_min_links_set() argument
1621 netdev_dbg(bond->dev, "Setting min links value to %llu\n", in bond_option_min_links_set()
1622 newval->value); in bond_option_min_links_set()
1623 bond->params.min_links = newval->value; in bond_option_min_links_set()
1624 bond_set_carrier(bond); in bond_option_min_links_set()
1629 static int bond_option_lp_interval_set(struct bonding *bond, in bond_option_lp_interval_set() argument
1632 bond->params.lp_interval = newval->value; in bond_option_lp_interval_set()
1637 static int bond_option_pps_set(struct bonding *bond, in bond_option_pps_set() argument
1640 netdev_dbg(bond->dev, "Setting packets per slave to %llu\n", in bond_option_pps_set()
1641 newval->value); in bond_option_pps_set()
1642 bond->params.packets_per_slave = newval->value; in bond_option_pps_set()
1643 if (newval->value > 0) { in bond_option_pps_set()
1644 bond->params.reciprocal_packets_per_slave = in bond_option_pps_set()
1645 reciprocal_value(newval->value); in bond_option_pps_set()
1650 bond->params.reciprocal_packets_per_slave = in bond_option_pps_set()
1657 static int bond_option_lacp_active_set(struct bonding *bond, in bond_option_lacp_active_set() argument
1660 netdev_dbg(bond->dev, "Setting LACP active to %s (%llu)\n", in bond_option_lacp_active_set()
1661 newval->string, newval->value); in bond_option_lacp_active_set()
1662 bond->params.lacp_active = newval->value; in bond_option_lacp_active_set()
1667 static int bond_option_lacp_rate_set(struct bonding *bond, in bond_option_lacp_rate_set() argument
1670 netdev_dbg(bond->dev, "Setting LACP rate to %s (%llu)\n", in bond_option_lacp_rate_set()
1671 newval->string, newval->value); in bond_option_lacp_rate_set()
1672 bond->params.lacp_fast = newval->value; in bond_option_lacp_rate_set()
1673 bond_3ad_update_lacp_rate(bond); in bond_option_lacp_rate_set()
1678 static int bond_option_ad_select_set(struct bonding *bond, in bond_option_ad_select_set() argument
1681 netdev_dbg(bond->dev, "Setting ad_select to %s (%llu)\n", in bond_option_ad_select_set()
1682 newval->string, newval->value); in bond_option_ad_select_set()
1683 bond->params.ad_select = newval->value; in bond_option_ad_select_set()
1688 static int bond_option_queue_id_set(struct bonding *bond, in bond_option_queue_id_set() argument
1699 delim = strchr(newval->string, ':'); in bond_option_queue_id_set()
1711 if (!dev_valid_name(newval->string) || in bond_option_queue_id_set()
1712 qid > bond->dev->real_num_tx_queues) in bond_option_queue_id_set()
1716 sdev = __dev_get_by_name(dev_net(bond->dev), newval->string); in bond_option_queue_id_set()
1722 bond_for_each_slave(bond, slave, iter) { in bond_option_queue_id_set()
1723 if (sdev == slave->dev) in bond_option_queue_id_set()
1728 else if (qid && qid == slave->queue_id) { in bond_option_queue_id_set()
1737 WRITE_ONCE(update_slave->queue_id, qid); in bond_option_queue_id_set()
1743 netdev_dbg(bond->dev, "invalid input for queue_id set\n"); in bond_option_queue_id_set()
1744 ret = -EPERM; in bond_option_queue_id_set()
1749 static int bond_option_slaves_set(struct bonding *bond, in bond_option_slaves_set() argument
1757 sscanf(newval->string, "%16s", command); /* IFNAMSIZ*/ in bond_option_slaves_set()
1760 (command[0] != '+' && command[0] != '-') || in bond_option_slaves_set()
1764 dev = __dev_get_by_name(dev_net(bond->dev), ifname); in bond_option_slaves_set()
1766 netdev_dbg(bond->dev, "interface %s does not exist!\n", in bond_option_slaves_set()
1768 ret = -ENODEV; in bond_option_slaves_set()
1774 slave_dbg(bond->dev, dev, "Enslaving interface\n"); in bond_option_slaves_set()
1775 ret = bond_enslave(bond->dev, dev, NULL); in bond_option_slaves_set()
1778 case '-': in bond_option_slaves_set()
1779 slave_dbg(bond->dev, dev, "Releasing interface\n"); in bond_option_slaves_set()
1780 ret = bond_release(bond->dev, dev); in bond_option_slaves_set()
1792 netdev_err(bond->dev, "no command found in slaves file - use +ifname or -ifname\n"); in bond_option_slaves_set()
1793 ret = -EPERM; in bond_option_slaves_set()
1797 static int bond_option_tlb_dynamic_lb_set(struct bonding *bond, in bond_option_tlb_dynamic_lb_set() argument
1800 netdev_dbg(bond->dev, "Setting dynamic-lb to %s (%llu)\n", in bond_option_tlb_dynamic_lb_set()
1801 newval->string, newval->value); in bond_option_tlb_dynamic_lb_set()
1802 bond->params.tlb_dynamic_lb = newval->value; in bond_option_tlb_dynamic_lb_set()
1807 static int bond_option_ad_actor_sys_prio_set(struct bonding *bond, in bond_option_ad_actor_sys_prio_set() argument
1810 netdev_dbg(bond->dev, "Setting ad_actor_sys_prio to %llu\n", in bond_option_ad_actor_sys_prio_set()
1811 newval->value); in bond_option_ad_actor_sys_prio_set()
1813 bond->params.ad_actor_sys_prio = newval->value; in bond_option_ad_actor_sys_prio_set()
1814 bond_3ad_update_ad_actor_settings(bond); in bond_option_ad_actor_sys_prio_set()
1819 static int bond_option_ad_actor_system_set(struct bonding *bond, in bond_option_ad_actor_system_set() argument
1825 if (newval->string) { in bond_option_ad_actor_system_set()
1826 if (!mac_pton(newval->string, macaddr)) in bond_option_ad_actor_system_set()
1830 mac = (u8 *)&newval->value; in bond_option_ad_actor_system_set()
1836 netdev_dbg(bond->dev, "Setting ad_actor_system to %pM\n", mac); in bond_option_ad_actor_system_set()
1837 ether_addr_copy(bond->params.ad_actor_system, mac); in bond_option_ad_actor_system_set()
1838 bond_3ad_update_ad_actor_settings(bond); in bond_option_ad_actor_system_set()
1843 netdev_err(bond->dev, "Invalid ad_actor_system MAC address.\n"); in bond_option_ad_actor_system_set()
1844 return -EINVAL; in bond_option_ad_actor_system_set()
1847 static int bond_option_ad_user_port_key_set(struct bonding *bond, in bond_option_ad_user_port_key_set() argument
1850 netdev_dbg(bond->dev, "Setting ad_user_port_key to %llu\n", in bond_option_ad_user_port_key_set()
1851 newval->value); in bond_option_ad_user_port_key_set()
1853 bond->params.ad_user_port_key = newval->value; in bond_option_ad_user_port_key_set()
1857 static int bond_option_coupled_control_set(struct bonding *bond, in bond_option_coupled_control_set() argument
1860 netdev_info(bond->dev, "Setting coupled_control to %s (%llu)\n", in bond_option_coupled_control_set()
1861 newval->string, newval->value); in bond_option_coupled_control_set()
1863 bond->params.coupled_control = newval->value; in bond_option_coupled_control_set()
1867 static int bond_option_broadcast_neigh_set(struct bonding *bond, in bond_option_broadcast_neigh_set() argument
1870 if (bond->params.broadcast_neighbor == newval->value) in bond_option_broadcast_neigh_set()
1873 bond->params.broadcast_neighbor = newval->value; in bond_option_broadcast_neigh_set()
1874 if (bond->dev->flags & IFF_UP) { in bond_option_broadcast_neigh_set()
1875 if (bond->params.broadcast_neighbor) in bond_option_broadcast_neigh_set()
1881 netdev_dbg(bond->dev, "Setting broadcast_neighbor to %s (%llu)\n", in bond_option_broadcast_neigh_set()
1882 newval->string, newval->value); in bond_option_broadcast_neigh_set()