net/kcm/kcmsock.c
Source file repositories/reference/linux-study-clean/net/kcm/kcmsock.c
File Facts
- System
- Linux kernel
- Corpus path
net/kcm/kcmsock.c- Extension
.c- Size
- 43545 bytes
- Lines
- 1951
- 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/bpf.hlinux/errno.hlinux/errqueue.hlinux/file.hlinux/filter.hlinux/in.hlinux/kernel.hlinux/module.hlinux/net.hlinux/netdevice.hlinux/poll.hlinux/rculist.hlinux/skbuff.hlinux/socket.hlinux/splice.hlinux/uaccess.hlinux/workqueue.hlinux/syscalls.hlinux/sched/signal.hlinux/uio.hnet/kcm.hnet/netns/generic.hnet/sock.huapi/linux/kcm.htrace/events/sock.h
Detected Declarations
function report_csk_errorfunction kcm_abort_tx_psockfunction kcm_update_rx_mux_statsfunction kcm_update_tx_mux_statsfunction kcm_rcv_readyfunction kcm_rfreefunction kcm_queue_rcv_skbfunction requeue_rx_msgsfunction kcm_done_workfunction unreserve_rx_kcmfunction psock_data_readyfunction kcm_rcv_strparserfunction kcm_parse_func_strparserfunction kcm_read_sock_donefunction psock_state_changefunction psock_write_spacefunction psock_now_availfunction unreserve_psockfunction kcm_report_tx_retryfunction kcm_write_msgsfunction kcm_tx_workfunction test_bitfunction kcm_pushfunction kcm_sendmsgfunction WARN_ONfunction kcm_splice_eoffunction kcm_recvmsgfunction kcm_splice_readfunction kcm_recv_disablefunction kcm_recv_enablefunction kcm_setsockoptfunction kcm_getsockoptfunction init_kcm_sockfunction kcm_attachfunction kcm_attach_ioctlfunction kcm_unattachfunction kcm_unattach_ioctlfunction list_for_each_entryfunction kcm_ioctlfunction release_muxfunction kcm_donefunction kcm_releasefunction kcm_createfunction kcm_init_netfunction kcm_exit_netfunction kcm_initfunction kcm_exitmodule init kcm_init
Annotated Snippet
static const struct proto_ops kcm_dgram_ops = {
.family = PF_KCM,
.owner = THIS_MODULE,
.release = kcm_release,
.bind = sock_no_bind,
.connect = sock_no_connect,
.socketpair = sock_no_socketpair,
.accept = sock_no_accept,
.getname = sock_no_getname,
.poll = datagram_poll,
.ioctl = kcm_ioctl,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.setsockopt = kcm_setsockopt,
.getsockopt_iter = kcm_getsockopt,
.sendmsg = kcm_sendmsg,
.recvmsg = kcm_recvmsg,
.mmap = sock_no_mmap,
.splice_eof = kcm_splice_eof,
};
static const struct proto_ops kcm_seqpacket_ops = {
.family = PF_KCM,
.owner = THIS_MODULE,
.release = kcm_release,
.bind = sock_no_bind,
.connect = sock_no_connect,
.socketpair = sock_no_socketpair,
.accept = sock_no_accept,
.getname = sock_no_getname,
.poll = datagram_poll,
.ioctl = kcm_ioctl,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.setsockopt = kcm_setsockopt,
.getsockopt_iter = kcm_getsockopt,
.sendmsg = kcm_sendmsg,
.recvmsg = kcm_recvmsg,
.mmap = sock_no_mmap,
.splice_eof = kcm_splice_eof,
.splice_read = kcm_splice_read,
};
/* Create proto operation for kcm sockets */
static int kcm_create(struct net *net, struct socket *sock,
int protocol, int kern)
{
struct kcm_net *knet = net_generic(net, kcm_net_id);
struct sock *sk;
struct kcm_mux *mux;
switch (sock->type) {
case SOCK_DGRAM:
sock->ops = &kcm_dgram_ops;
break;
case SOCK_SEQPACKET:
sock->ops = &kcm_seqpacket_ops;
break;
default:
return -ESOCKTNOSUPPORT;
}
if (protocol != KCMPROTO_CONNECTED)
return -EPROTONOSUPPORT;
sk = sk_alloc(net, PF_KCM, GFP_KERNEL, &kcm_proto, kern);
if (!sk)
return -ENOMEM;
/* Allocate a kcm mux, shared between KCM sockets */
mux = kmem_cache_zalloc(kcm_muxp, GFP_KERNEL);
if (!mux) {
sk_free(sk);
return -ENOMEM;
}
spin_lock_init(&mux->lock);
spin_lock_init(&mux->rx_lock);
INIT_LIST_HEAD(&mux->kcm_socks);
INIT_LIST_HEAD(&mux->kcm_rx_waiters);
INIT_LIST_HEAD(&mux->kcm_tx_waiters);
INIT_LIST_HEAD(&mux->psocks);
INIT_LIST_HEAD(&mux->psocks_ready);
INIT_LIST_HEAD(&mux->psocks_avail);
mux->knet = knet;
/* Add new MUX to list */
mutex_lock(&knet->mutex);
Annotation
- Immediate include surface: `linux/bpf.h`, `linux/errno.h`, `linux/errqueue.h`, `linux/file.h`, `linux/filter.h`, `linux/in.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `function report_csk_error`, `function kcm_abort_tx_psock`, `function kcm_update_rx_mux_stats`, `function kcm_update_tx_mux_stats`, `function kcm_rcv_ready`, `function kcm_rfree`, `function kcm_queue_rcv_skb`, `function requeue_rx_msgs`, `function kcm_done_work`, `function unreserve_rx_kcm`.
- 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.