^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * NCM: Network and Communications Management, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * BUT, I'm the one who modified it for ethernet, so:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This software may be used and distributed according to the terms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * of the GNU Public License, incorporated herein by reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef _NET_BONDING_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _NET_BONDING_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/if_bonding.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/cpumask.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/in6.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/netpoll.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/inetdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/reciprocal_div.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/if_link.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <net/bond_3ad.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <net/bond_alb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <net/bond_options.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define BOND_MAX_ARP_TARGETS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define BOND_DEFAULT_MIIMON 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #ifndef __long_aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define __long_aligned __attribute__((aligned((sizeof(long)))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define slave_info(bond_dev, slave_dev, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) netdev_info(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define slave_warn(bond_dev, slave_dev, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) netdev_warn(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define slave_dbg(bond_dev, slave_dev, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) netdev_dbg(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define slave_err(bond_dev, slave_dev, fmt, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) netdev_err(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define BOND_MODE(bond) ((bond)->params.mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* slave list primitives */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define bond_slave_list(bond) (&(bond)->dev->adj_list.lower)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define bond_has_slaves(bond) !list_empty(bond_slave_list(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #define bond_first_slave(bond) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) (bond_has_slaves(bond) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) netdev_adjacent_get_private(bond_slave_list(bond)->next) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define bond_last_slave(bond) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) (bond_has_slaves(bond) ? \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) netdev_adjacent_get_private(bond_slave_list(bond)->prev) : \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* Caller must have rcu_read_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define bond_first_slave_rcu(bond) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) netdev_lower_get_first_private_rcu(bond->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define bond_is_first_slave(bond, pos) (pos == bond_first_slave(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define bond_is_last_slave(bond, pos) (pos == bond_last_slave(bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * bond_for_each_slave - iterate over all slaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * @bond: the bond holding this list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * @pos: current slave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @iter: list_head * iterator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * Caller must hold RTNL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define bond_for_each_slave(bond, pos, iter) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) netdev_for_each_lower_private((bond)->dev, pos, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* Caller must have rcu_read_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #define bond_for_each_slave_rcu(bond, pos, iter) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) netdev_for_each_lower_private_rcu((bond)->dev, pos, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) NETIF_F_GSO_ESP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) extern atomic_t netpoll_block_tx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static inline void block_netpoll_tx(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) atomic_inc(&netpoll_block_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline void unblock_netpoll_tx(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) atomic_dec(&netpoll_block_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static inline int is_netpoll_tx_blocked(struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (unlikely(netpoll_tx_running(dev)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return atomic_read(&netpoll_block_tx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #define block_netpoll_tx()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #define unblock_netpoll_tx()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #define is_netpoll_tx_blocked(dev) (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct bond_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int xmit_policy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int miimon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 num_peer_notif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int arp_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int arp_validate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int arp_all_targets;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int use_carrier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int fail_over_mac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) int updelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int downdelay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) int peer_notif_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int lacp_fast;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned int min_links;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ad_select;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) char primary[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int primary_reselect;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) __be32 arp_targets[BOND_MAX_ARP_TARGETS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int tx_queues;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int all_slaves_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) int resend_igmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int lp_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) int packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) int tlb_dynamic_lb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct reciprocal_value reciprocal_packets_per_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) u16 ad_actor_sys_prio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) u16 ad_user_port_key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* 2 bytes of padding : see ether_addr_equal_64bits() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) u8 ad_actor_system[ETH_ALEN + 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct bond_parm_tbl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) char *modename;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) struct slave {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) struct net_device *dev; /* first - useful for panic debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct bonding *bond; /* our master */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) /* all three in jiffies */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) unsigned long last_link_up;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) unsigned long last_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) unsigned long target_last_arp_rx[BOND_MAX_ARP_TARGETS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) s8 link; /* one of BOND_LINK_XXXX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) s8 link_new_state; /* one of BOND_LINK_XXXX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u8 backup:1, /* indicates backup slave. Value corresponds with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) inactive:1, /* indicates inactive slave */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) should_notify:1, /* indicates whether the state changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) should_notify_link:1; /* indicates whether the link changed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u8 duplex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u32 original_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) u32 link_failure_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) u32 speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) u16 queue_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) u8 perm_hwaddr[MAX_ADDR_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct ad_slave_info *ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct tlb_slave_info tlb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) struct netpoll *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) struct delayed_work notify_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct kobject kobj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct rtnl_link_stats64 slave_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static inline struct slave *to_slave(struct kobject *kobj)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) return container_of(kobj, struct slave, kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct bond_up_slave {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) unsigned int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct rcu_head rcu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct slave *arr[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * Link pseudo-state only used internally by monitors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #define BOND_LINK_NOCHANGE -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct bond_ipsec {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct xfrm_state *xs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * Here are the locking policies for the two bonding locks:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Get rcu_read_lock when reading or RTNL when writing slave list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct bonding {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct net_device *dev; /* first - useful for panic debug */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct slave __rcu *curr_active_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct slave __rcu *current_arp_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct slave __rcu *primary_slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct bond_up_slave __rcu *usable_slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct bond_up_slave __rcu *all_slaves;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) bool force_primary;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) s32 slave_cnt; /* never change this value outside the attach/detach wrappers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int (*recv_probe)(const struct sk_buff *, struct bonding *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct slave *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* mode_lock is used for mode-specific locking needs, currently used by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * 3ad mode (4) - protect against running bond_3ad_unbind_slave() and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * bond_3ad_state_machine_handler() concurrently and also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * the access to the state machine shared variables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * TLB mode (5) - to sync the use and modifications of its hash table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * ALB mode (6) - to sync the use and modifications of its hash table
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) spinlock_t mode_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) spinlock_t stats_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) u8 send_peer_notif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) u8 igmp_retrans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct proc_dir_entry *proc_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) char proc_file_name[IFNAMSIZ];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #endif /* CONFIG_PROC_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct list_head bond_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) u32 rr_tx_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct ad_bond_info ad_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct alb_bond_info alb_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) struct bond_params params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct workqueue_struct *wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct delayed_work mii_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct delayed_work arp_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct delayed_work alb_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) struct delayed_work ad_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct delayed_work mcast_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct delayed_work slave_arr_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #ifdef CONFIG_DEBUG_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* debugging support via debugfs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct dentry *debug_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #endif /* CONFIG_DEBUG_FS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct rtnl_link_stats64 bond_stats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #ifdef CONFIG_XFRM_OFFLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct list_head ipsec_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /* protecting ipsec_list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) spinlock_t ipsec_lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #endif /* CONFIG_XFRM_OFFLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #define bond_slave_get_rcu(dev) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ((struct slave *) rcu_dereference(dev->rx_handler_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) #define bond_slave_get_rtnl(dev) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ((struct slave *) rtnl_dereference(dev->rx_handler_data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) void bond_queue_slave_event(struct slave *slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) void bond_lower_state_changed(struct slave *slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct bond_vlan_tag {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) __be16 vlan_proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) unsigned short vlan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) };
^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) * Returns NULL if the net_device does not belong to any of the bond's slaves
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * Caller must hold bond lock for read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static inline struct slave *bond_get_slave_by_dev(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) return netdev_lower_dev_get_private(bond->dev, slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return slave->bond;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) static inline bool bond_should_override_tx_queue(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) BOND_MODE(bond) == BOND_MODE_ROUNDROBIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline bool bond_is_lb(const struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) return BOND_MODE(bond) == BOND_MODE_TLB ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) BOND_MODE(bond) == BOND_MODE_ALB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) static inline bool bond_needs_speed_duplex(const struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return BOND_MODE(bond) == BOND_MODE_8023AD || bond_is_lb(bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static inline bool bond_is_nondyn_tlb(const struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return (bond_is_lb(bond) && bond->params.tlb_dynamic_lb == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) static inline bool bond_mode_can_use_xmit_hash(const struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) return (BOND_MODE(bond) == BOND_MODE_8023AD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) BOND_MODE(bond) == BOND_MODE_XOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) BOND_MODE(bond) == BOND_MODE_TLB ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) BOND_MODE(bond) == BOND_MODE_ALB);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) static inline bool bond_mode_uses_xmit_hash(const struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return (BOND_MODE(bond) == BOND_MODE_8023AD ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) BOND_MODE(bond) == BOND_MODE_XOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) bond_is_nondyn_tlb(bond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) static inline bool bond_mode_uses_arp(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return mode != BOND_MODE_8023AD && mode != BOND_MODE_TLB &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) mode != BOND_MODE_ALB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static inline bool bond_mode_uses_primary(int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return mode == BOND_MODE_ACTIVEBACKUP || mode == BOND_MODE_TLB ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) mode == BOND_MODE_ALB;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static inline bool bond_uses_primary(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return bond_mode_uses_primary(BOND_MODE(bond));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) static inline struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct slave *slave = rcu_dereference(bond->curr_active_slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return bond_uses_primary(bond) && slave ? slave->dev : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static inline bool bond_slave_is_up(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) return netif_running(slave->dev) && netif_carrier_ok(slave->dev);
^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) static inline void bond_set_active_slave(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (slave->backup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) slave->backup = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) bond_queue_slave_event(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) bond_lower_state_changed(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static inline void bond_set_backup_slave(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) if (!slave->backup) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) slave->backup = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) bond_queue_slave_event(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) bond_lower_state_changed(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) static inline void bond_set_slave_state(struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int slave_state, bool notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (slave->backup == slave_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) slave->backup = slave_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) bond_lower_state_changed(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) bond_queue_slave_event(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) slave->should_notify = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (slave->should_notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) slave->should_notify = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) slave->should_notify = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static inline void bond_slave_state_change(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) struct slave *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) bond_for_each_slave(bond, tmp, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) if (tmp->link == BOND_LINK_UP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) bond_set_active_slave(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) else if (tmp->link == BOND_LINK_DOWN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) bond_set_backup_slave(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static inline void bond_slave_state_notify(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) struct slave *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) bond_for_each_slave(bond, tmp, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (tmp->should_notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) bond_lower_state_changed(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) tmp->should_notify = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) static inline int bond_slave_state(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) return slave->backup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) static inline bool bond_is_active_slave(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) return !bond_slave_state(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) static inline bool bond_slave_can_tx(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return bond_slave_is_up(slave) && slave->link == BOND_LINK_UP &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) bond_is_active_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) static inline bool bond_is_active_slave_dev(const struct net_device *slave_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) struct slave *slave;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) bool active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) slave = bond_slave_get_rcu(slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) active = bond_is_active_slave(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) return active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) static inline void bond_hw_addr_copy(u8 *dst, const u8 *src, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (len == ETH_ALEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) ether_addr_copy(dst, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) return;
^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) memcpy(dst, src, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) #define BOND_PRI_RESELECT_ALWAYS 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) #define BOND_PRI_RESELECT_BETTER 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) #define BOND_PRI_RESELECT_FAILURE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) #define BOND_FOM_NONE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #define BOND_FOM_ACTIVE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #define BOND_FOM_FOLLOW 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #define BOND_ARP_TARGETS_ANY 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #define BOND_ARP_TARGETS_ALL 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) #define BOND_ARP_VALIDATE_NONE 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) #define BOND_ARP_VALIDATE_ACTIVE (1 << BOND_STATE_ACTIVE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) #define BOND_ARP_VALIDATE_BACKUP (1 << BOND_STATE_BACKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) #define BOND_ARP_VALIDATE_ALL (BOND_ARP_VALIDATE_ACTIVE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) BOND_ARP_VALIDATE_BACKUP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) #define BOND_ARP_FILTER (BOND_ARP_VALIDATE_ALL + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) #define BOND_ARP_FILTER_ACTIVE (BOND_ARP_VALIDATE_ACTIVE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) BOND_ARP_FILTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) #define BOND_ARP_FILTER_BACKUP (BOND_ARP_VALIDATE_BACKUP | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) BOND_ARP_FILTER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) #define BOND_SLAVE_NOTIFY_NOW true
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) #define BOND_SLAVE_NOTIFY_LATER false
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) static inline int slave_do_arp_validate(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) return bond->params.arp_validate & (1 << bond_slave_state(slave));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) static inline int slave_do_arp_validate_only(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return bond->params.arp_validate & BOND_ARP_FILTER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) static inline int bond_is_ip_target_ok(__be32 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return !ipv4_is_lbcast(addr) && !ipv4_is_zeronet(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* Get the oldest arp which we've received on this slave for bond's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * arp_targets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) static inline unsigned long slave_oldest_target_arp_rx(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) int i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) unsigned long ret = slave->target_last_arp_rx[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) for (; (i < BOND_MAX_ARP_TARGETS) && bond->params.arp_targets[i]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) if (time_before(slave->target_last_arp_rx[i], ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) ret = slave->target_last_arp_rx[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) return ret;
^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 inline unsigned long slave_last_rx(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (bond->params.arp_all_targets == BOND_ARP_TARGETS_ALL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) return slave_oldest_target_arp_rx(bond, slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) return slave->last_rx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) #ifdef CONFIG_NET_POLL_CONTROLLER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return netpoll_send_skb(slave->np, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return NETDEV_TX_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) static inline void bond_set_slave_inactive_flags(struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) bool notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (!bond_is_lb(slave->bond))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) bond_set_slave_state(slave, BOND_STATE_BACKUP, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) if (!slave->bond->params.all_slaves_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) slave->inactive = 1;
^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) static inline void bond_set_slave_active_flags(struct slave *slave,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) bool notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) bond_set_slave_state(slave, BOND_STATE_ACTIVE, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) slave->inactive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) static inline bool bond_is_slave_inactive(struct slave *slave)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return slave->inactive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) static inline void bond_propose_link_state(struct slave *slave, int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) slave->link_new_state = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) static inline void bond_commit_link_state(struct slave *slave, bool notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (slave->link_new_state == BOND_LINK_NOCHANGE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) slave->link = slave->link_new_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) if (notify) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) bond_queue_slave_event(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) bond_lower_state_changed(slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) slave->should_notify_link = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (slave->should_notify_link)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) slave->should_notify_link = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) slave->should_notify_link = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^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) static inline void bond_set_slave_link_state(struct slave *slave, int state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) bool notify)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) bond_propose_link_state(slave, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) bond_commit_link_state(slave, notify);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) static inline void bond_slave_link_notify(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) struct slave *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) bond_for_each_slave(bond, tmp, iter) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) if (tmp->should_notify_link) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) bond_queue_slave_event(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) bond_lower_state_changed(tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) tmp->should_notify_link = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) static inline __be32 bond_confirm_addr(struct net_device *dev, __be32 dst, __be32 local)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) struct in_device *in_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) __be32 addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) in_dev = __in_dev_get_rcu(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) if (in_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) addr = inet_confirm_addr(dev_net(dev), in_dev, dst, local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) RT_SCOPE_HOST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) struct bond_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) struct net *net; /* Associated network namespace */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct list_head dev_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct proc_dir_entry *proc_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) struct class_attribute class_attr_bonding_masters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) int bond_arp_rcv(const struct sk_buff *skb, struct bonding *bond, struct slave *slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) int bond_create(struct net *net, const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) int bond_create_sysfs(struct bond_net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) void bond_destroy_sysfs(struct bond_net *net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) void bond_prepare_sysfs_group(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) int bond_sysfs_slave_add(struct slave *slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) void bond_sysfs_slave_del(struct slave *slave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct netlink_ext_ack *extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) int bond_set_carrier(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) void bond_select_active_slave(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) void bond_create_debugfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) void bond_destroy_debugfs(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) void bond_debug_register(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) void bond_debug_unregister(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) void bond_debug_reregister(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) const char *bond_mode_name(int mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) void bond_setup(struct net_device *bond_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) unsigned int bond_get_num_tx_queues(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) int bond_netlink_init(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) void bond_netlink_fini(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) const char *bond_slave_link_status(s8 link);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct net_device *end_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) void bond_work_init_all(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) #ifdef CONFIG_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) void bond_create_proc_entry(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) void bond_remove_proc_entry(struct bonding *bond);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) void bond_create_proc_dir(struct bond_net *bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) void bond_destroy_proc_dir(struct bond_net *bn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static inline void bond_create_proc_entry(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) static inline void bond_remove_proc_entry(struct bonding *bond)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) static inline void bond_create_proc_dir(struct bond_net *bn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) static inline void bond_destroy_proc_dir(struct bond_net *bn)
^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) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static inline struct slave *bond_slave_has_mac(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) const u8 *mac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) struct slave *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) bond_for_each_slave(bond, tmp, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) /* Caller must hold rcu_read_lock() for read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) static inline struct slave *bond_slave_has_mac_rcu(struct bonding *bond,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) const u8 *mac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct slave *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) bond_for_each_slave_rcu(bond, tmp, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) return tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) /* Caller must hold rcu_read_lock() for read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) static inline bool bond_slave_has_mac_rx(struct bonding *bond, const u8 *mac)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) struct list_head *iter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) struct slave *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) struct netdev_hw_addr *ha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) bond_for_each_slave_rcu(bond, tmp, iter)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (netdev_uc_empty(bond->dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) netdev_for_each_uc_addr(ha, bond->dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) if (ether_addr_equal_64bits(mac, ha->addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /* Check if the ip is present in arp ip list, or first free slot if ip == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * Returns -1 if not found, index if found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) static inline int bond_get_targets_ip(__be32 *targets, __be32 ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (targets[i] == ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) else if (targets[i] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) /* exported from bond_main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) extern unsigned int bond_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) extern const struct bond_parm_tbl bond_lacp_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) extern const struct bond_parm_tbl xmit_hashtype_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) extern const struct bond_parm_tbl arp_validate_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) extern const struct bond_parm_tbl arp_all_targets_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) extern const struct bond_parm_tbl fail_over_mac_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) extern const struct bond_parm_tbl pri_reselect_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) extern struct bond_parm_tbl ad_select_tbl[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) /* exported from bond_netlink.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) extern struct rtnl_link_ops bond_link_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) /* exported from bond_sysfs_slave.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) extern const struct sysfs_ops slave_sysfs_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) static inline netdev_tx_t bond_tx_drop(struct net_device *dev, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) atomic_long_inc(&dev->tx_dropped);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) dev_kfree_skb_any(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) return NET_XMIT_DROP;
^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) #endif /* _NET_BONDING_H */