net/mctp/af_mctp.c
Source file repositories/reference/linux-study-clean/net/mctp/af_mctp.c
File Facts
- System
- Linux kernel
- Corpus path
net/mctp/af_mctp.c- Extension
.c- Size
- 20730 bytes
- Lines
- 912
- 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.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/compat.hlinux/if_arp.hlinux/net.hlinux/mctp.hlinux/module.hlinux/socket.hlinux/uio.hnet/mctp.hnet/mctpdevice.hnet/sock.htrace/events/mctp.htest/sock-test.c
Detected Declarations
function mctp_releasefunction mctp_sockaddr_is_okfunction mctp_sockaddr_ext_is_okfunction mctp_bindfunction bindfunction connectionsfunction mctp_sendmsgfunction mctp_recvmsgfunction __mctp_key_removefunction mctp_setsockoptfunction mctp_getsockoptfunction mctp_ioctl_tag_copy_from_userfunction mctp_ioctl_tag_copy_to_userfunction mctp_ioctl_alloctagfunction mctp_ioctl_droptagfunction mctp_ioctlfunction mctp_compat_ioctlfunction mctp_sk_expire_keysfunction hlist_for_each_entry_safefunction mctp_sk_initfunction mctp_sk_closefunction mctp_sk_hashfunction mctp_sk_unhashfunction mctp_sk_destructfunction mctp_pf_createfunction mctp_initfunction mctp_exitmodule init mctp_init
Annotated Snippet
static const struct proto_ops mctp_dgram_ops = {
.family = PF_MCTP,
.release = mctp_release,
.bind = mctp_bind,
.connect = mctp_connect,
.socketpair = sock_no_socketpair,
.accept = sock_no_accept,
.getname = sock_no_getname,
.poll = datagram_poll,
.ioctl = mctp_ioctl,
.gettstamp = sock_gettstamp,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.setsockopt = mctp_setsockopt,
.getsockopt_iter = mctp_getsockopt,
.sendmsg = mctp_sendmsg,
.recvmsg = mctp_recvmsg,
.mmap = sock_no_mmap,
#ifdef CONFIG_COMPAT
.compat_ioctl = mctp_compat_ioctl,
#endif
};
static void mctp_sk_expire_keys(struct timer_list *timer)
{
struct mctp_sock *msk = container_of(timer, struct mctp_sock,
key_expiry);
struct net *net = sock_net(&msk->sk);
unsigned long next_expiry, flags, fl2;
struct mctp_sk_key *key;
struct hlist_node *tmp;
bool next_expiry_valid = false;
spin_lock_irqsave(&net->mctp.keys_lock, flags);
hlist_for_each_entry_safe(key, tmp, &msk->keys, sklist) {
/* don't expire. manual_alloc is immutable, no locking
* required.
*/
if (key->manual_alloc)
continue;
spin_lock_irqsave(&key->lock, fl2);
if (!time_after_eq(key->expiry, jiffies)) {
__mctp_key_remove(key, net, fl2,
MCTP_TRACE_KEY_TIMEOUT);
continue;
}
if (next_expiry_valid) {
if (time_before(key->expiry, next_expiry))
next_expiry = key->expiry;
} else {
next_expiry = key->expiry;
next_expiry_valid = true;
}
spin_unlock_irqrestore(&key->lock, fl2);
}
spin_unlock_irqrestore(&net->mctp.keys_lock, flags);
if (next_expiry_valid)
mod_timer(timer, next_expiry);
}
static int mctp_sk_init(struct sock *sk)
{
struct mctp_sock *msk = container_of(sk, struct mctp_sock, sk);
INIT_HLIST_HEAD(&msk->keys);
timer_setup(&msk->key_expiry, mctp_sk_expire_keys, 0);
msk->bind_peer_set = false;
return 0;
}
static void mctp_sk_close(struct sock *sk, long timeout)
{
sk_common_release(sk);
}
static int mctp_sk_hash(struct sock *sk)
{
struct net *net = sock_net(sk);
struct sock *existing;
struct mctp_sock *msk;
mctp_eid_t remote;
u32 hash;
int rc;
msk = container_of(sk, struct mctp_sock, sk);
Annotation
- Immediate include surface: `linux/compat.h`, `linux/if_arp.h`, `linux/net.h`, `linux/mctp.h`, `linux/module.h`, `linux/socket.h`, `linux/uio.h`, `net/mctp.h`.
- Detected declarations: `function mctp_release`, `function mctp_sockaddr_is_ok`, `function mctp_sockaddr_ext_is_ok`, `function mctp_bind`, `function bind`, `function connections`, `function mctp_sendmsg`, `function mctp_recvmsg`, `function __mctp_key_remove`, `function mctp_setsockopt`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.