The Linux Kernel/Networking

Linux kernel network functionality spans from sockets interface through protocols to network cards.

⚲ Shell interfaces:


 * prints network connections, routing tables, interface statistics and other details
 * shows and configures routing, network devices, interfaces and tunnels
 * - socket statistics utility

Sockets
⚲ API:

sys/socket.h – main user mode sockets header

Basic common and client side interface:
 * ↪ creates an endpoint for communication
 * struct -  abstract socket address
 * shuts down part of a full-duplex connection
 * ↪ sends a message on a socket
 * ↪, receives a message from a socket
 * ↪, receives a message from a socket

Additional server side interface:
 * ↪ - binds a sockaddr to a socket
 * ↪ - listens for connections on a socket
 * ↪ - accepts a connection on a socket

⚙️ Internals
 * struct  @ contains
 * struct - abstract protocols interface
 * struct - network layer representation of sockets


 *  ↯ call hierarchy:
 * ->create.
 * for example . See Address families for another options.
 * ->create.
 * for example . See Address families for another options.
 * ->create.
 * for example . See Address families for another options.


 *  ↯ call hierarchy:
 * ->connect.
 * for example . See Protocols for another options.
 * ->connect.
 * for example . See Protocols for another options.
 * ->connect.
 * for example . See Protocols for another options.
 * for example . See Protocols for another options.



📚 References

Network storage
🚀 advanced topic

🔧 TODO

⚲ API:



See also Zero-copy between file descriptors



Names
⚲ API:, , ,

⚙️ Details
 * returns writable pointer to from  from  from.

📚 References:

Address families
⚲ API
 * Address Family (AF) domain defines address format and address length socklen_t.
 * , (derive socklen_t from AF)
 * Address Family (AF) domain defines address format and address length socklen_t.
 * , (derive socklen_t from AF)

Common AF:, ,.

PF - Protocol Family index actually is the same as Address Family index (AF).

⚙️ Internals of some AF
 * ↪ - sockets for local IPC
 * ↪ - IPv4
 * ↪ - communication between kernel and user space
 * ↪ - communication between VM and hypervisor
 * ↪ - device level interface
 * - Bluetooth
 * ↪ - communication between VM and hypervisor
 * ↪ - device level interface
 * - Bluetooth
 * - Bluetooth
 * - Bluetooth

Totally there are more than 40 AFs (see )

⚙️ Internals
 * - registers . See references to this identifiers to find more than 30 protocol families.

📚 Further reading
 * – protocol address management

Protocols
Each Protocol Family (PF, same index as Address Family AF) consists of several protocol implementations.

Directory /proc/net contains various files and subdirectories containing information about the networking layer. File /proc/net/protocols lists available and used protocols.

In each PF protocols are classified to different types, for example stream, datagram and raw socket. TCP is type of stream, UDP is type of datagram, raw and ping are type of raw.


 * - registers struct - protocol implementations:
 * In initcall,,  and  :
 * In initcall:
 * In initcall:
 * In initcall:
 * In initcall:
 * In initcall:
 * In initcall:

📚 References:


 * Transport layer and TCP

RDMA
🚀 advanced topic

🗝️ Acronyms:
 * IB —, an interconnect standard, competes with ,
 * IPoIB — IP network emulation layer over InfiniBand networks
 * SRP —
 * ULP — Upper-layer protocols
 * iSER —

⚲ Interfaces:
 * https://github.com/linux-rdma/rdma-core
 * — RDMA communication manager
 * — RDMA communication manager

⚙️ Internals:
 * — Upper-layer protocols
 * — software drivers
 * — hardware device drivers
 * — hardware device drivers

📚 References:

🚀 advanced topic

⚲ Interface:
 * ipset
 * ipset
 * ipset
 * ipset
 * ipset
 * ipset
 * ipset
 * ipset

⚙️ Internals:

📚 References:
 * https://wiki.nftables.org/
 * https://lwn.net/Kernel/Index/#Networking-Packet_filtering
 * https://wiki.nftables.org/
 * https://lwn.net/Kernel/Index/#Networking-Packet_filtering
 * https://wiki.nftables.org/
 * https://lwn.net/Kernel/Index/#Networking-Packet_filtering

Network device
⚲ Interfaces
 * registers, net_device_ops
 * socket buffer (skb)
 * queues socket buffers into transmit queue
 * socket buffer (skb)
 * queues socket buffers into transmit queue

👁 Example: - the most famous and simple interface lo

⚙️ Internals
 * function receives skb and passes it back with
 * function receives skb and passes it back with

📚 Further reading
 * – network device configuration
 * – manage and show interface statistics
 * – low-level access to Linux network devices
 * – packet interface on device level
 * Queueing in the Linux Network Stack

💾 Historical
 * LDP TLK Chapter 10 Networks

Network drivers



 * - before NAPI




 * NAPI Driver design
 * ⚲ API:
 * adds
 * - called by an IRQ handler to schedule a poll
 * - instead netif_rx, finally calls
 * - called from custom napi->poll
 * ⚙️ Internals:
 * calls custom napi->poll
 * 👁 example
 * calls
 * custom napi->poll calls
 * setups Ethernet network device
 * 👁 An example of Ethernet driver:
 * custom napi->poll calls
 * setups Ethernet network device
 * 👁 An example of Ethernet driver:

⚙️ Internals:

📚 References:
 * – query or control network driver and hardware settings
 * Data link layer: Ethernet
 * GRO - Generic Receive Offload
 * https://wireless.wiki.kernel.org
 * https://wireless.wiki.kernel.org

💾 Historical:
 * LDD2:Network Drivers
 * LDD3:Network Drivers
 * Kernel Analysis: Networking, 2003
 * network_overview

📖 Further reading about networking
 * https://lwn.net/Kernel/Index/#Networking
 * https://lartc.org/ – Linux Advanced Routing & Traffic Control
 * – show / manipulate routing, network devices, interfaces and tunnels
 * – show / manipulate traffic control settings
 * bcc/ebpf networking tools
 * eBPF-based Networking, Security, and Observability
 * Retis – tracing packets in the Linux networking stack & friends
 * eBPF-based Networking, Security, and Observability
 * Retis – tracing packets in the Linux networking stack & friends