include/net/sock.h
Source file repositories/reference/linux-study-clean/include/net/sock.h
File Facts
- System
- Linux kernel
- Corpus path
include/net/sock.h- Extension
.h- Size
- 91421 bytes
- Lines
- 3185
- 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.
- 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/hardirq.hlinux/kernel.hlinux/list.hlinux/list_nulls.hlinux/timer.hlinux/cache.hlinux/bitops.hlinux/lockdep.hlinux/netdevice.hlinux/skbuff.hlinux/mm.hlinux/security.hlinux/slab.hlinux/uaccess.hlinux/page_counter.hlinux/memcontrol.hlinux/static_key.hlinux/sched.hlinux/wait.hlinux/cgroup-defs.hlinux/rbtree.hlinux/rculist_nulls.hlinux/poll.hlinux/sockptr.hlinux/indirect_call_wrapper.hlinux/atomic.hlinux/refcount.hlinux/llist.hnet/dst.hnet/checksum.hnet/tcp_states.hlinux/net_tstamp.h
Detected Declarations
struct slock_ownedstruct sockstruct protostruct netstruct sock_commonstruct bpf_local_storagestruct sk_filterstruct sockstruct sock_bh_lockedstruct request_sock_opsstruct timewait_sock_opsstruct inet_hashinfostruct raw_hashinfostruct smc_hashinfostruct modulestruct sk_psockstruct proto_accept_argstruct protostruct prot_inusestruct socket_allocstruct sockcm_cookiestruct sock_skb_cbenum sk_pacingenum sock_flagsfunction sk_user_data_is_nocopyfunction __locked_read_sk_user_data_with_flagsfunction __rcu_dereference_sk_user_data_with_flagsfunction sock_net_setfunction sk_peek_offsetfunction sk_peek_offset_bwdfunction sk_peek_offset_fwdfunction sk_unhashedfunction sk_hashedfunction sk_node_initfunction __sk_del_nodefunction __sk_del_node_initfunction sock_holdfunction __sock_putfunction sk_del_node_initfunction __sk_nulls_del_node_init_rcufunction sk_nulls_del_node_init_rcufunction sk_nulls_replace_node_init_rcufunction __sk_add_nodefunction sk_add_nodefunction sk_add_node_rcufunction sk_add_node_tail_rcufunction __sk_nulls_add_node_rcufunction __sk_nulls_add_node_tail_rcu
Annotated Snippet
* Functions to fill in entries in struct proto_ops when a protocol
* does not implement a particular function.
*/
int sock_no_bind(struct socket *sock, struct sockaddr_unsized *saddr, int len);
int sock_no_connect(struct socket *sock, struct sockaddr_unsized *saddr, int len, int flags);
int sock_no_socketpair(struct socket *, struct socket *);
int sock_no_accept(struct socket *, struct socket *, struct proto_accept_arg *);
int sock_no_getname(struct socket *, struct sockaddr *, int);
int sock_no_ioctl(struct socket *, unsigned int, unsigned long);
int sock_no_listen(struct socket *, int);
int sock_no_shutdown(struct socket *, int);
int sock_no_sendmsg(struct socket *, struct msghdr *, size_t);
int sock_no_sendmsg_locked(struct sock *sk, struct msghdr *msg, size_t len);
int sock_no_recvmsg(struct socket *, struct msghdr *, size_t, int);
int sock_no_mmap(struct file *file, struct socket *sock,
struct vm_area_struct *vma);
/*
* Functions to fill in entries in struct proto_ops when a protocol
* uses the inet style.
*/
int sock_common_getsockopt(struct socket *sock, int level, int optname,
char __user *optval, int __user *optlen);
int sock_common_recvmsg(struct socket *sock, struct msghdr *msg, size_t size,
int flags);
int sock_common_setsockopt(struct socket *sock, int level, int optname,
sockptr_t optval, unsigned int optlen);
void sk_common_release(struct sock *sk);
/*
* Default socket callbacks and setup code
*/
/* Initialise core socket variables using an explicit uid. */
void sock_init_data_uid(struct socket *sock, struct sock *sk, kuid_t uid);
/* Initialise core socket variables.
* Assumes struct socket *sock is embedded in a struct socket_alloc.
*/
void sock_init_data(struct socket *sock, struct sock *sk);
/*
* Socket reference counting postulates.
*
* * Each user of socket SHOULD hold a reference count.
* * Each access point to socket (an hash table bucket, reference from a list,
* running timer, skb in flight MUST hold a reference count.
* * When reference count hits 0, it means it will never increase back.
* * When reference count hits 0, it means that no references from
* outside exist to this socket and current process on current CPU
* is last user and may/should destroy this socket.
* * sk_free is called from any context: process, BH, IRQ. When
* it is called, socket has no references from outside -> sk_free
* may release descendant resources allocated by the socket, but
* to the time when it is called, socket is NOT referenced by any
* hash tables, lists etc.
* * Packets, delivered from outside (from network or from another process)
* and enqueued on receive/error queues SHOULD NOT grab reference count,
* when they sit in queue. Otherwise, packets will leak to hole, when
* socket is looked up by one cpu and unhasing is made by another CPU.
* It is true for udp/raw, netlink (leak to receive and error queues), tcp
* (leak to backlog). Packet socket does all the processing inside
* BR_NETPROTO_LOCK, so that it has not this race condition. UNIX sockets
* use separate SMP lock, so that they are prone too.
*/
/* Ungrab socket and destroy it, if it was the last reference. */
static inline void sock_put(struct sock *sk)
{
if (refcount_dec_and_test(&sk->sk_refcnt))
sk_free(sk);
}
/* Generic version of sock_put(), dealing with all sockets
* (TCP_TIMEWAIT, TCP_NEW_SYN_RECV, ESTABLISHED...)
*/
void sock_gen_put(struct sock *sk);
int __sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested,
unsigned int trim_cap, bool refcounted);
static inline int sk_receive_skb(struct sock *sk, struct sk_buff *skb,
const int nested)
{
return __sk_receive_skb(sk, skb, nested, 1, true);
}
static inline void sk_tx_queue_set(struct sock *sk, int tx_queue)
{
/* sk_tx_queue_mapping accept only upto a 16-bit value */
if (WARN_ON_ONCE((unsigned short)tx_queue >= USHRT_MAX))
Annotation
- Immediate include surface: `linux/hardirq.h`, `linux/kernel.h`, `linux/list.h`, `linux/list_nulls.h`, `linux/timer.h`, `linux/cache.h`, `linux/bitops.h`, `linux/lockdep.h`.
- Detected declarations: `struct slock_owned`, `struct sock`, `struct proto`, `struct net`, `struct sock_common`, `struct bpf_local_storage`, `struct sk_filter`, `struct sock`, `struct sock_bh_locked`, `struct request_sock_ops`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- Implementation status: pattern 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.