Index: share/man/man9/ifiq_input.9 =================================================================== RCS file: /cvs/src/share/man/man9/ifiq_input.9,v diff -u -p -r1.4 ifiq_input.9 --- share/man/man9/ifiq_input.9 31 Mar 2022 17:27:23 -0000 1.4 +++ share/man/man9/ifiq_input.9 22 Sep 2024 23:56:54 -0000 @@ -25,12 +25,31 @@ .In net/if_var.h .Ft int .Fn ifiq_input "struct ifiqueue *ifiq" "struct mbuf_list *ml" -.Ft void +.Ft int .Fn ifiq_enqueue "struct ifiqueue *ifiq" "struct mbuf *m" .Sh DESCRIPTION The network interface input queue (ifiqueue) API provides functions for network drivers to queue received packets for processing by the network stack. +.Pp +The ifiqueue API also implements the following functionality on +behalf of network interface drivers: +.Pp +.Bl -enum -compact -offset indent +.It +Counting the received packets and bytes for the interface. +.It +Assigning the interface index and rdomain to each packet. +.It +Presenting each packet to the Berkely Packet Filter (BPF) and +dropping it if requested by the filter. +.It +Dropping packets in +.Fn ifiq_input +if the +.Dv IFXF_MONITOR +interface flag is set. +.El .Bl -tag -width Ds .It Fn ifiq_input "struct ifiqueue *ifq" "struct mbuf_list *ml" Enqueue the list of mbufs in @@ -46,6 +65,8 @@ Enqueue the mbuf on the .Fa ifiq interface input queue and notify the network stack to process it. +.Fn ifiq_enqueue +will drop the packet if it was unable to be queued. .El .Sh CONTEXT .Fn ifiq_input @@ -62,5 +83,10 @@ For example, if mbufs are being received hardware managed with the interface RX ring API, .Xr if_rxr_livelocked 9 can be called to indicate to the hardware that backpressure is required. +.Pp +.Fn ifiq_enqueue +returns zero if the mbuf was successfully queued, or non-zero if +the packet was unable to be queued. .Sh SEE ALSO +.Xr bpf_mtap 9 , .Xr if_rxr_livelocked 9 Index: sys/net/ifq.c =================================================================== RCS file: /cvs/src/sys/net/ifq.c,v diff -u -p -r1.53 ifq.c --- sys/net/ifq.c 10 Nov 2023 15:51:24 -0000 1.53 +++ sys/net/ifq.c 22 Sep 2024 23:56:55 -0000 @@ -794,6 +794,7 @@ int ifiq_enqueue(struct ifiqueue *ifiq, struct mbuf *m) { struct ifnet *ifp = ifiq->ifiq_if; + unsigned int len; #if NBPFILTER > 0 caddr_t if_bpf = ifp->if_bpf; #endif @@ -820,9 +821,21 @@ ifiq_enqueue(struct ifiqueue *ifiq, stru mtx_enter(&ifiq->ifiq_mtx); ifiq->ifiq_packets++; ifiq->ifiq_bytes += m->m_pkthdr.len; - ifiq->ifiq_enqueues++; - ml_enqueue(&ifiq->ifiq_ml, m); + + len = ml_len(&ifiq->ifiq_ml); + if (len > ifiq_maxlen_drop) + ifiq->ifiq_qdrops++; + else { + ifiq->ifiq_enqueues++; + ml_enqueue(&ifiq->ifiq_ml, m); + m = NULL; + } mtx_leave(&ifiq->ifiq_mtx); + + if (m != NULL) { + m_freem(m); + return (1); + } task_add(ifiq->ifiq_softnet, &ifiq->ifiq_task);