net/hsr/hsr_device.c
Source file repositories/reference/linux-study-clean/net/hsr/hsr_device.c
File Facts
- System
- Linux kernel
- Corpus path
net/hsr/hsr_device.c- Extension
.c- Size
- 20387 bytes
- Lines
- 828
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/netdevice.hlinux/skbuff.hlinux/etherdevice.hlinux/rtnetlink.hlinux/pkt_sched.hhsr_device.hhsr_slave.hhsr_framereg.hhsr_main.hhsr_forward.h
Detected Declarations
function Authorfunction is_slave_upfunction hsr_set_operstatefunction hsr_check_carrierfunction hsr_for_each_port_rtnlfunction hsr_check_announcefunction hsr_check_carrier_and_operstatefunction hsr_get_max_mtufunction hsr_dev_change_mtufunction hsr_dev_openfunction hsr_for_each_port_rtnlfunction hsr_dev_closefunction hsr_features_recomputefunction hsr_fix_featuresfunction hsr_dev_xmitfunction send_hsr_supervision_framefunction send_prp_supervision_framefunction hsr_announcefunction hsr_proxy_announcefunction list_for_each_entry_rcufunction hsr_del_portsfunction hsr_set_rx_modefunction hsr_for_each_port_rtnlfunction hsr_change_rx_flagsfunction hsr_for_each_port_rtnlfunction hsr_ndo_vlan_rx_add_vidfunction hsr_for_each_port_rtnlfunction hsr_ndo_vlan_rx_kill_vidfunction hsr_for_each_port_rtnlfunction hsr_dev_setupfunction is_hsr_masterfunction hsr_get_port_typefunction hsr_dev_finalizeexport is_hsr_masterexport hsr_get_port_ndevexport hsr_get_port_type
Annotated Snippet
static const struct net_device_ops hsr_device_ops = {
.ndo_change_mtu = hsr_dev_change_mtu,
.ndo_open = hsr_dev_open,
.ndo_stop = hsr_dev_close,
.ndo_start_xmit = hsr_dev_xmit,
.ndo_change_rx_flags = hsr_change_rx_flags,
.ndo_fix_features = hsr_fix_features,
.ndo_set_rx_mode = hsr_set_rx_mode,
.ndo_vlan_rx_add_vid = hsr_ndo_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = hsr_ndo_vlan_rx_kill_vid,
};
static const struct device_type hsr_type = {
.name = "hsr",
};
static const struct hsr_proto_ops hsr_ops = {
.send_sv_frame = send_hsr_supervision_frame,
.create_tagged_frame = hsr_create_tagged_frame,
.get_untagged_frame = hsr_get_untagged_frame,
.drop_frame = hsr_drop_frame,
.fill_frame_info = hsr_fill_frame_info,
.invalid_dan_ingress_frame = hsr_invalid_dan_ingress_frame,
.register_frame_out = hsr_register_frame_out,
};
static const struct hsr_proto_ops prp_ops = {
.send_sv_frame = send_prp_supervision_frame,
.create_tagged_frame = prp_create_tagged_frame,
.get_untagged_frame = prp_get_untagged_frame,
.drop_frame = prp_drop_frame,
.fill_frame_info = prp_fill_frame_info,
.handle_san_frame = prp_handle_san_frame,
.update_san_info = prp_update_san_info,
.register_frame_out = prp_register_frame_out,
};
void hsr_dev_setup(struct net_device *dev)
{
eth_hw_addr_random(dev);
ether_setup(dev);
dev->min_mtu = 0;
dev->header_ops = &hsr_header_ops;
dev->netdev_ops = &hsr_device_ops;
SET_NETDEV_DEVTYPE(dev, &hsr_type);
dev->priv_flags |= IFF_NO_QUEUE | IFF_DISABLE_NETPOLL;
/* Prevent recursive tx locking */
dev->lltx = true;
/* Not sure about this. Taken from bridge code. netdevice.h says
* it means "Does not change network namespaces".
*/
dev->netns_immutable = true;
dev->needs_free_netdev = true;
dev->hw_features = NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_HIGHDMA |
NETIF_F_GSO_MASK | NETIF_F_HW_CSUM |
NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_CTAG_FILTER;
dev->features = dev->hw_features;
}
/* Return true if dev is a HSR master; return false otherwise.
*/
bool is_hsr_master(struct net_device *dev)
{
return (dev->netdev_ops->ndo_start_xmit == hsr_dev_xmit);
}
EXPORT_SYMBOL(is_hsr_master);
struct net_device *hsr_get_port_ndev(struct net_device *ndev,
enum hsr_port_type pt)
{
struct hsr_priv *hsr = netdev_priv(ndev);
struct hsr_port *port;
rcu_read_lock();
hsr_for_each_port(hsr, port)
if (port->type == pt) {
dev_hold(port->dev);
rcu_read_unlock();
return port->dev;
}
rcu_read_unlock();
return NULL;
}
EXPORT_SYMBOL(hsr_get_port_ndev);
Annotation
- Immediate include surface: `linux/netdevice.h`, `linux/skbuff.h`, `linux/etherdevice.h`, `linux/rtnetlink.h`, `linux/pkt_sched.h`, `hsr_device.h`, `hsr_slave.h`, `hsr_framereg.h`.
- Detected declarations: `function Author`, `function is_slave_up`, `function hsr_set_operstate`, `function hsr_check_carrier`, `function hsr_for_each_port_rtnl`, `function hsr_check_announce`, `function hsr_check_carrier_and_operstate`, `function hsr_get_max_mtu`, `function hsr_dev_change_mtu`, `function hsr_dev_open`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern implementation candidate.
- 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.