drivers/net/bonding/bond_main.c
Source file repositories/reference/linux-study-clean/drivers/net/bonding/bond_main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/bonding/bond_main.c- Extension
.c- Size
- 183957 bytes
- Lines
- 6680
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/types.hlinux/fcntl.hlinux/filter.hlinux/interrupt.hlinux/ptrace.hlinux/ioport.hlinux/in.hnet/ip.hlinux/ip.hlinux/icmp.hlinux/icmpv6.hlinux/tcp.hlinux/udp.hlinux/slab.hlinux/string.hlinux/init.hlinux/timer.hlinux/socket.hlinux/ctype.hlinux/inet.hlinux/bitops.hlinux/io.hasm/dma.hlinux/uaccess.hlinux/errno.hlinux/netdevice.hlinux/inetdevice.hlinux/igmp.hlinux/etherdevice.hlinux/skbuff.h
Detected Declarations
function bond_dev_queue_xmitfunction bond_sk_checkfunction __bond_xdp_checkfunction bond_xdp_checkfunction referencedfunction bond_for_each_slavefunction bond_vlan_rx_kill_vidfunction bond_ipsec_add_safunction bond_ipsec_add_sa_allfunction netif_is_bond_masterfunction list_for_each_entryfunction bond_ipsec_del_safunction bond_ipsec_del_sa_allfunction bond_ipsec_free_safunction bond_ipsec_offload_okfunction bond_advance_esn_statefunction bond_xfrm_update_statsfunction bond_set_carrierfunction bond_for_each_slavefunction bond_update_speed_duplexfunction bond_set_promiscuityfunction bond_for_each_slavefunction bond_set_allmultifunction bond_for_each_slavefunction bond_resend_igmp_join_requests_delayedfunction bond_hw_addr_flushfunction bond_hw_addr_swapfunction bond_set_dev_addrfunction bond_for_each_slavefunction bond_do_fail_over_macfunction bond_for_each_slavefunction bond_should_notify_peersfunction bond_peer_notify_work_rearmfunction bond_peer_notify_resetfunction bond_peer_notify_handlerfunction bond_peer_notify_may_eventsfunction bond_change_active_slavefunction BOND_MODEfunction bond_select_active_slavefunction slave_enable_netpollfunction slave_disable_netpollfunction bond_poll_controllerfunction bond_for_each_slave_rcufunction bond_netpoll_cleanupfunction bond_netpoll_setupfunction bond_for_each_slavefunction slave_enable_netpollfunction slave_disable_netpoll
Annotated Snippet
const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
struct slave *new_slave = NULL, *prev_slave;
struct sockaddr_storage ss;
int res = 0, i;
if (slave_dev->type == ARPHRD_CAN) {
BOND_NL_ERR(bond_dev, extack,
"CAN devices cannot be enslaved");
return -EPERM;
}
if (slave_dev->flags & IFF_MASTER &&
!netif_is_bond_master(slave_dev)) {
BOND_NL_ERR(bond_dev, extack,
"Device type (master device) cannot be enslaved");
return -EPERM;
}
/* already in-use? */
if (netdev_is_rx_handler_busy(slave_dev)) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Device is in use and cannot be enslaved");
return -EBUSY;
}
if (bond_dev == slave_dev) {
BOND_NL_ERR(bond_dev, extack, "Cannot enslave bond to itself.");
return -EPERM;
}
/* vlan challenged mutual exclusion */
/* no need to lock since we're protected by rtnl_lock */
if (slave_dev->features & NETIF_F_VLAN_CHALLENGED) {
slave_dbg(bond_dev, slave_dev, "is NETIF_F_VLAN_CHALLENGED\n");
if (vlan_uses_dev(bond_dev)) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Can not enslave VLAN challenged device to VLAN enabled bond");
return -EPERM;
} else {
slave_warn(bond_dev, slave_dev, "enslaved VLAN challenged slave. Adding VLANs will be blocked as long as it is part of bond.\n");
}
} else {
slave_dbg(bond_dev, slave_dev, "is !NETIF_F_VLAN_CHALLENGED\n");
}
if (slave_dev->features & NETIF_F_HW_ESP)
slave_dbg(bond_dev, slave_dev, "is esp-hw-offload capable\n");
/* Old ifenslave binaries are no longer supported. These can
* be identified with moderate accuracy by the state of the slave:
* the current ifenslave will set the interface down prior to
* enslaving it; the old ifenslave will not.
*/
if (slave_dev->flags & IFF_UP) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"Device can not be enslaved while up");
return -EPERM;
}
/* set bonding device ether type by slave - bonding netdevices are
* created with ether_setup, so when the slave type is not ARPHRD_ETHER
* there is a need to override some of the type dependent attribs/funcs.
*
* bond ether type mutual exclusion - don't allow slaves of dissimilar
* ether type (eg ARPHRD_ETHER and ARPHRD_INFINIBAND) share the same bond
*/
if (!bond_has_slaves(bond)) {
if (bond_dev->type != slave_dev->type) {
if (slave_dev->type != ARPHRD_ETHER &&
BOND_MODE(bond) == BOND_MODE_8023AD) {
SLAVE_NL_ERR(bond_dev, slave_dev, extack,
"8023AD mode requires Ethernet devices");
return -EINVAL;
}
slave_dbg(bond_dev, slave_dev, "change device type from %d to %d\n",
bond_dev->type, slave_dev->type);
res = call_netdevice_notifiers(NETDEV_PRE_TYPE_CHANGE,
bond_dev);
res = notifier_to_errno(res);
if (res) {
slave_err(bond_dev, slave_dev, "refused to change device type\n");
return -EBUSY;
}
/* Flush unicast and multicast addresses */
dev_uc_flush(bond_dev);
dev_mc_flush(bond_dev);
if (slave_dev->type != ARPHRD_ETHER)
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/types.h`, `linux/fcntl.h`, `linux/filter.h`, `linux/interrupt.h`, `linux/ptrace.h`, `linux/ioport.h`.
- Detected declarations: `function bond_dev_queue_xmit`, `function bond_sk_check`, `function __bond_xdp_check`, `function bond_xdp_check`, `function referenced`, `function bond_for_each_slave`, `function bond_vlan_rx_kill_vid`, `function bond_ipsec_add_sa`, `function bond_ipsec_add_sa_all`, `function netif_is_bond_master`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.