STRUCT SOCK(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 with inet_timewait_sock
  • sk_drops β€” the raw/udp drops counter
  • sk_peek_off β€” whatever the current peek_offset value is
  • sk_error_queue β€” rarely used, lowkey the forgotten child
  • sk_receive_queue β€” incoming packets, the main character πŸ“₯
  • sk_backlog β€” always used with the per-socket spinlock held ⚠️ like, always
  • sk_rx_dst β€” the receive input route used by early demux
  • sk_rx_dst_ifindex β€” the ifindex for sk_rx_dst
  • sk_rx_dst_cookie β€” the cookie for sk_rx_dst πŸͺ
  • sk_ll_usec β€” usecs to busypoll when there's no data
  • sk_napi_id β€” id of the last napi context that received data for this sk
  • sk_busy_poll_budget β€” napi processing budget when busypolling
  • sk_prefer_busy_poll β€” prefers busypolling over softirq processing
  • sk_userlocks β€” the SO_SNDBUF and SO_RCVBUF settings
  • sk_rcvbuf β€” size of the receive buffer, in bytes
  • sk_filter β€” socket filtering instructions
  • {unnamed_union} β€” anonymous, mysterious, no name, we stan an enigma πŸ•΅οΈ
  • sk_wq β€” the sock wait queue and async head
  • sk_data_ready β€” callback that says hey, there's data to be processed πŸ’Œ
  • sk_rcvtimeo β€” the SO_RCVTIMEO setting
  • sk_rcvlowat β€” the SO_RCVLOWAT setting
  • sk_err β€” last error
  • sk_socket β€” Identd and reporting IO signals
  • sk_memcg β€” this socket's memory cgroup association
  • sk_policy β€” flow policy
  • psp_assoc β€” the PSP association, if the socket is PSP-secured
  • sk_lock β€” the synchronizer πŸ”’
  • sk_reserved_mem β€” space reserved and non-reclaimable for the socket
  • sk_forward_alloc β€” space allocated forward
  • sk_tsflags β€” the SO_TIMESTAMPING flags
  • sk_write_pending β€” a write to a stream socket is waiting to start
  • sk_omem_alloc β€” the "o" is "option" or "other", iykyk
  • sk_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 size
  • sk_wmem_alloc β€” transmit queue bytes committed
  • sk_tsq_flags β€” TCP Small Queues flags
  • {unnamed_union} β€” anonymous, again, it's a whole vibe
  • sk_send_head β€” front of stuff to transmit
  • tcp_rtx_queue β€” the TCP re-transmit queue [union with sk_send_head]
  • sk_write_queue β€” the Packet sending queue
  • sk_frag β€” cached page frag
  • {unnamed_union} β€” anonymous (yes, a third one, iconic)
  • sk_timer β€” the sock cleanup timer ⏰
  • tcp_retransmit_timer β€” the tcp retransmit timer
  • mptcp_retransmit_timer β€” the mptcp retransmit timer
  • sk_pacing_rate β€” Pacing rate (if it's supported by the transport/packet scheduler)
  • sk_zckey β€” counter to order MSG_ZEROCOPY notifications
  • sk_tskey β€” counter to disambiguate concurrent tstamp requests
  • sk_tx_queue_mapping_jiffies β€” time in jiffies of the last sk_tx_queue_mapping refresh.
  • sk_dst_pending_confirm β€” needs to confirm neighbour
  • sk_pacing_status β€” Pacing status (requested, handled by sch_fq)
  • sk_max_pacing_rate β€” Maximum pacing rate (SO_MAX_PACING_RATE)
  • sk_sndtimeo β€” the SO_SNDTIMEO setting
  • sk_priority β€” the SO_PRIORITY setting
  • sk_mark β€” generic packet mark
  • sk_uid β€” user id of the owner
  • sk_protocol β€” which protocol this socket belongs to in this network family
  • sk_type β€” socket type (SOCK_STREAM, etc)
  • sk_dst_cache β€” destination cache
  • sk_route_caps β€” route capabilities (e.g. NETIF_F_TSO)
  • sk_validate_xmit_skb β€” ptr to an optional validate function
  • sk_gso_type β€” GSO type (e.g. SKB_GSO_TCPV4)
  • sk_gso_max_segs β€” Maximum number of GSO segments
  • sk_gso_max_size β€” Maximum GSO segment size to build
  • sk_allocation β€” allocation mode
  • sk_txhash β€” computed flow hash for use on transmit
  • sk_sndbuf β€” size of the send buffer, in bytes
  • sk_pacing_shift β€” scaling factor for TCP Small Queues
  • sk_use_task_frag β€” allows sk_page_frag to use current->task_frag. Sockets that can be used under memory reclaim should set this to false. ⚠️ no cap, pay attention to that one
  • sk_gso_disabled β€” if set, NETIF_F_GSO_MASK is forbidden.
  • sk_kern_sock β€” True if the sock is using kernel lock classes
  • sk_no_check_tx β€” the SO_NO_CHECK setting, set checksum in TX packets
  • sk_no_check_rx β€” allow zero checksum in RX packets
  • sk_shutdown β€” mask of SEND_SHUTDOWN and/or RCV_SHUTDOWN
  • sk_lingertime β€” the SO_LINGER l_linger setting
  • sk_prot_creator β€” the sk_prot of the original sock creator (see ipv6_setsockopt, IPV6_ADDRFORM for instance)
  • sk_callback_lock β€” used with the callbacks at the end of this struct
  • sk_ack_backlog β€” current listen backlog
  • sk_max_ack_backlog β€” the listen backlog set in listen
  • sk_ino β€” inode number (zero if orphaned) πŸ₯Ί
  • sk_peer_lock β€” the lock protecting sk_peer_pid and sk_peer_cred
  • sk_bind_phc β€” SO_TIMESTAMPING bind PHC index of the PTP virtual clock for timestamping
  • sk_peer_pid β€” the struct pid for this socket's peer
  • sk_peer_cred β€” the SO_PEERCRED setting
  • sk_stamp β€” time stamp of the last packet received
  • sk_stamp_seq β€” lock for accessing sk_stamp, on 32 bit architectures only
  • sk_disconnects β€” number of disconnect operations performed on this sock
  • {unnamed_union} β€” anonymous πŸ™ˆ
  • sk_txrehash β€” enable TX hash rethink
  • sk_scm_recv_flags β€” all the flags used by scm_recv
  • {unnamed_struct} β€” anonymous
  • sk_scm_credentials β€” flagged by SO_PASSCRED to recv SCM_CREDENTIALS
  • sk_scm_security β€” flagged by SO_PASSSEC to recv SCM_SECURITY
  • sk_scm_pidfd β€” flagged by SO_PASSPIDFD to recv SCM_PIDFD
  • sk_scm_rights β€” flagged by SO_PASSRIGHTS to recv SCM_RIGHTS
  • sk_scm_unused β€” unused flags for scm_recv
  • sk_clockid β€” clockid used by time-based scheduling (SO_TXTIME)
  • sk_txtime_deadline_mode β€” set deadline mode for SO_TXTIME
  • sk_txtime_report_errors β€” set report errors mode for SO_TXTIME
  • sk_txtime_unused β€” unused txtime flags
  • sk_bpf_cb_flags β€” used in bpf_setsockopt
  • sk_user_data β€” RPC layer private data. Write-protected by sk_callback_lock. πŸ”
  • sk_security β€” used by security modules
  • sk_cgrp_data β€” cgroup data for this cgroup
  • sk_state_change β€” callback to indicate a change in the state of the sock
  • sk_write_space β€” callback to indicate there's bf sending space available
  • sk_error_report β€” callback to indicate errors (e.g. MSG_ERRQUEUE)
  • sk_backlog_rcv β€” callback to process the backlog
  • sk_destruct β€” called at sock freeing time, i.e. when all refcnt == 0 πŸ’€
  • sk_reuseport_cb β€” reuseport group container
  • sk_bpf_storage β€” ptr to cache and control for bpf_sk_storage
  • sk_drop_counters β€” optional pointer to numa_drop_counters
  • {unnamed_union} β€” anonymous, one last time ✨
  • sk_rcu β€” used during the RCU grace period
  • sk_freeptr β€” used for SLAB_TYPESAFE_BY_RCU managed sockets
  • ns_tracker β€” tracker for the netns reference
  • sk_user_frags β€” xarray of pages the user is holding a reference on.
  • sk_owner β€” reference to the real owner of the socket that calls sock_lock_init_class_and_name.

🌈 SEE ALSO 🌈

go read these next bestie, they're all linked fr fr πŸ¦‹


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