STRUCT SOCK(9)
π NAME π
okay bestie, welcome to the struct sock(9) page from the Kernel API Manual β and the whole point is struct sock, aka the network layer representation of sockets. that's it, that's the vibe. π«Ά
β¨ SYNOPSIS β¨
here's the sacred struct layout, and I mean sacred β copy it exactly, don't rename anything, don't βclean upβ the semicolons, don't touch the #defines. it's giving enormous-but-iconic. π
β¨
struct sock {
struct sock_common __sk_common;
#define sk_node __sk_common.skc_node;
#define sk_nulls_node __sk_common.skc_nulls_node;
#define sk_refcnt __sk_common.skc_refcnt;
#define sk_tx_queue_mapping __sk_common.skc_tx_queue_mapping;
#ifdef CONFIG_SOCK_RX_QUEUE_MAPPING;
#define sk_rx_queue_mapping __sk_common.skc_rx_queue_mapping;
#endif;
#define sk_dontcopy_begin __sk_common.skc_dontcopy_begin;
#define sk_dontcopy_end __sk_common.skc_dontcopy_end;
#define sk_hash __sk_common.skc_hash;
#define sk_portpair __sk_common.skc_portpair;
#define sk_num __sk_common.skc_num;
#define sk_dport __sk_common.skc_dport;
#define sk_addrpair __sk_common.skc_addrpair;
#define sk_daddr __sk_common.skc_daddr;
#define sk_rcv_saddr __sk_common.skc_rcv_saddr;
#define sk_family __sk_common.skc_family;
#define sk_state __sk_common.skc_state;
#define sk_reuse __sk_common.skc_reuse;
#define sk_reuseport __sk_common.skc_reuseport;
#define sk_ipv6only __sk_common.skc_ipv6only;
#define sk_net_refcnt __sk_common.skc_net_refcnt;
#define sk_bypass_prot_mem __sk_common.skc_bypass_prot_mem;
#define sk_bound_dev_if __sk_common.skc_bound_dev_if;
#define sk_bind_node __sk_common.skc_bind_node;
#define sk_prot __sk_common.skc_prot;
#define sk_net __sk_common.skc_net;
#define sk_v6_daddr __sk_common.skc_v6_daddr;
#define sk_v6_rcv_saddr __sk_common.skc_v6_rcv_saddr;
#define sk_cookie __sk_common.skc_cookie;
#define sk_incoming_cpu __sk_common.skc_incoming_cpu;
#define sk_flags __sk_common.skc_flags;
#define sk_rxhash __sk_common.skc_rxhash;
;
atomic_t sk_drops;
__s32 sk_peek_off;
struct sk_buff_head sk_error_queue;
struct sk_buff_head sk_receive_queue;
struct {
atomic_t rmem_alloc;
int len;
struct sk_buff *head;
struct sk_buff *tail;
} sk_backlog;
#define sk_rmem_alloc sk_backlog.rmem_alloc;
;
;
struct dst_entry *sk_rx_dst;
int sk_rx_dst_ifindex;
u32 sk_rx_dst_cookie;
#ifdef CONFIG_NET_RX_BUSY_POLL;
unsigned int sk_ll_usec;
unsigned int sk_napi_id;
u16 sk_busy_poll_budget;
u8 sk_prefer_busy_poll;
#endif;
u8 sk_userlocks;
int sk_rcvbuf;
struct sk_filter *sk_filter;
union {
struct socket_wq *sk_wq;
};
void (*sk_data_ready)(struct sock *sk);
long sk_rcvtimeo;
int sk_rcvlowat;
;
;
int sk_err;
struct socket *sk_socket;
#ifdef CONFIG_MEMCG;
struct mem_cgroup *sk_memcg;
#endif;
#ifdef CONFIG_XFRM;
struct xfrm_policy *sk_policy[2];
#endif;
#if IS_ENABLED(CONFIG_INET_PSP);
struct psp_assoc *psp_assoc;
#endif;
;
;
socket_lock_t sk_lock;
u32 sk_reserved_mem;
int sk_forward_alloc;
u32 sk_tsflags;
;
;
int sk_write_pending;
atomic_t sk_omem_alloc;
int sk_err_soft;
int sk_wmem_queued;
refcount_t sk_wmem_alloc;
unsigned long sk_tsq_flags;
union {
struct sk_buff *sk_send_head;
struct rb_root tcp_rtx_queue;
};
struct sk_buff_head sk_write_queue;
struct page_frag sk_frag;
union {
struct timer_list sk_timer;
struct timer_list tcp_retransmit_timer;
struct timer_list mptcp_retransmit_timer;
};
unsigned long sk_pacing_rate;
atomic_t sk_zckey;
atomic_t sk_tskey;
unsigned long sk_tx_queue_mapping_jiffies;
;
;
u32 sk_dst_pending_confirm;
u32 sk_pacing_status;
unsigned long sk_max_pacing_rate;
long sk_sndtimeo;
u32 sk_priority;
u32 sk_mark;
kuid_t sk_uid;
u16 sk_protocol;
u16 sk_type;
struct dst_entry *sk_dst_cache;
netdev_features_t sk_route_caps;
#ifdef CONFIG_SOCK_VALIDATE_XMIT;
struct sk_buff* (*sk_validate_xmit_skb)(struct sock *sk,
struct net_device *dev, struct sk_buff *skb);
#endif;
u16 sk_gso_type;
u16 sk_gso_max_segs;
unsigned int sk_gso_max_size;
gfp_t sk_allocation;
u32 sk_txhash;
int sk_sndbuf;
u8 sk_pacing_shift;
bool sk_use_task_frag;
;
u8 sk_gso_disabled : 1, sk_kern_sock : 1, sk_no_check_tx : 1,
sk_no_check_rx : 1;
u8 sk_shutdown;
unsigned long sk_lingertime;
struct proto *sk_prot_creator;
rwlock_t sk_callback_lock;
u32 sk_ack_backlog;
u32 sk_max_ack_backlog;
u64 sk_ino;
spinlock_t sk_peer_lock;
int sk_bind_phc;
struct pid *sk_peer_pid;
const struct cred *sk_peer_cred;
ktime_t sk_stamp;
#if BITS_PER_LONG==32;
seqlock_t sk_stamp_seq;
#endif;
int sk_disconnects;
union {
u8 sk_txrehash;
u8 sk_scm_recv_flags;
struct {
u8 sk_scm_credentials : 1, sk_scm_security : 1, sk_scm_pidfd :
1, sk_scm_rights : 1, sk_scm_unused : 4;
};
};
u8 sk_clockid;
u8 sk_txtime_deadline_mode : 1, sk_txtime_report_errors : 1,
sk_txtime_unused : 6;
#define SK_BPF_CB_FLAG_TEST(SK, FLAG) ((SK)->sk_bpf_cb_flags &
(FLAG));
u8 sk_bpf_cb_flags;
void *sk_user_data;
#ifdef CONFIG_SECURITY;
void *sk_security;
#endif;
struct sock_cgroup_data sk_cgrp_data;
void (*sk_state_change)(struct sock *sk);
void (*sk_write_space)(struct sock *sk);
void (*sk_error_report)(struct sock *sk);
int (*sk_backlog_rcv)(struct sock *sk, struct sk_buff *skb);
void (*sk_destruct)(struct sock *sk);
struct sock_reuseport *sk_reuseport_cb;
#ifdef CONFIG_BPF_SYSCALL;
struct bpf_local_storage *sk_bpf_storage;
#endif;
struct numa_drop_counters *sk_drop_counters;
union {
struct rcu_head sk_rcu;
freeptr_t sk_freeptr;
};
netns_tracker ns_tracker;
struct xarray sk_user_frags;
#if IS_ENABLED(CONFIG_PROVE_LOCKING) && IS_ENABLED(CONFIG_MODULES);
struct module *sk_owner;
#endif;
};
π MEMBERS π
okay bestie, buckle up π this is the big one β every single member of this struct, in order, no skips, no "etc." shortcuts. it's giving anatomy class but make it networking π«Ά
__sk_commonβ the shared layout it's got in common withinet_timewait_socksk_dropsβ the raw/udp drops countersk_peek_offβ whatever the currentpeek_offsetvalue issk_error_queueβ rarely used, lowkey the forgotten childsk_receive_queueβ incoming packets, the main character π₯sk_backlogβ always used with the per-socket spinlock held β οΈ like, alwayssk_rx_dstβ the receive input route used by early demuxsk_rx_dst_ifindexβ the ifindex forsk_rx_dstsk_rx_dst_cookieβ the cookie forsk_rx_dstπͺsk_ll_usecβ usecs to busypoll when there's no datask_napi_idβ id of the last napi context that received data for this sksk_busy_poll_budgetβ napi processing budget when busypollingsk_prefer_busy_pollβ prefers busypolling over softirq processingsk_userlocksβ theSO_SNDBUFandSO_RCVBUFsettingssk_rcvbufβ size of the receive buffer, in bytessk_filterβ socket filtering instructions{unnamed_union}β anonymous, mysterious, no name, we stan an enigma π΅οΈsk_wqβ the sock wait queue and async headsk_data_readyβ callback that says hey, there's data to be processed πsk_rcvtimeoβ theSO_RCVTIMEOsettingsk_rcvlowatβ theSO_RCVLOWATsettingsk_errβ last errorsk_socketβ Identd and reporting IO signalssk_memcgβ this socket's memory cgroup associationsk_policyβ flow policypsp_assocβ the PSP association, if the socket is PSP-securedsk_lockβ the synchronizer πsk_reserved_memβ space reserved and non-reclaimable for the socketsk_forward_allocβ space allocated forwardsk_tsflagsβ theSO_TIMESTAMPINGflagssk_write_pendingβ a write to a stream socket is waiting to startsk_omem_allocβ the"o"is"option"or"other", iykyksk_err_softβ errors that don't cause failure, but they are the cause of a persistent failure β and not just 'timed out' πsk_wmem_queuedβ persistent queue sizesk_wmem_allocβ transmit queue bytes committedsk_tsq_flagsβ TCP Small Queues flags{unnamed_union}β anonymous, again, it's a whole vibesk_send_headβ front of stuff to transmittcp_rtx_queueβ the TCP re-transmit queue [union withsk_send_head]sk_write_queueβ the Packet sending queuesk_fragβ cached page frag{unnamed_union}β anonymous (yes, a third one, iconic)sk_timerβ the sock cleanup timer β°tcp_retransmit_timerβ the tcp retransmit timermptcp_retransmit_timerβ the mptcp retransmit timersk_pacing_rateβ Pacing rate (if it's supported by the transport/packet scheduler)sk_zckeyβ counter to orderMSG_ZEROCOPYnotificationssk_tskeyβ counter to disambiguate concurrent tstamp requestssk_tx_queue_mapping_jiffiesβ time in jiffies of the lastsk_tx_queue_mappingrefresh.sk_dst_pending_confirmβ needs to confirm neighboursk_pacing_statusβ Pacing status (requested, handled bysch_fq)sk_max_pacing_rateβ Maximum pacing rate (SO_MAX_PACING_RATE)sk_sndtimeoβ theSO_SNDTIMEOsettingsk_priorityβ theSO_PRIORITYsettingsk_markβ generic packet marksk_uidβ user id of the ownersk_protocolβ which protocol this socket belongs to in this network familysk_typeβ socket type (SOCK_STREAM, etc)sk_dst_cacheβ destination cachesk_route_capsβ route capabilities (e.g.NETIF_F_TSO)sk_validate_xmit_skbβ ptr to an optional validate functionsk_gso_typeβ GSO type (e.g.SKB_GSO_TCPV4)sk_gso_max_segsβ Maximum number of GSO segmentssk_gso_max_sizeβ Maximum GSO segment size to buildsk_allocationβ allocation modesk_txhashβ computed flow hash for use on transmitsk_sndbufβ size of the send buffer, in bytessk_pacing_shiftβ scaling factor for TCP Small Queuessk_use_task_fragβ allowssk_page_fragto usecurrent->task_frag. Sockets that can be used under memory reclaim should set this tofalse. β οΈ no cap, pay attention to that onesk_gso_disabledβ if set,NETIF_F_GSO_MASKis forbidden.sk_kern_sockβ True if the sock is using kernel lock classessk_no_check_txβ theSO_NO_CHECKsetting, set checksum in TX packetssk_no_check_rxβ allow zero checksum in RX packetssk_shutdownβ mask ofSEND_SHUTDOWNand/orRCV_SHUTDOWNsk_lingertimeβ theSO_LINGERl_lingersettingsk_prot_creatorβ thesk_protof the original sock creator (seeipv6_setsockopt,IPV6_ADDRFORMfor instance)sk_callback_lockβ used with the callbacks at the end of this structsk_ack_backlogβ current listen backlogsk_max_ack_backlogβ the listen backlog set inlistensk_inoβ inode number (zero if orphaned) π₯Ίsk_peer_lockβ the lock protectingsk_peer_pidandsk_peer_credsk_bind_phcβSO_TIMESTAMPINGbind PHC index of the PTP virtual clock for timestampingsk_peer_pidβ thestruct pidfor this socket's peersk_peer_credβ theSO_PEERCREDsettingsk_stampβ time stamp of the last packet receivedsk_stamp_seqβ lock for accessingsk_stamp, on 32 bit architectures onlysk_disconnectsβ number of disconnect operations performed on this sock{unnamed_union}β anonymous πsk_txrehashβ enable TX hash rethinksk_scm_recv_flagsβ all the flags used byscm_recv{unnamed_struct}β anonymoussk_scm_credentialsβ flagged bySO_PASSCREDto recvSCM_CREDENTIALSsk_scm_securityβ flagged bySO_PASSSECto recvSCM_SECURITYsk_scm_pidfdβ flagged bySO_PASSPIDFDto recvSCM_PIDFDsk_scm_rightsβ flagged bySO_PASSRIGHTSto recvSCM_RIGHTSsk_scm_unusedβ unused flags forscm_recvsk_clockidβ clockid used by time-based scheduling (SO_TXTIME)sk_txtime_deadline_modeβ set deadline mode forSO_TXTIMEsk_txtime_report_errorsβ set report errors mode forSO_TXTIMEsk_txtime_unusedβ unused txtime flagssk_bpf_cb_flagsβ used inbpf_setsockoptsk_user_dataβ RPC layer private data. Write-protected bysk_callback_lock. πsk_securityβ used by security modulessk_cgrp_dataβ cgroup data for this cgroupsk_state_changeβ callback to indicate a change in the state of the socksk_write_spaceβ callback to indicate there's bf sending space availablesk_error_reportβ callback to indicate errors (e.g.MSG_ERRQUEUE)sk_backlog_rcvβ callback to process the backlogsk_destructβ called at sock freeing time, i.e. when allrefcnt == 0πsk_reuseport_cbβ reuseport group containersk_bpf_storageβ ptr to cache and control forbpf_sk_storagesk_drop_countersβ optional pointer tonuma_drop_counters{unnamed_union}β anonymous, one last time β¨sk_rcuβ used during the RCU grace periodsk_freeptrβ used forSLAB_TYPESAFE_BY_RCUmanaged socketsns_trackerβ tracker for the netns referencesk_user_fragsβ xarray of pages the user is holding a reference on.sk_ownerβ reference to the real owner of the socket that callssock_lock_init_class_and_name.
π SEE ALSO π
go read these next bestie, they're all linked fr fr π¦
- Kernel file
./include/net/sock.hstruct sock_common(9) sk_user_data_is_nocopy(9)__locked_read_sk_user_data_with_flags(9)__rcu_dereference_sk_user_data_with_flags(9)sk_for_each_entry_offset_rcu(9)SOCK_CONNECT_BIND(9)lock_sock_fast(9)unlock_sock_fast(9)sk_wmem_alloc_get(9)sk_rmem_alloc_get(9)sk_has_allocations(9)skwq_has_sleeper(9)sock_poll_wait(9)sk_page_frag(9)_sock_tx_timestamp(9)sk_eat_skb(9)
and that's the whole struct, bestie β you ate that π
β¨ this lil page lives in ./include/net, its version stamp is October 2026, and it's filed under struct sock(9). go forth and read headers, mwah π«Άππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms