STRUCT SOCK_COMMON(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– NAME πŸ’–

struct sock_common β€” the minimal network layer representation of sockets, bestie. Like, it's the kernel API manual page for it, and yes we're gonna get through all of it together 🫢


✨ SYNOPSIS ✨

okay so here's the whole struct, literally every line, do not touch:

struct sock_common {
    union {
      __addrpair skc_addrpair;
      struct {
        __be32 skc_daddr;
        __be32 skc_rcv_saddr;
      };
    };
    union {
      unsigned int    skc_hash;
      __u16 skc_u16hashes[2];
    };
    union {
      __portpair skc_portpair;
      struct {
        __be16 skc_dport;
        __u16 skc_num;
      };
    };
    unsigned short          skc_family;
    volatile unsigned char  skc_state;
    unsigned char           skc_reuse:4;
    unsigned char           skc_reuseport:1;
    unsigned char           skc_ipv6only:1;
    unsigned char           skc_net_refcnt:1;
    unsigned char           skc_bypass_prot_mem:1;
    int skc_bound_dev_if;
    union {
      struct hlist_node       skc_bind_node;
      struct hlist_node       skc_portaddr_node;
    };
    struct proto            *skc_prot;
    possible_net_t skc_net;
  #if IS_ENABLED(CONFIG_IPV6);
    struct in6_addr         skc_v6_daddr;
    struct in6_addr         skc_v6_rcv_saddr;
  #endif;
    atomic64_t skc_cookie;
    union {
      unsigned long   skc_flags;
      struct sock     *skc_listener;
      struct inet_timewait_death_row *skc_tw_dr;
    };
    union {
      struct hlist_node       skc_node;
      struct hlist_nulls_node skc_nulls_node;
    };
    unsigned short          skc_tx_queue_mapping;
  #ifdef CONFIG_SOCK_RX_QUEUE_MAPPING;
    unsigned short          skc_rx_queue_mapping;
  #endif;
    union {
      int skc_incoming_cpu;
      u32 skc_rcv_wnd;
      u32 skc_tw_rcv_nxt;
    };
    refcount_t skc_refcnt;
 };

πŸŽ€ Members πŸŽ€

the whole cast, one by one, no skips πŸ’…

  • {unnamed_union} β€” anonymous, it's giving mysterious
  • skc_addrpair β€” 8-byte-aligned __u64 union of skc_daddr & skc_rcv_saddr
  • {unnamed_struct} β€” anonymous
  • skc_daddr β€” foreign IPv4 addr
  • skc_rcv_saddr β€” bound local IPv4 addr
  • {unnamed_union} β€” anonymous
  • skc_hash β€” hash value used with various protocol lookup tables
  • skc_u16hashes β€” two u16 hash values used by UDP lookup tables
  • {unnamed_union} β€” anonymous
  • skc_portpair β€” __u32 union of skc_dport & skc_num
  • {unnamed_struct} β€” anonymous
  • skc_dport β€” placeholder for inet_dport/tw_dport
  • skc_num β€” placeholder for inet_num/tw_num
  • skc_family β€” network address family
  • skc_state β€” connection state
  • skc_reuse β€” SO_REUSEADDR setting
  • skc_reuseport β€” SO_REUSEPORT setting
  • skc_ipv6only β€” socket is IPV6 only
  • skc_net_refcnt β€” socket is using net ref counting
  • skc_bypass_prot_mem β€” bypass the per-protocol memory accounting for skb
  • skc_bound_dev_if β€” bound device index if != 0
  • {unnamed_union} β€” anonymous
  • skc_bind_node β€” bind hash linkage for various protocol lookup tables
  • skc_portaddr_node β€” second hash linkage for UDP
  • skc_prot β€” protocol handlers inside a network family
  • skc_net β€” reference to the network namespace of this socket
  • skc_v6_daddr β€” IPV6 destination address
  • skc_v6_rcv_saddr β€” IPV6 source address
  • skc_cookie β€” socket's cookie value
  • {unnamed_union} β€” anonymous
  • skc_flags β€” place holder for sk_flags SO_LINGER (l_onoff), SO_BROADCAST, SO_KEEPALIVE, SO_OOBINLINE settings, SO_TIMESTAMPING settings
  • skc_listener β€” connection request listener socket (aka rsk_listener) [union with skc_flags]
  • skc_tw_dr β€” (aka tw_dr) ptr to struct inet_timewait_death_row [union with skc_flags]
  • {unnamed_union} β€” anonymous
  • skc_node β€” main hash linkage for various protocol lookup tables
  • skc_nulls_node β€” main hash linkage for TCP
  • skc_tx_queue_mapping β€” tx queue number for this connection
  • skc_rx_queue_mapping β€” rx queue number for this connection
  • {unnamed_union} β€” anonymous
  • skc_incoming_cpu β€” record/match cpu processing incoming packets
  • skc_rcv_wnd β€” (aka rsk_rcv_wnd) TCP receive window size (possibly scaled) [union with skc_incoming_cpu]
  • skc_tw_rcv_nxt β€” (aka tw_rcv_nxt) TCP window next expected seq number [union with skc_incoming_cpu]
  • skc_refcnt β€” reference count

🌈 DESCRIPTION 🌈

so like, this is the minimal network layer representation of sockets β€” the header for struct sock and struct inet_timewait_sock, no cap. that's the whole vibe. it's the blueprint, the main character energy of the network stack 😌


πŸ’œ SEE ALSO πŸ’œ

the whole friend group, go say hi πŸ’«

Kernel file ./include/net/sock.h struct sock(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 page slay πŸ’… this one lives in ./include/net, it's the October 2026 edition, and it's officially titled struct sock_common(9) β€” go off, king πŸ‘‘πŸ¦‹

πŸ“¦ where this page comes from