xref: /openbmc/linux/include/net/bonding.h (revision e74216b8)
1613a0141SBagas Sanjaya /* SPDX-License-Identifier: GPL-1.0+ */
21ef8019bSDavid S. Miller /*
31ef8019bSDavid S. Miller  * Bond several ethernet interfaces into a Cisco, running 'Etherchannel'.
41ef8019bSDavid S. Miller  *
51ef8019bSDavid S. Miller  * Portions are (c) Copyright 1995 Simon "Guru Aleph-Null" Janes
61ef8019bSDavid S. Miller  * NCM: Network and Communications Management, Inc.
71ef8019bSDavid S. Miller  *
81ef8019bSDavid S. Miller  * BUT, I'm the one who modified it for ethernet, so:
91ef8019bSDavid S. Miller  * (c) Copyright 1999, Thomas Davis, tadavis@lbl.gov
101ef8019bSDavid S. Miller  *
111ef8019bSDavid S. Miller  */
121ef8019bSDavid S. Miller 
131ef8019bSDavid S. Miller #ifndef _NET_BONDING_H
141ef8019bSDavid S. Miller #define _NET_BONDING_H
151ef8019bSDavid S. Miller 
161ef8019bSDavid S. Miller #include <linux/timer.h>
171ef8019bSDavid S. Miller #include <linux/proc_fs.h>
181ef8019bSDavid S. Miller #include <linux/if_bonding.h>
191ef8019bSDavid S. Miller #include <linux/cpumask.h>
201ef8019bSDavid S. Miller #include <linux/in6.h>
211ef8019bSDavid S. Miller #include <linux/netpoll.h>
221ef8019bSDavid S. Miller #include <linux/inetdevice.h>
231ef8019bSDavid S. Miller #include <linux/etherdevice.h>
241ef8019bSDavid S. Miller #include <linux/reciprocal_div.h>
251ef8019bSDavid S. Miller #include <linux/if_link.h>
261ef8019bSDavid S. Miller 
271ef8019bSDavid S. Miller #include <net/bond_3ad.h>
281ef8019bSDavid S. Miller #include <net/bond_alb.h>
291ef8019bSDavid S. Miller #include <net/bond_options.h>
304e24be01SHangbin Liu #include <net/ipv6.h>
314e24be01SHangbin Liu #include <net/addrconf.h>
321ef8019bSDavid S. Miller 
331ef8019bSDavid S. Miller #define BOND_MAX_ARP_TARGETS	16
344e24be01SHangbin Liu #define BOND_MAX_NS_TARGETS	BOND_MAX_ARP_TARGETS
351ef8019bSDavid S. Miller 
361ef8019bSDavid S. Miller #define BOND_DEFAULT_MIIMON	100
371ef8019bSDavid S. Miller 
38f87fda00SEric Dumazet #ifndef __long_aligned
39f87fda00SEric Dumazet #define __long_aligned __attribute__((aligned((sizeof(long)))))
40f87fda00SEric Dumazet #endif
411ef8019bSDavid S. Miller 
425237ff79SJarod Wilson #define slave_info(bond_dev, slave_dev, fmt, ...) \
435237ff79SJarod Wilson 	netdev_info(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
445237ff79SJarod Wilson #define slave_warn(bond_dev, slave_dev, fmt, ...) \
455237ff79SJarod Wilson 	netdev_warn(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
465237ff79SJarod Wilson #define slave_dbg(bond_dev, slave_dev, fmt, ...) \
475237ff79SJarod Wilson 	netdev_dbg(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
485237ff79SJarod Wilson #define slave_err(bond_dev, slave_dev, fmt, ...) \
495237ff79SJarod Wilson 	netdev_err(bond_dev, "(slave %s): " fmt, (slave_dev)->name, ##__VA_ARGS__)
505237ff79SJarod Wilson 
511ef8019bSDavid S. Miller #define BOND_MODE(bond) ((bond)->params.mode)
521ef8019bSDavid S. Miller 
531ef8019bSDavid S. Miller /* slave list primitives */
541ef8019bSDavid S. Miller #define bond_slave_list(bond) (&(bond)->dev->adj_list.lower)
551ef8019bSDavid S. Miller 
561ef8019bSDavid S. Miller #define bond_has_slaves(bond) !list_empty(bond_slave_list(bond))
571ef8019bSDavid S. Miller 
581ef8019bSDavid S. Miller /* IMPORTANT: bond_first/last_slave can return NULL in case of an empty list */
591ef8019bSDavid S. Miller #define bond_first_slave(bond) \
601ef8019bSDavid S. Miller 	(bond_has_slaves(bond) ? \
611ef8019bSDavid S. Miller 		netdev_adjacent_get_private(bond_slave_list(bond)->next) : \
621ef8019bSDavid S. Miller 		NULL)
631ef8019bSDavid S. Miller #define bond_last_slave(bond) \
641ef8019bSDavid S. Miller 	(bond_has_slaves(bond) ? \
651ef8019bSDavid S. Miller 		netdev_adjacent_get_private(bond_slave_list(bond)->prev) : \
661ef8019bSDavid S. Miller 		NULL)
671ef8019bSDavid S. Miller 
681ef8019bSDavid S. Miller /* Caller must have rcu_read_lock */
691ef8019bSDavid S. Miller #define bond_first_slave_rcu(bond) \
701ef8019bSDavid S. Miller 	netdev_lower_get_first_private_rcu(bond->dev)
711ef8019bSDavid S. Miller 
721ef8019bSDavid S. Miller #define bond_is_first_slave(bond, pos) (pos == bond_first_slave(bond))
731ef8019bSDavid S. Miller #define bond_is_last_slave(bond, pos) (pos == bond_last_slave(bond))
741ef8019bSDavid S. Miller 
751ef8019bSDavid S. Miller /**
761ef8019bSDavid S. Miller  * bond_for_each_slave - iterate over all slaves
771ef8019bSDavid S. Miller  * @bond:	the bond holding this list
781ef8019bSDavid S. Miller  * @pos:	current slave
791ef8019bSDavid S. Miller  * @iter:	list_head * iterator
801ef8019bSDavid S. Miller  *
811ef8019bSDavid S. Miller  * Caller must hold RTNL
821ef8019bSDavid S. Miller  */
831ef8019bSDavid S. Miller #define bond_for_each_slave(bond, pos, iter) \
841ef8019bSDavid S. Miller 	netdev_for_each_lower_private((bond)->dev, pos, iter)
851ef8019bSDavid S. Miller 
861ef8019bSDavid S. Miller /* Caller must have rcu_read_lock */
871ef8019bSDavid S. Miller #define bond_for_each_slave_rcu(bond, pos, iter) \
881ef8019bSDavid S. Miller 	netdev_for_each_lower_private_rcu((bond)->dev, pos, iter)
891ef8019bSDavid S. Miller 
90a3b658cfSJarod Wilson #define BOND_XFRM_FEATURES (NETIF_F_HW_ESP | NETIF_F_HW_ESP_TX_CSUM | \
91a3b658cfSJarod Wilson 			    NETIF_F_GSO_ESP)
92a3b658cfSJarod Wilson 
931ef8019bSDavid S. Miller #ifdef CONFIG_NET_POLL_CONTROLLER
941ef8019bSDavid S. Miller extern atomic_t netpoll_block_tx;
951ef8019bSDavid S. Miller 
block_netpoll_tx(void)961ef8019bSDavid S. Miller static inline void block_netpoll_tx(void)
971ef8019bSDavid S. Miller {
981ef8019bSDavid S. Miller 	atomic_inc(&netpoll_block_tx);
991ef8019bSDavid S. Miller }
1001ef8019bSDavid S. Miller 
unblock_netpoll_tx(void)1011ef8019bSDavid S. Miller static inline void unblock_netpoll_tx(void)
1021ef8019bSDavid S. Miller {
1031ef8019bSDavid S. Miller 	atomic_dec(&netpoll_block_tx);
1041ef8019bSDavid S. Miller }
1051ef8019bSDavid S. Miller 
is_netpoll_tx_blocked(struct net_device * dev)1061ef8019bSDavid S. Miller static inline int is_netpoll_tx_blocked(struct net_device *dev)
1071ef8019bSDavid S. Miller {
1081ef8019bSDavid S. Miller 	if (unlikely(netpoll_tx_running(dev)))
1091ef8019bSDavid S. Miller 		return atomic_read(&netpoll_block_tx);
1101ef8019bSDavid S. Miller 	return 0;
1111ef8019bSDavid S. Miller }
1121ef8019bSDavid S. Miller #else
1131ef8019bSDavid S. Miller #define block_netpoll_tx()
1141ef8019bSDavid S. Miller #define unblock_netpoll_tx()
1151ef8019bSDavid S. Miller #define is_netpoll_tx_blocked(dev) (0)
1161ef8019bSDavid S. Miller #endif
1171ef8019bSDavid S. Miller 
1181ef8019bSDavid S. Miller struct bond_params {
1191ef8019bSDavid S. Miller 	int mode;
1201ef8019bSDavid S. Miller 	int xmit_policy;
1211ef8019bSDavid S. Miller 	int miimon;
1221ef8019bSDavid S. Miller 	u8 num_peer_notif;
1235944b5abSHangbin Liu 	u8 missed_max;
1241ef8019bSDavid S. Miller 	int arp_interval;
1251ef8019bSDavid S. Miller 	int arp_validate;
1261ef8019bSDavid S. Miller 	int arp_all_targets;
1271ef8019bSDavid S. Miller 	int use_carrier;
1281ef8019bSDavid S. Miller 	int fail_over_mac;
1291ef8019bSDavid S. Miller 	int updelay;
1301ef8019bSDavid S. Miller 	int downdelay;
13107a4ddecSVincent Bernat 	int peer_notif_delay;
1323a755cd8SHangbin Liu 	int lacp_active;
1331ef8019bSDavid S. Miller 	int lacp_fast;
1341ef8019bSDavid S. Miller 	unsigned int min_links;
1351ef8019bSDavid S. Miller 	int ad_select;
1361ef8019bSDavid S. Miller 	char primary[IFNAMSIZ];
1371ef8019bSDavid S. Miller 	int primary_reselect;
1381ef8019bSDavid S. Miller 	__be32 arp_targets[BOND_MAX_ARP_TARGETS];
1391ef8019bSDavid S. Miller 	int tx_queues;
1401ef8019bSDavid S. Miller 	int all_slaves_active;
1411ef8019bSDavid S. Miller 	int resend_igmp;
1421ef8019bSDavid S. Miller 	int lp_interval;
1431ef8019bSDavid S. Miller 	int packets_per_slave;
1441ef8019bSDavid S. Miller 	int tlb_dynamic_lb;
1451ef8019bSDavid S. Miller 	struct reciprocal_value reciprocal_packets_per_slave;
1466791e466SMahesh Bandewar 	u16 ad_actor_sys_prio;
147d22a5fc0SMahesh Bandewar 	u16 ad_user_port_key;
148c4caa500SHangbin Liu #if IS_ENABLED(CONFIG_IPV6)
1494e24be01SHangbin Liu 	struct in6_addr ns_targets[BOND_MAX_NS_TARGETS];
150c4caa500SHangbin Liu #endif
151f87fda00SEric Dumazet 
152f87fda00SEric Dumazet 	/* 2 bytes of padding : see ether_addr_equal_64bits() */
153f87fda00SEric Dumazet 	u8 ad_actor_system[ETH_ALEN + 2];
1541ef8019bSDavid S. Miller };
1551ef8019bSDavid S. Miller 
1561ef8019bSDavid S. Miller struct slave {
1571ef8019bSDavid S. Miller 	struct net_device *dev; /* first - useful for panic debug */
1581ef8019bSDavid S. Miller 	struct bonding *bond; /* our master */
1591ef8019bSDavid S. Miller 	int    delay;
16006799a90SVladimir Oltean 	/* all 4 in jiffies */
1611ef8019bSDavid S. Miller 	unsigned long last_link_up;
16206799a90SVladimir Oltean 	unsigned long last_tx;
1631ef8019bSDavid S. Miller 	unsigned long last_rx;
1641ef8019bSDavid S. Miller 	unsigned long target_last_arp_rx[BOND_MAX_ARP_TARGETS];
1651ef8019bSDavid S. Miller 	s8     link;		/* one of BOND_LINK_XXXX */
166f307668bSMahesh Bandewar 	s8     link_new_state;	/* one of BOND_LINK_XXXX */
1671ef8019bSDavid S. Miller 	u8     backup:1,   /* indicates backup slave. Value corresponds with
1681ef8019bSDavid S. Miller 			      BOND_STATE_ACTIVE and BOND_STATE_BACKUP */
1691ef8019bSDavid S. Miller 	       inactive:1, /* indicates inactive slave */
1705d397061SJiri Pirko 	       should_notify:1, /* indicates whether the state changed */
1715d397061SJiri Pirko 	       should_notify_link:1; /* indicates whether the link changed */
1721ef8019bSDavid S. Miller 	u8     duplex;
1731ef8019bSDavid S. Miller 	u32    original_mtu;
1741ef8019bSDavid S. Miller 	u32    link_failure_count;
1751ef8019bSDavid S. Miller 	u32    speed;
1761ef8019bSDavid S. Miller 	u16    queue_id;
177faeeb317SJarod Wilson 	u8     perm_hwaddr[MAX_ADDR_LEN];
1780a2ff7ccSHangbin Liu 	int    prio;
1791ef8019bSDavid S. Miller 	struct ad_slave_info *ad_info;
1801ef8019bSDavid S. Miller 	struct tlb_slave_info tlb_info;
1811ef8019bSDavid S. Miller #ifdef CONFIG_NET_POLL_CONTROLLER
1821ef8019bSDavid S. Miller 	struct netpoll *np;
1831ef8019bSDavid S. Miller #endif
184d4859d74SMahesh Bandewar 	struct delayed_work notify_work;
1851ef8019bSDavid S. Miller 	struct kobject kobj;
1861ef8019bSDavid S. Miller 	struct rtnl_link_stats64 slave_stats;
1871ef8019bSDavid S. Miller };
1881ef8019bSDavid S. Miller 
to_slave(struct kobject * kobj)189b9ad3e9fSJamie Iles static inline struct slave *to_slave(struct kobject *kobj)
190b9ad3e9fSJamie Iles {
191b9ad3e9fSJamie Iles 	return container_of(kobj, struct slave, kobj);
192b9ad3e9fSJamie Iles }
193b9ad3e9fSJamie Iles 
1941ef8019bSDavid S. Miller struct bond_up_slave {
1951ef8019bSDavid S. Miller 	unsigned int	count;
1961ef8019bSDavid S. Miller 	struct rcu_head rcu;
197749db093SGustavo A. R. Silva 	struct slave	*arr[];
1981ef8019bSDavid S. Miller };
1991ef8019bSDavid S. Miller 
2001ef8019bSDavid S. Miller /*
2011ef8019bSDavid S. Miller  * Link pseudo-state only used internally by monitors
2021ef8019bSDavid S. Miller  */
2031ef8019bSDavid S. Miller #define BOND_LINK_NOCHANGE -1
2041ef8019bSDavid S. Miller 
2059a560550STaehee Yoo struct bond_ipsec {
2069a560550STaehee Yoo 	struct list_head list;
2079a560550STaehee Yoo 	struct xfrm_state *xs;
2089a560550STaehee Yoo };
2099a560550STaehee Yoo 
2101ef8019bSDavid S. Miller /*
2111ef8019bSDavid S. Miller  * Here are the locking policies for the two bonding locks:
2121ef8019bSDavid S. Miller  * Get rcu_read_lock when reading or RTNL when writing slave list.
2131ef8019bSDavid S. Miller  */
2141ef8019bSDavid S. Miller struct bonding {
2151ef8019bSDavid S. Miller 	struct   net_device *dev; /* first - useful for panic debug */
2161ef8019bSDavid S. Miller 	struct   slave __rcu *curr_active_slave;
2171ef8019bSDavid S. Miller 	struct   slave __rcu *current_arp_slave;
2181ef8019bSDavid S. Miller 	struct   slave __rcu *primary_slave;
2196b447e76SMaor Gottlieb 	struct   bond_up_slave __rcu *usable_slaves;
2206b447e76SMaor Gottlieb 	struct   bond_up_slave __rcu *all_slaves;
2211ef8019bSDavid S. Miller 	bool     force_primary;
222ae9b15fbSTaehee Yoo 	bool     notifier_ctx;
2231ef8019bSDavid S. Miller 	s32      slave_cnt; /* never change this value outside the attach/detach wrappers */
2241ef8019bSDavid S. Miller 	int     (*recv_probe)(const struct sk_buff *, struct bonding *,
2251ef8019bSDavid S. Miller 			      struct slave *);
2261ef8019bSDavid S. Miller 	/* mode_lock is used for mode-specific locking needs, currently used by:
2271ef8019bSDavid S. Miller 	 * 3ad mode (4) - protect against running bond_3ad_unbind_slave() and
2281ef8019bSDavid S. Miller 	 *                bond_3ad_state_machine_handler() concurrently and also
2291ef8019bSDavid S. Miller 	 *                the access to the state machine shared variables.
2301ef8019bSDavid S. Miller 	 * TLB mode (5) - to sync the use and modifications of its hash table
2311ef8019bSDavid S. Miller 	 * ALB mode (6) - to sync the use and modifications of its hash table
2321ef8019bSDavid S. Miller 	 */
2331ef8019bSDavid S. Miller 	spinlock_t mode_lock;
234fe30937bSEric Dumazet 	spinlock_t stats_lock;
2359949e2efSHangbin Liu 	u32	 send_peer_notif;
2361ef8019bSDavid S. Miller 	u8       igmp_retrans;
2371ef8019bSDavid S. Miller #ifdef CONFIG_PROC_FS
2381ef8019bSDavid S. Miller 	struct   proc_dir_entry *proc_entry;
2391ef8019bSDavid S. Miller 	char     proc_file_name[IFNAMSIZ];
2401ef8019bSDavid S. Miller #endif /* CONFIG_PROC_FS */
2411ef8019bSDavid S. Miller 	struct   list_head bond_list;
242848ca918SJussi Maki 	u32 __percpu *rr_tx_counter;
2431ef8019bSDavid S. Miller 	struct   ad_bond_info ad_info;
2441ef8019bSDavid S. Miller 	struct   alb_bond_info alb_info;
2451ef8019bSDavid S. Miller 	struct   bond_params params;
2461ef8019bSDavid S. Miller 	struct   workqueue_struct *wq;
2471ef8019bSDavid S. Miller 	struct   delayed_work mii_work;
2481ef8019bSDavid S. Miller 	struct   delayed_work arp_work;
2491ef8019bSDavid S. Miller 	struct   delayed_work alb_work;
2501ef8019bSDavid S. Miller 	struct   delayed_work ad_work;
2511ef8019bSDavid S. Miller 	struct   delayed_work mcast_work;
2521ef8019bSDavid S. Miller 	struct   delayed_work slave_arr_work;
2531ef8019bSDavid S. Miller #ifdef CONFIG_DEBUG_FS
2541ef8019bSDavid S. Miller 	/* debugging support via debugfs */
2551ef8019bSDavid S. Miller 	struct	 dentry *debug_dir;
2561ef8019bSDavid S. Miller #endif /* CONFIG_DEBUG_FS */
2571ef8019bSDavid S. Miller 	struct rtnl_link_stats64 bond_stats;
25818cb261aSJarod Wilson #ifdef CONFIG_XFRM_OFFLOAD
2599a560550STaehee Yoo 	struct list_head ipsec_list;
2609a560550STaehee Yoo 	/* protecting ipsec_list */
2619a560550STaehee Yoo 	spinlock_t ipsec_lock;
26218cb261aSJarod Wilson #endif /* CONFIG_XFRM_OFFLOAD */
2639e2ee5c7SJussi Maki 	struct bpf_prog *xdp_prog;
2641ef8019bSDavid S. Miller };
2651ef8019bSDavid S. Miller 
2661ef8019bSDavid S. Miller #define bond_slave_get_rcu(dev) \
2671ef8019bSDavid S. Miller 	((struct slave *) rcu_dereference(dev->rx_handler_data))
2681ef8019bSDavid S. Miller 
2691ef8019bSDavid S. Miller #define bond_slave_get_rtnl(dev) \
2701ef8019bSDavid S. Miller 	((struct slave *) rtnl_dereference(dev->rx_handler_data))
2711ef8019bSDavid S. Miller 
27269e61133SMoni Shoua void bond_queue_slave_event(struct slave *slave);
273f7c7eb7fSJiri Pirko void bond_lower_state_changed(struct slave *slave);
27469e61133SMoni Shoua 
2751ef8019bSDavid S. Miller struct bond_vlan_tag {
2761ef8019bSDavid S. Miller 	__be16		vlan_proto;
2771ef8019bSDavid S. Miller 	unsigned short	vlan_id;
2781ef8019bSDavid S. Miller };
2791ef8019bSDavid S. Miller 
280a66557c7SRandy Dunlap /*
2811ef8019bSDavid S. Miller  * Returns NULL if the net_device does not belong to any of the bond's slaves
2821ef8019bSDavid S. Miller  *
2831ef8019bSDavid S. Miller  * Caller must hold bond lock for read
2841ef8019bSDavid S. Miller  */
bond_get_slave_by_dev(struct bonding * bond,struct net_device * slave_dev)2851ef8019bSDavid S. Miller static inline struct slave *bond_get_slave_by_dev(struct bonding *bond,
2861ef8019bSDavid S. Miller 						  struct net_device *slave_dev)
2871ef8019bSDavid S. Miller {
2881ef8019bSDavid S. Miller 	return netdev_lower_dev_get_private(bond->dev, slave_dev);
2891ef8019bSDavid S. Miller }
2901ef8019bSDavid S. Miller 
bond_get_bond_by_slave(struct slave * slave)2911ef8019bSDavid S. Miller static inline struct bonding *bond_get_bond_by_slave(struct slave *slave)
2921ef8019bSDavid S. Miller {
2931ef8019bSDavid S. Miller 	return slave->bond;
2941ef8019bSDavid S. Miller }
2951ef8019bSDavid S. Miller 
bond_should_override_tx_queue(struct bonding * bond)2961ef8019bSDavid S. Miller static inline bool bond_should_override_tx_queue(struct bonding *bond)
2971ef8019bSDavid S. Miller {
2981ef8019bSDavid S. Miller 	return BOND_MODE(bond) == BOND_MODE_ACTIVEBACKUP ||
2991ef8019bSDavid S. Miller 	       BOND_MODE(bond) == BOND_MODE_ROUNDROBIN;
3001ef8019bSDavid S. Miller }
3011ef8019bSDavid S. Miller 
bond_is_lb(const struct bonding * bond)3021ef8019bSDavid S. Miller static inline bool bond_is_lb(const struct bonding *bond)
3031ef8019bSDavid S. Miller {
3041ef8019bSDavid S. Miller 	return BOND_MODE(bond) == BOND_MODE_TLB ||
3051ef8019bSDavid S. Miller 	       BOND_MODE(bond) == BOND_MODE_ALB;
3061ef8019bSDavid S. Miller }
3071ef8019bSDavid S. Miller 
bond_needs_speed_duplex(const struct bonding * bond)308ad729bc9SAndreas Born static inline bool bond_needs_speed_duplex(const struct bonding *bond)
309ad729bc9SAndreas Born {
310ad729bc9SAndreas Born 	return BOND_MODE(bond) == BOND_MODE_8023AD || bond_is_lb(bond);
311ad729bc9SAndreas Born }
312ad729bc9SAndreas Born 
bond_is_nondyn_tlb(const struct bonding * bond)3131ef8019bSDavid S. Miller static inline bool bond_is_nondyn_tlb(const struct bonding *bond)
3141ef8019bSDavid S. Miller {
315e79c1055SDebabrata Banerjee 	return (bond_is_lb(bond) && bond->params.tlb_dynamic_lb == 0);
316e79c1055SDebabrata Banerjee }
317e79c1055SDebabrata Banerjee 
bond_mode_can_use_xmit_hash(const struct bonding * bond)318e79c1055SDebabrata Banerjee static inline bool bond_mode_can_use_xmit_hash(const struct bonding *bond)
319e79c1055SDebabrata Banerjee {
320e79c1055SDebabrata Banerjee 	return (BOND_MODE(bond) == BOND_MODE_8023AD ||
321e79c1055SDebabrata Banerjee 		BOND_MODE(bond) == BOND_MODE_XOR ||
322e79c1055SDebabrata Banerjee 		BOND_MODE(bond) == BOND_MODE_TLB ||
323e79c1055SDebabrata Banerjee 		BOND_MODE(bond) == BOND_MODE_ALB);
3241ef8019bSDavid S. Miller }
3251ef8019bSDavid S. Miller 
bond_mode_uses_xmit_hash(const struct bonding * bond)3261ef8019bSDavid S. Miller static inline bool bond_mode_uses_xmit_hash(const struct bonding *bond)
3271ef8019bSDavid S. Miller {
3281ef8019bSDavid S. Miller 	return (BOND_MODE(bond) == BOND_MODE_8023AD ||
3291ef8019bSDavid S. Miller 		BOND_MODE(bond) == BOND_MODE_XOR ||
3301ef8019bSDavid S. Miller 		bond_is_nondyn_tlb(bond));
3311ef8019bSDavid S. Miller }
3321ef8019bSDavid S. Miller 
bond_mode_uses_arp(int mode)3331ef8019bSDavid S. Miller static inline bool bond_mode_uses_arp(int mode)
3341ef8019bSDavid S. Miller {
3351ef8019bSDavid S. Miller 	return mode != BOND_MODE_8023AD && mode != BOND_MODE_TLB &&
3361ef8019bSDavid S. Miller 	       mode != BOND_MODE_ALB;
3371ef8019bSDavid S. Miller }
3381ef8019bSDavid S. Miller 
bond_mode_uses_primary(int mode)3391ef8019bSDavid S. Miller static inline bool bond_mode_uses_primary(int mode)
3401ef8019bSDavid S. Miller {
3411ef8019bSDavid S. Miller 	return mode == BOND_MODE_ACTIVEBACKUP || mode == BOND_MODE_TLB ||
3421ef8019bSDavid S. Miller 	       mode == BOND_MODE_ALB;
3431ef8019bSDavid S. Miller }
3441ef8019bSDavid S. Miller 
bond_uses_primary(struct bonding * bond)3451ef8019bSDavid S. Miller static inline bool bond_uses_primary(struct bonding *bond)
3461ef8019bSDavid S. Miller {
3471ef8019bSDavid S. Miller 	return bond_mode_uses_primary(BOND_MODE(bond));
3481ef8019bSDavid S. Miller }
3491ef8019bSDavid S. Miller 
bond_option_active_slave_get_rcu(struct bonding * bond)350e9998695SMatan Barak static inline struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond)
351e9998695SMatan Barak {
352aa603467SHangbin Liu 	struct slave *slave = rcu_dereference_rtnl(bond->curr_active_slave);
353e9998695SMatan Barak 
354e9998695SMatan Barak 	return bond_uses_primary(bond) && slave ? slave->dev : NULL;
355e9998695SMatan Barak }
356e9998695SMatan Barak 
bond_slave_is_up(struct slave * slave)3571ef8019bSDavid S. Miller static inline bool bond_slave_is_up(struct slave *slave)
3581ef8019bSDavid S. Miller {
3591ef8019bSDavid S. Miller 	return netif_running(slave->dev) && netif_carrier_ok(slave->dev);
3601ef8019bSDavid S. Miller }
3611ef8019bSDavid S. Miller 
bond_set_active_slave(struct slave * slave)3621ef8019bSDavid S. Miller static inline void bond_set_active_slave(struct slave *slave)
3631ef8019bSDavid S. Miller {
3641ef8019bSDavid S. Miller 	if (slave->backup) {
3651ef8019bSDavid S. Miller 		slave->backup = 0;
36669e61133SMoni Shoua 		bond_queue_slave_event(slave);
367f7c7eb7fSJiri Pirko 		bond_lower_state_changed(slave);
3681ef8019bSDavid S. Miller 	}
3691ef8019bSDavid S. Miller }
3701ef8019bSDavid S. Miller 
bond_set_backup_slave(struct slave * slave)3711ef8019bSDavid S. Miller static inline void bond_set_backup_slave(struct slave *slave)
3721ef8019bSDavid S. Miller {
3731ef8019bSDavid S. Miller 	if (!slave->backup) {
3741ef8019bSDavid S. Miller 		slave->backup = 1;
37569e61133SMoni Shoua 		bond_queue_slave_event(slave);
376f7c7eb7fSJiri Pirko 		bond_lower_state_changed(slave);
3771ef8019bSDavid S. Miller 	}
3781ef8019bSDavid S. Miller }
3791ef8019bSDavid S. Miller 
bond_set_slave_state(struct slave * slave,int slave_state,bool notify)3801ef8019bSDavid S. Miller static inline void bond_set_slave_state(struct slave *slave,
3811ef8019bSDavid S. Miller 					int slave_state, bool notify)
3821ef8019bSDavid S. Miller {
3831ef8019bSDavid S. Miller 	if (slave->backup == slave_state)
3841ef8019bSDavid S. Miller 		return;
3851ef8019bSDavid S. Miller 
3861ef8019bSDavid S. Miller 	slave->backup = slave_state;
3871ef8019bSDavid S. Miller 	if (notify) {
388f7c7eb7fSJiri Pirko 		bond_lower_state_changed(slave);
38969e61133SMoni Shoua 		bond_queue_slave_event(slave);
3901ef8019bSDavid S. Miller 		slave->should_notify = 0;
3911ef8019bSDavid S. Miller 	} else {
3921ef8019bSDavid S. Miller 		if (slave->should_notify)
3931ef8019bSDavid S. Miller 			slave->should_notify = 0;
3941ef8019bSDavid S. Miller 		else
3951ef8019bSDavid S. Miller 			slave->should_notify = 1;
3961ef8019bSDavid S. Miller 	}
3971ef8019bSDavid S. Miller }
3981ef8019bSDavid S. Miller 
bond_slave_state_change(struct bonding * bond)3991ef8019bSDavid S. Miller static inline void bond_slave_state_change(struct bonding *bond)
4001ef8019bSDavid S. Miller {
4011ef8019bSDavid S. Miller 	struct list_head *iter;
4021ef8019bSDavid S. Miller 	struct slave *tmp;
4031ef8019bSDavid S. Miller 
4041ef8019bSDavid S. Miller 	bond_for_each_slave(bond, tmp, iter) {
4051ef8019bSDavid S. Miller 		if (tmp->link == BOND_LINK_UP)
4061ef8019bSDavid S. Miller 			bond_set_active_slave(tmp);
4071ef8019bSDavid S. Miller 		else if (tmp->link == BOND_LINK_DOWN)
4081ef8019bSDavid S. Miller 			bond_set_backup_slave(tmp);
4091ef8019bSDavid S. Miller 	}
4101ef8019bSDavid S. Miller }
4111ef8019bSDavid S. Miller 
bond_slave_state_notify(struct bonding * bond)4121ef8019bSDavid S. Miller static inline void bond_slave_state_notify(struct bonding *bond)
4131ef8019bSDavid S. Miller {
4141ef8019bSDavid S. Miller 	struct list_head *iter;
4151ef8019bSDavid S. Miller 	struct slave *tmp;
4161ef8019bSDavid S. Miller 
4171ef8019bSDavid S. Miller 	bond_for_each_slave(bond, tmp, iter) {
4181ef8019bSDavid S. Miller 		if (tmp->should_notify) {
419f7c7eb7fSJiri Pirko 			bond_lower_state_changed(tmp);
4201ef8019bSDavid S. Miller 			tmp->should_notify = 0;
4211ef8019bSDavid S. Miller 		}
4221ef8019bSDavid S. Miller 	}
4231ef8019bSDavid S. Miller }
4241ef8019bSDavid S. Miller 
bond_slave_state(struct slave * slave)4251ef8019bSDavid S. Miller static inline int bond_slave_state(struct slave *slave)
4261ef8019bSDavid S. Miller {
4271ef8019bSDavid S. Miller 	return slave->backup;
4281ef8019bSDavid S. Miller }
4291ef8019bSDavid S. Miller 
bond_is_active_slave(struct slave * slave)4301ef8019bSDavid S. Miller static inline bool bond_is_active_slave(struct slave *slave)
4311ef8019bSDavid S. Miller {
4321ef8019bSDavid S. Miller 	return !bond_slave_state(slave);
4331ef8019bSDavid S. Miller }
4341ef8019bSDavid S. Miller 
bond_slave_can_tx(struct slave * slave)4351ef8019bSDavid S. Miller static inline bool bond_slave_can_tx(struct slave *slave)
4361ef8019bSDavid S. Miller {
4371ef8019bSDavid S. Miller 	return bond_slave_is_up(slave) && slave->link == BOND_LINK_UP &&
4381ef8019bSDavid S. Miller 	       bond_is_active_slave(slave);
4391ef8019bSDavid S. Miller }
4401ef8019bSDavid S. Miller 
bond_is_active_slave_dev(const struct net_device * slave_dev)441eeed992bSPetr Machata static inline bool bond_is_active_slave_dev(const struct net_device *slave_dev)
442eeed992bSPetr Machata {
443eeed992bSPetr Machata 	struct slave *slave;
444eeed992bSPetr Machata 	bool active;
445eeed992bSPetr Machata 
446eeed992bSPetr Machata 	rcu_read_lock();
447eeed992bSPetr Machata 	slave = bond_slave_get_rcu(slave_dev);
448eeed992bSPetr Machata 	active = bond_is_active_slave(slave);
449eeed992bSPetr Machata 	rcu_read_unlock();
450eeed992bSPetr Machata 
451eeed992bSPetr Machata 	return active;
452eeed992bSPetr Machata }
453eeed992bSPetr Machata 
bond_hw_addr_copy(u8 * dst,const u8 * src,unsigned int len)454faeeb317SJarod Wilson static inline void bond_hw_addr_copy(u8 *dst, const u8 *src, unsigned int len)
455faeeb317SJarod Wilson {
456faeeb317SJarod Wilson 	if (len == ETH_ALEN) {
457faeeb317SJarod Wilson 		ether_addr_copy(dst, src);
458faeeb317SJarod Wilson 		return;
459faeeb317SJarod Wilson 	}
460faeeb317SJarod Wilson 
461faeeb317SJarod Wilson 	memcpy(dst, src, len);
462faeeb317SJarod Wilson }
463faeeb317SJarod Wilson 
4641ef8019bSDavid S. Miller #define BOND_PRI_RESELECT_ALWAYS	0
4651ef8019bSDavid S. Miller #define BOND_PRI_RESELECT_BETTER	1
4661ef8019bSDavid S. Miller #define BOND_PRI_RESELECT_FAILURE	2
4671ef8019bSDavid S. Miller 
4681ef8019bSDavid S. Miller #define BOND_FOM_NONE			0
4691ef8019bSDavid S. Miller #define BOND_FOM_ACTIVE			1
4701ef8019bSDavid S. Miller #define BOND_FOM_FOLLOW			2
4711ef8019bSDavid S. Miller 
4721ef8019bSDavid S. Miller #define BOND_ARP_TARGETS_ANY		0
4731ef8019bSDavid S. Miller #define BOND_ARP_TARGETS_ALL		1
4741ef8019bSDavid S. Miller 
4751ef8019bSDavid S. Miller #define BOND_ARP_VALIDATE_NONE		0
4761ef8019bSDavid S. Miller #define BOND_ARP_VALIDATE_ACTIVE	(1 << BOND_STATE_ACTIVE)
4771ef8019bSDavid S. Miller #define BOND_ARP_VALIDATE_BACKUP	(1 << BOND_STATE_BACKUP)
4781ef8019bSDavid S. Miller #define BOND_ARP_VALIDATE_ALL		(BOND_ARP_VALIDATE_ACTIVE | \
4791ef8019bSDavid S. Miller 					 BOND_ARP_VALIDATE_BACKUP)
4801ef8019bSDavid S. Miller #define BOND_ARP_FILTER			(BOND_ARP_VALIDATE_ALL + 1)
4811ef8019bSDavid S. Miller #define BOND_ARP_FILTER_ACTIVE		(BOND_ARP_VALIDATE_ACTIVE | \
4821ef8019bSDavid S. Miller 					 BOND_ARP_FILTER)
4831ef8019bSDavid S. Miller #define BOND_ARP_FILTER_BACKUP		(BOND_ARP_VALIDATE_BACKUP | \
4841ef8019bSDavid S. Miller 					 BOND_ARP_FILTER)
4851ef8019bSDavid S. Miller 
4861ef8019bSDavid S. Miller #define BOND_SLAVE_NOTIFY_NOW		true
4871ef8019bSDavid S. Miller #define BOND_SLAVE_NOTIFY_LATER		false
4881ef8019bSDavid S. Miller 
slave_do_arp_validate(struct bonding * bond,struct slave * slave)4891ef8019bSDavid S. Miller static inline int slave_do_arp_validate(struct bonding *bond,
4901ef8019bSDavid S. Miller 					struct slave *slave)
4911ef8019bSDavid S. Miller {
4921ef8019bSDavid S. Miller 	return bond->params.arp_validate & (1 << bond_slave_state(slave));
4931ef8019bSDavid S. Miller }
4941ef8019bSDavid S. Miller 
slave_do_arp_validate_only(struct bonding * bond)4951ef8019bSDavid S. Miller static inline int slave_do_arp_validate_only(struct bonding *bond)
4961ef8019bSDavid S. Miller {
4971ef8019bSDavid S. Miller 	return bond->params.arp_validate & BOND_ARP_FILTER;
4981ef8019bSDavid S. Miller }
4991ef8019bSDavid S. Miller 
bond_is_ip_target_ok(__be32 addr)5001ef8019bSDavid S. Miller static inline int bond_is_ip_target_ok(__be32 addr)
5011ef8019bSDavid S. Miller {
5021ef8019bSDavid S. Miller 	return !ipv4_is_lbcast(addr) && !ipv4_is_zeronet(addr);
5031ef8019bSDavid S. Miller }
5041ef8019bSDavid S. Miller 
505c4caa500SHangbin Liu #if IS_ENABLED(CONFIG_IPV6)
bond_is_ip6_target_ok(struct in6_addr * addr)506129e3c1bSHangbin Liu static inline int bond_is_ip6_target_ok(struct in6_addr *addr)
507129e3c1bSHangbin Liu {
508129e3c1bSHangbin Liu 	return !ipv6_addr_any(addr) &&
509129e3c1bSHangbin Liu 	       !ipv6_addr_loopback(addr) &&
510129e3c1bSHangbin Liu 	       !ipv6_addr_is_multicast(addr);
511129e3c1bSHangbin Liu }
512c4caa500SHangbin Liu #endif
513129e3c1bSHangbin Liu 
5141ef8019bSDavid S. Miller /* Get the oldest arp which we've received on this slave for bond's
5151ef8019bSDavid S. Miller  * arp_targets.
5161ef8019bSDavid S. Miller  */
slave_oldest_target_arp_rx(struct bonding * bond,struct slave * slave)5171ef8019bSDavid S. Miller static inline unsigned long slave_oldest_target_arp_rx(struct bonding *bond,
5181ef8019bSDavid S. Miller 						       struct slave *slave)
5191ef8019bSDavid S. Miller {
5201ef8019bSDavid S. Miller 	int i = 1;
5211ef8019bSDavid S. Miller 	unsigned long ret = slave->target_last_arp_rx[0];
5221ef8019bSDavid S. Miller 
5231ef8019bSDavid S. Miller 	for (; (i < BOND_MAX_ARP_TARGETS) && bond->params.arp_targets[i]; i++)
5241ef8019bSDavid S. Miller 		if (time_before(slave->target_last_arp_rx[i], ret))
5251ef8019bSDavid S. Miller 			ret = slave->target_last_arp_rx[i];
5261ef8019bSDavid S. Miller 
5271ef8019bSDavid S. Miller 	return ret;
5281ef8019bSDavid S. Miller }
5291ef8019bSDavid S. Miller 
slave_last_rx(struct bonding * bond,struct slave * slave)5301ef8019bSDavid S. Miller static inline unsigned long slave_last_rx(struct bonding *bond,
5311ef8019bSDavid S. Miller 					struct slave *slave)
5321ef8019bSDavid S. Miller {
5331ef8019bSDavid S. Miller 	if (bond->params.arp_all_targets == BOND_ARP_TARGETS_ALL)
5341ef8019bSDavid S. Miller 		return slave_oldest_target_arp_rx(bond, slave);
5351ef8019bSDavid S. Miller 
5361ef8019bSDavid S. Miller 	return slave->last_rx;
5371ef8019bSDavid S. Miller }
5381ef8019bSDavid S. Miller 
slave_update_last_tx(struct slave * slave)53906799a90SVladimir Oltean static inline void slave_update_last_tx(struct slave *slave)
54006799a90SVladimir Oltean {
54106799a90SVladimir Oltean 	WRITE_ONCE(slave->last_tx, jiffies);
54206799a90SVladimir Oltean }
54306799a90SVladimir Oltean 
slave_last_tx(struct slave * slave)54406799a90SVladimir Oltean static inline unsigned long slave_last_tx(struct slave *slave)
54506799a90SVladimir Oltean {
54606799a90SVladimir Oltean 	return READ_ONCE(slave->last_tx);
54706799a90SVladimir Oltean }
54806799a90SVladimir Oltean 
5491ef8019bSDavid S. Miller #ifdef CONFIG_NET_POLL_CONTROLLER
bond_netpoll_send_skb(const struct slave * slave,struct sk_buff * skb)550ae46f184SEric Dumazet static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
5511ef8019bSDavid S. Miller 					 struct sk_buff *skb)
5521ef8019bSDavid S. Miller {
553ae46f184SEric Dumazet 	return netpoll_send_skb(slave->np, skb);
5541ef8019bSDavid S. Miller }
5551ef8019bSDavid S. Miller #else
bond_netpoll_send_skb(const struct slave * slave,struct sk_buff * skb)556ae46f184SEric Dumazet static inline netdev_tx_t bond_netpoll_send_skb(const struct slave *slave,
5571ef8019bSDavid S. Miller 					 struct sk_buff *skb)
5581ef8019bSDavid S. Miller {
559ae46f184SEric Dumazet 	BUG();
560ae46f184SEric Dumazet 	return NETDEV_TX_OK;
5611ef8019bSDavid S. Miller }
5621ef8019bSDavid S. Miller #endif
5631ef8019bSDavid S. Miller 
bond_set_slave_inactive_flags(struct slave * slave,bool notify)5641ef8019bSDavid S. Miller static inline void bond_set_slave_inactive_flags(struct slave *slave,
5651ef8019bSDavid S. Miller 						 bool notify)
5661ef8019bSDavid S. Miller {
5671ef8019bSDavid S. Miller 	if (!bond_is_lb(slave->bond))
5681ef8019bSDavid S. Miller 		bond_set_slave_state(slave, BOND_STATE_BACKUP, notify);
5691ef8019bSDavid S. Miller 	if (!slave->bond->params.all_slaves_active)
5701ef8019bSDavid S. Miller 		slave->inactive = 1;
5711ef8019bSDavid S. Miller }
5721ef8019bSDavid S. Miller 
bond_set_slave_active_flags(struct slave * slave,bool notify)5731ef8019bSDavid S. Miller static inline void bond_set_slave_active_flags(struct slave *slave,
5741ef8019bSDavid S. Miller 					       bool notify)
5751ef8019bSDavid S. Miller {
5761ef8019bSDavid S. Miller 	bond_set_slave_state(slave, BOND_STATE_ACTIVE, notify);
5771ef8019bSDavid S. Miller 	slave->inactive = 0;
5781ef8019bSDavid S. Miller }
5791ef8019bSDavid S. Miller 
bond_is_slave_inactive(struct slave * slave)5801ef8019bSDavid S. Miller static inline bool bond_is_slave_inactive(struct slave *slave)
5811ef8019bSDavid S. Miller {
5821ef8019bSDavid S. Miller 	return slave->inactive;
5831ef8019bSDavid S. Miller }
5841ef8019bSDavid S. Miller 
bond_propose_link_state(struct slave * slave,int state)585f307668bSMahesh Bandewar static inline void bond_propose_link_state(struct slave *slave, int state)
58669a2338eSMoni Shoua {
587f307668bSMahesh Bandewar 	slave->link_new_state = state;
588f307668bSMahesh Bandewar }
589f307668bSMahesh Bandewar 
bond_commit_link_state(struct slave * slave,bool notify)590f307668bSMahesh Bandewar static inline void bond_commit_link_state(struct slave *slave, bool notify)
591f307668bSMahesh Bandewar {
5921899bb32SJay Vosburgh 	if (slave->link_new_state == BOND_LINK_NOCHANGE)
5935d397061SJiri Pirko 		return;
5945d397061SJiri Pirko 
595f307668bSMahesh Bandewar 	slave->link = slave->link_new_state;
5965d397061SJiri Pirko 	if (notify) {
59769e61133SMoni Shoua 		bond_queue_slave_event(slave);
598f7c7eb7fSJiri Pirko 		bond_lower_state_changed(slave);
5995d397061SJiri Pirko 		slave->should_notify_link = 0;
6005d397061SJiri Pirko 	} else {
6015d397061SJiri Pirko 		if (slave->should_notify_link)
6025d397061SJiri Pirko 			slave->should_notify_link = 0;
6035d397061SJiri Pirko 		else
6045d397061SJiri Pirko 			slave->should_notify_link = 1;
6055d397061SJiri Pirko 	}
6065d397061SJiri Pirko }
6075d397061SJiri Pirko 
bond_set_slave_link_state(struct slave * slave,int state,bool notify)608f307668bSMahesh Bandewar static inline void bond_set_slave_link_state(struct slave *slave, int state,
609f307668bSMahesh Bandewar 					     bool notify)
610f307668bSMahesh Bandewar {
611f307668bSMahesh Bandewar 	bond_propose_link_state(slave, state);
612f307668bSMahesh Bandewar 	bond_commit_link_state(slave, notify);
613f307668bSMahesh Bandewar }
614f307668bSMahesh Bandewar 
bond_slave_link_notify(struct bonding * bond)6155d397061SJiri Pirko static inline void bond_slave_link_notify(struct bonding *bond)
6165d397061SJiri Pirko {
6175d397061SJiri Pirko 	struct list_head *iter;
6185d397061SJiri Pirko 	struct slave *tmp;
6195d397061SJiri Pirko 
6205d397061SJiri Pirko 	bond_for_each_slave(bond, tmp, iter) {
6215d397061SJiri Pirko 		if (tmp->should_notify_link) {
6225d397061SJiri Pirko 			bond_queue_slave_event(tmp);
623f7c7eb7fSJiri Pirko 			bond_lower_state_changed(tmp);
6245d397061SJiri Pirko 			tmp->should_notify_link = 0;
6255d397061SJiri Pirko 		}
6265d397061SJiri Pirko 	}
62769a2338eSMoni Shoua }
62869a2338eSMoni Shoua 
bond_confirm_addr(struct net_device * dev,__be32 dst,__be32 local)6291ef8019bSDavid S. Miller static inline __be32 bond_confirm_addr(struct net_device *dev, __be32 dst, __be32 local)
6301ef8019bSDavid S. Miller {
6311ef8019bSDavid S. Miller 	struct in_device *in_dev;
6321ef8019bSDavid S. Miller 	__be32 addr = 0;
6331ef8019bSDavid S. Miller 
6341ef8019bSDavid S. Miller 	rcu_read_lock();
6351ef8019bSDavid S. Miller 	in_dev = __in_dev_get_rcu(dev);
6361ef8019bSDavid S. Miller 
6371ef8019bSDavid S. Miller 	if (in_dev)
6381ef8019bSDavid S. Miller 		addr = inet_confirm_addr(dev_net(dev), in_dev, dst, local,
6391ef8019bSDavid S. Miller 					 RT_SCOPE_HOST);
6401ef8019bSDavid S. Miller 	rcu_read_unlock();
6411ef8019bSDavid S. Miller 	return addr;
6421ef8019bSDavid S. Miller }
6431ef8019bSDavid S. Miller 
6441ef8019bSDavid S. Miller struct bond_net {
6451ef8019bSDavid S. Miller 	struct net		*net;	/* Associated network namespace */
6461ef8019bSDavid S. Miller 	struct list_head	dev_list;
6471ef8019bSDavid S. Miller #ifdef CONFIG_PROC_FS
6481ef8019bSDavid S. Miller 	struct proc_dir_entry	*proc_dir;
6491ef8019bSDavid S. Miller #endif
6501ef8019bSDavid S. Miller 	struct class_attribute	class_attr_bonding_masters;
6511ef8019bSDavid S. Miller };
6521ef8019bSDavid S. Miller 
6534e24be01SHangbin Liu int bond_rcv_validate(const struct sk_buff *skb, struct bonding *bond, struct slave *slave);
654ae46f184SEric Dumazet netdev_tx_t bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb, struct net_device *slave_dev);
6551ef8019bSDavid S. Miller int bond_create(struct net *net, const char *name);
6561ef8019bSDavid S. Miller int bond_create_sysfs(struct bond_net *net);
6571ef8019bSDavid S. Miller void bond_destroy_sysfs(struct bond_net *net);
6581ef8019bSDavid S. Miller void bond_prepare_sysfs_group(struct bonding *bond);
6591ef8019bSDavid S. Miller int bond_sysfs_slave_add(struct slave *slave);
6601ef8019bSDavid S. Miller void bond_sysfs_slave_del(struct slave *slave);
661cb9e6e58SLorenzo Bianconi void bond_xdp_set_features(struct net_device *bond_dev);
66233eaf2a6SDavid Ahern int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
66333eaf2a6SDavid Ahern 		 struct netlink_ext_ack *extack);
6641ef8019bSDavid S. Miller int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
6651ef8019bSDavid S. Miller u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb);
6662477bc9aSJonathan Toppins int bond_set_carrier(struct bonding *bond);
6671ef8019bSDavid S. Miller void bond_select_active_slave(struct bonding *bond);
6681ef8019bSDavid S. Miller void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
6691ef8019bSDavid S. Miller void bond_create_debugfs(void);
6701ef8019bSDavid S. Miller void bond_destroy_debugfs(void);
6711ef8019bSDavid S. Miller void bond_debug_register(struct bonding *bond);
6721ef8019bSDavid S. Miller void bond_debug_unregister(struct bonding *bond);
6731ef8019bSDavid S. Miller void bond_debug_reregister(struct bonding *bond);
6741ef8019bSDavid S. Miller const char *bond_mode_name(int mode);
6751ef8019bSDavid S. Miller void bond_setup(struct net_device *bond_dev);
6761ef8019bSDavid S. Miller unsigned int bond_get_num_tx_queues(void);
6771ef8019bSDavid S. Miller int bond_netlink_init(void);
6781ef8019bSDavid S. Miller void bond_netlink_fini(void);
6791ef8019bSDavid S. Miller struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
6801ef8019bSDavid S. Miller const char *bond_slave_link_status(s8 link);
6811ef8019bSDavid S. Miller struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
6821ef8019bSDavid S. Miller 					      struct net_device *end_dev,
6831ef8019bSDavid S. Miller 					      int level);
6841ef8019bSDavid S. Miller int bond_update_slave_arr(struct bonding *bond, struct slave *skipslave);
6851ef8019bSDavid S. Miller void bond_slave_arr_work_rearm(struct bonding *bond, unsigned long delay);
686ea8ffc08SMahesh Bandewar void bond_work_init_all(struct bonding *bond);
6871ef8019bSDavid S. Miller 
6881ef8019bSDavid S. Miller #ifdef CONFIG_PROC_FS
6891ef8019bSDavid S. Miller void bond_create_proc_entry(struct bonding *bond);
6901ef8019bSDavid S. Miller void bond_remove_proc_entry(struct bonding *bond);
6911ef8019bSDavid S. Miller void bond_create_proc_dir(struct bond_net *bn);
6921ef8019bSDavid S. Miller void bond_destroy_proc_dir(struct bond_net *bn);
6931ef8019bSDavid S. Miller #else
bond_create_proc_entry(struct bonding * bond)6941ef8019bSDavid S. Miller static inline void bond_create_proc_entry(struct bonding *bond)
6951ef8019bSDavid S. Miller {
6961ef8019bSDavid S. Miller }
6971ef8019bSDavid S. Miller 
bond_remove_proc_entry(struct bonding * bond)6981ef8019bSDavid S. Miller static inline void bond_remove_proc_entry(struct bonding *bond)
6991ef8019bSDavid S. Miller {
7001ef8019bSDavid S. Miller }
7011ef8019bSDavid S. Miller 
bond_create_proc_dir(struct bond_net * bn)7021ef8019bSDavid S. Miller static inline void bond_create_proc_dir(struct bond_net *bn)
7031ef8019bSDavid S. Miller {
7041ef8019bSDavid S. Miller }
7051ef8019bSDavid S. Miller 
bond_destroy_proc_dir(struct bond_net * bn)7061ef8019bSDavid S. Miller static inline void bond_destroy_proc_dir(struct bond_net *bn)
7071ef8019bSDavid S. Miller {
7081ef8019bSDavid S. Miller }
7091ef8019bSDavid S. Miller #endif
7101ef8019bSDavid S. Miller 
bond_slave_has_mac(struct bonding * bond,const u8 * mac)7111ef8019bSDavid S. Miller static inline struct slave *bond_slave_has_mac(struct bonding *bond,
7121ef8019bSDavid S. Miller 					       const u8 *mac)
7131ef8019bSDavid S. Miller {
7141ef8019bSDavid S. Miller 	struct list_head *iter;
7151ef8019bSDavid S. Miller 	struct slave *tmp;
7161ef8019bSDavid S. Miller 
7171ef8019bSDavid S. Miller 	bond_for_each_slave(bond, tmp, iter)
7181ef8019bSDavid S. Miller 		if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
7191ef8019bSDavid S. Miller 			return tmp;
7201ef8019bSDavid S. Miller 
7211ef8019bSDavid S. Miller 	return NULL;
7221ef8019bSDavid S. Miller }
7231ef8019bSDavid S. Miller 
7241ef8019bSDavid S. Miller /* Caller must hold rcu_read_lock() for read */
bond_slave_has_mac_rcu(struct bonding * bond,const u8 * mac)725*e74216b8SHangbin Liu static inline bool bond_slave_has_mac_rcu(struct bonding *bond, const u8 *mac)
7261ef8019bSDavid S. Miller {
7271ef8019bSDavid S. Miller 	struct list_head *iter;
7281ef8019bSDavid S. Miller 	struct slave *tmp;
7291ef8019bSDavid S. Miller 
7301ef8019bSDavid S. Miller 	bond_for_each_slave_rcu(bond, tmp, iter)
7311ef8019bSDavid S. Miller 		if (ether_addr_equal_64bits(mac, tmp->dev->dev_addr))
7321ef8019bSDavid S. Miller 			return true;
7331ef8019bSDavid S. Miller 	return false;
7341ef8019bSDavid S. Miller }
7351ef8019bSDavid S. Miller 
7361ef8019bSDavid S. Miller /* Check if the ip is present in arp ip list, or first free slot if ip == 0
7371ef8019bSDavid S. Miller  * Returns -1 if not found, index if found
7381ef8019bSDavid S. Miller  */
bond_get_targets_ip(__be32 * targets,__be32 ip)7391ef8019bSDavid S. Miller static inline int bond_get_targets_ip(__be32 *targets, __be32 ip)
7401ef8019bSDavid S. Miller {
7411ef8019bSDavid S. Miller 	int i;
7421ef8019bSDavid S. Miller 
7431ef8019bSDavid S. Miller 	for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
7441ef8019bSDavid S. Miller 		if (targets[i] == ip)
7451ef8019bSDavid S. Miller 			return i;
7461ef8019bSDavid S. Miller 		else if (targets[i] == 0)
7471ef8019bSDavid S. Miller 			break;
7481ef8019bSDavid S. Miller 
7491ef8019bSDavid S. Miller 	return -1;
7501ef8019bSDavid S. Miller }
7511ef8019bSDavid S. Miller 
752c4caa500SHangbin Liu #if IS_ENABLED(CONFIG_IPV6)
bond_get_targets_ip6(struct in6_addr * targets,struct in6_addr * ip)7534e24be01SHangbin Liu static inline int bond_get_targets_ip6(struct in6_addr *targets, struct in6_addr *ip)
7544e24be01SHangbin Liu {
7554598380fSHangbin Liu 	struct in6_addr mcaddr;
7564e24be01SHangbin Liu 	int i;
7574e24be01SHangbin Liu 
7584598380fSHangbin Liu 	for (i = 0; i < BOND_MAX_NS_TARGETS; i++) {
7594598380fSHangbin Liu 		addrconf_addr_solict_mult(&targets[i], &mcaddr);
7604598380fSHangbin Liu 		if ((ipv6_addr_equal(&targets[i], ip)) ||
7614598380fSHangbin Liu 		    (ipv6_addr_equal(&mcaddr, ip)))
7624e24be01SHangbin Liu 			return i;
7634e24be01SHangbin Liu 		else if (ipv6_addr_any(&targets[i]))
7644e24be01SHangbin Liu 			break;
7654598380fSHangbin Liu 	}
7664e24be01SHangbin Liu 
7674e24be01SHangbin Liu 	return -1;
7684e24be01SHangbin Liu }
769c4caa500SHangbin Liu #endif
7704e24be01SHangbin Liu 
7711ef8019bSDavid S. Miller /* exported from bond_main.c */
772c7d03a00SAlexey Dobriyan extern unsigned int bond_net_id;
7731ef8019bSDavid S. Miller 
7741ef8019bSDavid S. Miller /* exported from bond_netlink.c */
7751ef8019bSDavid S. Miller extern struct rtnl_link_ops bond_link_ops;
7761ef8019bSDavid S. Miller 
777b9ad3e9fSJamie Iles /* exported from bond_sysfs_slave.c */
778b9ad3e9fSJamie Iles extern const struct sysfs_ops slave_sysfs_ops;
779b9ad3e9fSJamie Iles 
7801d9a143eSBenjamin Poirier /* exported from bond_3ad.c */
7811d9a143eSBenjamin Poirier extern const u8 lacpdu_mcast_addr[];
7821d9a143eSBenjamin Poirier 
bond_tx_drop(struct net_device * dev,struct sk_buff * skb)783ae46f184SEric Dumazet static inline netdev_tx_t bond_tx_drop(struct net_device *dev, struct sk_buff *skb)
7841ef8019bSDavid S. Miller {
785625788b5SEric Dumazet 	dev_core_stats_tx_dropped_inc(dev);
7861ef8019bSDavid S. Miller 	dev_kfree_skb_any(skb);
787ae46f184SEric Dumazet 	return NET_XMIT_DROP;
7881ef8019bSDavid S. Miller }
7891ef8019bSDavid S. Miller 
7901ef8019bSDavid S. Miller #endif /* _NET_BONDING_H */
791