net/unix/af_unix.c
Source file repositories/reference/linux-study-clean/net/unix/af_unix.c
File Facts
- System
- Linux kernel
- Corpus path
net/unix/af_unix.c- Extension
.c- Size
- 93430 bytes
- Lines
- 3971
- 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.
- 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/bpf-cgroup.hlinux/btf_ids.hlinux/dcache.hlinux/errno.hlinux/fcntl.hlinux/file.hlinux/filter.hlinux/fs.hlinux/fs_struct.hlinux/init.hlinux/kernel.hlinux/mount.hlinux/namei.hlinux/net.hlinux/pidfs.hlinux/poll.hlinux/proc_fs.hlinux/sched/signal.hlinux/security.hlinux/seq_file.hlinux/skbuff.hlinux/slab.hlinux/socket.hlinux/splice.hlinux/string.hlinux/uaccess.hnet/af_unix.hnet/net_namespace.hnet/scm.hnet/tcp_states.huapi/linux/sockios.huapi/linux/termios.h
Detected Declarations
struct unix_peercredstruct unix_stream_read_statestruct bpf_unix_iter_statestruct bpf_iter__unixfunction unix_table_lock_cmp_fnfunction unix_state_lock_cmp_fnfunction unix_recvq_lock_cmp_fnfunction unix_unbound_hashfunction unix_bsd_hashfunction unix_abstract_hashfunction unix_table_double_lockfunction unix_table_double_unlockfunction unix_get_secdatafunction unix_set_secdatafunction unix_secdata_eqfunction unix_get_secdatafunction unix_may_sendfunction unix_recvq_full_locklessfunction unix_release_addrfunction unix_validate_addrfunction unix_mkname_bsdfunction __unix_remove_socketfunction __unix_insert_socketfunction __unix_set_addr_hashfunction unix_remove_socketfunction unix_insert_unbound_socketfunction unix_insert_bsd_socketfunction unix_remove_bsd_socketfunction sk_for_eachfunction socketfunction unix_dgram_peer_wake_connectfunction unix_dgram_peer_wake_disconnectfunction unix_dgram_peer_wake_disconnect_wakeupfunction unix_dgram_peer_wake_mefunction unix_writablefunction unix_write_spacefunction unix_dgram_disconnectedfunction unix_sock_destructorfunction unix_skb_lenfunction unix_release_sockfunction prepare_peercredfunction drop_peercredfunction init_peercredfunction update_peercredfunction copy_peercredfunction unix_may_passcredfunction unix_listenfunction unix_count_nr_fds
Annotated Snippet
static const struct proto_ops unix_stream_ops = {
.family = PF_UNIX,
.owner = THIS_MODULE,
.release = unix_release,
.bind = unix_bind,
.connect = unix_stream_connect,
.socketpair = unix_socketpair,
.accept = unix_accept,
.getname = unix_getname,
.poll = unix_poll,
.ioctl = unix_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = unix_compat_ioctl,
#endif
.listen = unix_listen,
.shutdown = unix_shutdown,
.setsockopt = unix_setsockopt,
.sendmsg = unix_stream_sendmsg,
.recvmsg = unix_stream_recvmsg,
.read_skb = unix_stream_read_skb,
.mmap = sock_no_mmap,
.splice_read = unix_stream_splice_read,
.set_peek_off = sk_set_peek_off,
.show_fdinfo = unix_show_fdinfo,
};
static const struct proto_ops unix_dgram_ops = {
.family = PF_UNIX,
.owner = THIS_MODULE,
.release = unix_release,
.bind = unix_bind,
.connect = unix_dgram_connect,
.socketpair = unix_socketpair,
.accept = sock_no_accept,
.getname = unix_getname,
.poll = unix_dgram_poll,
.ioctl = unix_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = unix_compat_ioctl,
#endif
.listen = sock_no_listen,
.shutdown = unix_shutdown,
.sendmsg = unix_dgram_sendmsg,
.read_skb = unix_read_skb,
.recvmsg = unix_dgram_recvmsg,
.mmap = sock_no_mmap,
.set_peek_off = sk_set_peek_off,
.show_fdinfo = unix_show_fdinfo,
};
static const struct proto_ops unix_seqpacket_ops = {
.family = PF_UNIX,
.owner = THIS_MODULE,
.release = unix_release,
.bind = unix_bind,
.connect = unix_stream_connect,
.socketpair = unix_socketpair,
.accept = unix_accept,
.getname = unix_getname,
.poll = unix_dgram_poll,
.ioctl = unix_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = unix_compat_ioctl,
#endif
.listen = unix_listen,
.shutdown = unix_shutdown,
.sendmsg = unix_seqpacket_sendmsg,
.recvmsg = unix_seqpacket_recvmsg,
.mmap = sock_no_mmap,
.set_peek_off = sk_set_peek_off,
.show_fdinfo = unix_show_fdinfo,
};
static void unix_close(struct sock *sk, long timeout)
{
/* Nothing to do here, unix socket does not need a ->close().
* This is merely for sockmap.
*/
}
static bool unix_bpf_bypass_getsockopt(int level, int optname)
{
if (level == SOL_SOCKET) {
switch (optname) {
case SO_PEERPIDFD:
return true;
default:
return false;
}
}
Annotation
- Immediate include surface: `linux/bpf-cgroup.h`, `linux/btf_ids.h`, `linux/dcache.h`, `linux/errno.h`, `linux/fcntl.h`, `linux/file.h`, `linux/filter.h`, `linux/fs.h`.
- Detected declarations: `struct unix_peercred`, `struct unix_stream_read_state`, `struct bpf_unix_iter_state`, `struct bpf_iter__unix`, `function unix_table_lock_cmp_fn`, `function unix_state_lock_cmp_fn`, `function unix_recvq_lock_cmp_fn`, `function unix_unbound_hash`, `function unix_bsd_hash`, `function unix_abstract_hash`.
- 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.