^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * originally based on the dummy device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 1999, Thomas Davis, tadavis@lbl.gov.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Licensed under the GPL. Based on dummy.c, and eql.c devices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * bonding.c: an Ethernet Bonding driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This is useful to talk to a Cisco EtherChannel compatible equipment:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Cisco 5500
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Sun Trunking (Solaris)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Alteon AceDirector Trunks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Linux Bonding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * and probably many L2 switches ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * How it works:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * ifconfig bond0 ipaddress netmask up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * will setup a network device, with an ip address. No mac address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * will be assigned at this time. The hw mac address will come from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * the first slave bonded to the channel. All slaves will then use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * this hw mac address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * ifconfig bond0 down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * will release all slaves, marking them as down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * ifenslave bond0 eth0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * will attach eth0 to bond0 as a slave. eth0 hw mac address will either
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * a: be used as initial mac address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * b: if a hw mac address already is there, eth0's hw mac address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * will then be set from bond0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <net/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <linux/ip.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <linux/icmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <linux/icmpv6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <linux/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/udp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <linux/socket.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <linux/ctype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <linux/inet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #include <linux/igmp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #include <net/sock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #include <linux/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #include <net/arp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #include <linux/mii.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #include <linux/ethtool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #include <linux/if_bonding.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #include <linux/preempt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #include <net/route.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #include <net/pkt_sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #include <net/flow_dissector.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #include <net/xfrm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #include <net/bonding.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #include <net/bond_3ad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #include <net/bond_alb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #include "bonding_priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*---------------------------- Module parameters ----------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* monitor all links that often (in milliseconds). <=0 disables monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static int max_bonds = BOND_DEFAULT_MAX_BONDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static int tx_queues = BOND_DEFAULT_TX_QUEUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static int num_peer_notif = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) static int miimon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static int updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static int downdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static int use_carrier = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static char *mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) static char *primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static char *primary_reselect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) static char *lacp_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int min_links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static char *ad_select;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static char *xmit_hash_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int arp_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) static char *arp_ip_target[BOND_MAX_ARP_TARGETS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static char *arp_validate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static char *arp_all_targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static char *fail_over_mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static int all_slaves_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static struct bond_params bonding_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static int resend_igmp = BOND_DEFAULT_RESEND_IGMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int packets_per_slave = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) static int lp_interval = BOND_ALB_DEFAULT_LP_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) module_param(max_bonds, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) MODULE_PARM_DESC(max_bonds, "Max number of bonded devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) module_param(tx_queues, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_PARM_DESC(tx_queues, "Max number of transmit queues (default = 16)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) module_param_named(num_grat_arp, num_peer_notif, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_PARM_DESC(num_grat_arp, "Number of peer notifications to send on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) "failover event (alias of num_unsol_na)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) module_param_named(num_unsol_na, num_peer_notif, int, 0644);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) MODULE_PARM_DESC(num_unsol_na, "Number of peer notifications to send on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) "failover event (alias of num_grat_arp)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) module_param(miimon, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_PARM_DESC(miimon, "Link check interval in milliseconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) module_param(updelay, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) MODULE_PARM_DESC(updelay, "Delay before considering link up, in milliseconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) module_param(downdelay, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) MODULE_PARM_DESC(downdelay, "Delay before considering link down, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) "in milliseconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) module_param(use_carrier, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) MODULE_PARM_DESC(use_carrier, "Use netif_carrier_ok (vs MII ioctls) in miimon; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) "0 for off, 1 for on (default)");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) module_param(mode, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) MODULE_PARM_DESC(mode, "Mode of operation; 0 for balance-rr, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) "1 for active-backup, 2 for balance-xor, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) "3 for broadcast, 4 for 802.3ad, 5 for balance-tlb, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) "6 for balance-alb");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) module_param(primary, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) MODULE_PARM_DESC(primary, "Primary network device to use");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) module_param(primary_reselect, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) MODULE_PARM_DESC(primary_reselect, "Reselect primary slave "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) "once it comes up; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) "0 for always (default), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) "1 for only if speed of primary is "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) "better, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) "2 for only on active slave "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) "failure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) module_param(lacp_rate, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) MODULE_PARM_DESC(lacp_rate, "LACPDU tx rate to request from 802.3ad partner; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) "0 for slow, 1 for fast");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) module_param(ad_select, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) MODULE_PARM_DESC(ad_select, "802.3ad aggregation selection logic; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) "0 for stable (default), 1 for bandwidth, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) "2 for count");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) module_param(min_links, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) MODULE_PARM_DESC(min_links, "Minimum number of available links before turning on carrier");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) module_param(xmit_hash_policy, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) MODULE_PARM_DESC(xmit_hash_policy, "balance-alb, balance-tlb, balance-xor, 802.3ad hashing method; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) "0 for layer 2 (default), 1 for layer 3+4, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) "2 for layer 2+3, 3 for encap layer 2+3, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) "4 for encap layer 3+4");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) module_param(arp_interval, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) MODULE_PARM_DESC(arp_interval, "arp interval in milliseconds");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) module_param_array(arp_ip_target, charp, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) MODULE_PARM_DESC(arp_ip_target, "arp targets in n.n.n.n form");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) module_param(arp_validate, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) MODULE_PARM_DESC(arp_validate, "validate src/dst of ARP probes; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) "0 for none (default), 1 for active, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) "2 for backup, 3 for all");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) module_param(arp_all_targets, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) MODULE_PARM_DESC(arp_all_targets, "fail on any/all arp targets timeout; 0 for any (default), 1 for all");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) module_param(fail_over_mac, charp, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) MODULE_PARM_DESC(fail_over_mac, "For active-backup, do not set all slaves to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) "the same MAC; 0 for none (default), "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) "1 for active, 2 for follow");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) module_param(all_slaves_active, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) MODULE_PARM_DESC(all_slaves_active, "Keep all frames received on an interface "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) "by setting active flag for all slaves; "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) "0 for never (default), 1 for always.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) module_param(resend_igmp, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) MODULE_PARM_DESC(resend_igmp, "Number of IGMP membership reports to send on "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) "link failure");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) module_param(packets_per_slave, int, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) MODULE_PARM_DESC(packets_per_slave, "Packets to send per slave in balance-rr "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) "mode; 0 for a random slave, 1 packet per "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) "slave (default), >1 packets per slave.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) module_param(lp_interval, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) MODULE_PARM_DESC(lp_interval, "The number of seconds between instances where "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) "the bonding driver sends learning packets to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) "each slaves peer switch. The default is 1.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /*----------------------------- Global variables ----------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) atomic_t netpoll_block_tx = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned int bond_net_id __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) static const struct flow_dissector_key flow_keys_bonding_keys[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .key_id = FLOW_DISSECTOR_KEY_CONTROL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .offset = offsetof(struct flow_keys, control),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) .key_id = FLOW_DISSECTOR_KEY_BASIC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) .offset = offsetof(struct flow_keys, basic),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .key_id = FLOW_DISSECTOR_KEY_IPV4_ADDRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .offset = offsetof(struct flow_keys, addrs.v4addrs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .key_id = FLOW_DISSECTOR_KEY_IPV6_ADDRS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .offset = offsetof(struct flow_keys, addrs.v6addrs),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) .key_id = FLOW_DISSECTOR_KEY_TIPC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .offset = offsetof(struct flow_keys, addrs.tipckey),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) .key_id = FLOW_DISSECTOR_KEY_PORTS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) .offset = offsetof(struct flow_keys, ports),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) .key_id = FLOW_DISSECTOR_KEY_ICMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) .offset = offsetof(struct flow_keys, icmp),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) .key_id = FLOW_DISSECTOR_KEY_VLAN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .offset = offsetof(struct flow_keys, vlan),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .key_id = FLOW_DISSECTOR_KEY_FLOW_LABEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .offset = offsetof(struct flow_keys, tags),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .key_id = FLOW_DISSECTOR_KEY_GRE_KEYID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) .offset = offsetof(struct flow_keys, keyid),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct flow_dissector flow_keys_bonding __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) /*-------------------------- Forward declarations ---------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int bond_init(struct net_device *bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static void bond_uninit(struct net_device *bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static void bond_get_stats(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct rtnl_link_stats64 *stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) static void bond_slave_arr_handler(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) int mod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) static void bond_netdev_notify_work(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*---------------------------- General routines -----------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) const char *bond_mode_name(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static const char *names[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) [BOND_MODE_ROUNDROBIN] = "load balancing (round-robin)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) [BOND_MODE_ACTIVEBACKUP] = "fault-tolerance (active-backup)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) [BOND_MODE_XOR] = "load balancing (xor)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) [BOND_MODE_BROADCAST] = "fault-tolerance (broadcast)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) [BOND_MODE_8023AD] = "IEEE 802.3ad Dynamic link aggregation",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) [BOND_MODE_TLB] = "transmit load balancing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) [BOND_MODE_ALB] = "adaptive load balancing",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (mode < BOND_MODE_ROUNDROBIN || mode > BOND_MODE_ALB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) return "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return names[mode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * bond_dev_queue_xmit - Prepare skb for xmit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * @bond: bond device that got this skb for tx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * @skb: hw accel VLAN tagged skb to transmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * @slave_dev: slave that is supposed to xmit this skbuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) skb->dev = slave_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) BUILD_BUG_ON(sizeof(skb->queue_mapping) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) sizeof(qdisc_skb_cb(skb)->slave_dev_queue_mapping));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) skb_set_queue_mapping(skb, qdisc_skb_cb(skb)->slave_dev_queue_mapping);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (unlikely(netpoll_tx_running(bond->dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return bond_netpoll_send_skb(bond_get_slave_by_dev(bond, slave_dev), skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) return dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) /*---------------------------------- VLAN -----------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) /* In the following 2 functions, bond_vlan_rx_add_vid and bond_vlan_rx_kill_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * We don't protect the slave list iteration with a lock because:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * a. This operation is performed in IOCTL context,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * b. The operation is protected by the RTNL semaphore in the 8021q code,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * c. Holding a lock with BH disabled while directly calling a base driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * entry point is generally a BAD idea.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * The design of synchronization/protection for this operation in the 8021q
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * module is good for one or more VLAN devices over a single physical device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) * and cannot be extended for a teaming solution like bonding, so there is a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) * potential race condition here where a net device from the vlan group might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * be referenced (either by a base driver or the 8021q code) while it is being
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * removed from the system. However, it turns out we're not making matters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * worse, and if it works for regular VLAN usage it will work here too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * bond_vlan_rx_add_vid - Propagates adding an id to slaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) * @bond_dev: bonding net device that got called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * @proto: network protocol ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * @vid: vlan id being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static int bond_vlan_rx_add_vid(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) struct slave *slave, *rollback_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) res = vlan_vid_add(slave->dev, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) goto unwind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) unwind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) /* unwind to the slave that failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) bond_for_each_slave(bond, rollback_slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) if (rollback_slave == slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) vlan_vid_del(rollback_slave->dev, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * bond_vlan_rx_kill_vid - Propagates deleting an id to slaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * @bond_dev: bonding net device that got called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * @proto: network protocol ID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * @vid: vlan id being removed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) static int bond_vlan_rx_kill_vid(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) __be16 proto, u16 vid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) bond_for_each_slave(bond, slave, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) vlan_vid_del(slave->dev, proto, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) if (bond_is_lb(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) bond_alb_clear_vlan(bond, vid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /*---------------------------------- XFRM -----------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * bond_ipsec_add_sa - program device with a security association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) * @xs: pointer to transformer state struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) static int bond_ipsec_add_sa(struct xfrm_state *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) struct net_device *bond_dev = xs->xso.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) struct bond_ipsec *ipsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) if (!bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (!slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!slave->dev->xfrmdev_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) netif_is_bond_master(slave->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) slave_warn(bond_dev, slave->dev, "Slave does not support ipsec offload\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) ipsec = kmalloc(sizeof(*ipsec), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (!ipsec) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) xs->xso.real_dev = slave->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) err = slave->dev->xfrmdev_ops->xdo_dev_state_add(xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (!err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) ipsec->xs = xs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) INIT_LIST_HEAD(&ipsec->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) spin_lock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) list_add(&ipsec->list, &bond->ipsec_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) spin_unlock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) kfree(ipsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static void bond_ipsec_add_sa_all(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct net_device *bond_dev = bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) struct bond_ipsec *ipsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) if (!slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (!slave->dev->xfrmdev_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) !slave->dev->xfrmdev_ops->xdo_dev_state_add ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) netif_is_bond_master(slave->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) spin_lock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) if (!list_empty(&bond->ipsec_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) slave_warn(bond_dev, slave->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) "%s: no slave xdo_dev_state_add\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) spin_unlock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) spin_lock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) list_for_each_entry(ipsec, &bond->ipsec_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) ipsec->xs->xso.real_dev = slave->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (slave->dev->xfrmdev_ops->xdo_dev_state_add(ipsec->xs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) slave_warn(bond_dev, slave->dev, "%s: failed to add SA\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) ipsec->xs->xso.real_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) spin_unlock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * bond_ipsec_del_sa - clear out this specific SA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * @xs: pointer to transformer state struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static void bond_ipsec_del_sa(struct xfrm_state *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) struct net_device *bond_dev = xs->xso.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) struct bond_ipsec *ipsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (!bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (!slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) if (!xs->xso.real_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) WARN_ON(xs->xso.real_dev != slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (!slave->dev->xfrmdev_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) netif_is_bond_master(slave->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) slave_warn(bond_dev, slave->dev, "%s: no slave xdo_dev_state_delete\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) slave->dev->xfrmdev_ops->xdo_dev_state_delete(xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) spin_lock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) list_for_each_entry(ipsec, &bond->ipsec_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (ipsec->xs == xs) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) list_del(&ipsec->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) kfree(ipsec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) spin_unlock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) static void bond_ipsec_del_sa_all(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) struct net_device *bond_dev = bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) struct bond_ipsec *ipsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (!slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) spin_lock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) list_for_each_entry(ipsec, &bond->ipsec_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!ipsec->xs->xso.real_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (!slave->dev->xfrmdev_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) !slave->dev->xfrmdev_ops->xdo_dev_state_delete ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) netif_is_bond_master(slave->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) slave_warn(bond_dev, slave->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) "%s: no slave xdo_dev_state_delete\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) slave->dev->xfrmdev_ops->xdo_dev_state_delete(ipsec->xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) ipsec->xs->xso.real_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) spin_unlock_bh(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * bond_ipsec_offload_ok - can this packet use the xfrm hw offload
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * @skb: current data packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * @xs: pointer to transformer state struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) static bool bond_ipsec_offload_ok(struct sk_buff *skb, struct xfrm_state *xs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) struct net_device *bond_dev = xs->xso.dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) struct net_device *real_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) struct slave *curr_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) curr_active = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) real_dev = curr_active->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) err = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (!xs->xso.real_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) err = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (!real_dev->xfrmdev_ops ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) !real_dev->xfrmdev_ops->xdo_dev_offload_ok ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) netif_is_bond_master(real_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) err = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) err = real_dev->xfrmdev_ops->xdo_dev_offload_ok(skb, xs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static const struct xfrmdev_ops bond_xfrmdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) .xdo_dev_state_add = bond_ipsec_add_sa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) .xdo_dev_state_delete = bond_ipsec_del_sa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) .xdo_dev_offload_ok = bond_ipsec_offload_ok,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) /*------------------------------- Link status -------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) /* Set the carrier state for the master according to the state of its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) * slaves. If any slaves are up, the master is up. In 802.3ad mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) * do special 802.3ad magic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) * Returns zero if carrier state does not change, nonzero if it does.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) int bond_set_carrier(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) if (!bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) goto down;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return bond_3ad_set_carrier(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (slave->link == BOND_LINK_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) if (!netif_carrier_ok(bond->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) netif_carrier_on(bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) down:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) if (netif_carrier_ok(bond->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) netif_carrier_off(bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /* Get link speed and duplex from the slave's base driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) * using ethtool. If for some reason the call fails or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * values are invalid, set speed and duplex to -1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * and return. Return 1 if speed or duplex settings are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * UNKNOWN; 0 otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) static int bond_update_speed_duplex(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) struct net_device *slave_dev = slave->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) struct ethtool_link_ksettings ecmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) slave->speed = SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) slave->duplex = DUPLEX_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) res = __ethtool_get_link_ksettings(slave_dev, &ecmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) if (res < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) if (ecmd.base.speed == 0 || ecmd.base.speed == ((__u32)-1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) switch (ecmd.base.duplex) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) case DUPLEX_FULL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) case DUPLEX_HALF:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) slave->speed = ecmd.base.speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) slave->duplex = ecmd.base.duplex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) const char *bond_slave_link_status(s8 link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) switch (link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) case BOND_LINK_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) return "up";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) case BOND_LINK_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return "going down";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) case BOND_LINK_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) return "down";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) case BOND_LINK_BACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return "going back";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) return "unknown";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* if <dev> supports MII link status reporting, check its link status.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) * We either do MII/ETHTOOL ioctls, or check netif_carrier_ok(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) * depending upon the setting of the use_carrier parameter.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) * Return either BMSR_LSTATUS, meaning that the link is up (or we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) * can't tell and just pretend it is), or 0, meaning that the link is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * down.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * If reporting is non-zero, instead of faking link up, return -1 if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * both ETHTOOL and MII ioctls fail (meaning the device does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) * support them). If use_carrier is set, return whatever it says.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) * It'd be nice if there was a good way to tell if a driver supports
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) * netif_carrier, but there really isn't.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static int bond_check_dev_link(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct net_device *slave_dev, int reporting)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) int (*ioctl)(struct net_device *, struct ifreq *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct ifreq ifr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) struct mii_ioctl_data *mii;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (!reporting && !netif_running(slave_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) if (bond->params.use_carrier)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) return netif_carrier_ok(slave_dev) ? BMSR_LSTATUS : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /* Try to get link status using Ethtool first. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (slave_dev->ethtool_ops->get_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) return slave_dev->ethtool_ops->get_link(slave_dev) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) BMSR_LSTATUS : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) /* Ethtool can't be used, fallback to MII ioctls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) ioctl = slave_ops->ndo_do_ioctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (ioctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /* TODO: set pointer to correct ioctl on a per team member
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) * bases to make this more efficient. that is, once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) * we determine the correct ioctl, we will always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) * call it and not the others for that team
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) * member.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) /* We cannot assume that SIOCGMIIPHY will also read a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * register; not all network drivers (e.g., e100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * support that.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) /* Yes, the mii is overlaid on the ifreq.ifr_ifru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) strncpy(ifr.ifr_name, slave_dev->name, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) mii = if_mii(&ifr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) if (ioctl(slave_dev, &ifr, SIOCGMIIPHY) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) mii->reg_num = MII_BMSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) if (ioctl(slave_dev, &ifr, SIOCGMIIREG) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return mii->val_out & BMSR_LSTATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /* If reporting, report that either there's no dev->do_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * or both SIOCGMIIREG and get_link failed (meaning that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * cannot report link status). If not reporting, pretend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * we're ok.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) return reporting ? -1 : BMSR_LSTATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) /*----------------------------- Multicast list ------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) /* Push the promiscuity flag down to appropriate slaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) static int bond_set_promiscuity(struct bonding *bond, int inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (curr_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) err = dev_set_promiscuity(curr_active->dev, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) err = dev_set_promiscuity(slave->dev, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) /* Push the allmulti flag down to all slaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) static int bond_set_allmulti(struct bonding *bond, int inc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) if (bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) struct slave *curr_active = rtnl_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) if (curr_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) err = dev_set_allmulti(curr_active->dev, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) err = dev_set_allmulti(slave->dev, inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /* Retrieve the list of registered multicast addresses for the bonding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * device and retransmit an IGMP JOIN request to the current active
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) static void bond_resend_igmp_join_requests_delayed(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) struct bonding *bond = container_of(work, struct bonding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) mcast_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) if (!rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) queue_delayed_work(bond->wq, &bond->mcast_work, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) call_netdevice_notifiers(NETDEV_RESEND_IGMP, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) if (bond->igmp_retrans > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) bond->igmp_retrans--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) queue_delayed_work(bond->wq, &bond->mcast_work, HZ/5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) /* Flush bond's hardware addresses from slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) static void bond_hw_addr_flush(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) dev_uc_unsync(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) dev_mc_unsync(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) /* del lacpdu mc addr from mc list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) dev_mc_del(slave_dev, lacpdu_multicast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /*--------------------------- Active slave change ---------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) /* Update the hardware address list and promisc/allmulti for the new and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * old active slaves (if any). Modes that are not using primary keep all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * slaves up date at all times; only the modes that use primary need to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * this function to swap these settings during a failover.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) struct slave *old_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) if (old_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) if (bond->dev->flags & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) dev_set_promiscuity(old_active->dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) if (bond->dev->flags & IFF_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) dev_set_allmulti(old_active->dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) bond_hw_addr_flush(bond->dev, old_active->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (new_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) /* FIXME: Signal errors upstream. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) if (bond->dev->flags & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) dev_set_promiscuity(new_active->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (bond->dev->flags & IFF_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) dev_set_allmulti(new_active->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) netif_addr_lock_bh(bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) dev_uc_sync(new_active->dev, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) dev_mc_sync(new_active->dev, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) netif_addr_unlock_bh(bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * bond_set_dev_addr - clone slave's address to bond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * @bond_dev: bond net device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) * @slave_dev: slave net device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) * Should be called with RTNL held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) static int bond_set_dev_addr(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) slave_dbg(bond_dev, slave_dev, "bond_dev=%p slave_dev=%p slave_dev->addr_len=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) bond_dev, slave_dev, slave_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) err = dev_pre_changeaddr_notify(bond_dev, slave_dev->dev_addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) memcpy(bond_dev->dev_addr, slave_dev->dev_addr, slave_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) bond_dev->addr_assign_type = NET_ADDR_STOLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) call_netdevice_notifiers(NETDEV_CHANGEADDR, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) static struct slave *bond_get_old_active(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) struct slave *new_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (slave == new_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) if (ether_addr_equal(bond->dev->dev_addr, slave->dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) /* bond_do_fail_over_mac
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) * Perform special MAC address swapping for fail_over_mac settings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) * Called with RTNL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) static void bond_do_fail_over_mac(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) struct slave *new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) struct slave *old_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) u8 tmp_mac[MAX_ADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) struct sockaddr_storage ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) switch (bond->params.fail_over_mac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) case BOND_FOM_ACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (new_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) rv = bond_set_dev_addr(bond->dev, new_active->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) slave_err(bond->dev, new_active->dev, "Error %d setting bond MAC from slave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) -rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) case BOND_FOM_FOLLOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) /* if new_active && old_active, swap them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) * if just old_active, do nothing (going to no active slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) * if just new_active, set new_active to bond's MAC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (!new_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (!old_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) old_active = bond_get_old_active(bond, new_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) if (old_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) bond_hw_addr_copy(tmp_mac, new_active->dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) new_active->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) bond_hw_addr_copy(ss.__data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) old_active->dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) old_active->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) ss.ss_family = new_active->dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) bond_hw_addr_copy(ss.__data, bond->dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) bond->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) ss.ss_family = bond->dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) rv = dev_set_mac_address(new_active->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) (struct sockaddr *)&ss, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) if (rv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) slave_err(bond->dev, new_active->dev, "Error %d setting MAC of new active slave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) -rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) if (!old_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) bond_hw_addr_copy(ss.__data, tmp_mac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) new_active->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) ss.ss_family = old_active->dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) rv = dev_set_mac_address(old_active->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) (struct sockaddr *)&ss, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) if (rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) slave_err(bond->dev, old_active->dev, "Error %d setting MAC of old active slave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) -rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) netdev_err(bond->dev, "bond_do_fail_over_mac impossible: bad policy %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) bond->params.fail_over_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) static struct slave *bond_choose_primary_or_current(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) struct slave *prim = rtnl_dereference(bond->primary_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) struct slave *curr = rtnl_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996) if (!prim || prim->link != BOND_LINK_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) if (!curr || curr->link != BOND_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) if (bond->force_primary) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) bond->force_primary = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) return prim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) if (!curr || curr->link != BOND_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) return prim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) /* At this point, prim and curr are both up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) switch (bond->params.primary_reselect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) case BOND_PRI_RESELECT_ALWAYS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) return prim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) case BOND_PRI_RESELECT_BETTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) if (prim->speed < curr->speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) if (prim->speed == curr->speed && prim->duplex <= curr->duplex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) return prim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) case BOND_PRI_RESELECT_FAILURE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) netdev_err(bond->dev, "impossible primary_reselect %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) bond->params.primary_reselect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) * bond_find_best_slave - select the best available slave to be the active one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) * @bond: our bonding struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) static struct slave *bond_find_best_slave(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) struct slave *slave, *bestslave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int mintime = bond->params.updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) slave = bond_choose_primary_or_current(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) if (slave->link == BOND_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) if (slave->link == BOND_LINK_BACK && bond_slave_is_up(slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) slave->delay < mintime) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) mintime = slave->delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) bestslave = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return bestslave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) static bool bond_should_notify_peers(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) if (!slave || !bond->send_peer_notif ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) bond->send_peer_notif %
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) max(1, bond->params.peer_notif_delay) != 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) !netif_carrier_ok(bond->dev) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) test_bit(__LINK_STATE_LINKWATCH_PENDING, &slave->dev->state))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) netdev_dbg(bond->dev, "bond_should_notify_peers: slave %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) slave ? slave->dev->name : "NULL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) * change_active_interface - change the active slave into the specified one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) * @bond: our bonding struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) * @new_active: the new slave to make the active one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) * Set the new slave to the bond's settings and unset them on the old
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) * curr_active_slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) * Setting include flags, mc-list, promiscuity, allmulti, etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) * If @new's link state is %BOND_LINK_BACK we'll set it to %BOND_LINK_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) * because it is apparently the best available slave we have, even though its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) * updelay hasn't timed out yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) * Caller must hold RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) void bond_change_active_slave(struct bonding *bond, struct slave *new_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) struct slave *old_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) old_active = rtnl_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) if (old_active == new_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) bond_ipsec_del_sa_all(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) if (new_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) new_active->last_link_up = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) if (new_active->link == BOND_LINK_BACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) if (bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) slave_info(bond->dev, new_active->dev, "making interface the new active one %d ms earlier\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) (bond->params.updelay - new_active->delay) * bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) new_active->delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) bond_set_slave_link_state(new_active, BOND_LINK_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) if (BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) bond_3ad_handle_link_change(new_active, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (bond_is_lb(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) bond_alb_handle_link_change(bond, new_active, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) if (bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) slave_info(bond->dev, new_active->dev, "making interface the new active one\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) if (bond_uses_primary(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) bond_hw_addr_swap(bond, new_active, old_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (bond_is_lb(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) bond_alb_handle_active_change(bond, new_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) if (old_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) bond_set_slave_inactive_flags(old_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (new_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) bond_set_slave_active_flags(new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) rcu_assign_pointer(bond->curr_active_slave, new_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (old_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) bond_set_slave_inactive_flags(old_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) if (new_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) bool should_notify_peers = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) bond_set_slave_active_flags(new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) if (bond->params.fail_over_mac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) bond_do_fail_over_mac(bond, new_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) old_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) if (netif_running(bond->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) bond->send_peer_notif =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) bond->params.num_peer_notif *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) max(1, bond->params.peer_notif_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) should_notify_peers =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) bond_should_notify_peers(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) call_netdevice_notifiers(NETDEV_BONDING_FAILOVER, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) if (should_notify_peers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) bond->send_peer_notif--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) bond_ipsec_add_sa_all(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /* resend IGMP joins since active slave has changed or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) * all were sent on curr_active_slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) * resend only if bond is brought up with the affected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) * bonding modes and the retransmission is enabled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (netif_running(bond->dev) && (bond->params.resend_igmp > 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) ((bond_uses_primary(bond) && new_active) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) BOND_MODE(bond) == BOND_MODE_ROUNDROBIN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) bond->igmp_retrans = bond->params.resend_igmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) queue_delayed_work(bond->wq, &bond->mcast_work, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) * bond_select_active_slave - select a new active slave, if needed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) * @bond: our bonding struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) * This functions should be called when one of the following occurs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) * - The old curr_active_slave has been released or lost its link.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) * - The primary_slave has got its link back.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) * - A slave has got its link back and there's no old curr_active_slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) * Caller must hold RTNL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) void bond_select_active_slave(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) struct slave *best_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) ASSERT_RTNL();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) best_slave = bond_find_best_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (best_slave != rtnl_dereference(bond->curr_active_slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) bond_change_active_slave(bond, best_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) rv = bond_set_carrier(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) if (!rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) if (netif_carrier_ok(bond->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) netdev_info(bond->dev, "active interface up!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) netdev_info(bond->dev, "now running without any active interface!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) static inline int slave_enable_netpoll(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) struct netpoll *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) np = kzalloc(sizeof(*np), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) err = __netpoll_setup(np, slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) kfree(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) slave->np = np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) static inline void slave_disable_netpoll(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) struct netpoll *np = slave->np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) slave->np = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) __netpoll_free(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) static void bond_poll_controller(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) struct slave *slave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) if (BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) if (bond_3ad_get_active_agg_info(bond, &ad_info))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) if (!bond_slave_is_up(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) struct aggregator *agg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) SLAVE_AD_INFO(slave)->port.aggregator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) if (agg &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) agg->aggregator_identifier != ad_info.aggregator_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) netpoll_poll_dev(slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) static void bond_netpoll_cleanup(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) bond_for_each_slave(bond, slave, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (bond_slave_is_up(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) slave_disable_netpoll(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) static int bond_netpoll_setup(struct net_device *dev, struct netpoll_info *ni)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) struct bonding *bond = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) err = slave_enable_netpoll(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) bond_netpoll_cleanup(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) static inline int slave_enable_netpoll(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) static inline void slave_disable_netpoll(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) static void bond_netpoll_cleanup(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) /*---------------------------------- IOCTL ----------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) static netdev_features_t bond_fix_features(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) netdev_features_t features)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) struct bonding *bond = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) netdev_features_t mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) mask = features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) features &= ~NETIF_F_ONE_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) features |= NETIF_F_ALL_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) features = netdev_increment_features(features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) slave->dev->features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) features = netdev_add_tso_features(features, mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) return features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) #define BOND_VLAN_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) NETIF_F_FRAGLIST | NETIF_F_ALL_TSO | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) NETIF_F_HIGHDMA | NETIF_F_LRO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) #define BOND_ENC_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) NETIF_F_RXCSUM | NETIF_F_ALL_TSO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) #define BOND_MPLS_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) NETIF_F_ALL_TSO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) static void bond_compute_features(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) unsigned int dst_release_flag = IFF_XMIT_DST_RELEASE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) IFF_XMIT_DST_RELEASE_PERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) netdev_features_t vlan_features = BOND_VLAN_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) netdev_features_t enc_features = BOND_ENC_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) netdev_features_t xfrm_features = BOND_XFRM_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) netdev_features_t mpls_features = BOND_MPLS_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) struct net_device *bond_dev = bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) unsigned short max_hard_header_len = ETH_HLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) unsigned int gso_max_size = GSO_MAX_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) u16 gso_max_segs = GSO_MAX_SEGS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) if (!bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) vlan_features &= NETIF_F_ALL_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) mpls_features &= NETIF_F_ALL_FOR_ALL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) vlan_features = netdev_increment_features(vlan_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) slave->dev->vlan_features, BOND_VLAN_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) enc_features = netdev_increment_features(enc_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) slave->dev->hw_enc_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) BOND_ENC_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) xfrm_features = netdev_increment_features(xfrm_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) slave->dev->hw_enc_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) BOND_XFRM_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) mpls_features = netdev_increment_features(mpls_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) slave->dev->mpls_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) BOND_MPLS_FEATURES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) dst_release_flag &= slave->dev->priv_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) if (slave->dev->hard_header_len > max_hard_header_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) max_hard_header_len = slave->dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) gso_max_size = min(gso_max_size, slave->dev->gso_max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) gso_max_segs = min(gso_max_segs, slave->dev->gso_max_segs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) bond_dev->hard_header_len = max_hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) bond_dev->vlan_features = vlan_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) bond_dev->hw_enc_features = enc_features | NETIF_F_GSO_ENCAP_ALL |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) NETIF_F_HW_VLAN_CTAG_TX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) NETIF_F_HW_VLAN_STAG_TX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) NETIF_F_GSO_UDP_L4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) bond_dev->hw_enc_features |= xfrm_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) bond_dev->mpls_features = mpls_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) bond_dev->gso_max_segs = gso_max_segs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) netif_set_gso_max_size(bond_dev, gso_max_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) bond_dev->priv_flags &= ~IFF_XMIT_DST_RELEASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) if ((bond_dev->priv_flags & IFF_XMIT_DST_RELEASE_PERM) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) dst_release_flag == (IFF_XMIT_DST_RELEASE | IFF_XMIT_DST_RELEASE_PERM))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) bond_dev->priv_flags |= IFF_XMIT_DST_RELEASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) netdev_change_features(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) static void bond_setup_by_slave(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) bond_dev->header_ops = slave_dev->header_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) bond_dev->type = slave_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) bond_dev->hard_header_len = slave_dev->hard_header_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) bond_dev->needed_headroom = slave_dev->needed_headroom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) bond_dev->addr_len = slave_dev->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) memcpy(bond_dev->broadcast, slave_dev->broadcast,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) slave_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) /* On bonding slaves other than the currently active slave, suppress
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) * duplicates except for alb non-mcast/bcast.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) static bool bond_should_deliver_exact_match(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) if (bond_is_slave_inactive(slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) if (BOND_MODE(bond) == BOND_MODE_ALB &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) skb->pkt_type != PACKET_BROADCAST &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) skb->pkt_type != PACKET_MULTICAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) static rx_handler_result_t bond_handle_frame(struct sk_buff **pskb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) struct sk_buff *skb = *pskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) int (*recv_probe)(const struct sk_buff *, struct bonding *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) struct slave *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) int ret = RX_HANDLER_ANOTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) skb = skb_share_check(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) return RX_HANDLER_CONSUMED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) *pskb = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) slave = bond_slave_get_rcu(skb->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) bond = slave->bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) recv_probe = READ_ONCE(bond->recv_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) if (recv_probe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) ret = recv_probe(skb, bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) if (ret == RX_HANDLER_CONSUMED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) * For packets determined by bond_should_deliver_exact_match() call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) * be suppressed we want to make an exception for link-local packets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) * This is necessary for e.g. LLDP daemons to be able to monitor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) * inactive slave links without being forced to bind to them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) * explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) * At the same time, packets that are passed to the bonding master
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) * (including link-local ones) can have their originating interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) * determined via PACKET_ORIGDEV socket option.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) if (bond_should_deliver_exact_match(skb, slave, bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (is_link_local_ether_addr(eth_hdr(skb)->h_dest))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) return RX_HANDLER_PASS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) return RX_HANDLER_EXACT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) skb->dev = bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) if (BOND_MODE(bond) == BOND_MODE_ALB &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) netif_is_bridge_port(bond->dev) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) skb->pkt_type == PACKET_HOST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) if (unlikely(skb_cow_head(skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) skb->data - skb_mac_header(skb)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) return RX_HANDLER_CONSUMED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) bond_hw_addr_copy(eth_hdr(skb)->h_dest, bond->dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) bond->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) static enum netdev_lag_tx_type bond_lag_tx_type(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) switch (BOND_MODE(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) case BOND_MODE_ROUNDROBIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) return NETDEV_LAG_TX_TYPE_ROUNDROBIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) case BOND_MODE_ACTIVEBACKUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) return NETDEV_LAG_TX_TYPE_ACTIVEBACKUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) case BOND_MODE_BROADCAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) return NETDEV_LAG_TX_TYPE_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) case BOND_MODE_XOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) case BOND_MODE_8023AD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) return NETDEV_LAG_TX_TYPE_HASH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) return NETDEV_LAG_TX_TYPE_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) static enum netdev_lag_hash bond_lag_hash_type(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) enum netdev_lag_tx_type type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) if (type != NETDEV_LAG_TX_TYPE_HASH)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) return NETDEV_LAG_HASH_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) switch (bond->params.xmit_policy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) case BOND_XMIT_POLICY_LAYER2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) return NETDEV_LAG_HASH_L2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) case BOND_XMIT_POLICY_LAYER34:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) return NETDEV_LAG_HASH_L34;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) case BOND_XMIT_POLICY_LAYER23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) return NETDEV_LAG_HASH_L23;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) case BOND_XMIT_POLICY_ENCAP23:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) return NETDEV_LAG_HASH_E23;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) case BOND_XMIT_POLICY_ENCAP34:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) return NETDEV_LAG_HASH_E34;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) return NETDEV_LAG_HASH_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) static int bond_master_upper_dev_link(struct bonding *bond, struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) struct netdev_lag_upper_info lag_upper_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) enum netdev_lag_tx_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) type = bond_lag_tx_type(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) lag_upper_info.tx_type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) lag_upper_info.hash_type = bond_lag_hash_type(bond, type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) return netdev_master_upper_dev_link(slave->dev, bond->dev, slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) &lag_upper_info, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) static void bond_upper_dev_unlink(struct bonding *bond, struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) netdev_upper_dev_unlink(slave->dev, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) slave->dev->flags &= ~IFF_SLAVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) static void slave_kobj_release(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) struct slave *slave = to_slave(kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) struct bonding *bond = bond_get_bond_by_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) cancel_delayed_work_sync(&slave->notify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) if (BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) kfree(SLAVE_AD_INFO(slave));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) kfree(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static struct kobj_type slave_ktype = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) .release = slave_kobj_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) #ifdef CONFIG_SYSFS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) .sysfs_ops = &slave_sysfs_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) static int bond_kobj_init(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) err = kobject_init_and_add(&slave->kobj, &slave_ktype,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) &(slave->dev->dev.kobj), "bonding_slave");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) kobject_put(&slave->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) static struct slave *bond_alloc_slave(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct slave *slave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) slave = kzalloc(sizeof(*slave), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) if (!slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) slave->bond = bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) slave->dev = slave_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) INIT_DELAYED_WORK(&slave->notify_work, bond_netdev_notify_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) if (bond_kobj_init(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) SLAVE_AD_INFO(slave) = kzalloc(sizeof(struct ad_slave_info),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) if (!SLAVE_AD_INFO(slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) kobject_put(&slave->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) static void bond_fill_ifbond(struct bonding *bond, struct ifbond *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) info->bond_mode = BOND_MODE(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) info->miimon = bond->params.miimon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) info->num_slaves = bond->slave_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) static void bond_fill_ifslave(struct slave *slave, struct ifslave *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) strcpy(info->slave_name, slave->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) info->link = slave->link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) info->state = bond_slave_state(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) info->link_failure_count = slave->link_failure_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) static void bond_netdev_notify_work(struct work_struct *_work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) struct slave *slave = container_of(_work, struct slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) notify_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) if (rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) struct netdev_bonding_info binfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) bond_fill_ifslave(slave, &binfo.slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) bond_fill_ifbond(slave->bond, &binfo.master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) netdev_bonding_info_change(slave->dev, &binfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) queue_delayed_work(slave->bond->wq, &slave->notify_work, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) void bond_queue_slave_event(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) queue_delayed_work(slave->bond->wq, &slave->notify_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) void bond_lower_state_changed(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) struct netdev_lag_lower_state_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) info.link_up = slave->link == BOND_LINK_UP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) slave->link == BOND_LINK_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) info.tx_enabled = bond_is_active_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) netdev_lower_state_changed(slave->dev, &info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) /* enslave device <slave> to bond device <master> */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) struct slave *new_slave = NULL, *prev_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) struct sockaddr_storage ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) int link_reporting;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) int res = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) if (!bond->params.use_carrier &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) slave_dev->ethtool_ops->get_link == NULL &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) slave_ops->ndo_do_ioctl == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) slave_warn(bond_dev, slave_dev, "no link monitoring support\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) /* already in-use? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) if (netdev_is_rx_handler_busy(slave_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) NL_SET_ERR_MSG(extack, "Device is in use and cannot be enslaved");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) slave_err(bond_dev, slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) "Error: Device is in use and cannot be enslaved\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) if (bond_dev == slave_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) NL_SET_ERR_MSG(extack, "Cannot enslave bond to itself.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) netdev_err(bond_dev, "cannot enslave bond to itself.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) /* vlan challenged mutual exclusion */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) /* no need to lock since we're protected by rtnl_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) slave_dbg(bond_dev, slave_dev, "is NETIF_F_VLAN_CHALLENGED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) if (vlan_uses_dev(bond_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) NL_SET_ERR_MSG(extack, "Can not enslave VLAN challenged device to VLAN enabled bond");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) slave_err(bond_dev, slave_dev, "Error: cannot enslave VLAN challenged slave on VLAN enabled bond\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) slave_dbg(bond_dev, slave_dev, "is !NETIF_F_VLAN_CHALLENGED\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) if (slave_dev->features & NETIF_F_HW_ESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) slave_dbg(bond_dev, slave_dev, "is esp-hw-offload capable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) /* Old ifenslave binaries are no longer supported. These can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) * be identified with moderate accuracy by the state of the slave:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) * the current ifenslave will set the interface down prior to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) * enslaving it; the old ifenslave will not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) if (slave_dev->flags & IFF_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) NL_SET_ERR_MSG(extack, "Device can not be enslaved while up");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) slave_err(bond_dev, slave_dev, "slave is up - this may be due to an out of date ifenslave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) /* set bonding device ether type by slave - bonding netdevices are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) * created with ether_setup, so when the slave type is not ARPHRD_ETHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) * there is a need to override some of the type dependent attribs/funcs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) * bond ether type mutual exclusion - don't allow slaves of dissimilar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) * ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) if (!bond_has_slaves(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) if (bond_dev->type != slave_dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) slave_dbg(bond_dev, slave_dev, "change device type from %d to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) bond_dev->type, slave_dev->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) res = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) res = notifier_to_errno(res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) slave_err(bond_dev, slave_dev, "refused to change device type\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) /* Flush unicast and multicast addresses */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) dev_uc_flush(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) dev_mc_flush(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) if (slave_dev->type != ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) bond_setup_by_slave(bond_dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) ether_setup(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) call_netdevice_notifiers(NETDEV_POST_TYPE_CHANGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) } else if (bond_dev->type != slave_dev->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) NL_SET_ERR_MSG(extack, "Device type is different from other slaves");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) slave_err(bond_dev, slave_dev, "ether type (%d) is different from other slaves (%d), can not enslave it\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) slave_dev->type, bond_dev->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) if (slave_dev->type == ARPHRD_INFINIBAND &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) NL_SET_ERR_MSG(extack, "Only active-backup mode is supported for infiniband slaves");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) slave_warn(bond_dev, slave_dev, "Type (%d) supports only active-backup mode\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) slave_dev->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) res = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) goto err_undo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) if (!slave_ops->ndo_set_mac_address ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) slave_dev->type == ARPHRD_INFINIBAND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) slave_warn(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) bond->params.fail_over_mac != BOND_FOM_ACTIVE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) if (!bond_has_slaves(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) bond->params.fail_over_mac = BOND_FOM_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) slave_warn(bond_dev, slave_dev, "Setting fail_over_mac to active for active-backup mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) NL_SET_ERR_MSG(extack, "Slave device does not support setting the MAC address, but fail_over_mac is not set to active");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) slave_err(bond_dev, slave_dev, "The slave device specified does not support setting the MAC address, but fail_over_mac is not set to active\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) res = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) goto err_undo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) call_netdevice_notifiers(NETDEV_JOIN, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) /* If this is the first slave, then we need to set the master's hardware
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) * address to be the same as the slave's.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) if (!bond_has_slaves(bond) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) bond->dev->addr_assign_type == NET_ADDR_RANDOM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) res = bond_set_dev_addr(bond->dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) goto err_undo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) new_slave = bond_alloc_slave(bond, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) if (!new_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) res = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) goto err_undo_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) /* Set the new_slave's queue_id to be zero. Queue ID mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) * is set via sysfs or module option if desired.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) new_slave->queue_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) /* Save slave's original mtu and then set it to match the bond */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) new_slave->original_mtu = slave_dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) res = dev_set_mtu(slave_dev, bond->dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) slave_err(bond_dev, slave_dev, "Error %d calling dev_set_mtu\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) goto err_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) /* Save slave's original ("permanent") mac address for modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) * that need it, and for restoring it upon release, and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) * set it to the master's address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) bond_hw_addr_copy(new_slave->perm_hwaddr, slave_dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) slave_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) if (!bond->params.fail_over_mac ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) /* Set slave to master's mac address. The application already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) * set the master's mac address to that of the first slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) memcpy(ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) ss.ss_family = slave_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) res = dev_set_mac_address(slave_dev, (struct sockaddr *)&ss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) slave_err(bond_dev, slave_dev, "Error %d calling set_mac_address\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) goto err_restore_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) /* set slave flag before open to prevent IPv6 addrconf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) slave_dev->flags |= IFF_SLAVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) /* open the slave since the application closed it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) res = dev_open(slave_dev, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) slave_err(bond_dev, slave_dev, "Opening slave failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) goto err_restore_mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) slave_dev->priv_flags |= IFF_BONDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) /* initialize slave stats */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) dev_get_stats(new_slave->dev, &new_slave->slave_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) if (bond_is_lb(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) /* bond_alb_init_slave() must be called before all other stages since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) * it might fail and we do not want to have to undo everything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) res = bond_alb_init_slave(bond, new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) goto err_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) res = vlan_vids_add_by_dev(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) slave_err(bond_dev, slave_dev, "Couldn't add bond vlan ids\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) goto err_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) prev_slave = bond_last_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) new_slave->delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) new_slave->link_failure_count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) if (bond_update_speed_duplex(new_slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) bond_needs_speed_duplex(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) new_slave->link = BOND_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) new_slave->last_rx = jiffies -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) (msecs_to_jiffies(bond->params.arp_interval) + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) new_slave->target_last_arp_rx[i] = new_slave->last_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) if (bond->params.miimon && !bond->params.use_carrier) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) link_reporting = bond_check_dev_link(bond, slave_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) if ((link_reporting == -1) && !bond->params.arp_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) /* miimon is set but a bonded network driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) * does not support ETHTOOL/MII and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) * arp_interval is not set. Note: if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) * use_carrier is enabled, we will never go
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) * here (because netif_carrier is always
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) * supported); thus, we don't need to change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) * the messages for netif_carrier.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) slave_warn(bond_dev, slave_dev, "MII and ETHTOOL support not available for slave, and arp_interval/arp_ip_target module parameters not specified, thus bonding will not detect link failures! see bonding.txt for details\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) } else if (link_reporting == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) /* unable get link status using mii/ethtool */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) slave_warn(bond_dev, slave_dev, "can't get link status from slave; the network driver associated with this interface does not support MII or ETHTOOL link status reporting, thus miimon has no effect on this interface\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) /* check for initial state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) new_slave->link = BOND_LINK_NOCHANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) if (bond->params.miimon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (bond_check_dev_link(bond, slave_dev, 0) == BMSR_LSTATUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) if (bond->params.updelay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) bond_set_slave_link_state(new_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) BOND_LINK_BACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) new_slave->delay = bond->params.updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) bond_set_slave_link_state(new_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) BOND_LINK_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) bond_set_slave_link_state(new_slave, BOND_LINK_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) } else if (bond->params.arp_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) bond_set_slave_link_state(new_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) (netif_carrier_ok(slave_dev) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) BOND_LINK_UP : BOND_LINK_DOWN),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) bond_set_slave_link_state(new_slave, BOND_LINK_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) if (new_slave->link != BOND_LINK_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) new_slave->last_link_up = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) new_slave->link == BOND_LINK_DOWN ? "DOWN" :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) (new_slave->link == BOND_LINK_UP ? "UP" : "BACK"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) if (bond_uses_primary(bond) && bond->params.primary[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) /* if there is a primary slave, remember it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) if (strcmp(bond->params.primary, new_slave->dev->name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) rcu_assign_pointer(bond->primary_slave, new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) bond->force_primary = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) switch (BOND_MODE(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) case BOND_MODE_ACTIVEBACKUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) bond_set_slave_inactive_flags(new_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) case BOND_MODE_8023AD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) /* in 802.3ad mode, the internal mechanism
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) * will activate the slaves in the selected
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) * aggregator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) /* if this is the first slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) if (!prev_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) SLAVE_AD_INFO(new_slave)->id = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) /* Initialize AD with the number of times that the AD timer is called in 1 second
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) * can be called only after the mac address of the bond is set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) bond_3ad_initialize(bond, 1000/AD_TIMER_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) SLAVE_AD_INFO(new_slave)->id =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) SLAVE_AD_INFO(prev_slave)->id + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) bond_3ad_bind_slave(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) case BOND_MODE_TLB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) case BOND_MODE_ALB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) bond_set_active_slave(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) bond_set_slave_inactive_flags(new_slave, BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) slave_dbg(bond_dev, slave_dev, "This slave is always active in trunk mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) /* always active in trunk mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) bond_set_active_slave(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) /* In trunking mode there is little meaning to curr_active_slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) * anyway (it holds no special properties of the bond device),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) * so we can change it without calling change_active_interface()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) if (!rcu_access_pointer(bond->curr_active_slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) new_slave->link == BOND_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) rcu_assign_pointer(bond->curr_active_slave, new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) } /* switch(bond_mode) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) if (bond->dev->npinfo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) if (slave_enable_netpoll(new_slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) slave_info(bond_dev, slave_dev, "master_dev is using netpoll, but new slave device does not support netpoll\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) res = -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) goto err_detach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) if (!(bond_dev->features & NETIF_F_LRO))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) dev_disable_lro(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) res = netdev_rx_handler_register(slave_dev, bond_handle_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) slave_dbg(bond_dev, slave_dev, "Error %d calling netdev_rx_handler_register\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) goto err_detach;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) res = bond_master_upper_dev_link(bond, new_slave, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) slave_dbg(bond_dev, slave_dev, "Error %d calling bond_master_upper_dev_link\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) goto err_unregister;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) res = bond_sysfs_slave_add(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) slave_dbg(bond_dev, slave_dev, "Error %d calling bond_sysfs_slave_add\n", res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) goto err_upper_unlink;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) /* If the mode uses primary, then the following is handled by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) * bond_change_active_slave().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) if (!bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) /* set promiscuity level to new slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) if (bond_dev->flags & IFF_PROMISC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) res = dev_set_promiscuity(slave_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) goto err_sysfs_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) /* set allmulti level to new slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) if (bond_dev->flags & IFF_ALLMULTI) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) res = dev_set_allmulti(slave_dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) if (bond_dev->flags & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) dev_set_promiscuity(slave_dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) goto err_sysfs_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) netif_addr_lock_bh(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) dev_mc_sync_multiple(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) dev_uc_sync_multiple(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) netif_addr_unlock_bh(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) /* add lacpdu mc addr to mc list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) u8 lacpdu_multicast[ETH_ALEN] = MULTICAST_LACPDU_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) dev_mc_add(slave_dev, lacpdu_multicast);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) bond->slave_cnt++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) bond_compute_features(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) bond_set_carrier(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) if (bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) if (bond_mode_can_use_xmit_hash(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) bond_update_slave_arr(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) slave_info(bond_dev, slave_dev, "Enslaving as %s interface with %s link\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) bond_is_active_slave(new_slave) ? "an active" : "a backup",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) new_slave->link != BOND_LINK_DOWN ? "an up" : "a down");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) /* enslave is successful */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) bond_queue_slave_event(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) /* Undo stages on error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) err_sysfs_del:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) bond_sysfs_slave_del(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) err_upper_unlink:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) bond_upper_dev_unlink(bond, new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) err_unregister:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) netdev_rx_handler_unregister(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) err_detach:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) vlan_vids_del_by_dev(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) if (rcu_access_pointer(bond->primary_slave) == new_slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) RCU_INIT_POINTER(bond->primary_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) if (rcu_access_pointer(bond->curr_active_slave) == new_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) bond_change_active_slave(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) /* either primary_slave or curr_active_slave might've changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) slave_disable_netpoll(new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) err_close:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) if (!netif_is_bond_master(slave_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) slave_dev->priv_flags &= ~IFF_BONDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) dev_close(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) err_restore_mac:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) slave_dev->flags &= ~IFF_SLAVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) if (!bond->params.fail_over_mac ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) /* XXX TODO - fom follow mode needs to change master's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) * MAC if this slave's MAC is in use by the bond, or at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) * least print a warning.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) bond_hw_addr_copy(ss.__data, new_slave->perm_hwaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) new_slave->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) ss.ss_family = slave_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) err_restore_mtu:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) dev_set_mtu(slave_dev, new_slave->original_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) err_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) kobject_put(&new_slave->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) err_undo_flags:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) /* Enslave of first slave has failed and we need to fix master's mac */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) if (!bond_has_slaves(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) if (ether_addr_equal_64bits(bond_dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) slave_dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) eth_hw_addr_random(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) if (bond_dev->type != ARPHRD_ETHER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) dev_close(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) ether_setup(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) bond_dev->flags |= IFF_MASTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) bond_dev->priv_flags &= ~IFF_TX_SKB_SHARING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) /* Try to release the slave device <slave> from the bond device <master>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) * It is legal to access curr_active_slave without a lock because all the function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) * is RTNL-locked. If "all" is true it means that the function is being called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) * while destroying a bond interface and all slaves are being released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) * The rules for slave state should be:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) * for Active/Backup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) * Active stays on all backups go down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) * for Bonded connections:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) * The first up interface should be left on and all others downed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) static int __bond_release_one(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) struct net_device *slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) bool all, bool unregister)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) struct slave *slave, *oldcurrent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) struct sockaddr_storage ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) int old_flags = bond_dev->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) netdev_features_t old_features = bond_dev->features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) /* slave is not a slave or master is not master of this slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) if (!(slave_dev->flags & IFF_SLAVE) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) !netdev_has_upper_dev(slave_dev, bond_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) slave_dbg(bond_dev, slave_dev, "cannot release slave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) slave = bond_get_slave_by_dev(bond, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) if (!slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) /* not a slave of this bond */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) slave_info(bond_dev, slave_dev, "interface not enslaved\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) bond_set_slave_inactive_flags(slave, BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) bond_sysfs_slave_del(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) /* recompute stats just before removing the slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) bond_get_stats(bond->dev, &bond->bond_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) /* unregister rx_handler early so bond_handle_frame wouldn't be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) * for this slave anymore.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) netdev_rx_handler_unregister(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) if (BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) bond_3ad_unbind_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) bond_upper_dev_unlink(bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) if (bond_mode_can_use_xmit_hash(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) bond_update_slave_arr(bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) slave_info(bond_dev, slave_dev, "Releasing %s interface\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) bond_is_active_slave(slave) ? "active" : "backup");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) oldcurrent = rcu_access_pointer(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) RCU_INIT_POINTER(bond->current_arp_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) if (!all && (!bond->params.fail_over_mac ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) if (ether_addr_equal_64bits(bond_dev->dev_addr, slave->perm_hwaddr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) slave_warn(bond_dev, slave_dev, "the permanent HWaddr of slave - %pM - is still in use by bond - set the HWaddr of slave to a different address to avoid conflicts\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) slave->perm_hwaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) if (rtnl_dereference(bond->primary_slave) == slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) RCU_INIT_POINTER(bond->primary_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) if (oldcurrent == slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) bond_change_active_slave(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) if (bond_is_lb(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) /* Must be called only after the slave has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) * detached from the list and the curr_active_slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) * has been cleared (if our_slave == old_current),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) * but before a new active slave is selected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262) bond_alb_deinit_slave(bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265) if (all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266) RCU_INIT_POINTER(bond->curr_active_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267) } else if (oldcurrent == slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268) /* Note that we hold RTNL over this sequence, so there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269) * is no concern that another slave add/remove event
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) * will interfere.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) bond_set_carrier(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) if (!bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) eth_hw_addr_random(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) bond->slave_cnt--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) if (!bond_has_slaves(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) call_netdevice_notifiers(NETDEV_CHANGEADDR, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) call_netdevice_notifiers(NETDEV_RELEASE, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288) bond_compute_features(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289) if (!(bond_dev->features & NETIF_F_VLAN_CHALLENGED) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290) (old_features & NETIF_F_VLAN_CHALLENGED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291) slave_info(bond_dev, slave_dev, "last VLAN challenged slave left bond - VLAN blocking is removed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293) vlan_vids_del_by_dev(slave_dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295) /* If the mode uses primary, then this case was handled above by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296) * bond_change_active_slave(..., NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) if (!bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) /* unset promiscuity level from slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) * NOTE: The NETDEV_CHANGEADDR call above may change the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) * of the IFF_PROMISC flag in the bond_dev, but we need the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) * value of that flag before that change, as that was the value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) * when this slave was attached, so we cache at the start of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) * function and use it here. Same goes for ALLMULTI below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) if (old_flags & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) dev_set_promiscuity(slave_dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) /* unset allmulti level from slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) if (old_flags & IFF_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) dev_set_allmulti(slave_dev, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) bond_hw_addr_flush(bond_dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316) slave_disable_netpoll(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318) /* close slave before restoring its mac address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319) dev_close(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321) if (bond->params.fail_over_mac != BOND_FOM_ACTIVE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322) BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323) /* restore original ("permanent") mac address */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) bond_hw_addr_copy(ss.__data, slave->perm_hwaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) slave->dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) ss.ss_family = slave_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) dev_set_mac_address(slave_dev, (struct sockaddr *)&ss, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) if (unregister)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) __dev_set_mtu(slave_dev, slave->original_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) dev_set_mtu(slave_dev, slave->original_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) if (!netif_is_bond_master(slave_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) slave_dev->priv_flags &= ~IFF_BONDING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) kobject_put(&slave->kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) /* A wrapper used because of ndo_del_link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) int bond_release(struct net_device *bond_dev, struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) return __bond_release_one(bond_dev, slave_dev, false, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) /* First release a slave and then destroy the bond if no more slaves are left.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) * Must be under rtnl_lock when this function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) static int bond_release_and_destroy(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) ret = __bond_release_one(bond_dev, slave_dev, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) if (ret == 0 && !bond_has_slaves(bond) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) bond_dev->reg_state != NETREG_UNREGISTERING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) bond_dev->priv_flags |= IFF_DISABLE_NETPOLL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) netdev_info(bond_dev, "Destroying bond\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) bond_remove_proc_entry(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) unregister_netdevice(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) static void bond_info_query(struct net_device *bond_dev, struct ifbond *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) bond_fill_ifbond(bond, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) static int bond_slave_info_query(struct net_device *bond_dev, struct ifslave *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) int i = 0, res = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) if (i++ == (int)info->slave_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) bond_fill_ifslave(slave, info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) /*-------------------------------- Monitoring -------------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) /* called with rcu_read_lock() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) static int bond_miimon_inspect(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) int link_state, commit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) bool ignore_updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) ignore_updelay = !rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) link_state = bond_check_dev_link(bond, slave->dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) switch (slave->link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) case BOND_LINK_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) if (link_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) bond_propose_link_state(slave, BOND_LINK_FAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) slave->delay = bond->params.downdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) if (slave->delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) slave_info(bond->dev, slave->dev, "link status down for %sinterface, disabling it in %d ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) (BOND_MODE(bond) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) BOND_MODE_ACTIVEBACKUP) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) (bond_is_active_slave(slave) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) "active " : "backup ") : "",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) bond->params.downdelay * bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) case BOND_LINK_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) if (link_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) /* recovered before downdelay expired */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) bond_propose_link_state(slave, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) slave->last_link_up = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) slave_info(bond->dev, slave->dev, "link status up again after %d ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) (bond->params.downdelay - slave->delay) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) if (slave->delay <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) bond_propose_link_state(slave, BOND_LINK_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) slave->delay--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) case BOND_LINK_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) if (!link_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) bond_propose_link_state(slave, BOND_LINK_BACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) slave->delay = bond->params.updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) if (slave->delay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) slave_info(bond->dev, slave->dev, "link status up, enabling it in %d ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) ignore_updelay ? 0 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) bond->params.updelay *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) case BOND_LINK_BACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) if (!link_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) bond_propose_link_state(slave, BOND_LINK_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) slave_info(bond->dev, slave->dev, "link status down again after %d ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) (bond->params.updelay - slave->delay) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) if (ignore_updelay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) slave->delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) if (slave->delay <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) bond_propose_link_state(slave, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) ignore_updelay = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) slave->delay--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) return commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) static void bond_miimon_link_change(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) char link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) switch (BOND_MODE(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) case BOND_MODE_8023AD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) bond_3ad_handle_link_change(slave, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) case BOND_MODE_TLB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) case BOND_MODE_ALB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) bond_alb_handle_link_change(bond, slave, link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) case BOND_MODE_XOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) bond_update_slave_arr(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) static void bond_miimon_commit(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2511) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2512) struct slave *slave, *primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2514) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2515) switch (slave->link_new_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2516) case BOND_LINK_NOCHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2517) /* For 802.3ad mode, check current slave speed and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2518) * duplex again in case its port was disabled after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2519) * invalid speed/duplex reporting but recovered before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2520) * link monitoring could make a decision on the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2521) * link status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2522) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2523) if (BOND_MODE(bond) == BOND_MODE_8023AD &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2524) slave->link == BOND_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2525) bond_3ad_adapter_speed_duplex_changed(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2526) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2527)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2528) case BOND_LINK_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2529) if (bond_update_speed_duplex(slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2530) bond_needs_speed_duplex(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2531) slave->link = BOND_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2532) if (net_ratelimit())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2533) slave_warn(bond->dev, slave->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2534) "failed to get link speed/duplex\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2535) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2537) bond_set_slave_link_state(slave, BOND_LINK_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2538) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2539) slave->last_link_up = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2541) primary = rtnl_dereference(bond->primary_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2542) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2543) /* prevent it from being the active one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2544) bond_set_backup_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2545) } else if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2546) /* make it immediately active */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2547) bond_set_active_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2550) slave_info(bond->dev, slave->dev, "link status definitely up, %u Mbps %s duplex\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2551) slave->speed == SPEED_UNKNOWN ? 0 : slave->speed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2552) slave->duplex ? "full" : "half");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2554) bond_miimon_link_change(bond, slave, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2556) if (!bond->curr_active_slave || slave == primary)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2557) goto do_failover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2559) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2561) case BOND_LINK_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2562) if (slave->link_failure_count < UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2563) slave->link_failure_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2565) bond_set_slave_link_state(slave, BOND_LINK_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2566) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2568) if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2569) BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2570) bond_set_slave_inactive_flags(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2571) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2573) slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2574)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2575) bond_miimon_link_change(bond, slave, BOND_LINK_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2577) if (slave == rcu_access_pointer(bond->curr_active_slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2578) goto do_failover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2580) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2582) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2583) slave_err(bond->dev, slave->dev, "invalid new link %d on slave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2584) slave->link_new_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2585) bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2587) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2590) do_failover:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2591) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2592) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2593) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2596) bond_set_carrier(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2599) /* bond_mii_monitor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2600) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2601) * Really a wrapper that splits the mii monitor into two phases: an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2602) * inspection, then (if inspection indicates something needs to be done)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2603) * an acquisition of appropriate locks followed by a commit phase to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2604) * implement whatever link state changes are indicated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2605) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2606) static void bond_mii_monitor(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2607) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2608) struct bonding *bond = container_of(work, struct bonding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2609) mii_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2610) bool should_notify_peers = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2611) bool commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2612) unsigned long delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2613) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2614) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2616) delay = msecs_to_jiffies(bond->params.miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2618) if (!bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2619) goto re_arm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2621) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2622) should_notify_peers = bond_should_notify_peers(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2623) commit = !!bond_miimon_inspect(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2624) if (bond->send_peer_notif) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2625) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2626) if (rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2627) bond->send_peer_notif--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2628) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2630) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2631) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2632) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2634) if (commit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2635) /* Race avoidance with bond_close cancel of workqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2636) if (!rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2637) delay = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2638) should_notify_peers = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2639) goto re_arm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2640) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2642) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2643) bond_commit_link_state(slave, BOND_SLAVE_NOTIFY_LATER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2645) bond_miimon_commit(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2647) rtnl_unlock(); /* might sleep, hold no other locks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2650) re_arm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2651) if (bond->params.miimon)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2652) queue_delayed_work(bond->wq, &bond->mii_work, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2653)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2654) if (should_notify_peers) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2655) if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2656) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2657) call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2658) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2662) static int bond_upper_dev_walk(struct net_device *upper,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2663) struct netdev_nested_priv *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2665) __be32 ip = *(__be32 *)priv->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2666)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2667) return ip == bond_confirm_addr(upper, 0, ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2668) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2670) static bool bond_has_this_ip(struct bonding *bond, __be32 ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2671) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2672) struct netdev_nested_priv priv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2673) .data = (void *)&ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2674) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2675) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2677) if (ip == bond_confirm_addr(bond->dev, 0, ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2678) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2679)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2680) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2681) if (netdev_walk_all_upper_dev_rcu(bond->dev, bond_upper_dev_walk, &priv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2682) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2683) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2685) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2688) /* We go to the (large) trouble of VLAN tagging ARP frames because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2689) * switches in VLAN mode (especially if ports are configured as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2690) * "native" to a VLAN) might not pass non-tagged frames.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2691) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2692) static void bond_arp_send(struct slave *slave, int arp_op, __be32 dest_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2693) __be32 src_ip, struct bond_vlan_tag *tags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2695) struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2696) struct bond_vlan_tag *outer_tag = tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2697) struct net_device *slave_dev = slave->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2698) struct net_device *bond_dev = slave->bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2700) slave_dbg(bond_dev, slave_dev, "arp %d on slave: dst %pI4 src %pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2701) arp_op, &dest_ip, &src_ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2703) skb = arp_create(arp_op, ETH_P_ARP, dest_ip, slave_dev, src_ip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2704) NULL, slave_dev->dev_addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2706) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2707) net_err_ratelimited("ARP packet allocation failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2708) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2711) if (!tags || tags->vlan_proto == VLAN_N_VID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2712) goto xmit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2714) tags++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2716) /* Go through all the tags backwards and add them to the packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2717) while (tags->vlan_proto != VLAN_N_VID) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2718) if (!tags->vlan_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2719) tags++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2720) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2721) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2723) slave_dbg(bond_dev, slave_dev, "inner tag: proto %X vid %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2724) ntohs(outer_tag->vlan_proto), tags->vlan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2725) skb = vlan_insert_tag_set_proto(skb, tags->vlan_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2726) tags->vlan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2727) if (!skb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2728) net_err_ratelimited("failed to insert inner VLAN tag\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2729) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2732) tags++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2733) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2734) /* Set the outer tag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2735) if (outer_tag->vlan_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2736) slave_dbg(bond_dev, slave_dev, "outer tag: proto %X vid %X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2737) ntohs(outer_tag->vlan_proto), outer_tag->vlan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2738) __vlan_hwaccel_put_tag(skb, outer_tag->vlan_proto,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2739) outer_tag->vlan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2742) xmit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2743) arp_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2746) /* Validate the device path between the @start_dev and the @end_dev.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2747) * The path is valid if the @end_dev is reachable through device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2748) * stacking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2749) * When the path is validated, collect any vlan information in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2750) * path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2751) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2752) struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2753) struct net_device *end_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2754) int level)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2755) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2756) struct bond_vlan_tag *tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2757) struct net_device *upper;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2758) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2760) if (start_dev == end_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2761) tags = kcalloc(level + 1, sizeof(*tags), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2762) if (!tags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2763) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2764) tags[level].vlan_proto = VLAN_N_VID;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2765) return tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2768) netdev_for_each_upper_dev_rcu(start_dev, upper, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2769) tags = bond_verify_device_path(upper, end_dev, level + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2770) if (IS_ERR_OR_NULL(tags)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2771) if (IS_ERR(tags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2772) return tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2773) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2774) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2775) if (is_vlan_dev(upper)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2776) tags[level].vlan_proto = vlan_dev_vlan_proto(upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2777) tags[level].vlan_id = vlan_dev_vlan_id(upper);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2780) return tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2783) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2786) static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2787) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2788) struct rtable *rt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2789) struct bond_vlan_tag *tags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2790) __be32 *targets = bond->params.arp_targets, addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2791) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2793) for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2794) slave_dbg(bond->dev, slave->dev, "%s: target %pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2795) __func__, &targets[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2796) tags = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2798) /* Find out through which dev should the packet go */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2799) rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2800) RTO_ONLINK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2801) if (IS_ERR(rt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2802) /* there's no route to target - try to send arp
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2803) * probe to generate any traffic (arp_validate=0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2804) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2805) if (bond->params.arp_validate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2806) net_warn_ratelimited("%s: no route to arp_ip_target %pI4 and arp_validate is set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2807) bond->dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2808) &targets[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2809) bond_arp_send(slave, ARPOP_REQUEST, targets[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2810) 0, tags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2811) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2813)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2814) /* bond device itself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2815) if (rt->dst.dev == bond->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2816) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2817)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2818) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2819) tags = bond_verify_device_path(bond->dev, rt->dst.dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2820) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2821)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2822) if (!IS_ERR_OR_NULL(tags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2823) goto found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2825) /* Not our device - skip */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2826) slave_dbg(bond->dev, slave->dev, "no path to arp_ip_target %pI4 via rt.dev %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2827) &targets[i], rt->dst.dev ? rt->dst.dev->name : "NULL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2829) ip_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2830) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2832) found:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2833) addr = bond_confirm_addr(rt->dst.dev, targets[i], 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2834) ip_rt_put(rt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2835) bond_arp_send(slave, ARPOP_REQUEST, targets[i], addr, tags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2836) kfree(tags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2840) static void bond_validate_arp(struct bonding *bond, struct slave *slave, __be32 sip, __be32 tip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2842) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2844) if (!sip || !bond_has_this_ip(bond, tip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2845) slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 tip %pI4 not found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2846) __func__, &sip, &tip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2847) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2848) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2850) i = bond_get_targets_ip(bond->params.arp_targets, sip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2851) if (i == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2852) slave_dbg(bond->dev, slave->dev, "%s: sip %pI4 not found in targets\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2853) __func__, &sip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2854) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2855) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2856) slave->last_rx = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2857) slave->target_last_arp_rx[i] = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2860) int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2861) struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2862) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2863) struct arphdr *arp = (struct arphdr *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2864) struct slave *curr_active_slave, *curr_arp_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2865) unsigned char *arp_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2866) __be32 sip, tip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2867) int is_arp = skb->protocol == __cpu_to_be16(ETH_P_ARP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2868) unsigned int alen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2870) if (!slave_do_arp_validate(bond, slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2871) if ((slave_do_arp_validate_only(bond) && is_arp) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2872) !slave_do_arp_validate_only(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2873) slave->last_rx = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2874) return RX_HANDLER_ANOTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2875) } else if (!is_arp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2876) return RX_HANDLER_ANOTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2877) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2879) alen = arp_hdr_len(bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2880)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2881) slave_dbg(bond->dev, slave->dev, "%s: skb->dev %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2882) __func__, skb->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2883)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2884) if (alen > skb_headlen(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2885) arp = kmalloc(alen, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2886) if (!arp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2887) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2888) if (skb_copy_bits(skb, 0, arp, alen) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2889) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2892) if (arp->ar_hln != bond->dev->addr_len ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2893) skb->pkt_type == PACKET_OTHERHOST ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2894) skb->pkt_type == PACKET_LOOPBACK ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2895) arp->ar_hrd != htons(ARPHRD_ETHER) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2896) arp->ar_pro != htons(ETH_P_IP) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2897) arp->ar_pln != 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2898) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2899)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2900) arp_ptr = (unsigned char *)(arp + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2901) arp_ptr += bond->dev->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2902) memcpy(&sip, arp_ptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2903) arp_ptr += 4 + bond->dev->addr_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2904) memcpy(&tip, arp_ptr, 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2906) slave_dbg(bond->dev, slave->dev, "%s: %s/%d av %d sv %d sip %pI4 tip %pI4\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2907) __func__, slave->dev->name, bond_slave_state(slave),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2908) bond->params.arp_validate, slave_do_arp_validate(bond, slave),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2909) &sip, &tip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2910)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2911) curr_active_slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2912) curr_arp_slave = rcu_dereference(bond->current_arp_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2913)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2914) /* We 'trust' the received ARP enough to validate it if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2915) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2916) * (a) the slave receiving the ARP is active (which includes the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2917) * current ARP slave, if any), or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2918) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2919) * (b) the receiving slave isn't active, but there is a currently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2920) * active slave and it received valid arp reply(s) after it became
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2921) * the currently active slave, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2922) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2923) * (c) there is an ARP slave that sent an ARP during the prior ARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2924) * interval, and we receive an ARP reply on any slave. We accept
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2925) * these because switch FDB update delays may deliver the ARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2926) * reply to a slave other than the sender of the ARP request.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2927) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2928) * Note: for (b), backup slaves are receiving the broadcast ARP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2929) * request, not a reply. This request passes from the sending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2930) * slave through the L2 switch(es) to the receiving slave. Since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2931) * this is checking the request, sip/tip are swapped for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2932) * validation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2933) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2934) * This is done to avoid endless looping when we can't reach the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2935) * arp_ip_target and fool ourselves with our own arp requests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2936) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2937) if (bond_is_active_slave(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2938) bond_validate_arp(bond, slave, sip, tip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2939) else if (curr_active_slave &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2940) time_after(slave_last_rx(bond, curr_active_slave),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2941) curr_active_slave->last_link_up))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2942) bond_validate_arp(bond, slave, tip, sip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2943) else if (curr_arp_slave && (arp->ar_op == htons(ARPOP_REPLY)) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2944) bond_time_in_interval(bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2945) dev_trans_start(curr_arp_slave->dev), 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2946) bond_validate_arp(bond, slave, sip, tip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2948) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2949) if (arp != (struct arphdr *)skb->data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2950) kfree(arp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2951) return RX_HANDLER_ANOTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2952) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2954) /* function to verify if we're in the arp_interval timeslice, returns true if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2955) * (last_act - arp_interval) <= jiffies <= (last_act + mod * arp_interval +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2956) * arp_interval/2) . the arp_interval/2 is needed for really fast networks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2957) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2958) static bool bond_time_in_interval(struct bonding *bond, unsigned long last_act,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2959) int mod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2961) int delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2963) return time_in_range(jiffies,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2964) last_act - delta_in_ticks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2965) last_act + mod * delta_in_ticks + delta_in_ticks/2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2968) /* This function is called regularly to monitor each slave's link
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2969) * ensuring that traffic is being sent and received when arp monitoring
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2970) * is used in load-balancing mode. if the adapter has been dormant, then an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2971) * arp is transmitted to generate traffic. see activebackup_arp_monitor for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2972) * arp monitoring in active backup mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2973) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2974) static void bond_loadbalance_arp_mon(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2975) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2976) struct slave *slave, *oldcurrent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2977) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2978) int do_failover = 0, slave_state_changed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2979)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2980) if (!bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2981) goto re_arm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2982)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2983) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2984)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2985) oldcurrent = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2986) /* see if any of the previous devices are up now (i.e. they have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2987) * xmt and rcv traffic). the curr_active_slave does not come into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2988) * the picture unless it is null. also, slave->last_link_up is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2989) * needed here because we send an arp on each slave and give a slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2990) * as long as it needs to get the tx/rx within the delta.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2991) * TODO: what about up/down delay in arp mode? it wasn't here before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2992) * so it can wait
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2993) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2994) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2995) unsigned long trans_start = dev_trans_start(slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2997) bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2999) if (slave->link != BOND_LINK_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3000) if (bond_time_in_interval(bond, trans_start, 1) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3001) bond_time_in_interval(bond, slave->last_rx, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3002)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3003) bond_propose_link_state(slave, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3004) slave_state_changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3006) /* primary_slave has no meaning in round-robin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3007) * mode. the window of a slave being up and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3008) * curr_active_slave being null after enslaving
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3009) * is closed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3010) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3011) if (!oldcurrent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3012) slave_info(bond->dev, slave->dev, "link status definitely up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3013) do_failover = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3014) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3015) slave_info(bond->dev, slave->dev, "interface is now up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3018) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3019) /* slave->link == BOND_LINK_UP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3021) /* not all switches will respond to an arp request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3022) * when the source ip is 0, so don't take the link down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3023) * if we don't know our ip yet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3024) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3025) if (!bond_time_in_interval(bond, trans_start, 2) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3026) !bond_time_in_interval(bond, slave->last_rx, 2)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3028) bond_propose_link_state(slave, BOND_LINK_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3029) slave_state_changed = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3030)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3031) if (slave->link_failure_count < UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3032) slave->link_failure_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3034) slave_info(bond->dev, slave->dev, "interface is now down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3036) if (slave == oldcurrent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3037) do_failover = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3039) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3040)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3041) /* note: if switch is in round-robin mode, all links
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3042) * must tx arp to ensure all links rx an arp - otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3043) * links may oscillate or not come up at all; if switch is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3044) * in something like xor mode, there is nothing we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3045) * do - all replies will be rx'ed on same link causing slaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3046) * to be unstable during low/no traffic periods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3047) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3048) if (bond_slave_is_up(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3049) bond_arp_send_all(bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3052) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3053)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3054) if (do_failover || slave_state_changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3055) if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3056) goto re_arm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3057)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3058) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3059) if (slave->link_new_state != BOND_LINK_NOCHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3060) slave->link = slave->link_new_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3063) if (slave_state_changed) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3064) bond_slave_state_change(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3065) if (BOND_MODE(bond) == BOND_MODE_XOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3066) bond_update_slave_arr(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3067) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3068) if (do_failover) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3069) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3070) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3071) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3073) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3074) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3076) re_arm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3077) if (bond->params.arp_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3078) queue_delayed_work(bond->wq, &bond->arp_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3079) msecs_to_jiffies(bond->params.arp_interval));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3080) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3082) /* Called to inspect slaves for active-backup mode ARP monitor link state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3083) * changes. Sets proposed link state in slaves to specify what action
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3084) * should take place for the slave. Returns 0 if no changes are found, >0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3085) * if changes to link states must be committed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3086) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3087) * Called with rcu_read_lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3088) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3089) static int bond_ab_arp_inspect(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3090) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3091) unsigned long trans_start, last_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3092) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3093) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3094) int commit = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3095)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3096) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3097) bond_propose_link_state(slave, BOND_LINK_NOCHANGE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3098) last_rx = slave_last_rx(bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3100) if (slave->link != BOND_LINK_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3101) if (bond_time_in_interval(bond, last_rx, 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3102) bond_propose_link_state(slave, BOND_LINK_UP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3103) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3104) } else if (slave->link == BOND_LINK_BACK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3105) bond_propose_link_state(slave, BOND_LINK_FAIL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3106) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3108) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3111) /* Give slaves 2*delta after being enslaved or made
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3112) * active. This avoids bouncing, as the last receive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3113) * times need a full ARP monitor cycle to be updated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3114) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3115) if (bond_time_in_interval(bond, slave->last_link_up, 2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3116) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3118) /* Backup slave is down if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3119) * - No current_arp_slave AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3120) * - more than 3*delta since last receive AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3121) * - the bond has an IP address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3122) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3123) * Note: a non-null current_arp_slave indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3124) * the curr_active_slave went down and we are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3125) * searching for a new one; under this condition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3126) * we only take the curr_active_slave down - this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3127) * gives each slave a chance to tx/rx traffic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3128) * before being taken out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3130) if (!bond_is_active_slave(slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3131) !rcu_access_pointer(bond->current_arp_slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3132) !bond_time_in_interval(bond, last_rx, 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3133) bond_propose_link_state(slave, BOND_LINK_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3134) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3137) /* Active slave is down if:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3138) * - more than 2*delta since transmitting OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3139) * - (more than 2*delta since receive AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3140) * the bond has an IP address)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3142) trans_start = dev_trans_start(slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3143) if (bond_is_active_slave(slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3144) (!bond_time_in_interval(bond, trans_start, 2) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3145) !bond_time_in_interval(bond, last_rx, 2))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3146) bond_propose_link_state(slave, BOND_LINK_DOWN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3147) commit++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3151) return commit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3154) /* Called to commit link state changes noted by inspection step of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3155) * active-backup mode ARP monitor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3156) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3157) * Called with RTNL hold.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3158) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3159) static void bond_ab_arp_commit(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3160) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3161) unsigned long trans_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3162) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3163) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3165) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3166) switch (slave->link_new_state) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3167) case BOND_LINK_NOCHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3168) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3170) case BOND_LINK_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3171) trans_start = dev_trans_start(slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3172) if (rtnl_dereference(bond->curr_active_slave) != slave ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3173) (!rtnl_dereference(bond->curr_active_slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3174) bond_time_in_interval(bond, trans_start, 1))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3175) struct slave *current_arp_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3177) current_arp_slave = rtnl_dereference(bond->current_arp_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3178) bond_set_slave_link_state(slave, BOND_LINK_UP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3179) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3180) if (current_arp_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3181) bond_set_slave_inactive_flags(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3182) current_arp_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3183) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3184) RCU_INIT_POINTER(bond->current_arp_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3187) slave_info(bond->dev, slave->dev, "link status definitely up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3189) if (!rtnl_dereference(bond->curr_active_slave) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3190) slave == rtnl_dereference(bond->primary_slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3191) goto do_failover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3195) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3197) case BOND_LINK_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3198) if (slave->link_failure_count < UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3199) slave->link_failure_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3201) bond_set_slave_link_state(slave, BOND_LINK_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3202) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3203) bond_set_slave_inactive_flags(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3204) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3206) slave_info(bond->dev, slave->dev, "link status definitely down, disabling slave\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3208) if (slave == rtnl_dereference(bond->curr_active_slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3209) RCU_INIT_POINTER(bond->current_arp_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3210) goto do_failover;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3213) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3215) case BOND_LINK_FAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3216) bond_set_slave_link_state(slave, BOND_LINK_FAIL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3217) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3218) bond_set_slave_inactive_flags(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3219) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3221) /* A slave has just been enslaved and has become
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3222) * the current active slave.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3223) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3224) if (rtnl_dereference(bond->curr_active_slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3225) RCU_INIT_POINTER(bond->current_arp_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3226) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3228) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3229) slave_err(bond->dev, slave->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3230) "impossible: link_new_state %d on slave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3231) slave->link_new_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3232) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3235) do_failover:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3236) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3237) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3238) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3241) bond_set_carrier(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3244) /* Send ARP probes for active-backup mode ARP monitor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3245) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3246) * Called with rcu_read_lock held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3247) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3248) static bool bond_ab_arp_probe(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3250) struct slave *slave, *before = NULL, *new_slave = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3251) *curr_arp_slave = rcu_dereference(bond->current_arp_slave),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3252) *curr_active_slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3253) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3254) bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3255) bool should_notify_rtnl = BOND_SLAVE_NOTIFY_LATER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3257) if (curr_arp_slave && curr_active_slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3258) netdev_info(bond->dev, "PROBE: c_arp %s && cas %s BAD\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3259) curr_arp_slave->dev->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3260) curr_active_slave->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3262) if (curr_active_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3263) bond_arp_send_all(bond, curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3264) return should_notify_rtnl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3267) /* if we don't have a curr_active_slave, search for the next available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3268) * backup slave from the current_arp_slave and make it the candidate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3269) * for becoming the curr_active_slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3272) if (!curr_arp_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3273) curr_arp_slave = bond_first_slave_rcu(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3274) if (!curr_arp_slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3275) return should_notify_rtnl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3278) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3279) if (!found && !before && bond_slave_is_up(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3280) before = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3282) if (found && !new_slave && bond_slave_is_up(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3283) new_slave = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3284) /* if the link state is up at this point, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3285) * mark it down - this can happen if we have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3286) * simultaneous link failures and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3287) * reselect_active_interface doesn't make this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3288) * one the current slave so it is still marked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3289) * up when it is actually down
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3290) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3291) if (!bond_slave_is_up(slave) && slave->link == BOND_LINK_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3292) bond_set_slave_link_state(slave, BOND_LINK_DOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3293) BOND_SLAVE_NOTIFY_LATER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3294) if (slave->link_failure_count < UINT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3295) slave->link_failure_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3297) bond_set_slave_inactive_flags(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3298) BOND_SLAVE_NOTIFY_LATER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3300) slave_info(bond->dev, slave->dev, "backup interface is now down\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3302) if (slave == curr_arp_slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3303) found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3306) if (!new_slave && before)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3307) new_slave = before;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3309) if (!new_slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3310) goto check_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3312) bond_set_slave_link_state(new_slave, BOND_LINK_BACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3313) BOND_SLAVE_NOTIFY_LATER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3314) bond_set_slave_active_flags(new_slave, BOND_SLAVE_NOTIFY_LATER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3315) bond_arp_send_all(bond, new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3316) new_slave->last_link_up = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3317) rcu_assign_pointer(bond->current_arp_slave, new_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3319) check_state:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3320) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3321) if (slave->should_notify || slave->should_notify_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3322) should_notify_rtnl = BOND_SLAVE_NOTIFY_NOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3323) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3324) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3326) return should_notify_rtnl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3329) static void bond_activebackup_arp_mon(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3330) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3331) bool should_notify_peers = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3332) bool should_notify_rtnl = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3333) int delta_in_ticks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3335) delta_in_ticks = msecs_to_jiffies(bond->params.arp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3337) if (!bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3338) goto re_arm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3340) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3342) should_notify_peers = bond_should_notify_peers(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3344) if (bond_ab_arp_inspect(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3345) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3347) /* Race avoidance with bond_close flush of workqueue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3348) if (!rtnl_trylock()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3349) delta_in_ticks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3350) should_notify_peers = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3351) goto re_arm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3354) bond_ab_arp_commit(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3356) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3357) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3358) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3360) should_notify_rtnl = bond_ab_arp_probe(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3361) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3363) re_arm:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3364) if (bond->params.arp_interval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3365) queue_delayed_work(bond->wq, &bond->arp_work, delta_in_ticks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3367) if (should_notify_peers || should_notify_rtnl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3368) if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3369) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3371) if (should_notify_peers)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3372) call_netdevice_notifiers(NETDEV_NOTIFY_PEERS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3373) bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3374) if (should_notify_rtnl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3375) bond_slave_state_notify(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3376) bond_slave_link_notify(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3379) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3383) static void bond_arp_monitor(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3385) struct bonding *bond = container_of(work, struct bonding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3386) arp_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3388) if (BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3389) bond_activebackup_arp_mon(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3390) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3391) bond_loadbalance_arp_mon(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3394) /*-------------------------- netdev event handling --------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3396) /* Change device name */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3397) static int bond_event_changename(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3399) bond_remove_proc_entry(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3400) bond_create_proc_entry(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3402) bond_debug_reregister(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3404) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3407) static int bond_master_netdev_event(unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3408) struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3410) struct bonding *event_bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3412) netdev_dbg(bond_dev, "%s called\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3414) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3415) case NETDEV_CHANGENAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3416) return bond_event_changename(event_bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3417) case NETDEV_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3418) bond_remove_proc_entry(event_bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3419) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3420) xfrm_dev_state_flush(dev_net(bond_dev), bond_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3421) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3422) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3423) case NETDEV_REGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3424) bond_create_proc_entry(event_bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3425) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3426) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3427) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3430) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3431) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3433) static int bond_slave_netdev_event(unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3434) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3435) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3436) struct slave *slave = bond_slave_get_rtnl(slave_dev), *primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3437) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3438) struct net_device *bond_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3440) /* A netdev event can be generated while enslaving a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3441) * before netdev_rx_handler_register is called in which case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3442) * slave will be NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3444) if (!slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3445) netdev_dbg(slave_dev, "%s called on NULL slave\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3446) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3449) bond_dev = slave->bond->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3450) bond = slave->bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3451) primary = rtnl_dereference(bond->primary_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3452)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3453) slave_dbg(bond_dev, slave_dev, "%s called\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3455) switch (event) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3456) case NETDEV_UNREGISTER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3457) if (bond_dev->type != ARPHRD_ETHER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3458) bond_release_and_destroy(bond_dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3459) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3460) __bond_release_one(bond_dev, slave_dev, false, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3461) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3462) case NETDEV_UP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3463) case NETDEV_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3464) /* For 802.3ad mode only:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3465) * Getting invalid Speed/Duplex values here will put slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3466) * in weird state. Mark it as link-fail if the link was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3467) * previously up or link-down if it hasn't yet come up, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3468) * let link-monitoring (miimon) set it right when correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3469) * speeds/duplex are available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3470) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3471) if (bond_update_speed_duplex(slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3472) BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3473) if (slave->last_link_up)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3474) slave->link = BOND_LINK_FAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3475) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3476) slave->link = BOND_LINK_DOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3477) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3479) if (BOND_MODE(bond) == BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3480) bond_3ad_adapter_speed_duplex_changed(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3481) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3482) case NETDEV_DOWN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3483) /* Refresh slave-array if applicable!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3484) * If the setup does not use miimon or arpmon (mode-specific!),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3485) * then these events will not cause the slave-array to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3486) * refreshed. This will cause xmit to use a slave that is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3487) * usable. Avoid such situation by refeshing the array at these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3488) * events. If these (miimon/arpmon) parameters are configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3489) * then array gets refreshed twice and that should be fine!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3490) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3491) if (bond_mode_can_use_xmit_hash(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3492) bond_update_slave_arr(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3493) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3494) case NETDEV_CHANGEMTU:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3495) /* TODO: Should slaves be allowed to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3496) * independently alter their MTU? For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3497) * an active-backup bond, slaves need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3498) * not be the same type of device, so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3499) * MTUs may vary. For other modes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3500) * slaves arguably should have the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3501) * same MTUs. To do this, we'd need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3502) * take over the slave's change_mtu
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3503) * function for the duration of their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3504) * servitude.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3505) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3506) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3507) case NETDEV_CHANGENAME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3508) /* we don't care if we don't have primary set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3509) if (!bond_uses_primary(bond) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3510) !bond->params.primary[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3511) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3513) if (slave == primary) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3514) /* slave's name changed - he's no longer primary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3515) RCU_INIT_POINTER(bond->primary_slave, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3516) } else if (!strcmp(slave_dev->name, bond->params.primary)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3517) /* we have a new primary slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3518) rcu_assign_pointer(bond->primary_slave, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3519) } else { /* we didn't change primary - exit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3520) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3521) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3523) netdev_info(bond->dev, "Primary slave changed to %s, reselecting active slave\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3524) primary ? slave_dev->name : "none");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3526) block_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3527) bond_select_active_slave(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3528) unblock_netpoll_tx();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3529) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3530) case NETDEV_FEAT_CHANGE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3531) bond_compute_features(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3532) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3533) case NETDEV_RESEND_IGMP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3534) /* Propagate to master device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3535) call_netdevice_notifiers(event, slave->bond->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3536) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3537) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3538) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3539) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3540)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3541) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3544) /* bond_netdev_event: handle netdev notifier chain events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3545) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3546) * This function receives events for the netdev chain. The caller (an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3547) * ioctl handler calling blocking_notifier_call_chain) holds the necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3548) * locks for us to safely manipulate the slave devices (RTNL lock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3549) * dev_probe_lock).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3550) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3551) static int bond_netdev_event(struct notifier_block *this,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3552) unsigned long event, void *ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3554) struct net_device *event_dev = netdev_notifier_info_to_dev(ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3556) netdev_dbg(event_dev, "%s received %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3557) __func__, netdev_cmd_to_name(event));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3559) if (!(event_dev->priv_flags & IFF_BONDING))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3560) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3562) if (event_dev->flags & IFF_MASTER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3563) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3565) ret = bond_master_netdev_event(event, event_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3566) if (ret != NOTIFY_DONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3567) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3570) if (event_dev->flags & IFF_SLAVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3571) return bond_slave_netdev_event(event, event_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3573) return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3574) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3575)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3576) static struct notifier_block bond_netdev_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3577) .notifier_call = bond_netdev_event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3578) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3580) /*---------------------------- Hashing Policies -----------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3582) /* L2 hash helper */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3583) static inline u32 bond_eth_hash(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3585) struct ethhdr *ep, hdr_tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3587) ep = skb_header_pointer(skb, 0, sizeof(hdr_tmp), &hdr_tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3588) if (ep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3589) return ep->h_dest[5] ^ ep->h_source[5] ^ ep->h_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3590) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3591) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3593) static bool bond_flow_ip(struct sk_buff *skb, struct flow_keys *fk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3594) int *noff, int *proto, bool l34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3596) const struct ipv6hdr *iph6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3597) const struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3599) if (skb->protocol == htons(ETH_P_IP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3600) if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3601) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3602) iph = (const struct iphdr *)(skb->data + *noff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3603) iph_to_flow_copy_v4addrs(fk, iph);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3604) *noff += iph->ihl << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3605) if (!ip_is_fragment(iph))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3606) *proto = iph->protocol;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3607) } else if (skb->protocol == htons(ETH_P_IPV6)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3608) if (unlikely(!pskb_may_pull(skb, *noff + sizeof(*iph6))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3609) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3610) iph6 = (const struct ipv6hdr *)(skb->data + *noff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3611) iph_to_flow_copy_v6addrs(fk, iph6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3612) *noff += sizeof(*iph6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3613) *proto = iph6->nexthdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3614) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3615) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3616) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3617)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3618) if (l34 && *proto >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3619) fk->ports.ports = skb_flow_get_ports(skb, *noff, *proto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3621) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3624) /* Extract the appropriate headers based on bond's xmit policy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3625) static bool bond_flow_dissect(struct bonding *bond, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3626) struct flow_keys *fk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3627) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3628) bool l34 = bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER34;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3629) int noff, proto = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3630)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3631) if (bond->params.xmit_policy > BOND_XMIT_POLICY_LAYER23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3632) memset(fk, 0, sizeof(*fk));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3633) return __skb_flow_dissect(NULL, skb, &flow_keys_bonding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3634) fk, NULL, 0, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3635) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3636)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3637) fk->ports.ports = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3638) memset(&fk->icmp, 0, sizeof(fk->icmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3639) noff = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3640) if (!bond_flow_ip(skb, fk, &noff, &proto, l34))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3641) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3643) /* ICMP error packets contains at least 8 bytes of the header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3644) * of the packet which generated the error. Use this information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3645) * to correlate ICMP error packets within the same flow which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3646) * generated the error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3647) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3648) if (proto == IPPROTO_ICMP || proto == IPPROTO_ICMPV6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3649) skb_flow_get_icmp_tci(skb, &fk->icmp, skb->data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3650) skb_transport_offset(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3651) skb_headlen(skb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3652) if (proto == IPPROTO_ICMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3653) if (!icmp_is_err(fk->icmp.type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3654) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3656) noff += sizeof(struct icmphdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3657) } else if (proto == IPPROTO_ICMPV6) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3658) if (!icmpv6_is_err(fk->icmp.type))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3659) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3661) noff += sizeof(struct icmp6hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3663) return bond_flow_ip(skb, fk, &noff, &proto, l34);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3666) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3667) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3669) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3670) * bond_xmit_hash - generate a hash value based on the xmit policy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3671) * @bond: bonding device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3672) * @skb: buffer to use for headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3673) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3674) * This function will extract the necessary headers from the skb buffer and use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3675) * them to generate a hash based on the xmit_policy set in the bonding device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3676) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3677) u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3679) struct flow_keys flow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3680) u32 hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3682) if (bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP34 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3683) skb->l4_hash)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3684) return skb->hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3686) if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER2 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3687) !bond_flow_dissect(bond, skb, &flow))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3688) return bond_eth_hash(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3690) if (bond->params.xmit_policy == BOND_XMIT_POLICY_LAYER23 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3691) bond->params.xmit_policy == BOND_XMIT_POLICY_ENCAP23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3692) hash = bond_eth_hash(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3693) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3694) if (flow.icmp.id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3695) memcpy(&hash, &flow.icmp, sizeof(hash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3696) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3697) memcpy(&hash, &flow.ports.ports, sizeof(hash));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3699) hash ^= (__force u32)flow_get_u32_dst(&flow) ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3700) (__force u32)flow_get_u32_src(&flow);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3701) hash ^= (hash >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3702) hash ^= (hash >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3703)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3704) return hash >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3705) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3706)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3707) /*-------------------------- Device entry points ----------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3708)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3709) void bond_work_init_all(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3710) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3711) INIT_DELAYED_WORK(&bond->mcast_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3712) bond_resend_igmp_join_requests_delayed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3713) INIT_DELAYED_WORK(&bond->alb_work, bond_alb_monitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3714) INIT_DELAYED_WORK(&bond->mii_work, bond_mii_monitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3715) INIT_DELAYED_WORK(&bond->arp_work, bond_arp_monitor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3716) INIT_DELAYED_WORK(&bond->ad_work, bond_3ad_state_machine_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3717) INIT_DELAYED_WORK(&bond->slave_arr_work, bond_slave_arr_handler);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3720) static void bond_work_cancel_all(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3721) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3722) cancel_delayed_work_sync(&bond->mii_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3723) cancel_delayed_work_sync(&bond->arp_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3724) cancel_delayed_work_sync(&bond->alb_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3725) cancel_delayed_work_sync(&bond->ad_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3726) cancel_delayed_work_sync(&bond->mcast_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3727) cancel_delayed_work_sync(&bond->slave_arr_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3728) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3730) static int bond_open(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3731) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3732) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3733) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3734) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3735)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3736) /* reset slave->backup and slave->inactive */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3737) if (bond_has_slaves(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3738) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3739) if (bond_uses_primary(bond) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3740) slave != rcu_access_pointer(bond->curr_active_slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3741) bond_set_slave_inactive_flags(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3742) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3743) } else if (BOND_MODE(bond) != BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3744) bond_set_slave_active_flags(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3745) BOND_SLAVE_NOTIFY_NOW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3746) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3750) if (bond_is_lb(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3751) /* bond_alb_initialize must be called before the timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3752) * is started.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3753) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3754) if (bond_alb_initialize(bond, (BOND_MODE(bond) == BOND_MODE_ALB)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3755) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3756) if (bond->params.tlb_dynamic_lb || BOND_MODE(bond) == BOND_MODE_ALB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3757) queue_delayed_work(bond->wq, &bond->alb_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3758) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3760) if (bond->params.miimon) /* link check interval, in milliseconds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3761) queue_delayed_work(bond->wq, &bond->mii_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3763) if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3764) queue_delayed_work(bond->wq, &bond->arp_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3765) bond->recv_probe = bond_arp_rcv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3766) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3768) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3769) queue_delayed_work(bond->wq, &bond->ad_work, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3770) /* register to receive LACPDUs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3771) bond->recv_probe = bond_3ad_lacpdu_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3772) bond_3ad_initiate_agg_selection(bond, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3775) if (bond_mode_can_use_xmit_hash(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3776) bond_update_slave_arr(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3778) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3781) static int bond_close(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3782) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3783) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3784)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3785) bond_work_cancel_all(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3786) bond->send_peer_notif = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3787) if (bond_is_lb(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3788) bond_alb_deinitialize(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3789) bond->recv_probe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3791) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3792) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3793)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3794) /* fold stats, assuming all rtnl_link_stats64 fields are u64, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3795) * that some drivers can provide 32bit values only.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3796) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3797) static void bond_fold_stats(struct rtnl_link_stats64 *_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3798) const struct rtnl_link_stats64 *_new,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3799) const struct rtnl_link_stats64 *_old)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3800) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3801) const u64 *new = (const u64 *)_new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3802) const u64 *old = (const u64 *)_old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3803) u64 *res = (u64 *)_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3804) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3806) for (i = 0; i < sizeof(*_res) / sizeof(u64); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3807) u64 nv = new[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3808) u64 ov = old[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3809) s64 delta = nv - ov;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3810)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3811) /* detects if this particular field is 32bit only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3812) if (((nv | ov) >> 32) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3813) delta = (s64)(s32)((u32)nv - (u32)ov);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3815) /* filter anomalies, some drivers reset their stats
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3816) * at down/up events.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3817) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3818) if (delta > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3819) res[i] += delta;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3820) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3821) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3823) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3824) static int bond_get_lowest_level_rcu(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3826) struct net_device *ldev, *next, *now, *dev_stack[MAX_NEST_DEV + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3827) struct list_head *niter, *iter, *iter_stack[MAX_NEST_DEV + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3828) int cur = 0, max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3830) now = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3831) iter = &dev->adj_list.lower;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3833) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3834) next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3835) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3836) ldev = netdev_next_lower_dev_rcu(now, &iter);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3837) if (!ldev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3838) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3840) next = ldev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3841) niter = &ldev->adj_list.lower;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3842) dev_stack[cur] = now;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3843) iter_stack[cur++] = iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3844) if (max <= cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3845) max = cur;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3846) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3847) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3849) if (!next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3850) if (!cur)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3851) return max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3852) next = dev_stack[--cur];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3853) niter = iter_stack[cur];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3856) now = next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3857) iter = niter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3858) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3859)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3860) return max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3862) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3863)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3864) static void bond_get_stats(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3865) struct rtnl_link_stats64 *stats)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3866) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3867) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3868) struct rtnl_link_stats64 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3869) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3870) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3871) int nest_level = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3874) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3875) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3876) nest_level = bond_get_lowest_level_rcu(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3877) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3879) spin_lock_nested(&bond->stats_lock, nest_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3880) memcpy(stats, &bond->bond_stats, sizeof(*stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3881)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3882) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3883) const struct rtnl_link_stats64 *new =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3884) dev_get_stats(slave->dev, &temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3886) bond_fold_stats(stats, new, &slave->slave_stats);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3888) /* save off the slave stats for the next run */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3889) memcpy(&slave->slave_stats, new, sizeof(*new));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3890) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3891)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3892) memcpy(&bond->bond_stats, stats, sizeof(*stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3893) spin_unlock(&bond->stats_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3894) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3897) static int bond_do_ioctl(struct net_device *bond_dev, struct ifreq *ifr, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3898) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3899) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3900) struct net_device *slave_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3901) struct ifbond k_binfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3902) struct ifbond __user *u_binfo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3903) struct ifslave k_sinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3904) struct ifslave __user *u_sinfo = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3905) struct mii_ioctl_data *mii = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3906) struct bond_opt_value newval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3907) struct net *net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3908) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3909)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3910) netdev_dbg(bond_dev, "bond_ioctl: cmd=%d\n", cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3912) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3913) case SIOCGMIIPHY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3914) mii = if_mii(ifr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3915) if (!mii)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3916) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3917)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3918) mii->phy_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3919) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3920) case SIOCGMIIREG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3921) /* We do this again just in case we were called by SIOCGMIIREG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3922) * instead of SIOCGMIIPHY.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3923) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3924) mii = if_mii(ifr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3925) if (!mii)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3926) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3928) if (mii->reg_num == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3929) mii->val_out = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3930) if (netif_carrier_ok(bond->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3931) mii->val_out = BMSR_LSTATUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3934) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3935) case BOND_INFO_QUERY_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3936) case SIOCBONDINFOQUERY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3937) u_binfo = (struct ifbond __user *)ifr->ifr_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3939) if (copy_from_user(&k_binfo, u_binfo, sizeof(ifbond)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3940) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3942) bond_info_query(bond_dev, &k_binfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3943) if (copy_to_user(u_binfo, &k_binfo, sizeof(ifbond)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3944) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3945)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3946) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3947) case BOND_SLAVE_INFO_QUERY_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3948) case SIOCBONDSLAVEINFOQUERY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3949) u_sinfo = (struct ifslave __user *)ifr->ifr_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3950)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3951) if (copy_from_user(&k_sinfo, u_sinfo, sizeof(ifslave)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3952) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3954) res = bond_slave_info_query(bond_dev, &k_sinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3955) if (res == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3956) copy_to_user(u_sinfo, &k_sinfo, sizeof(ifslave)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3957) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3959) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3960) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3961) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3962) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3963)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3964) net = dev_net(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3966) if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3967) return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3968)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3969) slave_dev = __dev_get_by_name(net, ifr->ifr_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3970)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3971) slave_dbg(bond_dev, slave_dev, "slave_dev=%p:\n", slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3972)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3973) if (!slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3974) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3975)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3976) switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3977) case BOND_ENSLAVE_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3978) case SIOCBONDENSLAVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3979) res = bond_enslave(bond_dev, slave_dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3980) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3981) case BOND_RELEASE_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3982) case SIOCBONDRELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3983) res = bond_release(bond_dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3984) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3985) case BOND_SETHWADDR_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3986) case SIOCBONDSETHWADDR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3987) res = bond_set_dev_addr(bond_dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3988) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3989) case BOND_CHANGE_ACTIVE_OLD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3990) case SIOCBONDCHANGEACTIVE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3991) bond_opt_initstr(&newval, slave_dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3992) res = __bond_opt_set_notify(bond, BOND_OPT_ACTIVE_SLAVE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3993) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3994) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3995) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3996) res = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3997) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3998)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3999) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4000) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4001)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4002) static void bond_change_rx_flags(struct net_device *bond_dev, int change)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4003) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4004) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4006) if (change & IFF_PROMISC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4007) bond_set_promiscuity(bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4008) bond_dev->flags & IFF_PROMISC ? 1 : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4009)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4010) if (change & IFF_ALLMULTI)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4011) bond_set_allmulti(bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4012) bond_dev->flags & IFF_ALLMULTI ? 1 : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4013) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4014)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4015) static void bond_set_rx_mode(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4016) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4017) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4018) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4019) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4020)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4021) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4022) if (bond_uses_primary(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4023) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4024) if (slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4025) dev_uc_sync(slave->dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4026) dev_mc_sync(slave->dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4027) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4028) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4029) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4030) dev_uc_sync_multiple(slave->dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4031) dev_mc_sync_multiple(slave->dev, bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4033) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4034) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4035) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4036)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4037) static int bond_neigh_init(struct neighbour *n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4038) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4039) struct bonding *bond = netdev_priv(n->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4040) const struct net_device_ops *slave_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4041) struct neigh_parms parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4042) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4043) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4045) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4046) slave = bond_first_slave_rcu(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4047) if (!slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4048) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4049) slave_ops = slave->dev->netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4050) if (!slave_ops->ndo_neigh_setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4051) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4053) /* TODO: find another way [1] to implement this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4054) * Passing a zeroed structure is fragile,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4055) * but at least we do not pass garbage.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4056) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4057) * [1] One way would be that ndo_neigh_setup() never touch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4058) * struct neigh_parms, but propagate the new neigh_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4059) * back to ___neigh_create() / neigh_parms_alloc()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4060) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4061) memset(&parms, 0, sizeof(parms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4062) ret = slave_ops->ndo_neigh_setup(slave->dev, &parms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4063)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4064) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4065) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4067) if (parms.neigh_setup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4068) ret = parms.neigh_setup(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4069) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4070) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4071) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4073)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4074) /* The bonding ndo_neigh_setup is called at init time beofre any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4075) * slave exists. So we must declare proxy setup function which will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4076) * be used at run time to resolve the actual slave neigh param setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4077) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4078) * It's also called by master devices (such as vlans) to setup their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4079) * underlying devices. In that case - do nothing, we're already set up from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4080) * our init.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4081) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4082) static int bond_neigh_setup(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4083) struct neigh_parms *parms)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4084) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4085) /* modify only our neigh_parms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4086) if (parms->dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4087) parms->neigh_setup = bond_neigh_init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4088)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4089) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4090) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4092) /* Change the MTU of all of a master's slaves to match the master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4093) static int bond_change_mtu(struct net_device *bond_dev, int new_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4095) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4096) struct slave *slave, *rollback_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4097) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4098) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4099)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4100) netdev_dbg(bond_dev, "bond=%p, new_mtu=%d\n", bond, new_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4102) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4103) slave_dbg(bond_dev, slave->dev, "s %p c_m %p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4104) slave, slave->dev->netdev_ops->ndo_change_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4106) res = dev_set_mtu(slave->dev, new_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4108) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4109) /* If we failed to set the slave's mtu to the new value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4110) * we must abort the operation even in ACTIVE_BACKUP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4111) * mode, because if we allow the backup slaves to have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4112) * different mtu values than the active slave we'll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4113) * need to change their mtu when doing a failover. That
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4114) * means changing their mtu from timer context, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4115) * is probably not a good idea.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4117) slave_dbg(bond_dev, slave->dev, "err %d setting mtu to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4118) res, new_mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4119) goto unwind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4123) bond_dev->mtu = new_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4125) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4127) unwind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4128) /* unwind from head to the slave that failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4129) bond_for_each_slave(bond, rollback_slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4130) int tmp_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4132) if (rollback_slave == slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4133) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4135) tmp_res = dev_set_mtu(rollback_slave->dev, bond_dev->mtu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4136) if (tmp_res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4137) slave_dbg(bond_dev, rollback_slave->dev, "unwind err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4138) tmp_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4141) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4144) /* Change HW address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4145) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4146) * Note that many devices must be down to change the HW address, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4147) * downing the master releases all slaves. We can make bonds full of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4148) * bonding devices to test this, however.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4150) static int bond_set_mac_address(struct net_device *bond_dev, void *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4152) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4153) struct slave *slave, *rollback_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4154) struct sockaddr_storage *ss = addr, tmp_ss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4155) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4156) int res = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4158) if (BOND_MODE(bond) == BOND_MODE_ALB)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4159) return bond_alb_set_mac_address(bond_dev, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4162) netdev_dbg(bond_dev, "%s: bond=%p\n", __func__, bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4164) /* If fail_over_mac is enabled, do nothing and return success.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4165) * Returning an error causes ifenslave to fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4167) if (bond->params.fail_over_mac &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4168) BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4169) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4171) if (!is_valid_ether_addr(ss->__data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4172) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4174) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4175) slave_dbg(bond_dev, slave->dev, "%s: slave=%p\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4176) __func__, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4177) res = dev_set_mac_address(slave->dev, addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4178) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4179) /* TODO: consider downing the slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4180) * and retry ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4181) * User should expect communications
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4182) * breakage anyway until ARP finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4183) * updating, so...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4184) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4185) slave_dbg(bond_dev, slave->dev, "%s: err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4186) __func__, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4187) goto unwind;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4191) /* success */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4192) memcpy(bond_dev->dev_addr, ss->__data, bond_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4193) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4195) unwind:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4196) memcpy(tmp_ss.__data, bond_dev->dev_addr, bond_dev->addr_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4197) tmp_ss.ss_family = bond_dev->type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4199) /* unwind from head to the slave that failed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4200) bond_for_each_slave(bond, rollback_slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4201) int tmp_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4203) if (rollback_slave == slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4204) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4206) tmp_res = dev_set_mac_address(rollback_slave->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4207) (struct sockaddr *)&tmp_ss, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4208) if (tmp_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4209) slave_dbg(bond_dev, rollback_slave->dev, "%s: unwind err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4210) __func__, tmp_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4214) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4217) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4218) * bond_get_slave_by_id - get xmit slave with slave_id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4219) * @bond: bonding device that is transmitting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4220) * @slave_id: slave id up to slave_cnt-1 through which to transmit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4221) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4222) * This function tries to get slave with slave_id but in case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4223) * it fails, it tries to find the first available slave for transmission.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4224) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4225) static struct slave *bond_get_slave_by_id(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4226) int slave_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4228) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4229) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4230) int i = slave_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4232) /* Here we start from the slave with slave_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4233) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4234) if (--i < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4235) if (bond_slave_can_tx(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4236) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4240) /* Here we start from the first slave up to slave_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4241) i = slave_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4242) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4243) if (--i < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4244) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4245) if (bond_slave_can_tx(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4246) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4248) /* no slave that can tx has been found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4249) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4250) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4252) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4253) * bond_rr_gen_slave_id - generate slave id based on packets_per_slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4254) * @bond: bonding device to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4255) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4256) * Based on the value of the bonding device's packets_per_slave parameter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4257) * this function generates a slave id, which is usually used as the next
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4258) * slave to transmit through.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4260) static u32 bond_rr_gen_slave_id(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4262) u32 slave_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4263) struct reciprocal_value reciprocal_packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4264) int packets_per_slave = bond->params.packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4266) switch (packets_per_slave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4267) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4268) slave_id = prandom_u32();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4269) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4270) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4271) slave_id = bond->rr_tx_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4272) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4273) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4274) reciprocal_packets_per_slave =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4275) bond->params.reciprocal_packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4276) slave_id = reciprocal_divide(bond->rr_tx_counter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4277) reciprocal_packets_per_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4278) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4280) bond->rr_tx_counter++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4282) return slave_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4285) static struct slave *bond_xmit_roundrobin_slave_get(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4286) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4288) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4289) int slave_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4290) u32 slave_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4292) /* Start with the curr_active_slave that joined the bond as the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4293) * default for sending IGMP traffic. For failover purposes one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4294) * needs to maintain some consistency for the interface that will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4295) * send the join/membership reports. The curr_active_slave found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4296) * will send all of this type of traffic.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4298) if (skb->protocol == htons(ETH_P_IP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4299) int noff = skb_network_offset(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4300) struct iphdr *iph;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4302) if (unlikely(!pskb_may_pull(skb, noff + sizeof(*iph))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4303) goto non_igmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4305) iph = ip_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4306) if (iph->protocol == IPPROTO_IGMP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4307) slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4308) if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4309) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4310) return bond_get_slave_by_id(bond, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4314) non_igmp:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4315) slave_cnt = READ_ONCE(bond->slave_cnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4316) if (likely(slave_cnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4317) slave_id = bond_rr_gen_slave_id(bond) % slave_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4318) return bond_get_slave_by_id(bond, slave_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4320) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4323) static netdev_tx_t bond_xmit_roundrobin(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4324) struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4326) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4327) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4329) slave = bond_xmit_roundrobin_slave_get(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4330) if (likely(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4331) return bond_dev_queue_xmit(bond, skb, slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4333) return bond_tx_drop(bond_dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4335)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4336) static struct slave *bond_xmit_activebackup_slave_get(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4337) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4338) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4339) return rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4342) /* In active-backup mode, we know that bond->curr_active_slave is always valid if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4343) * the bond has a usable interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4344) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4345) static netdev_tx_t bond_xmit_activebackup(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4346) struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4347) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4348) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4349) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4351) slave = bond_xmit_activebackup_slave_get(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4352) if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4353) return bond_dev_queue_xmit(bond, skb, slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4355) return bond_tx_drop(bond_dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4358) /* Use this to update slave_array when (a) it's not appropriate to update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4359) * slave_array right away (note that update_slave_array() may sleep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4360) * and / or (b) RTNL is not held.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4361) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4362) void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4364) queue_delayed_work(bond->wq, &bond->slave_arr_work, delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4367) /* Slave array work handler. Holds only RTNL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4368) static void bond_slave_arr_handler(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4370) struct bonding *bond = container_of(work, struct bonding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4371) slave_arr_work.work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4372) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4374) if (!rtnl_trylock())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4375) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4377) ret = bond_update_slave_arr(bond, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4378) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4379) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4380) pr_warn_ratelimited("Failed to update slave array from WT\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4381) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4382) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4383) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4385) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4386) bond_slave_arr_work_rearm(bond, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4389) static void bond_skip_slave(struct bond_up_slave *slaves,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4390) struct slave *skipslave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4392) int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4394) /* Rare situation where caller has asked to skip a specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4395) * slave but allocation failed (most likely!). BTW this is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4396) * only possible when the call is initiated from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4397) * __bond_release_one(). In this situation; overwrite the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4398) * skipslave entry in the array with the last entry from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4399) * array to avoid a situation where the xmit path may choose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4400) * this to-be-skipped slave to send a packet out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4401) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4402) for (idx = 0; slaves && idx < slaves->count; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4403) if (skipslave == slaves->arr[idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4404) slaves->arr[idx] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4405) slaves->arr[slaves->count - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4406) slaves->count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4407) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4409) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4412) static void bond_set_slave_arr(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4413) struct bond_up_slave *usable_slaves,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4414) struct bond_up_slave *all_slaves)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4416) struct bond_up_slave *usable, *all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4417)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4418) usable = rtnl_dereference(bond->usable_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4419) rcu_assign_pointer(bond->usable_slaves, usable_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4420) kfree_rcu(usable, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4422) all = rtnl_dereference(bond->all_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4423) rcu_assign_pointer(bond->all_slaves, all_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4424) kfree_rcu(all, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4427) static void bond_reset_slave_arr(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4429) struct bond_up_slave *usable, *all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4431) usable = rtnl_dereference(bond->usable_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4432) if (usable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4433) RCU_INIT_POINTER(bond->usable_slaves, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4434) kfree_rcu(usable, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4437) all = rtnl_dereference(bond->all_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4438) if (all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4439) RCU_INIT_POINTER(bond->all_slaves, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4440) kfree_rcu(all, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4444) /* Build the usable slaves array in control path for modes that use xmit-hash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4445) * to determine the slave interface -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4446) * (a) BOND_MODE_8023AD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4447) * (b) BOND_MODE_XOR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4448) * (c) (BOND_MODE_TLB || BOND_MODE_ALB) && tlb_dynamic_lb == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4449) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4450) * The caller is expected to hold RTNL only and NO other lock!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4452) int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4454) struct bond_up_slave *usable_slaves = NULL, *all_slaves = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4455) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4456) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4457) int agg_id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4458) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4460) #ifdef CONFIG_LOCKDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4461) WARN_ON(lockdep_is_held(&bond->mode_lock));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4462) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4464) usable_slaves = kzalloc(struct_size(usable_slaves, arr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4465) bond->slave_cnt), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4466) all_slaves = kzalloc(struct_size(all_slaves, arr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4467) bond->slave_cnt), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4468) if (!usable_slaves || !all_slaves) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4469) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4470) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4471) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4472) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4473) struct ad_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4475) if (bond_3ad_get_active_agg_info(bond, &ad_info)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4476) pr_debug("bond_3ad_get_active_agg_info failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4477) /* No active aggragator means it's not safe to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4478) * the previous array.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4479) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4480) bond_reset_slave_arr(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4481) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4483) agg_id = ad_info.aggregator_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4485) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4486) if (skipslave == slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4487) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4489) all_slaves->arr[all_slaves->count++] = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4490) if (BOND_MODE(bond) == BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4491) struct aggregator *agg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4493) agg = SLAVE_AD_INFO(slave)->port.aggregator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4494) if (!agg || agg->aggregator_identifier != agg_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4495) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4496) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4497) if (!bond_slave_can_tx(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4498) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4500) slave_dbg(bond->dev, slave->dev, "Adding slave to tx hash array[%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4501) usable_slaves->count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4503) usable_slaves->arr[usable_slaves->count++] = slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4504) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4506) bond_set_slave_arr(bond, usable_slaves, all_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4507) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4508) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4509) if (ret != 0 && skipslave) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4510) bond_skip_slave(rtnl_dereference(bond->all_slaves),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4511) skipslave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4512) bond_skip_slave(rtnl_dereference(bond->usable_slaves),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4513) skipslave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4515) kfree_rcu(all_slaves, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4516) kfree_rcu(usable_slaves, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4518) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4521) static struct slave *bond_xmit_3ad_xor_slave_get(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4522) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4523) struct bond_up_slave *slaves)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4524) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4525) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4526) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4527) u32 hash;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4529) hash = bond_xmit_hash(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4530) count = slaves ? READ_ONCE(slaves->count) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4531) if (unlikely(!count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4532) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4534) slave = slaves->arr[hash % count];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4535) return slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4537)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4538) /* Use this Xmit function for 3AD as well as XOR modes. The current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4539) * usable slave array is formed in the control path. The xmit function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4540) * just calculates hash and sends the packet out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4542) static netdev_tx_t bond_3ad_xor_xmit(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4543) struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4545) struct bonding *bond = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4546) struct bond_up_slave *slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4547) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4549) slaves = rcu_dereference(bond->usable_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4550) slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4551) if (likely(slave))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4552) return bond_dev_queue_xmit(bond, skb, slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4553)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4554) return bond_tx_drop(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4555) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4557) /* in broadcast mode, we send everything to all usable interfaces. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4558) static netdev_tx_t bond_xmit_broadcast(struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4559) struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4561) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4562) struct slave *slave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4563) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4564) bool xmit_suc = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4565) bool skb_used = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4566)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4567) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4568) struct sk_buff *skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4569)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4570) if (!(bond_slave_is_up(slave) && slave->link == BOND_LINK_UP))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4571) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4573) if (bond_is_last_slave(bond, slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4574) skb2 = skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4575) skb_used = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4576) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4577) skb2 = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4578) if (!skb2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4579) net_err_ratelimited("%s: Error: %s: skb_clone() failed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4580) bond_dev->name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4581) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4582) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4585) if (bond_dev_queue_xmit(bond, skb2, slave->dev) == NETDEV_TX_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4586) xmit_suc = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4589) if (!skb_used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4590) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4592) if (xmit_suc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4593) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4595) atomic_long_inc(&bond_dev->tx_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4596) return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4599) /*------------------------- Device initialization ---------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4601) /* Lookup the slave that corresponds to a qid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4602) static inline int bond_slave_override(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4603) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4605) struct slave *slave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4606) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4608) if (!skb_rx_queue_recorded(skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4609) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4611) /* Find out if any slaves have the same mapping as this skb. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4612) bond_for_each_slave_rcu(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4613) if (slave->queue_id == skb_get_queue_mapping(skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4614) if (bond_slave_is_up(slave) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4615) slave->link == BOND_LINK_UP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4616) bond_dev_queue_xmit(bond, skb, slave->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4617) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4619) /* If the slave isn't UP, use default transmit policy. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4620) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4622) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4624) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4628) static u16 bond_select_queue(struct net_device *dev, struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4629) struct net_device *sb_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4630) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4631) /* This helper function exists to help dev_pick_tx get the correct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4632) * destination queue. Using a helper function skips a call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4633) * skb_tx_hash and will put the skbs in the queue we expect on their
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4634) * way down to the bonding driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4635) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4636) u16 txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4638) /* Save the original txq to restore before passing to the driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4639) qdisc_skb_cb(skb)->slave_dev_queue_mapping = skb_get_queue_mapping(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4641) if (unlikely(txq >= dev->real_num_tx_queues)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4642) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4643) txq -= dev->real_num_tx_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4644) } while (txq >= dev->real_num_tx_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4645) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4646) return txq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4647) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4649) static struct net_device *bond_xmit_get_slave(struct net_device *master_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4650) struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4651) bool all_slaves)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4653) struct bonding *bond = netdev_priv(master_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4654) struct bond_up_slave *slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4655) struct slave *slave = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4657) switch (BOND_MODE(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4658) case BOND_MODE_ROUNDROBIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4659) slave = bond_xmit_roundrobin_slave_get(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4660) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4661) case BOND_MODE_ACTIVEBACKUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4662) slave = bond_xmit_activebackup_slave_get(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4663) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4664) case BOND_MODE_8023AD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4665) case BOND_MODE_XOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4666) if (all_slaves)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4667) slaves = rcu_dereference(bond->all_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4668) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4669) slaves = rcu_dereference(bond->usable_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4670) slave = bond_xmit_3ad_xor_slave_get(bond, skb, slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4671) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4672) case BOND_MODE_BROADCAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4673) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4674) case BOND_MODE_ALB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4675) slave = bond_xmit_alb_slave_get(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4676) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4677) case BOND_MODE_TLB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4678) slave = bond_xmit_tlb_slave_get(bond, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4679) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4680) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4681) /* Should never happen, mode already checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4682) WARN_ONCE(true, "Unknown bonding mode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4683) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4686) if (slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4687) return slave->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4688) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4689) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4690)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4691) static netdev_tx_t __bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4692) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4693) struct bonding *bond = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4694)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4695) if (bond_should_override_tx_queue(bond) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4696) !bond_slave_override(bond, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4697) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4699) switch (BOND_MODE(bond)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4700) case BOND_MODE_ROUNDROBIN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4701) return bond_xmit_roundrobin(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4702) case BOND_MODE_ACTIVEBACKUP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4703) return bond_xmit_activebackup(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4704) case BOND_MODE_8023AD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4705) case BOND_MODE_XOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4706) return bond_3ad_xor_xmit(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4707) case BOND_MODE_BROADCAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4708) return bond_xmit_broadcast(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4709) case BOND_MODE_ALB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4710) return bond_alb_xmit(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4711) case BOND_MODE_TLB:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4712) return bond_tlb_xmit(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4713) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4714) /* Should never happen, mode already checked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4715) netdev_err(dev, "Unknown bonding mode %d\n", BOND_MODE(bond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4716) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4717) return bond_tx_drop(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4719) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4721) static netdev_tx_t bond_start_xmit(struct sk_buff *skb, struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4722) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4723) struct bonding *bond = netdev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4724) netdev_tx_t ret = NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4725)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4726) /* If we risk deadlock from transmitting this in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4727) * netpoll path, tell netpoll to queue the frame for later tx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4728) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4729) if (unlikely(is_netpoll_tx_blocked(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4730) return NETDEV_TX_BUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4732) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4733) if (bond_has_slaves(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4734) ret = __bond_start_xmit(skb, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4735) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4736) ret = bond_tx_drop(dev, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4737) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4738)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4739) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4742) static u32 bond_mode_bcast_speed(struct slave *slave, u32 speed)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4743) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4744) if (speed == 0 || speed == SPEED_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4745) speed = slave->speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4746) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4747) speed = min(speed, slave->speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4749) return speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4752) static int bond_ethtool_get_link_ksettings(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4753) struct ethtool_link_ksettings *cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4754) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4755) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4756) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4757) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4758) u32 speed = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4760) cmd->base.duplex = DUPLEX_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4761) cmd->base.port = PORT_OTHER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4763) /* Since bond_slave_can_tx returns false for all inactive or down slaves, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4764) * do not need to check mode. Though link speed might not represent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4765) * the true receive or transmit bandwidth (not all modes are symmetric)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4766) * this is an accurate maximum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4767) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4768) bond_for_each_slave(bond, slave, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4769) if (bond_slave_can_tx(slave)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4770) if (slave->speed != SPEED_UNKNOWN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4771) if (BOND_MODE(bond) == BOND_MODE_BROADCAST)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4772) speed = bond_mode_bcast_speed(slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4773) speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4774) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4775) speed += slave->speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4776) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4777) if (cmd->base.duplex == DUPLEX_UNKNOWN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4778) slave->duplex != DUPLEX_UNKNOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4779) cmd->base.duplex = slave->duplex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4781) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4782) cmd->base.speed = speed ? : SPEED_UNKNOWN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4784) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4785) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4787) static void bond_ethtool_get_drvinfo(struct net_device *bond_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4788) struct ethtool_drvinfo *drvinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4790) strlcpy(drvinfo->driver, DRV_NAME, sizeof(drvinfo->driver));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4791) snprintf(drvinfo->fw_version, sizeof(drvinfo->fw_version), "%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4792) BOND_ABI_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4793) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4795) static const struct ethtool_ops bond_ethtool_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4796) .get_drvinfo = bond_ethtool_get_drvinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4797) .get_link = ethtool_op_get_link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4798) .get_link_ksettings = bond_ethtool_get_link_ksettings,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4799) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4800)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4801) static const struct net_device_ops bond_netdev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4802) .ndo_init = bond_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4803) .ndo_uninit = bond_uninit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4804) .ndo_open = bond_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4805) .ndo_stop = bond_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4806) .ndo_start_xmit = bond_start_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4807) .ndo_select_queue = bond_select_queue,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4808) .ndo_get_stats64 = bond_get_stats,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4809) .ndo_do_ioctl = bond_do_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4810) .ndo_change_rx_flags = bond_change_rx_flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4811) .ndo_set_rx_mode = bond_set_rx_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4812) .ndo_change_mtu = bond_change_mtu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4813) .ndo_set_mac_address = bond_set_mac_address,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4814) .ndo_neigh_setup = bond_neigh_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4815) .ndo_vlan_rx_add_vid = bond_vlan_rx_add_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4816) .ndo_vlan_rx_kill_vid = bond_vlan_rx_kill_vid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4817) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4818) .ndo_netpoll_setup = bond_netpoll_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4819) .ndo_netpoll_cleanup = bond_netpoll_cleanup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4820) .ndo_poll_controller = bond_poll_controller,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4821) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4822) .ndo_add_slave = bond_enslave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4823) .ndo_del_slave = bond_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4824) .ndo_fix_features = bond_fix_features,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4825) .ndo_features_check = passthru_features_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4826) .ndo_get_xmit_slave = bond_xmit_get_slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4827) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4829) static const struct device_type bond_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4830) .name = "bond",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4831) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4833) static void bond_destructor(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4834) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4835) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4836) if (bond->wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4837) destroy_workqueue(bond->wq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4838) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4839)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4840) void bond_setup(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4841) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4842) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4844) spin_lock_init(&bond->mode_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4845) bond->params = bonding_defaults;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4846)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4847) /* Initialize pointers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4848) bond->dev = bond_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4849)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4850) /* Initialize the device entry points */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4851) ether_setup(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4852) bond_dev->max_mtu = ETH_MAX_MTU;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4853) bond_dev->netdev_ops = &bond_netdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4854) bond_dev->ethtool_ops = &bond_ethtool_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4856) bond_dev->needs_free_netdev = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4857) bond_dev->priv_destructor = bond_destructor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4858)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4859) SET_NETDEV_DEVTYPE(bond_dev, &bond_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4861) /* Initialize the device options */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4862) bond_dev->flags |= IFF_MASTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4863) bond_dev->priv_flags |= IFF_BONDING | IFF_UNICAST_FLT | IFF_NO_QUEUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4864) bond_dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4866) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4867) /* set up xfrm device ops (only supported in active-backup right now) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4868) bond_dev->xfrmdev_ops = &bond_xfrmdev_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4869) INIT_LIST_HEAD(&bond->ipsec_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4870) spin_lock_init(&bond->ipsec_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4871) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4872)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4873) /* don't acquire bond device's netif_tx_lock when transmitting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4874) bond_dev->features |= NETIF_F_LLTX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4876) /* By default, we declare the bond to be fully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4877) * VLAN hardware accelerated capable. Special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4878) * care is taken in the various xmit functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4879) * when there are slaves that are not hw accel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4880) * capable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4881) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4883) /* Don't allow bond devices to change network namespaces. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4884) bond_dev->features |= NETIF_F_NETNS_LOCAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4886) bond_dev->hw_features = BOND_VLAN_FEATURES |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4887) NETIF_F_HW_VLAN_CTAG_RX |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4888) NETIF_F_HW_VLAN_CTAG_FILTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4890) bond_dev->hw_features |= NETIF_F_GSO_ENCAP_ALL | NETIF_F_GSO_UDP_L4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4891) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4892) bond_dev->hw_features |= BOND_XFRM_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4893) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4894) bond_dev->features |= bond_dev->hw_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4895) bond_dev->features |= NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_STAG_TX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4896) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4897) /* Disable XFRM features if this isn't an active-backup config */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4898) if (BOND_MODE(bond) != BOND_MODE_ACTIVEBACKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4899) bond_dev->features &= ~BOND_XFRM_FEATURES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4900) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4901) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4903) /* Destroy a bonding device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4904) * Must be under rtnl_lock when this function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4905) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4906) static void bond_uninit(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4908) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4909) struct bond_up_slave *usable, *all;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4910) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4911) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4913) bond_netpoll_cleanup(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4914)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4915) /* Release the bonded slaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4916) bond_for_each_slave(bond, slave, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4917) __bond_release_one(bond_dev, slave->dev, true, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4918) netdev_info(bond_dev, "Released all slaves\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4919)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4920) usable = rtnl_dereference(bond->usable_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4921) if (usable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4922) RCU_INIT_POINTER(bond->usable_slaves, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4923) kfree_rcu(usable, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4924) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4926) all = rtnl_dereference(bond->all_slaves);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4927) if (all) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4928) RCU_INIT_POINTER(bond->all_slaves, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4929) kfree_rcu(all, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4932) list_del(&bond->bond_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4934) bond_debug_unregister(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4936)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4937) /*------------------------- Module initialization ---------------------------*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4938)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4939) static int bond_check_params(struct bond_params *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4940) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4941) int arp_validate_value, fail_over_mac_value, primary_reselect_value, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4942) struct bond_opt_value newval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4943) const struct bond_opt_value *valptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4944) int arp_all_targets_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4945) u16 ad_actor_sys_prio = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4946) u16 ad_user_port_key = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4947) __be32 arp_target[BOND_MAX_ARP_TARGETS] = { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4948) int arp_ip_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4949) int bond_mode = BOND_MODE_ROUNDROBIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4950) int xmit_hashtype = BOND_XMIT_POLICY_LAYER2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4951) int lacp_fast = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4952) int tlb_dynamic_lb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4953)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4954) /* Convert string parameters. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4955) if (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4956) bond_opt_initstr(&newval, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4957) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_MODE), &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4958) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4959) pr_err("Error: Invalid bonding mode \"%s\"\n", mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4960) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4962) bond_mode = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4963) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4964)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4965) if (xmit_hash_policy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4966) if (bond_mode == BOND_MODE_ROUNDROBIN ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4967) bond_mode == BOND_MODE_ACTIVEBACKUP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4968) bond_mode == BOND_MODE_BROADCAST) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4969) pr_info("xmit_hash_policy param is irrelevant in mode %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4970) bond_mode_name(bond_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4971) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4972) bond_opt_initstr(&newval, xmit_hash_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4973) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_XMIT_HASH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4974) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4975) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4976) pr_err("Error: Invalid xmit_hash_policy \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4977) xmit_hash_policy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4978) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4979) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4980) xmit_hashtype = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4981) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4983)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4984) if (lacp_rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4985) if (bond_mode != BOND_MODE_8023AD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4986) pr_info("lacp_rate param is irrelevant in mode %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4987) bond_mode_name(bond_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4988) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4989) bond_opt_initstr(&newval, lacp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4990) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_LACP_RATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4991) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4992) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4993) pr_err("Error: Invalid lacp rate \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4994) lacp_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4995) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4997) lacp_fast = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4999) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5001) if (ad_select) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5002) bond_opt_initstr(&newval, ad_select);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5003) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_AD_SELECT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5004) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5005) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5006) pr_err("Error: Invalid ad_select \"%s\"\n", ad_select);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5007) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5008) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5009) params->ad_select = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5010) if (bond_mode != BOND_MODE_8023AD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5011) pr_warn("ad_select param only affects 802.3ad mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5012) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5013) params->ad_select = BOND_AD_STABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5014) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5015)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5016) if (max_bonds < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5017) pr_warn("Warning: max_bonds (%d) not in range %d-%d, so it was reset to BOND_DEFAULT_MAX_BONDS (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5018) max_bonds, 0, INT_MAX, BOND_DEFAULT_MAX_BONDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5019) max_bonds = BOND_DEFAULT_MAX_BONDS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5021)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5022) if (miimon < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5023) pr_warn("Warning: miimon module parameter (%d), not in range 0-%d, so it was reset to 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5024) miimon, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5025) miimon = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5026) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5027)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5028) if (updelay < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5029) pr_warn("Warning: updelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5030) updelay, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5031) updelay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5032) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5033)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5034) if (downdelay < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5035) pr_warn("Warning: downdelay module parameter (%d), not in range 0-%d, so it was reset to 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5036) downdelay, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5037) downdelay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5038) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5040) if ((use_carrier != 0) && (use_carrier != 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5041) pr_warn("Warning: use_carrier module parameter (%d), not of valid value (0/1), so it was set to 1\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5042) use_carrier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5043) use_carrier = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5045)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5046) if (num_peer_notif < 0 || num_peer_notif > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5047) pr_warn("Warning: num_grat_arp/num_unsol_na (%d) not in range 0-255 so it was reset to 1\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5048) num_peer_notif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5049) num_peer_notif = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5051)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5052) /* reset values for 802.3ad/TLB/ALB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5053) if (!bond_mode_uses_arp(bond_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5054) if (!miimon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5055) pr_warn("Warning: miimon must be specified, otherwise bonding will not detect link failure, speed and duplex which are essential for 802.3ad operation\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5056) pr_warn("Forcing miimon to 100msec\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5057) miimon = BOND_DEFAULT_MIIMON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5058) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5059) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5060)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5061) if (tx_queues < 1 || tx_queues > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5062) pr_warn("Warning: tx_queues (%d) should be between 1 and 255, resetting to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5063) tx_queues, BOND_DEFAULT_TX_QUEUES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5064) tx_queues = BOND_DEFAULT_TX_QUEUES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5065) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5066)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5067) if ((all_slaves_active != 0) && (all_slaves_active != 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5068) pr_warn("Warning: all_slaves_active module parameter (%d), not of valid value (0/1), so it was set to 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5069) all_slaves_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5070) all_slaves_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5073) if (resend_igmp < 0 || resend_igmp > 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5074) pr_warn("Warning: resend_igmp (%d) should be between 0 and 255, resetting to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5075) resend_igmp, BOND_DEFAULT_RESEND_IGMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5076) resend_igmp = BOND_DEFAULT_RESEND_IGMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5077) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5078)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5079) bond_opt_initval(&newval, packets_per_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5080) if (!bond_opt_parse(bond_opt_get(BOND_OPT_PACKETS_PER_SLAVE), &newval)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5081) pr_warn("Warning: packets_per_slave (%d) should be between 0 and %u resetting to 1\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5082) packets_per_slave, USHRT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5083) packets_per_slave = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5085)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5086) if (bond_mode == BOND_MODE_ALB) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5087) pr_notice("In ALB mode you might experience client disconnections upon reconnection of a link if the bonding module updelay parameter (%d msec) is incompatible with the forwarding delay time of the switch\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5088) updelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5090)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5091) if (!miimon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5092) if (updelay || downdelay) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5093) /* just warn the user the up/down delay will have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5094) * no effect since miimon is zero...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5095) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5096) pr_warn("Warning: miimon module parameter not set and updelay (%d) or downdelay (%d) module parameter is set; updelay and downdelay have no effect unless miimon is set\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5097) updelay, downdelay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5098) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5099) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5100) /* don't allow arp monitoring */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5101) if (arp_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5102) pr_warn("Warning: miimon (%d) and arp_interval (%d) can't be used simultaneously, disabling ARP monitoring\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5103) miimon, arp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5104) arp_interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5107) if ((updelay % miimon) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5108) pr_warn("Warning: updelay (%d) is not a multiple of miimon (%d), updelay rounded to %d ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5109) updelay, miimon, (updelay / miimon) * miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5112) updelay /= miimon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5114) if ((downdelay % miimon) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5115) pr_warn("Warning: downdelay (%d) is not a multiple of miimon (%d), downdelay rounded to %d ms\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5116) downdelay, miimon,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5117) (downdelay / miimon) * miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5120) downdelay /= miimon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5123) if (arp_interval < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5124) pr_warn("Warning: arp_interval module parameter (%d), not in range 0-%d, so it was reset to 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5125) arp_interval, INT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5126) arp_interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5129) for (arp_ip_count = 0, i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5130) (arp_ip_count < BOND_MAX_ARP_TARGETS) && arp_ip_target[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5131) __be32 ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5133) /* not a complete check, but good enough to catch mistakes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5134) if (!in4_pton(arp_ip_target[i], -1, (u8 *)&ip, -1, NULL) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5135) !bond_is_ip_target_ok(ip)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5136) pr_warn("Warning: bad arp_ip_target module parameter (%s), ARP monitoring will not be performed\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5137) arp_ip_target[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5138) arp_interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5139) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5140) if (bond_get_targets_ip(arp_target, ip) == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5141) arp_target[arp_ip_count++] = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5142) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5143) pr_warn("Warning: duplicate address %pI4 in arp_ip_target, skipping\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5144) &ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5148) if (arp_interval && !arp_ip_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5149) /* don't allow arping if no arp_ip_target given... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5150) pr_warn("Warning: arp_interval module parameter (%d) specified without providing an arp_ip_target parameter, arp_interval was reset to 0\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5151) arp_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5152) arp_interval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5155) if (arp_validate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5156) if (!arp_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5157) pr_err("arp_validate requires arp_interval\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5158) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5161) bond_opt_initstr(&newval, arp_validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5162) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_ARP_VALIDATE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5163) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5164) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5165) pr_err("Error: invalid arp_validate \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5166) arp_validate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5167) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5169) arp_validate_value = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5170) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5171) arp_validate_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5174) if (arp_all_targets) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5175) bond_opt_initstr(&newval, arp_all_targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5176) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_ARP_ALL_TARGETS),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5177) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5178) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5179) pr_err("Error: invalid arp_all_targets_value \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5180) arp_all_targets);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5181) arp_all_targets_value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5182) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5183) arp_all_targets_value = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5187) if (miimon) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5188) pr_info("MII link monitoring set to %d ms\n", miimon);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5189) } else if (arp_interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5190) valptr = bond_opt_get_val(BOND_OPT_ARP_VALIDATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5191) arp_validate_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5192) pr_info("ARP monitoring set to %d ms, validate %s, with %d target(s):",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5193) arp_interval, valptr->string, arp_ip_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5195) for (i = 0; i < arp_ip_count; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5196) pr_cont(" %s", arp_ip_target[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5198) pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5200) } else if (max_bonds) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5201) /* miimon and arp_interval not set, we need one so things
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5202) * work as expected, see bonding.txt for details
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5204) pr_debug("Warning: either miimon or arp_interval and arp_ip_target module parameters must be specified, otherwise bonding will not detect link failures! see bonding.txt for details\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5207) if (primary && !bond_mode_uses_primary(bond_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5208) /* currently, using a primary only makes sense
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5209) * in active backup, TLB or ALB modes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5211) pr_warn("Warning: %s primary device specified but has no effect in %s mode\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5212) primary, bond_mode_name(bond_mode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5213) primary = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5216) if (primary && primary_reselect) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5217) bond_opt_initstr(&newval, primary_reselect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5218) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_PRIMARY_RESELECT),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5219) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5220) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5221) pr_err("Error: Invalid primary_reselect \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5222) primary_reselect);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5223) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5225) primary_reselect_value = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5226) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5227) primary_reselect_value = BOND_PRI_RESELECT_ALWAYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5230) if (fail_over_mac) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5231) bond_opt_initstr(&newval, fail_over_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5232) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_FAIL_OVER_MAC),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5233) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5234) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5235) pr_err("Error: invalid fail_over_mac \"%s\"\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5236) fail_over_mac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5237) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5239) fail_over_mac_value = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5240) if (bond_mode != BOND_MODE_ACTIVEBACKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5241) pr_warn("Warning: fail_over_mac only affects active-backup mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5242) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5243) fail_over_mac_value = BOND_FOM_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5246) bond_opt_initstr(&newval, "default");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5247) valptr = bond_opt_parse(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5248) bond_opt_get(BOND_OPT_AD_ACTOR_SYS_PRIO),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5249) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5250) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5251) pr_err("Error: No ad_actor_sys_prio default value");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5252) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5254) ad_actor_sys_prio = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5256) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_AD_USER_PORT_KEY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5257) &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5258) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5259) pr_err("Error: No ad_user_port_key default value");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5260) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5262) ad_user_port_key = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5264) bond_opt_initstr(&newval, "default");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5265) valptr = bond_opt_parse(bond_opt_get(BOND_OPT_TLB_DYNAMIC_LB), &newval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5266) if (!valptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5267) pr_err("Error: No tlb_dynamic_lb default value");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5268) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5270) tlb_dynamic_lb = valptr->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5272) if (lp_interval == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5273) pr_warn("Warning: ip_interval must be between 1 and %d, so it was reset to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5274) INT_MAX, BOND_ALB_DEFAULT_LP_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5275) lp_interval = BOND_ALB_DEFAULT_LP_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5278) /* fill params struct with the proper values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5279) params->mode = bond_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5280) params->xmit_policy = xmit_hashtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5281) params->miimon = miimon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5282) params->num_peer_notif = num_peer_notif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5283) params->arp_interval = arp_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5284) params->arp_validate = arp_validate_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5285) params->arp_all_targets = arp_all_targets_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5286) params->updelay = updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5287) params->downdelay = downdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5288) params->peer_notif_delay = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5289) params->use_carrier = use_carrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5290) params->lacp_fast = lacp_fast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5291) params->primary[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5292) params->primary_reselect = primary_reselect_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5293) params->fail_over_mac = fail_over_mac_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5294) params->tx_queues = tx_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5295) params->all_slaves_active = all_slaves_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5296) params->resend_igmp = resend_igmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5297) params->min_links = min_links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5298) params->lp_interval = lp_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5299) params->packets_per_slave = packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5300) params->tlb_dynamic_lb = tlb_dynamic_lb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5301) params->ad_actor_sys_prio = ad_actor_sys_prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5302) eth_zero_addr(params->ad_actor_system);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5303) params->ad_user_port_key = ad_user_port_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5304) if (packets_per_slave > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5305) params->reciprocal_packets_per_slave =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5306) reciprocal_value(packets_per_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5307) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5308) /* reciprocal_packets_per_slave is unused if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5309) * packets_per_slave is 0 or 1, just initialize it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5310) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5311) params->reciprocal_packets_per_slave =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5312) (struct reciprocal_value) { 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5314)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5315) if (primary) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5316) strncpy(params->primary, primary, IFNAMSIZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5317) params->primary[IFNAMSIZ - 1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5320) memcpy(params->arp_targets, arp_target, sizeof(arp_target));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5322) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5325) /* Called from registration process */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5326) static int bond_init(struct net_device *bond_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5327) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5328) struct bonding *bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5329) struct bond_net *bn = net_generic(dev_net(bond_dev), bond_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5331) netdev_dbg(bond_dev, "Begin bond_init\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5333) bond->wq = alloc_ordered_workqueue(bond_dev->name, WQ_MEM_RECLAIM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5334) if (!bond->wq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5335) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5337) spin_lock_init(&bond->stats_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5338) netdev_lockdep_set_classes(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5340) list_add_tail(&bond->bond_list, &bn->dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5342) bond_prepare_sysfs_group(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5344) bond_debug_register(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5346) /* Ensure valid dev_addr */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5347) if (is_zero_ether_addr(bond_dev->dev_addr) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5348) bond_dev->addr_assign_type == NET_ADDR_PERM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5349) eth_hw_addr_random(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5351) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5354) unsigned int bond_get_num_tx_queues(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5356) return tx_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5359) /* Create a new bond based on the specified name and bonding parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5360) * If name is NULL, obtain a suitable "bond%d" name for us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5361) * Caller must NOT hold rtnl_lock; we need to release it here before we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5362) * set up our sysfs entries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5363) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5364) int bond_create(struct net *net, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5366) struct net_device *bond_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5367) struct bonding *bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5368) struct alb_bond_info *bond_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5369) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5371) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5373) bond_dev = alloc_netdev_mq(sizeof(struct bonding),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5374) name ? name : "bond%d", NET_NAME_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5375) bond_setup, tx_queues);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5376) if (!bond_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5377) pr_err("%s: eek! can't alloc netdev!\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5378) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5379) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5382) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5383) * Initialize rx_hashtbl_used_head to RLB_NULL_INDEX.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5384) * It is set to 0 by default which is wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5385) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5386) bond = netdev_priv(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5387) bond_info = &(BOND_ALB_INFO(bond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5388) bond_info->rx_hashtbl_used_head = RLB_NULL_INDEX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5390) dev_net_set(bond_dev, net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5391) bond_dev->rtnl_link_ops = &bond_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5393) res = register_netdevice(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5394) if (res < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5395) free_netdev(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5396) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5398) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5399) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5401) netif_carrier_off(bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5403) bond_work_init_all(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5405) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5406) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5409) static int __net_init bond_net_init(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5411) struct bond_net *bn = net_generic(net, bond_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5413) bn->net = net;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5414) INIT_LIST_HEAD(&bn->dev_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5416) bond_create_proc_dir(bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5417) bond_create_sysfs(bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5419) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5422) static void __net_exit bond_net_exit(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5424) struct bond_net *bn = net_generic(net, bond_net_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5425) struct bonding *bond, *tmp_bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5426) LIST_HEAD(list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5428) bond_destroy_sysfs(bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5430) /* Kill off any bonds created after unregistering bond rtnl ops */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5431) rtnl_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5432) list_for_each_entry_safe(bond, tmp_bond, &bn->dev_list, bond_list)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5433) unregister_netdevice_queue(bond->dev, &list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5434) unregister_netdevice_many(&list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5435) rtnl_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5437) bond_destroy_proc_dir(bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5438) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5440) static struct pernet_operations bond_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5441) .init = bond_net_init,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5442) .exit = bond_net_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5443) .id = &bond_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5444) .size = sizeof(struct bond_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5445) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5447) static int __init bonding_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5449) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5450) int res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5452) res = bond_check_params(&bonding_defaults);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5453) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5454) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5456) res = register_pernet_subsys(&bond_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5457) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5458) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5460) res = bond_netlink_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5461) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5462) goto err_link;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5464) bond_create_debugfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5466) for (i = 0; i < max_bonds; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5467) res = bond_create(&init_net, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5468) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5469) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5470) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5472) skb_flow_dissector_init(&flow_keys_bonding,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5473) flow_keys_bonding_keys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5474) ARRAY_SIZE(flow_keys_bonding_keys));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5476) register_netdevice_notifier(&bond_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5477) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5478) return res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5479) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5480) bond_destroy_debugfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5481) bond_netlink_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5482) err_link:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5483) unregister_pernet_subsys(&bond_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5484) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5488) static void __exit bonding_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5490) unregister_netdevice_notifier(&bond_netdev_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5492) bond_destroy_debugfs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5494) bond_netlink_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5495) unregister_pernet_subsys(&bond_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5497) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5498) /* Make sure we don't have an imbalance on our netpoll blocking */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5499) WARN_ON(atomic_read(&netpoll_block_tx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5500) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5503) module_init(bonding_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5504) module_exit(bonding_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5505) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5506) MODULE_DESCRIPTION(DRV_DESCRIPTION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5507) MODULE_AUTHOR("Thomas Davis, tadavis@lbl.gov and many others");