16b8eb655SRobert Watson.\" 26b8eb655SRobert Watson.\" Copyright (c) 2009 Robert N. M. Watson 36b8eb655SRobert Watson.\" All rights reserved. 46b8eb655SRobert Watson.\" 56b8eb655SRobert Watson.\" Redistribution and use in source and binary forms, with or without 66b8eb655SRobert Watson.\" modification, are permitted provided that the following conditions 76b8eb655SRobert Watson.\" are met: 86b8eb655SRobert Watson.\" 1. Redistributions of source code must retain the above copyright 96b8eb655SRobert Watson.\" notice(s), this list of conditions and the following disclaimer as 106b8eb655SRobert Watson.\" the first lines of this file unmodified other than the possible 116b8eb655SRobert Watson.\" addition of one or more copyright notices. 126b8eb655SRobert Watson.\" 2. Redistributions in binary form must reproduce the above copyright 136b8eb655SRobert Watson.\" notice(s), this list of conditions and the following disclaimer in the 146b8eb655SRobert Watson.\" documentation and/or other materials provided with the distribution. 156b8eb655SRobert Watson.\" 166b8eb655SRobert Watson.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 176b8eb655SRobert Watson.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 186b8eb655SRobert Watson.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 196b8eb655SRobert Watson.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 206b8eb655SRobert Watson.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 216b8eb655SRobert Watson.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 226b8eb655SRobert Watson.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 236b8eb655SRobert Watson.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 246b8eb655SRobert Watson.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 256b8eb655SRobert Watson.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 266b8eb655SRobert Watson.\" DAMAGE. 276b8eb655SRobert Watson.\" 28*b4f1582fSMark Johnston.Dd April 12, 2023 296b8eb655SRobert Watson.Dt NETISR 9 306b8eb655SRobert Watson.Os 316b8eb655SRobert Watson.Sh NAME 326b8eb655SRobert Watson.Nm netisr 336b8eb655SRobert Watson.Nd Kernel network dispatch service 346b8eb655SRobert Watson.Sh SYNOPSIS 356b8eb655SRobert Watson.In net/netisr.h 366b8eb655SRobert Watson.Ft void 376b8eb655SRobert Watson.Fn netisr_register "const struct netisr_handler *nhp" 386b8eb655SRobert Watson.Ft void 396b8eb655SRobert Watson.Fn netisr_unregister "const struct netisr_handler *nhp" 406b8eb655SRobert Watson.Ft int 416b8eb655SRobert Watson.Fn netisr_dispatch "u_int proto" "struct mbuf *m" 426b8eb655SRobert Watson.Ft int 436b8eb655SRobert Watson.Fn netisr_dispatch_src "u_int proto" "uintptr_t source" "struct mbuf *m" 446b8eb655SRobert Watson.Ft int 456b8eb655SRobert Watson.Fn netisr_queue "u_int proto" "struct mbuf *m" 466b8eb655SRobert Watson.Ft int 476b8eb655SRobert Watson.Fn netisr_queue_src "u_int proto" "uintptr_t source" "struct mbuf *m" 486b8eb655SRobert Watson.Ft void 496b8eb655SRobert Watson.Fn netisr_clearqdrops "const struct netisr_handler *nhp" 506b8eb655SRobert Watson.Ft void 516b99842aSEd Schouten.Fn netisr_getqdrops "const struct netisr_handler *nhp" "uint64_t *qdropsp" 5244549f13SBjoern A. Zeeb.Ft void 536b8eb655SRobert Watson.Fn netisr_getqlimit "const struct netisr_handler *nhp" "u_int *qlimitp" 546b8eb655SRobert Watson.Ft int 556b8eb655SRobert Watson.Fn netisr_setqlimit "const struct netisr_handler *nhp" "u_int qlimit" 566b8eb655SRobert Watson.Ft u_int 576b8eb655SRobert Watson.Fn netisr_default_flow2cpu "u_int flowid" 586b8eb655SRobert Watson.Ft u_int 596b8eb655SRobert Watson.Fn netisr_get_cpucount "void" 606b8eb655SRobert Watson.Ft u_int 616b8eb655SRobert Watson.Fn netisr_get_cpuid "u_int cpunumber" 62484149deSBjoern A. Zeeb.Pp 63484149deSBjoern A. ZeebWith optional virtual network stack support enabled via the following kernel 64484149deSBjoern A. Zeebcompile option: 65484149deSBjoern A. Zeeb.Bd -ragged -offset indent 66484149deSBjoern A. Zeeb.Cd "options VIMAGE" 67484149deSBjoern A. Zeeb.Ed 68484149deSBjoern A. Zeeb.Ft void 69484149deSBjoern A. Zeeb.Fn netisr_register_vnet "const struct netisr_handler *nhp" 70484149deSBjoern A. Zeeb.Ft void 71484149deSBjoern A. Zeeb.Fn netisr_unregister_vnet "const struct netisr_handler *nhp" 726b8eb655SRobert Watson.Sh DESCRIPTION 736b8eb655SRobert WatsonThe 746b8eb655SRobert Watson.Nm 756b8eb655SRobert Watsonkernel interface suite allows device drivers (and other packet sources) to 766b8eb655SRobert Watsondirect packets to protocols for directly dispatched or deferred processing. 77497c391cSRobert WatsonProtocol registration and work stream statistics may be monitored using 78497c391cSRobert Watson.Xr netstat 1 . 796b8eb655SRobert Watson.Ss Protocol registration 806b8eb655SRobert WatsonProtocols register and unregister handlers using 816b8eb655SRobert Watson.Fn netisr_register 826b8eb655SRobert Watsonand 836b8eb655SRobert Watson.Fn netisr_unregister , 846b8eb655SRobert Watsonand may also manage queue limits and statistics using the 856b8eb655SRobert Watson.Fn netisr_clearqdrops , 866b8eb655SRobert Watson.Fn netisr_getqdrops , 876b8eb655SRobert Watson.Fn netisr_getqlimit , 886b8eb655SRobert Watsonand 896b8eb655SRobert Watson.Fn netisr_setqlimit . 906b8eb655SRobert Watson.Pp 91484149deSBjoern A. ZeebIn case of VIMAGE kernels each virtual network stack (vnet), that is not the 92484149deSBjoern A. Zeebdefault base system network stack, calls 93484149deSBjoern A. Zeeb.Fn netisr_register_vnet 94484149deSBjoern A. Zeeband 95484149deSBjoern A. Zeeb.Fn netisr_unregister_vnet 96484149deSBjoern A. Zeebto enable or disable packet processing by the 97484149deSBjoern A. Zeeb.Nm 98484149deSBjoern A. Zeebfor each protocol. 99484149deSBjoern A. ZeebDisabling will also purge any outstanding packet from the protocol queue. 100484149deSBjoern A. Zeeb.Pp 1016b8eb655SRobert Watson.Nm 1026b8eb655SRobert Watsonsupports multi-processor execution of handlers, and relies on a combination 1036b8eb655SRobert Watsonof source ordering and protocol-specific ordering and work-placement 104f0e6364eSMark Johnstonpolicies to decide how to distribute work across one or more worker 1056b8eb655SRobert Watsonthreads. 1066b8eb655SRobert WatsonRegistering protocols will declare one of three policies: 1076b8eb655SRobert Watson.Bl -tag -width NETISR_POLICY_SOURCE 1086b8eb655SRobert Watson.It Dv NETISR_POLICY_SOURCE 1096b8eb655SRobert Watson.Nm 1106b8eb655SRobert Watsonshould maintain source ordering without advice from the protocol. 1116b8eb655SRobert Watson.Nm 1126b8eb655SRobert Watsonwill ignore any flow IDs present on 1136b8eb655SRobert Watson.Vt mbuf 1146b8eb655SRobert Watsonheaders for the purposes of work placement. 1156b8eb655SRobert Watson.It Dv NETISR_POLICY_FLOW 1166b8eb655SRobert Watson.Nm 1176b8eb655SRobert Watsonshould maintain flow ordering as defined by the 1186b8eb655SRobert Watson.Vt mbuf 1196b8eb655SRobert Watsonheader flow ID field. 1206b8eb655SRobert WatsonIf the protocol implements 1216b8eb655SRobert Watson.Va nh_m2flow , 1226b8eb655SRobert Watsonthen 1236b8eb655SRobert Watson.Nm 124c2025a76SJoel Dahlwill query the protocol in the event that the 1256b8eb655SRobert Watson.Vt mbuf 1266b8eb655SRobert Watsondoesn't have a flow ID, falling back on source ordering. 1276b8eb655SRobert Watson.It NETISR_POLICY_CPU 1286b8eb655SRobert Watson.Nm 1296b8eb655SRobert Watsonwill entirely delegate all work placement decisions to the protocol, 1306b8eb655SRobert Watsonquerying 1316b8eb655SRobert Watson.Va nh_m2cpuid 1326b8eb655SRobert Watsonfor each packet. 1336b8eb655SRobert Watson.El 1346b8eb655SRobert Watson.Pp 1356b8eb655SRobert WatsonRegistration is declared using 1366b8eb655SRobert Watson.Vt "struct netisr_handler" , 1376b8eb655SRobert Watsonwhose fields are defined as follows: 1386b8eb655SRobert Watson.Bl -tag -width "netisr_handler_t nh_handler" 1396b8eb655SRobert Watson.It Vt "const char *" Va nh_name 1406b8eb655SRobert WatsonUnique character string name of the protocol, which may be included in 141225636dcSEdward Tomasz Napierala.Xr sysctl 3 1426b8eb655SRobert WatsonMIB names, so should not contain whitespace. 1436b8eb655SRobert Watson.It Vt netisr_handler_t Va nh_handler 1446b8eb655SRobert WatsonProtocol handler function that will be invoked on each packet received for 1456b8eb655SRobert Watsonthe protocol. 1466b8eb655SRobert Watson.It Vt netisr_m2flow_t Va nh_m2flow 147eff7715cSHans Petter SelaskyOptional protocol function to generate a flow ID and set a valid 148eff7715cSHans Petter Selaskyhashtype for packets that enter the 1496b8eb655SRobert Watson.Nm 1506b8eb655SRobert Watsonwith 151eff7715cSHans Petter Selasky.Dv M_HASHTYPE_GET(m) 152eff7715cSHans Petter Selaskyequal to 153eff7715cSHans Petter Selasky.Dv M_HASHTYPE_NONE . 1546b8eb655SRobert WatsonWill be used only with 1556b8eb655SRobert Watson.Dv NETISR_POLICY_FLOW . 1566b8eb655SRobert Watson.It Vt netisr_m2cpuid_t Va nh_m2cpuid 1576b8eb655SRobert WatsonProtocol function to determine what CPU a packet should be processed on. 1586b8eb655SRobert WatsonWill be used only with 1596b8eb655SRobert Watson.Dv NETISR_POLICY_CPU . 160ed655c8cSBjoern A. Zeeb.It Vt netisr_drainedcpu_t Va nh_drainedcpu 161ed655c8cSBjoern A. ZeebOptional callback function that will be invoked when a per-CPU queue 162ed655c8cSBjoern A. Zeebwas drained. 163ed655c8cSBjoern A. ZeebIt will never fire for directly dispatched packets. 164ed655c8cSBjoern A. ZeebUnless fully understood, this special-purpose function should not be used. 165ed655c8cSBjoern A. Zeeb.\" In case you intend to use this please send 50 chocolate bars to each 166ed655c8cSBjoern A. Zeeb.\" of rwatson and bz and wait for an answer. 1676b8eb655SRobert Watson.It Vt u_int Va nh_proto 1686b8eb655SRobert WatsonProtocol number used by both protocols to identify themselves to 1696b8eb655SRobert Watson.Nm , 1706b8eb655SRobert Watsonand by packet sources to select what handler will be used to process 1716b8eb655SRobert Watsonpackets. 1726b8eb655SRobert WatsonA table of supported protocol numbers appears below. 1736b8eb655SRobert WatsonFor implementation reasons, protocol numbers great than 15 are currently 1746b8eb655SRobert Watsonunsupported. 1756b8eb655SRobert Watson.It Vt u_int Va nh_qlimit 1766b8eb655SRobert WatsonThe maximum per-CPU queue depth for the protocol; due to internal 1776b8eb655SRobert Watsonimplementation details, the effective queue depth may be as much as twice 1786b8eb655SRobert Watsonthis number. 1796b8eb655SRobert Watson.It Vt u_int Va nh_policy 1806b8eb655SRobert WatsonThe ordering and work placement policy for the protocol, as described 1816b8eb655SRobert Watsonearlier. 1826b8eb655SRobert Watson.El 1836b8eb655SRobert Watson.Ss Packet source interface 1846b8eb655SRobert WatsonPacket sources, such as network interfaces, may request protocol processing 1856b8eb655SRobert Watsonusing the 1866b8eb655SRobert Watson.Fn netisr_dispatch 1876b8eb655SRobert Watsonand 1886b8eb655SRobert Watson.Fn netisr_queue 1896b8eb655SRobert Watsoninterfaces. 1906b8eb655SRobert WatsonBoth accept a protocol number and 1916b8eb655SRobert Watson.Vt mbuf 1926b8eb655SRobert Watsonargument, but while 1936b8eb655SRobert Watson.Fn netisr_queue 194b06cfd40SJoel Dahlwill always execute the protocol handler asynchronously in a deferred 1956b8eb655SRobert Watsoncontext, 1966b8eb655SRobert Watson.Fn netisr_dispatch 1976b8eb655SRobert Watsonwill optionally direct dispatch if permitted by global and per-protocol 1986b8eb655SRobert Watsonpolicy. 1996b8eb655SRobert Watson.Pp 2006b8eb655SRobert WatsonIn order to provide additional load balancing and flow information, 2016b8eb655SRobert Watsonpacket sources may also specify an opaque source identifier, which in 2026b8eb655SRobert Watsonpractice might be a network interface number or socket pointer, using 2036b8eb655SRobert Watsonthe 2046b8eb655SRobert Watson.Fn netisr_dispatch_src 2056b8eb655SRobert Watsonand 2066b8eb655SRobert Watson.Fn netisr_queue_src 2076b8eb655SRobert Watsonvariants. 2086b8eb655SRobert Watson.Ss Protocol number constants 2096b8eb655SRobert WatsonThe follow protocol numbers are currently defined: 21045c203fcSGleb Smirnoff.Bl -tag -width NETISR_ROUTE 2116b8eb655SRobert Watson.It Dv NETISR_IP 2126b8eb655SRobert WatsonIPv4 2136b8eb655SRobert Watson.It Dv NETISR_IGMP 2146b8eb655SRobert WatsonIGMPv3 loopback 2156b8eb655SRobert Watson.It Dv NETISR_ROUTE 2166b8eb655SRobert WatsonRouting socket loopback 2176b8eb655SRobert Watson.It Dv NETISR_ARP 2186b8eb655SRobert WatsonARP 2196b8eb655SRobert Watson.It Dv NETISR_IPV6 2206b8eb655SRobert WatsonIPv6 2216b8eb655SRobert Watson.El 2226b8eb655SRobert Watson.Sh AUTHORS 2236b8eb655SRobert WatsonThis manual page and the 2246b8eb655SRobert Watson.Nm 2256b8eb655SRobert Watsonimplementation were written by 2266b8eb655SRobert Watson.An Robert N. M. Watson . 227