net/tipc/bearer.c
Source file repositories/reference/linux-study-clean/net/tipc/bearer.c
File Facts
- System
- Linux kernel
- Corpus path
net/tipc/bearer.c- Extension
.c- Size
- 33457 bytes
- Lines
- 1379
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source 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.
- 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
net/sock.hcore.hbearer.hlink.hdiscover.hmonitor.hbcast.hnetlink.hudp_media.htrace.hcrypto.h
Detected Declarations
function tipc_media_addr_printffunction bearer_name_validatefunction tipc_bearer_get_namefunction tipc_bearer_add_destfunction tipc_bearer_remove_destfunction tipc_enable_bearerfunction tipc_reset_bearerfunction tipc_bearer_holdfunction tipc_bearer_putfunction bearer_disablefunction tipc_enable_l2_mediafunction tipc_disable_l2_mediafunction tipc_l2_send_msgfunction tipc_bearer_bcast_supportfunction tipc_bearer_mtufunction tipc_bearer_min_mtufunction tipc_bearer_xmit_skbfunction tipc_bearer_xmitfunction tipc_bearer_bc_xmitfunction nodesfunction tipc_l2_device_eventfunction tipc_bearer_setupfunction tipc_bearer_cleanupfunction tipc_bearer_stopfunction tipc_clone_to_loopbackfunction skb_queue_walkfunction tipc_loopback_rcv_pktfunction tipc_attach_loopbackfunction tipc_detach_loopbackfunction __tipc_nl_add_bearerfunction tipc_nl_bearer_dumpfunction tipc_nl_bearer_getfunction __tipc_nl_bearer_disablefunction tipc_nl_bearer_disablefunction __tipc_nl_bearer_enablefunction tipc_nl_bearer_enablefunction tipc_nl_bearer_addfunction __tipc_nl_bearer_setfunction tipc_nl_bearer_setfunction __tipc_nl_add_mediafunction tipc_nl_media_dumpfunction tipc_nl_media_getfunction __tipc_nl_media_setfunction tipc_nl_media_set
Annotated Snippet
if (!b) {
bearer_id = i;
continue;
}
if (!strcmp(name, b->name)) {
errstr = "already enabled";
NL_SET_ERR_MSG(extack, "Already enabled");
goto rejected;
}
if (b->priority == prio &&
(++with_this_prio > 2)) {
pr_warn("Bearer <%s>: already 2 bearers with priority %u\n",
name, prio);
if (prio == TIPC_MIN_LINK_PRI) {
errstr = "cannot adjust to lower";
NL_SET_ERR_MSG(extack, "Cannot adjust to lower");
goto rejected;
}
pr_warn("Bearer <%s>: trying with adjusted priority\n",
name);
prio--;
bearer_id = MAX_BEARERS;
i = MAX_BEARERS;
with_this_prio = 1;
}
}
if (bearer_id >= MAX_BEARERS) {
errstr = "max 3 bearers permitted";
NL_SET_ERR_MSG(extack, "Max 3 bearers permitted");
goto rejected;
}
b = kzalloc_obj(*b, GFP_ATOMIC);
if (!b)
return -ENOMEM;
strscpy(b->name, name);
b->media = m;
res = m->enable_media(net, b, attr);
if (res) {
kfree(b);
errstr = "failed to enable media";
NL_SET_ERR_MSG(extack, "Failed to enable media");
goto rejected;
}
b->identity = bearer_id;
b->tolerance = m->tolerance;
b->min_win = m->min_win;
b->max_win = m->max_win;
b->domain = disc_domain;
b->net_plane = bearer_id + 'A';
b->priority = prio;
refcount_set(&b->refcnt, 1);
res = tipc_disc_create(net, b, &b->bcast_addr, &skb);
if (res) {
bearer_disable(net, b);
errstr = "failed to create discoverer";
NL_SET_ERR_MSG(extack, "Failed to create discoverer");
goto rejected;
}
/* Create monitoring data before accepting activate messages */
if (tipc_mon_create(net, bearer_id)) {
bearer_disable(net, b);
kfree_skb(skb);
return -ENOMEM;
}
test_and_set_bit_lock(0, &b->up);
rcu_assign_pointer(tn->bearer_list[bearer_id], b);
if (skb)
tipc_bearer_xmit_skb(net, bearer_id, skb, &b->bcast_addr);
pr_info("Enabled bearer <%s>, priority %u\n", name, prio);
return res;
rejected:
pr_warn("Enabling of bearer <%s> rejected, %s\n", name, errstr);
return res;
}
/**
* tipc_reset_bearer - Reset all links established over this bearer
* @net: the applicable net namespace
Annotation
- Immediate include surface: `net/sock.h`, `core.h`, `bearer.h`, `link.h`, `discover.h`, `monitor.h`, `bcast.h`, `netlink.h`.
- Detected declarations: `function tipc_media_addr_printf`, `function bearer_name_validate`, `function tipc_bearer_get_name`, `function tipc_bearer_add_dest`, `function tipc_bearer_remove_dest`, `function tipc_enable_bearer`, `function tipc_reset_bearer`, `function tipc_bearer_hold`, `function tipc_bearer_put`, `function bearer_disable`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: source 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.