The Linux packet receive path, from NIC to socket
How Linux 7.2 moves a packet from a NIC ring to a socket, which bounded queue drops it, and how to find that queue with counters and skb:kfree_skb.
When someone reports packet loss on a Linux host, the first suspect is almost always the NIC: a cheap card, an undersized ring, a bad cable. In my experience the NIC is rarely where the decision to drop is made. Between the wire and an application, the kernel can hold a received packet in several bounded queues, each owned by a different piece of the kernel, each with its own size, its own counter and its own failure mode. Which of them a packet crosses depends on the path; on the receive path of a single device it is two or three. A packet from a physical NIC always crosses the descriptor ring, and a packet for a local socket always crosses that socket's buffer, which is sized in bytes. A per-CPU backlog sized in packets sits between them only when Receive Packet Steering is enabled or when the driver delivers through netif_rx(), as a veth does by default. A veth can instead put a ring of its own, which most dashboards never look at, in front of a NAPI poll, but only when its receiving end has GRO or XDP enabled and the packet passes an eligibility test that, while the sender keeps its default TSO and no XDP program is attached, admits only locally sent traffic and only when the receiving end also has an extra GRO feature enabled. A packet forwarded into a Kubernetes pod crosses two receive paths in turn, the node NIC's and then the pod veth's. Most of these queues overflow because a CPU did not get to them in time, and the reason the CPU did not get to them is written in the NAPI budget, not in the hardware.
This article walks the receive path of Linux 7.2 from the DMA descriptor to the socket receive queue, with the function names, data structures and default values taken from the v7.2 tag of the kernel tree. It ends with a lab that anyone can run without root on a stock Fedora 43 laptop, which pushes 64-byte UDP datagrams across a veth pair, the same device type that connects a Kubernetes pod to its node, and shows which counter moves when packets are lost. In the lab, the interface counter that most monitoring scrapes stays at zero while several million packets disappear.
The queues on the path
Before the mechanisms, here is the map. The table lists every place on the IPv4 receive path where the kernel can hold a packet and therefore can refuse one; the figure after it shows which of them are on every path and which only on some. Defaults are those compiled into net/core/hotdata.c1 and the Intel igb driver2, which I use as the example of a physical NIC because its receive code is compact and representative.
| Queue | Owner and unit | Default bound | Drop counted in |
|---|---|---|---|
| RX descriptor ring | NIC and driver, descriptors | 256 descriptors in igb (IGB_DEFAULT_RXD), 64 to 4096 allowed, backed by the controller's on-chip packet buffer | Driver statistics via ethtool -S. For igb: rx_missed_errors (MPC) when the on-chip packet buffer overflows, rx_queue_<n>_drops (RQDPC) when the queue has Drop_En set. rx_no_buffer_count (RNBC) counts descriptor starvation, not loss. No skb exists, so no drop reason |
| NAPI poll | One napi_struct per queue, packets per poll | weight 64 (NAPI_POLL_WEIGHT) | Nothing is dropped here; unfinished work is requeued |
net_rx_action round | Per-CPU softirq, packets and time | netdev_budget 300, netdev_budget_usecs 2 jiffies | Column 3 of /proc/net/softnet_stat (time_squeeze), which counts early exits, not drops |
| GRO hash | Per NAPI instance, held skbs | 8 buckets of 8 skbs | Nothing is dropped; the oldest held skb is flushed up the stack |
CPU backlog (input_pkt_queue), only with RPS or netif_rx() delivery | Per CPU, packets | netdev_max_backlog 1000 | Column 2 of softnet_stat, rx_dropped of the device, reason CPU_BACKLOG |
veth peer ring, only when the receiving queue has a NAPI instance (GRO or XDP) and veth_skb_is_eligible_for_gro() admits the skb; otherwise netif_rx() delivery | Per veth receive queue, skb pointers | 256 (VETH_RING_SIZE) | tx_dropped of the sending veth end; reason NOT_SPECIFIED |
| Socket receive queue | Per socket, bytes of truesize | sk_rcvbuf | RcvbufErrors in /proc/net/snmp for UDP; reason SOCKET_RCVBUFF |
Two features of this map drive everything that follows. First, the queues are sized in different units: descriptors, packets, skb pointers, bytes. A rate that one queue absorbs easily can overflow the next, and a burst of small packets is far more dangerous to a packet-counted queue than the same number of bytes in jumbo frames. Second, the counters live in different places. There is no single "dropped" number for a host, and the rx_dropped field that ip -s link prints covers only a subset of these queues.
DMA rings and NAPI
A NIC does not hand packets to the kernel; it writes them into memory the driver lent it. The lending happens through a ring of descriptors. For the igb family the descriptor is union e1000_adv_rx_desc, 16 bytes with two views of the same memory3. In the read view the driver writes two 64-bit DMA addresses, pkt_addr and hdr_addr, telling the device where to put the next frame. When the frame has landed, the device overwrites the slot with the writeback view: a pkt_info field with RSS and packet type, a 32-bit rss hash, status_error, the frame length and the stripped vlan tag.
union e1000_adv_rx_desc {
struct {
__le64 pkt_addr; /* Packet buffer address */
__le64 hdr_addr; /* Header buffer address */
} read;
struct {
struct {
struct {
__le16 pkt_info; /* RSS type, Packet type */
__le16 hdr_info; /* Split Head, buf len */
} lo_dword;
union {
__le32 rss; /* RSS Hash */
/* ... */
} hi_dword;
} lower;
struct {
__le32 status_error; /* ext status/error */
__le16 length; /* Packet length */
__le16 vlan; /* VLAN tag */
} upper;
} wb; /* writeback */
};The ring is a producer and consumer pair over this array. The device consumes descriptors that carry a buffer address and produces completed ones; the driver consumes completions and produces fresh buffers. What happens when a frame arrives and the host ring has no free descriptor depends on the queue's configuration, and the two igb counters usually quoted for it mean different things. Intel's developer manual for the 82575, the oldest controller igb drives, defines RNBC as the number of times frames were received when no buffers were available in host memory, and adds that the packet is still received if there is space in the FIFO4. The frame waits in the controller's on-chip packet buffer. MPC counts packets missed because the receive FIFO had insufficient space to store them5. igb exports the two registers as rx_no_buffer_count and rx_missed_errors6. A climbing rx_no_buffer_count with a flat rx_missed_errors is therefore a warning that the driver is late returning buffers, not loss; loss starts when the on-chip buffer overflows.
One configuration moves the drop decision to the empty slot. When a queue has the Drop_En bit set, the controller drops frames for that queue when the host ring has no free descriptors to store them7. igb_setup_srrctl() sets the bit, as E1000_SRRCTL_DROP_EN, when virtual functions are allocated, or when the adapter runs more than one receive queue and receive flow control is off. Those drops are read from the per-queue RQDPC register and appear as rx_queue_<n>_drops in ethtool -S. The device's rx_fifo_errors does not isolate them: igb_update_stats() adds every queue's RQDPC and also MPC to it, while rx_missed_errors is MPC alone86. Drop_En drops are therefore the sum of rx_queue_<n>_drops, or rx_fifo_errors minus rx_missed_errors; adding rx_fifo_errors and rx_missed_errors counts every packet-buffer overflow twice. In every variant the ring ran dry because software had not returned buffers fast enough. These are the only drops on the path that the NIC itself decides, and the NIC is reporting a CPU problem.
Software learns about completions through an interrupt, but only the first one. The MSI-X handler of an igb queue, igb_msix_ring(), does two things: it writes the interrupt throttle value and calls napi_schedule_irqoff() on the queue vector's napi_struct8. From that moment the queue's interrupt stays masked and the kernel polls. The NAPI documentation is explicit that drivers should keep interrupts masked after scheduling, and unmask only after a successful napi_complete_done()9. Scheduling sets NAPI_STATE_SCHED in napi_struct.state and links the instance into the poll_list of the current CPU's struct softnet_data, then raises NET_RX_SOFTIRQ.
The poll function is where the per-queue budget lives. igb_poll() calls igb_clean_rx_irq(q_vector, budget), which loops while (likely(total_packets < budget)). Each iteration reads the descriptor at next_to_clean, stops if its length is zero (nothing written back yet), issues dma_rmb() so no other field is read before the writeback is visible, builds or extends an skb from the page fragment, copies the RSS hash from the descriptor into skb->hash through igb_rx_hash(), and hands the skb to napi_gro_receive(). Buffers are returned to the device in batches of IGB_RX_BUFFER_WRITE, which is 16, because a register write per descriptor is too slow2.
if (q_vector->rx.ring) {
int cleaned;
/* ... */
cleaned = igb_clean_rx_irq(q_vector, budget);
work_done += cleaned;
if (cleaned >= budget)
clean_complete = false;
}
/* If all work not completed, return budget and keep polling */
if (!clean_complete)
return budget;
if (likely(napi_complete_done(napi, work_done)))
igb_ring_irq_enable(q_vector);
return work_done;The contract is the one napi.rst lays down: a poll that still has work returns exactly budget and keeps ownership of the instance; a poll that finished calls napi_complete_done(), which releases ownership, and only then re-enables the interrupt9. The budget a driver receives is napi_struct.weight; the standard registration helper, netif_napi_add(), sets it to NAPI_POLL_WEIGHT, 6410. The core enforces the contract in __napi_poll(): if the poll returned less than its weight it is done; if it returned the full weight, the core flushes held GRO packets (only the aged ones when HZ is at least 1000), sets repoll and the instance goes back on the list for another turn11.
The softirq budget and time_squeeze
One CPU usually polls several NAPI instances: queues of different NICs, the per-CPU backlog, veth instances. The round-robin across them is net_rx_action() in net/core/dev.c. It reads two limits once at entry: a packet budget from netdev_budget, 300 by default, and a deadline of jiffies plus netdev_budget_usecs converted to jiffies11. The default for the latter is 2 * USEC_PER_SEC / HZ, two jiffies, with the comment that it must be at least two jiffies to guarantee one jiffy of timeout1. On a kernel built with HZ=1000, as Fedora's is, that is 2000 microseconds; with HZ=250 the same default means 8000 microseconds. The sysctl documentation describes both values but does not state either default, so read them from the source or from the running system12.
n = list_first_entry(&list, struct napi_struct, poll_list);
budget -= napi_poll(n, &repoll);
/* If softirq window is exhausted then punt.
* Allow this to run for 2 jiffies since which will allow
* an average latency of 1.5/HZ.
*/
if (unlikely(budget <= 0 ||
time_after_eq(jiffies, time_limit))) {
/* Pairs with READ_ONCE() in softnet_seq_show() */
WRITE_ONCE(sd->time_squeeze, sd->time_squeeze + 1);
break;
}The budget is checked only after a poll returns, and a poll is never cut to the budget that remains: __napi_poll() hands every instance its full n->weight11. With default settings and weight-64 instances, four full polls leave 44 units of budget, the fifth poll still processes up to 64 packets, and the round ends at 320. In general a round can process up to netdev_budget plus one poll's weight minus one. When the round ends early, time_squeeze is incremented and the remaining instances, plus everything that asked to be repolled, are spliced back onto sd->poll_list and NET_RX_SOFTIRQ is raised again. Nothing is dropped at this point. time_squeeze is a pressure gauge, not a loss counter. Raising netdev_budget because it is non-zero is a common reflex, and it is the wrong one when the loss is happening three queues later.
What happens after the punt matters more than the punt. The generic softirq loop, handle_softirqs() in kernel/softirq.c, jumps back to restart while softirqs are still pending only if less than MAX_SOFTIRQ_TIME (2 ms) has passed, need_resched() is false and --max_restart, which starts at MAX_SOFTIRQ_RESTART (10), is still non-zero. That is at most ten passes, nine of them restarts; when any condition fails with work still pending, it calls wakeup_softirqd()13. From then on, receive processing for that CPU runs in the per-CPU ksoftirqd thread, which the scheduler treats like any other task. If the CPU is busy with application threads, ksoftirqd waits its turn, the driver does not return buffers, and the ring runs dry. The resulting rx_missed_errors or per-queue drops are booked against the NIC, but the cause is CPU time.
Threaded NAPI changes the context but not the arithmetic. With threaded enabled in sysfs or per instance over netlink, each NAPI instance gets its own kernel thread named napi/<ifname>-<napi-id>, and the documentation recommends pinning that thread to the CPU that services the interrupt9. This makes receive work visible to the scheduler and to CPU accounting, which I consider an advantage on hosts that also run latency-sensitive applications, but it does not create cycles. A queue that needs more CPU than it gets will overflow whether it is served by a softirq or by a thread.
GRO: batching before the stack
napi_gro_receive() is a thin wrapper around gro_receive_skb(&napi->gro, skb)10. Each NAPI instance embeds a struct gro_node: a bitmask of occupied buckets, an array of GRO_HASH_BUCKETS (8) gro_list heads, an rx_list of packets that GRO decided not to hold and an rx_count of the segments on that list10. dev_gro_receive() picks the bucket with skb_get_hash_raw(skb) & (GRO_HASH_BUCKETS - 1), so the RSS hash the NIC wrote into the descriptor is reused here14. gro_list_prepare() walks the bucket and marks each held skb same_flow only if the hash, the device, the VLAN, metadata and the Ethernet header all match.
The protocol callbacks then decide whether the new segment can be merged. For TCP, tcp_gro_receive() refuses to merge when the flags other than FIN and PSH differ, when ack_seq differs, when any TCP option word differs, when the segment is larger than the held packet's MSS, or when the new sequence number is not exactly the old one plus the held length. It forces a flush of the merged packet when the segment carries URG, PSH, RST, SYN or FIN, or when it is shorter than the MSS15. The merge itself, skb_gro_receive(), stops at the device's GRO size limit and, for anything that is not plain TCP, at GRO_LEGACY_MAX_SIZE, 65536 bytes14.
A bucket holds at most MAX_GRO_SKBS, 8, flows in progress. A ninth distinct flow hashing into a full bucket forces gro_flush_oldest() to complete the oldest one. Completed packets are not passed up one by one either. gro_normal_one() appends each to rx_list and adds its segment count to rx_count, NAPI_GRO_CB(skb)->count for a merged skb and 1 for one that was never held. Once rx_count reaches gro_normal_batch, 8 segments by default, it calls gro_normal_list(), which hands the whole list to netif_receive_skb_list_internal()1614. This is why I describe GRO as batching rather than as an offload. Its value for a busy server is that the IP and TCP layers run once per merged packet and once per list, so the per-packet cost of everything after the driver shrinks.
GRO never drops a packet. It can, however, change which packets exist: a capture taken after GRO, with tcpdump on the receiving interface, shows merged segments larger than the MTU, and a counter that counts packets above this point counts merged packets. Keep that in mind when you compare ethtool -S packet counts with nstat counts on the same host.
RSS, RPS and RFS
Everything so far ran on the CPU that took the interrupt, and that CPU is chosen by the NIC. Receive Side Scaling computes a hash over addresses and ports, usually a Toeplitz hash, and indexes an indirection table with its low-order bits to pick a receive queue; each queue has its own MSI-X vector and therefore its own CPU17. The kernel documentation recommends an indirection table at least four times the queue count, which it says leaves about 16 percent imbalance between queues. It also warns that the interrupt count grows with every queue, so the most efficient high-rate setup is the smallest number of queues where none overflows17. I agree with that warning, and I would add that "one queue per CPU" is a latency choice, not a throughput default.
Receive Packet Steering is the software version, applied later. It is compiled in on SMP kernels but disabled until /sys/class/net/<dev>/queues/rx-<n>/rps_cpus is set to a non-zero mask17. When it is enabled, netif_receive_skb_list_internal() calls get_rps_cpu() for each skb, which hashes the flow and picks a CPU from the queue's rps_map; the skb is then placed with enqueue_to_backlog() on that CPU's input_pkt_queue and an inter-processor interrupt wakes the CPU's backlog NAPI11. Receive Flow Steering adds two tables so that the chosen CPU is the one where the consuming thread last called recvmsg() or sendmsg(): a global rps_sock_flow_table holding the desired CPU, and a per-queue rps_dev_flow_table holding the current CPU and the backlog tail position of the last enqueued packet. When the desired CPU differs from the current one, the flow moves only if the old CPU's queue head counter has reached the recorded tail (head >= tail), so no packet of the flow is still waiting there and ordering is preserved, or if the current CPU is unset (>= nr_cpu_ids) or offline17.
The backlog is the queue to remember from this section. Its bound is net_hotdata.max_backlog, the netdev_max_backlog sysctl, 1000 packets by default1. enqueue_to_backlog() reads the queue length without the lock, drops if it is above the bound or if the flow limiter says so, and otherwise takes the backlog lock, checks again and appends:
qlen = skb_queue_len_lockless(&sd->input_pkt_queue);
max_backlog = READ_ONCE(net_hotdata.max_backlog);
if (unlikely(qlen > max_backlog) ||
skb_flow_limit(skb, qlen, max_backlog))
goto cpu_backlog_drop;
/* ... lock, recheck, __skb_queue_tail(), return NET_RX_SUCCESS ... */
cpu_backlog_drop:
reason = SKB_DROP_REASON_CPU_BACKLOG;
numa_drop_add(&sd->drop_counters, 1);
bad_dev:
dev_core_stats_rx_dropped_inc(skb->dev);
kfree_skb_reason(skb, reason);
return NET_RX_DROP;The flow limiter, skb_flow_limit(), does nothing while the queue is below half of max_backlog. Above that, if it was enabled per CPU through net.core.flow_limit_cpu_bitmap, it keeps a history of the last FLOW_LIMIT_HISTORY packets, 128 at v7.2, each recorded as a bucket of a hash table of flow_limit_table_len entries, and drops the new packet when its bucket then holds more than 64 of those 128, so one elephant flow cannot starve the others1811. Documentation/networking/scaling.rst still describes a history of 256 packets; the source is authoritative17. Because the history counts hash buckets, two flows that collide in the table are limited together. Both kinds of drop increment the same per-CPU drop counter and carry the same reason, CPU_BACKLOG; only column 11 of softnet_stat, the flow-limit count, separates them.
Here is the part that matters for anyone running containers. The backlog is not only an RPS mechanism. Any driver that delivers through netif_rx() or __netif_rx() instead of its own NAPI instance lands in netif_rx_internal(), which enqueues to the backlog of the current CPU when RPS is off11. veth is such a driver. veth_xmit() computes use_napi = rcu_access_pointer(rq->napi) && veth_skb_is_eligible_for_gro(dev, rcv, skb) and passes it to veth_forward_skb(), which calls veth_xdp_rx() when it is true and __netif_rx() otherwise19. Both halves matter. The receiving queue has a NAPI instance only when an XDP program is attached or GRO is enabled on the receiving end. The eligibility test is true when the sending device has none of the NETIF_F_ALL_TSO features, or when the skb's destructor is sock_wfree and the receiving device has NETIF_F_GRO_FRAGLIST or NETIF_F_GRO_UDP_FWD, which ethtool -k shows as rx-gro-list and rx-udp-gro-forwarding19. The test does not look at the protocol: a TCP skb from a sender without TSO qualifies like a UDP one. On the lab machine ethtool -k reports a freshly created pair with GRO off and tcp-segmentation-offload on. With TSO on, enabling GRO alone admits nothing. A datagram from a local UDP socket carries sock_wfree, set by skb_set_owner_w()20, but still needs one of the two receive features. Segments sent from an established TCP socket carry tcp_wfree, or __sock_wfree for a pure ACK, set in __tcp_transmit_skb(), so they never match21. Two kinds of TCP control packet do carry sock_wfree. A Fast Open SYN-ACK is charged with skb_set_owner_w() in tcp_make_synack() to the child socket that tcp_try_fastopen() created, because tcp_conn_request() passes that child, not the listener, to send_synack()2122. Over IPv4, a RST that answers a segment for which no socket exists is built on the per-CPU TCP control socket by ip_send_unicast_reply(), whose call to ip_append_data() leaves it with sock_wfree. Only when the reply belongs to an existing socket, such as a TIME_WAIT or request socket, does skb_set_owner_edemux() replace that owner2324. An skb the host forwards into a pod belongs to no local socket and does not match either. Attaching XDP is the exception: veth_fix_features() clears NETIF_F_GSO_SOFTWARE, which includes TSO, on the peer of the device that runs the program, so every skb that peer sends is eligible19. With the defaults, every packet a pod sends through its veth is queued on the sending CPU's backlog and processed by that CPU's backlog NAPI in process_backlog(). The pod's traffic is therefore subject to netdev_max_backlog and is counted in softnet_stat and time_squeeze like any physical receive.
For the skbs that do take the NAPI path, the bound changes completely. veth_xdp_rx() pushes the skb into a ptr_ring of VETH_RING_SIZE entries, 256, and returns NETDEV_TX_BUSY if it is full. A veth has no qdisc by default, so veth_xmit() frees the skb and increments the sending device's priv->dropped, which veth_get_stats64() reports as tx_dropped19. The free goes through dev_kfree_skb_any(), which carries the reason SKB_DROP_REASON_NOT_SPECIFIED10. A 256-entry ring replaces a 1000-entry backlog, the loss appears on the other end of the pair, and the drop reason says nothing. The lab below shows this happening.
Inside __netif_receive_skb_core
Whether a packet arrives from a GRO list or from the backlog, it passes through __netif_receive_skb_core(), but the two sources call it differently. A singly delivered skb, from process_backlog() or netif_receive_skb(), goes through __netif_receive_skb_one_core(), which calls the function and then the selected handler's func. A GRO rx_list goes through __netif_receive_skb_list_core(), which calls the function once per skb, groups consecutive skbs that selected the same handler and device, and hands each group to the handler's list_func when it has one11. This function is the switchboard of the receive path, and the order of its steps explains several things practitioners trip over. At another_round it sets skb_iif and increments softnet_data.processed, the first column of softnet_stat11. Then, in order:
- Generic XDP, if any device has a generic (skb mode) XDP program:
do_xdp_generic()runs and anything butXDP_PASSends processing. Native XDP ran earlier, inside the driver, before an skb existed;igb_clean_rx_irq()callsigb_run_xdp()on the raw buffer8. - VLAN untagging of in-band tags with
skb_vlan_untag(). - Taps: every
packet_typeon the namespace'sptype_alllist and on the device's ownptype_allgets a reference throughdeliver_skb(). This is whereAF_PACKETsockets, and thereforetcpdump, see the packet. It is before tc and netfilter, which is why a capture shows packets that a firewall later drops. - tc ingress through
sch_handle_ingress(), where cls_bpf programs run, followed by the netfilter ingress hooknf_hook_ingress()when an nftablesingresschain exists. Both sit behind the static keyingress_needed_key, so they cost nothing when unused. - The device's
rx_handler, which is how bridge, bond, macvlan and team devices take the packet over. The handler can consume it, ask foranother_roundon a different device, or pass it on. - Protocol selection:
deliver_ptype_list_skb()overptype_basehashed byskb->protocol, and over the per-namespace and per-deviceptype_specificlists. Every match but the last is delivered at once; the last one, for IPv4 thepacket_typethat namesip_rcv()asfuncandip_list_rcv()aslist_func, is not called here but returned to the caller throughppt_prev11. If no handler matched, the packet is dropped with reasonUNHANDLED_PROTOandrx_droppedorrx_nohandlerof the device is incremented.
IPv4 therefore has two entry points. A singly delivered skb enters ip_rcv(), which validates the header in ip_rcv_core() and then enters netfilter with NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, ..., ip_rcv_finish). A list from GRO, the common case for a NAPI driver with RPS off, enters ip_list_rcv(), which runs ip_rcv_core() on each skb, splits the list into sublists by device and network namespace, and passes each sublist through NF_HOOK_LIST at the same PRE_ROUTING hook before ip_list_rcv_finish()25. On both paths, everything registered at PRE_ROUTING, connection tracking and destination NAT included, therefore acts before the routing lookup in ip_rcv_finish() decides whether the packet is for this host at all. A packet routed to the local host goes through ip_local_deliver(), which reassembles fragments and runs the second hook, NF_INET_LOCAL_IN, before ip_local_deliver_finish() hands it to the transport protocol25. Any rule that returns DROP at either hook frees the skb with reason NETFILTER_DROP26.
The last queue is the socket. For UDP, __udp_queue_rcv_skb() calls __udp_enqueue_schedule_skb(), which compares the socket's allocated receive memory plus the skb's truesize with sk_rcvbuf and refuses the packet with -ENOMEM when the buffer is full and not empty27. The caller then increments UDP_MIB_RCVBUFERRORS and UDP_MIB_INERRORS (the source comments that an ENOMEM is charged twice) and drops with SKB_DROP_REASON_SOCKET_RCVBUFF. Two details make this queue smaller than it looks. It is accounted in truesize, the full allocation behind the skb, not in payload bytes, so a 64-byte datagram consumes far more than 64 bytes of buffer. And when no socket is bound to the destination port, the datagram is counted in UDP_MIB_NOPORTS, an ICMP port unreachable is sent, and the reason is NO_SOCKET27.
Drop reasons and what they cannot see
For most of Linux's history, a dropped skb was freed with kfree_skb() and the only trace was the caller's address. The drop reason infrastructure changed that. include/net/dropreason-core.h defines enum skb_drop_reason with a documented value for each cause; at v7.2 the DEFINE_DROP_REASON list has 124 core entries before the MAX sentinel, from NOT_SPECIFIED and NO_SOCKET to CPU_BACKLOG, NETFILTER_DROP, SOCKET_RCVBUFF and the TCP-specific ones26. Code that drops a packet calls kfree_skb_reason() or sk_skb_reason_drop(), and the common path in net/core/skbuff.c fires trace_consume_skb() for SKB_CONSUMED and trace_kfree_skb() for every other reason28. A consumed packet, one that was delivered, therefore never appears on the kfree_skb tracepoint.
The tracepoint skb:kfree_skb records five fields: skbaddr, location, rx_sk, protocol and reason29. location is __builtin_return_address(0) taken in sk_skb_reason_drop(), which is marked __fix_address so that it stays a real function, and it therefore names the code that called it28. That is precise for drops like SOCKET_RCVBUFF, where the caller is in the UDP receive code. Behind a generic helper, what location names depends on code generation. A veth ring overflow is freed by dev_kfree_skb_any(), which with interrupts enabled ends in dev_kfree_skb_any_reason() calling kfree_skb_reason(), an inline wrapper around sk_skb_reason_drop()1130. On the lab kernel, Fedora's 7.2.13-100.fc43.x86_64, that last call is compiled as a tail call: disassembling dev_kfree_skb_any_reason from the shipped vmlinuz shows it ending in a jmp to sk_skb_reason_drop. The helper leaves no return address behind, so location resolves to veth_xmit and the reason is NOT_SPECIFIED. On a build with frame pointers, where the kernel Makefile adds -fno-optimize-sibling-calls, the same drop is attributed to dev_kfree_skb_any_reason and only a stack shows veth_xmit31. Fedora builds with the ORC unwinder and without CONFIG_FRAME_POINTER, so the flag is absent there. Treat location as the immediate caller in the compiled code, not in the source.
One helper defeats both location and the stack. When an skb is freed from hard interrupt context or with interrupts disabled, dev_kfree_skb_any_reason() takes the other branch, dev_kfree_skb_irq_reason(), which stores the reason in the skb, puts it on the per-CPU completion_queue and raises NET_TX_SOFTIRQ. The tracepoint fires later in net_tx_action(), which passes its own address as location, from a stack that holds only the softirq11. For such drops the reason is the only attribution the tracepoint can give.
| Drop | skb:kfree_skb reason | softnet_stat | Device stats (ip -s link) | Other |
|---|---|---|---|---|
| NIC ring overrun | not visible, no skb | no | driver specific; in igb rx_missed_errors is MPC alone (packet buffer overflow), while rx_fifo_errors is MPC plus every queue's RQDPC (Drop_En drops), so it does not separate the two causes | ethtool -S: rx_missed_errors, rx_queue_<n>_drops; rx_no_buffer_count is starvation, not loss |
| Softirq round cut short | not a drop | column 3 time_squeeze | no | none |
| CPU backlog full or flow limit | CPU_BACKLOG | column 2, column 11 for flow limit | rx_dropped of the device | none |
| veth peer ring full | NOT_SPECIFIED | no | tx_dropped of the sending end | none |
| Netfilter rule | NETFILTER_DROP | no | no | rule counters in nft list ruleset |
| No UDP socket on port | NO_SOCKET | no | no | NoPorts in /proc/net/snmp |
| UDP socket buffer full | SOCKET_RCVBUFF | no | no | RcvbufErrors in /proc/net/snmp |
The second column of softnet_stat deserves a precise definition because it is often misread. In v7.2, softnet_seq_show() prints fifteen 8-digit hexadecimal fields per online CPU: processed, the backlog drop counter, time_squeeze, six zeros kept for compatibility, received_rps, the flow-limit count, the total backlog length, the CPU index, and the two halves of the backlog length32. The only writer of the drop counter, drop_counters, is the cpu_backlog_drop label in enqueue_to_backlog()11. A non-zero value means the backlog overflowed, nothing else. It says nothing about ring overruns, socket buffers or firewalls.
Lab: losing packets on a veth pair
The lab runs on a laptop with a 13th Gen Intel Core i9-13900H (20 logical CPUs), Fedora Linux 43 Workstation, kernel 7.2.13-100.fc43.x86_64 built with CONFIG_HZ=1000, iproute2 6.14.0, ethtool 7.1, Python 3.14.8 and GNU Awk 5.3.2. The source references in this article are the upstream v7.2 tag; the Fedora kernel is a later 7.2 stable release, and none of the functions quoted here differ in a way the lab could detect. Everything except the last step runs as an unprivileged user: unshare -rn creates a user namespace and a network namespace in which the user holds CAP_NET_ADMIN, enough to create veth devices and change their offloads.
Start by reading the defaults the running kernel actually uses. On the lab machine they match the compiled-in values from hotdata.c, and netdev_budget_usecs shows the two-jiffy default at HZ=1000.
$ sysctl net.core.netdev_budget net.core.netdev_budget_usecs \
net.core.netdev_max_backlog net.core.dev_weight \
net.core.gro_normal_batch net.core.rps_sock_flow_entries \
net.core.flow_limit_table_len
net.core.netdev_budget = 300
net.core.netdev_budget_usecs = 2000
net.core.netdev_max_backlog = 1000
net.core.dev_weight = 64
net.core.gro_normal_batch = 8
net.core.rps_sock_flow_entries = 0
net.core.flow_limit_table_len = 4096softnet_stat is unreadable raw. This decoder prints the fields that are still live, per CPU, in decimal; strtonum is a GNU Awk extension.
$ awk '{printf "cpu=%-3d processed=%-10d dropped=%-6d squeezed=%-6d rps=%-8d flow_limit=%-6d backlog=%d\n", strtonum("0x"$13), strtonum("0x"$1), strtonum("0x"$2), strtonum("0x"$3), strtonum("0x"$10), strtonum("0x"$11), strtonum("0x"$12)}' /proc/net/softnet_stat | head -4
cpu=0 processed=1198504 dropped=0 squeezed=0 rps=0 flow_limit=0 backlog=0
cpu=1 processed=1579069 dropped=0 squeezed=0 rps=0 flow_limit=0 backlog=0
cpu=2 processed=1669771 dropped=0 squeezed=0 rps=0 flow_limit=0 backlog=0
cpu=3 processed=1826152 dropped=0 squeezed=0 rps=0 flow_limit=0 backlog=0The experiment needs three files in one directory. blast.py forks a number of senders that each write 64-byte UDP datagrams to port 9 as fast as Python allows. sink.py binds port 9 with a requested SO_RCVBUF and reads one datagram every 10 ms, a deliberately slow consumer.
import os, socket, sys, time
# usage: blast.py DST_IP SECONDS SENDERS
dst, secs, n = sys.argv[1], float(sys.argv[2]), int(sys.argv[3])
pids = []
for _ in range(n):
pid = os.fork()
if pid == 0:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
payload, end = b"x" * 64, time.time() + secs
while time.time() < end:
for _ in range(1000):
s.sendto(payload, (dst, 9))
os._exit(0)
pids.append(pid)
for pid in pids:
os.waitpid(pid, 0)import socket, sys, time
# usage: sink.py RCVBUF_BYTES ; binds UDP :9 and reads one datagram every 10 ms
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, int(sys.argv[1]))
s.bind(("0.0.0.0", 9))
while True:
s.recv(2048)
time.sleep(0.01)lab.sh creates a veth pair whose v1 end lives in a second network namespace, then runs three cases for three seconds each with eight senders: A, no listener; B, a listener with SO_RCVBUF 4096; C, the same listener after enabling GRO and UDP GRO forwarding on v1. The second option matters because v0 keeps TSO on, so veth_skb_is_eligible_for_gro() admits the locally sent datagrams only when v1 has NETIF_F_GRO_FRAGLIST or NETIF_F_GRO_UDP_FWD19. A control run after the table shows that GRO alone is not enough. After each case the script prints the global softnet_stat drops and squeezes, the packet and drop counts of both veth ends, and the UDP MIB of the receiving namespace. Counters are cumulative across the three cases.
set -e
D=$(dirname $(readlink -f $0))
unshare -n sleep 120 & PEER=$!
sleep 0.3
ip link add v0 type veth peer name v1 netns $PEER
ip addr add 10.99.0.1/24 dev v0; ip link set v0 up
nsenter -t $PEER -n sh -c 'ip addr add 10.99.0.2/24 dev v1; ip link set v1 up'
snap() { awk '{d+=strtonum("0x"$2); s+=strtonum("0x"$3)} END{printf "softnet dropped=%d time_squeeze=%d\n", d, s}' /proc/net/softnet_stat
nsenter -t $PEER -n ip -s link show v1 | awk 'NR==4{print "v1 rx packets="$2" dropped="$4}'
ip -s link show v0 | awk 'NR==6{print "v0 tx packets="$2" dropped="$4}'
nsenter -t $PEER -n awk '/^Udp:/{getline; print "Udp InDatagrams="$2" NoPorts="$3" RcvbufErrors="$6}' /proc/net/snmp; }
echo "--- run A: no listener"; snap; python3 $D/blast.py 10.99.0.2 3 8; snap
echo "--- run B: listener, SO_RCVBUF 4096"
nsenter -t $PEER -n python3 $D/sink.py 4096 & SINK=$!; sleep 0.5
python3 $D/blast.py 10.99.0.2 3 8; snap
kill $SINK
echo "--- run C: GRO and UDP GRO forwarding on v1, listener"
nsenter -t $PEER -n ethtool -K v1 gro on rx-udp-gro-forwarding on
nsenter -t $PEER -n python3 $D/sink.py 4096 & SINK=$!; sleep 0.5
python3 $D/blast.py 10.99.0.2 3 8; snap
kill $SINK $PEERI ran the script twice. The table gives the per-case deltas computed from the cumulative counters of each run. Absolute rates differ between runs because a laptop's clock speed is not stable under load. What is stable is where each loss is counted; how many packets a case loses relative to how many it delivers is not.
| Case | Packets through the pair | v1 rx dropped | v0 tx dropped | softnet dropped | NoPorts | RcvbufErrors | InDatagrams |
|---|---|---|---|---|---|---|---|
| A: no listener | 7,822,006 / 5,112,006 | 0 / 0 | 0 / 0 | 0 / 0 | 7,822,000 / 5,112,000 | 0 / 0 | 0 / 0 |
| B: listener, SO_RCVBUF 4096 | 7,624,002 / 5,873,002 | 0 / 0 | 0 / 0 | 0 / 0 | 0 / 0 | 7,623,695 / 5,872,694 | 299 / 300 |
| C: GRO and UDP GRO forwarding on v1, listener | 4,014,983 / 2,742,342 | 0 / 0 | 5,760,017 / 3,595,658 | 0 / 0 | 0 / 0 | 4,014,678 / 2,742,036 | 299 / 301 |
Case A shows the backlog path doing its job. Several million packets crossed the pair through __netif_rx() and the sending CPU's backlog, softnet_stat recorded no drop and no squeeze, and every datagram reached UDP, which discarded it as NoPorts. The backlog was drained as soon as each transmit re-enabled bottom halves on the sending CPU, so it never came close to its 1000-packet bound.
Case B is the most common loss in production and the one with the least visibility. The interface counters are clean, the softirq counters are clean, and almost every packet is gone: RcvbufErrors is within a few hundred of the number of packets that crossed the pair. InDatagrams is 299 or 300, which is what a reader that sleeps 10 ms per datagram can take in three seconds. The kernel delivered everything to the socket boundary and the application did not keep up. Raising netdev_max_backlog or netdev_budget would have changed nothing.
Case C is the one I find most instructive. Enabling GRO and UDP GRO forwarding on the receiving end moved delivery from the 1000-packet backlog to the 256-entry ptr_ring of the veth receive queue, and the ring dropped millions of packets. In these two runs it dropped more than it delivered, but that ratio depends on how the sender and receiver CPUs are scheduled and is not stable between runs. The placement is: the drops appear only as tx_dropped on v0, the end in the sender's namespace, while v1, the interface a monitoring agent inside the receiving namespace would scrape, reports zero dropped, and so does softnet_stat. On a Kubernetes node the two ends of a pod's veth pair live in different network namespaces, and depending on direction this is the difference between a node-level and a pod-level metric. This exposure is narrower than "GRO on veth" suggests. It applies to the traffic that the eligibility test admits: skbs owned by a local socket through sock_wfree, in practice UDP and raw sockets and TCP control replies, when the receiving end has UDP GRO forwarding or GRO fraglist enabled, any traffic from a veth end with TSO turned off, and any traffic into an end that runs an XDP program. For that traffic a 256-entry ring absorbs bursts of small packets instead of a 1000-packet backlog, and the counter that shows the loss is on the other side.
The control isolates the eligibility test. I repeated case C once on a fresh pair, with v1 given GRO but not UDP GRO forwarding, so its queue has a NAPI instance while v0 keeps TSO on. Every datagram went through __netif_rx() and the backlog again: v0 dropped nothing, softnet_stat dropped nothing, and the loss returned to RcvbufErrors, exactly as in case B.
ethtool -k v0 | grep -E '^tcp-segmentation-offload|^generic-receive-offload'
echo "--- control: GRO only on v1, listener"
nsenter -t $PEER -n ethtool -K v1 gro on
nsenter -t $PEER -n ethtool -k v1 | grep -E '^generic-receive-offload|rx-udp-gro-forwarding|rx-gro-list'
snap
nsenter -t $PEER -n python3 $D/sink.py 4096 & SINK=$!; sleep 0.5
python3 $D/blast.py 10.99.0.2 3 8; snap
kill $SINK $PEER
tcp-segmentation-offload: on
generic-receive-offload: off
--- control: GRO only on v1, listener
generic-receive-offload: on
rx-gro-list: off
rx-udp-gro-forwarding: off
softnet dropped=0 time_squeeze=13
v1 rx packets=2 dropped=0
v0 tx packets=2 dropped=0
Udp InDatagrams=0 NoPorts=0 RcvbufErrors=0
softnet dropped=0 time_squeeze=13
v1 rx packets=2566007 dropped=0
v0 tx packets=2566007 dropped=0
Udp InDatagrams=302 NoPorts=0 RcvbufErrors=2565695The last step attributes those drops to code. It needs root on the host, because attaching a BPF program is not possible from an unprivileged user namespace, so I could not run it on the lab machine and it is marked as inspected: the command is checked against the bpftrace 0.24.2 documentation and the v7.2 tracepoint definition, not executed. Fedora 43 ships bpftrace 0.24.2. Since 0.22 bpftrace prints enum values symbolically when they are map keys, and 0.24.2 fixed the resolution of enum-typed tracepoint arguments, so args.reason keys print as names33. ksym() resolves args.location to a kernel symbol and kstack(5) keeps the five innermost frames34.
$ sudo bpftrace -e '
tracepoint:skb:kfree_skb {
@by_reason[args.reason, ksym(args.location)] = count();
if (args.reason == SKB_DROP_REASON_NOT_SPECIFIED) {
@unspecified[kstack(5)] = count();
}
}
interval:s:10 { exit(); }'Run during case B, the expected top entry is SOCKET_RCVBUFF with a location in the UDP receive code. Run during case C on the lab kernel, the expected top entries are SOCKET_RCVBUFF for the packets that made it through the ring and NOT_SPECIFIED at veth_xmit, because of the tail call described above. In the @unspecified stacks, veth_xmit is expected directly below sk_skb_reason_drop, with no frame for dev_kfree_skb_any_reason. On a frame-pointer build the location would read dev_kfree_skb_any_reason instead. Run during case A, the entries would be NO_SOCKET from the UDP lookup. The tracepoint sees every network namespace on the host, which is what you want on a Kubernetes node: one program attributes drops for every pod. What it can never show is a ring overrun on a physical NIC, because that packet never became an skb. For that, ethtool -S <dev> remains the only source.
Reading a loss report
The order in which I look at counters follows the path backwards, from the socket to the wire, because the queues near the application are the ones that fill first and are checked last by most runbooks. nstat -az or /proc/net/snmp tell you within seconds whether RcvbufErrors or NoPorts is climbing; if they are, the network is fine and the conversation is about the application or its SO_RCVBUF. Next come netfilter counters, then softnet_stat column 2 per CPU, then veth tx_dropped on the host side of every pod interface, and only then ethtool -S on the physical device.
When the loss really is at the ring, I read time_squeeze and the CPU time of ksoftirqd threads on the CPUs that own the busy queues before touching any ring size. A ring overrun with a climbing time_squeeze on the same CPU means the softirq budget was spent and ksoftirqd lost the scheduling contest. Making the ring bigger with ethtool -G buys time to absorb a burst, which is legitimate, but it also adds queueing delay and does not add CPU. The structural fixes are spreading queues across more CPUs with RSS and IRQ affinity, keeping application threads off the CPUs that service receive interrupts, or moving receive work into threaded NAPI so the scheduler can see and weigh it. netdev_budget is the last knob I reach for, because a larger budget makes each softirq round longer and moves the cost onto whatever task that CPU interrupted.
Drop reasons have made this work far less speculative than it was. Before them, a drop was an address in a stack trace and an argument about which counter to believe. Now the kernel says, for most drops, which queue refused the packet and why, and the few places where it does not, ring overruns and drops that carry no specific reason like the veth ring, are known and checkable. The work left for the engineer is to know which queue each counter belongs to, and to look in the right namespace.
المراجع
- net/core/hotdata.c (struct net_hotdata defaults), Linux v7.2 Linux kernel source, torvalds/linux
- drivers/net/ethernet/intel/igb/igb.h (IGB_DEFAULT_RXD, IGB_RX_BUFFER_WRITE), Linux v7.2 Linux kernel source, torvalds/linux
- drivers/net/ethernet/intel/igb/e1000_82575.h (union e1000_adv_rx_desc), Linux v7.2 Linux kernel source, torvalds/linux
- Intel 82575EB Gigabit Ethernet Controller Software Developer's Manual (324632-003), section 14.9.31, Receive No Buffers Count (RNBC) Intel, document mirror on ManualsOnline
- Intel 82575EB Gigabit Ethernet Controller Software Developer's Manual (324632-003), section 14.9.5, Missed Packets Count (MPC) Intel, document mirror on ManualsOnline
- drivers/net/ethernet/intel/igb/igb_ethtool.c (driver statistics), Linux v7.2 Linux kernel source, torvalds/linux
- Intel 82575EB Gigabit Ethernet Controller Software Developer's Manual (324632-003), receive queue Drop_En field Intel, document mirror on ManualsOnline
- drivers/net/ethernet/intel/igb/igb_main.c (igb_msix_ring, igb_poll, igb_clean_rx_irq, igb_setup_srrctl, igb_update_stats), Linux v7.2 Linux kernel source, torvalds/linux
- NAPI, Documentation/networking/napi.rst, Linux v7.2 Linux kernel documentation
- include/linux/netdevice.h (napi_struct, struct gro_node, softnet_data, NAPI_POLL_WEIGHT), Linux v7.2 Linux kernel source, torvalds/linux
- net/core/dev.c (net_rx_action, __napi_poll, enqueue_to_backlog, skb_flow_limit, __netif_receive_skb_core, __netif_receive_skb_list_core, dev_kfree_skb_any_reason, net_tx_action), Linux v7.2 Linux kernel source, torvalds/linux
- Documentation for /proc/sys/net/, Documentation/admin-guide/sysctl/net.rst, Linux v7.2 Linux kernel documentation
- kernel/softirq.c (handle_softirqs, MAX_SOFTIRQ_TIME, MAX_SOFTIRQ_RESTART), Linux v7.2 Linux kernel source, torvalds/linux
- net/core/gro.c (dev_gro_receive, skb_gro_receive, MAX_GRO_SKBS), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/tcp_offload.c (tcp_gro_receive), Linux v7.2 Linux kernel source, torvalds/linux
- include/net/gro.h (gro_normal_one, gro_normal_list), Linux v7.2 Linux kernel source, torvalds/linux
- Scaling in the Linux Networking Stack, Documentation/networking/scaling.rst, Linux v7.2 Linux kernel documentation
- net/core/dev.h (FLOW_LIMIT_HISTORY, struct sd_flow_limit), Linux v7.2 Linux kernel source, torvalds/linux
- drivers/net/veth.c (veth_xmit, veth_forward_skb, veth_skb_is_eligible_for_gro, veth_fix_features, VETH_RING_SIZE), Linux v7.2 Linux kernel source, torvalds/linux
- net/core/sock.c (skb_set_owner_w, sock_wfree), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/tcp_output.c (__tcp_transmit_skb, tcp_wfree), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/tcp_input.c (tcp_conn_request), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/ip_output.c (__ip_append_data, ip_send_unicast_reply), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/tcp_ipv4.c (tcp_v4_send_reset, ipv4_tcp_sk), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/ip_input.c (ip_rcv, ip_list_rcv, ip_local_deliver), Linux v7.2 Linux kernel source, torvalds/linux
- include/net/dropreason-core.h (enum skb_drop_reason), Linux v7.2 Linux kernel source, torvalds/linux
- net/ipv4/udp.c (__udp_queue_rcv_skb, __udp_enqueue_schedule_skb), Linux v7.2 Linux kernel source, torvalds/linux
- net/core/skbuff.c (sk_skb_reason_drop), Linux v7.2 Linux kernel source, torvalds/linux
- include/trace/events/skb.h (kfree_skb tracepoint), Linux v7.2 Linux kernel source, torvalds/linux
- include/linux/skbuff.h (kfree_skb_reason), Linux v7.2 Linux kernel source, torvalds/linux
- Top-level Makefile (CONFIG_FRAME_POINTER compiler flags), Linux v7.2 Linux kernel source, torvalds/linux
- net/core/net-procfs.c (softnet_seq_show), Linux v7.2 Linux kernel source, torvalds/linux
- bpftrace CHANGELOG, v0.24.2 bpftrace project
- bpftrace standard library (ksym, kstack), v0.24.2 bpftrace project