net/mctp/route.c
Source file repositories/reference/linux-study-clean/net/mctp/route.c
File Facts
- System
- Linux kernel
- Corpus path
net/mctp/route.c- Extension
.c- Size
- 41967 bytes
- Lines
- 1791
- 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
linux/idr.hlinux/kconfig.hlinux/mctp.hlinux/netdevice.hlinux/rtnetlink.hlinux/skbuff.hkunit/static_stub.huapi/linux/if_arp.hnet/mctp.hnet/mctpdevice.hnet/netlink.hnet/sock.htrace/events/mctp.htest/route-test.c
Detected Declarations
function mctp_dst_discardfunction sk_for_each_rcufunction withfunction hlist_for_each_entryfunction mctp_key_unreffunction mctp_key_addfunction hlist_for_each_entryfunction __mctp_key_done_infunction mctp_skb_set_flowfunction mctp_flow_prepare_outputfunction mctp_skb_set_flowfunction mctp_dst_inputfunction mctp_dst_outputfunction mctp_route_releasefunction mctp_default_netfunction mctp_default_net_setfunction mctp_reserve_tagfunction hlist_for_each_entryfunction mctp_route_netidfunction mctp_rt_match_eidfunction mctp_rt_compare_exactfunction mctp_dev_saddrfunction mctp_dst_from_routefunction mctp_dst_from_extaddrfunction mctp_dst_releasefunction list_for_each_entry_rcufunction mctp_route_lookupfunction mctp_dst_input_nullfunction mctp_do_fragment_routefunction mctp_local_outputfunction mctp_route_allocfunction mctp_route_removefunction list_for_each_entry_safefunction mctp_route_add_localfunction mctp_route_remove_localfunction mctp_route_remove_devfunction mctp_pkttype_receivefunction routesfunction componentsfunction routesfunction mctp_newroutefunction mctp_delroutefunction mctp_fill_rtinfofunction mctp_dump_rtinfofunction mctp_routes_net_initfunction mctp_routes_net_exitfunction mctp_routes_initfunction mctp_routes_exit
Annotated Snippet
if (key->valid) {
refcount_inc(&key->refs);
ret = key;
break;
}
spin_unlock(&key->lock);
}
if (ret) {
spin_unlock(&net->mctp.keys_lock);
*irqflags = flags;
} else {
spin_unlock_irqrestore(&net->mctp.keys_lock, flags);
}
return ret;
}
static struct mctp_sk_key *mctp_key_alloc(struct mctp_sock *msk,
unsigned int net,
mctp_eid_t local, mctp_eid_t peer,
u8 tag, gfp_t gfp)
{
struct mctp_sk_key *key;
key = kzalloc_obj(*key, gfp);
if (!key)
return NULL;
key->net = net;
key->peer_addr = peer;
key->local_addr = local;
key->tag = tag;
key->sk = &msk->sk;
key->valid = true;
spin_lock_init(&key->lock);
refcount_set(&key->refs, 1);
sock_hold(key->sk);
return key;
}
void mctp_key_unref(struct mctp_sk_key *key)
{
unsigned long flags;
if (!refcount_dec_and_test(&key->refs))
return;
/* even though no refs exist here, the lock allows us to stay
* consistent with the locking requirement of mctp_dev_release_key
*/
spin_lock_irqsave(&key->lock, flags);
mctp_dev_release_key(key->dev, key);
spin_unlock_irqrestore(&key->lock, flags);
sock_put(key->sk);
kfree(key);
}
static int mctp_key_add(struct mctp_sk_key *key, struct mctp_sock *msk)
{
struct net *net = sock_net(&msk->sk);
struct mctp_sk_key *tmp;
unsigned long flags;
int rc = 0;
spin_lock_irqsave(&net->mctp.keys_lock, flags);
if (sock_flag(&msk->sk, SOCK_DEAD)) {
rc = -EINVAL;
goto out_unlock;
}
hlist_for_each_entry(tmp, &net->mctp.keys, hlist) {
if (mctp_key_match(tmp, key->net, key->local_addr,
key->peer_addr, key->tag)) {
spin_lock(&tmp->lock);
if (tmp->valid)
rc = -EEXIST;
spin_unlock(&tmp->lock);
if (rc)
break;
}
}
if (!rc) {
refcount_inc(&key->refs);
key->expiry = jiffies + mctp_key_lifetime;
timer_reduce(&msk->key_expiry, key->expiry);
Annotation
- Immediate include surface: `linux/idr.h`, `linux/kconfig.h`, `linux/mctp.h`, `linux/netdevice.h`, `linux/rtnetlink.h`, `linux/skbuff.h`, `kunit/static_stub.h`, `uapi/linux/if_arp.h`.
- Detected declarations: `function mctp_dst_discard`, `function sk_for_each_rcu`, `function with`, `function hlist_for_each_entry`, `function mctp_key_unref`, `function mctp_key_add`, `function hlist_for_each_entry`, `function __mctp_key_done_in`, `function mctp_skb_set_flow`, `function mctp_flow_prepare_output`.
- 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.