189a68827SSam Leffler.\" $NetBSD: pfil.9,v 1.22 2003/07/01 13:04:06 wiz Exp $ 289a68827SSam Leffler.\" 3*b252313fSGleb Smirnoff.\" Copyright (c) 2019 Gleb Smirnoff <glebius@FreeBSD.org> 4e9c7bebfSDarren Reed.\" Copyright (c) 1996 Matthew R. Green 5e9c7bebfSDarren Reed.\" All rights reserved. 6e9c7bebfSDarren Reed.\" 7e9c7bebfSDarren Reed.\" Redistribution and use in source and binary forms, with or without 8e9c7bebfSDarren Reed.\" modification, are permitted provided that the following conditions 9e9c7bebfSDarren Reed.\" are met: 10e9c7bebfSDarren Reed.\" 1. Redistributions of source code must retain the above copyright 11e9c7bebfSDarren Reed.\" notice, this list of conditions and the following disclaimer. 12e9c7bebfSDarren Reed.\" 2. Redistributions in binary form must reproduce the above copyright 13e9c7bebfSDarren Reed.\" notice, this list of conditions and the following disclaimer in the 14e9c7bebfSDarren Reed.\" documentation and/or other materials provided with the distribution. 15e9c7bebfSDarren Reed.\" 3. The name of the author may not be used to endorse or promote products 16e9c7bebfSDarren Reed.\" derived from this software without specific prior written permission. 17e9c7bebfSDarren Reed.\" 18e9c7bebfSDarren Reed.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19e9c7bebfSDarren Reed.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20e9c7bebfSDarren Reed.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21e9c7bebfSDarren Reed.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22e9c7bebfSDarren Reed.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23e9c7bebfSDarren Reed.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24e9c7bebfSDarren Reed.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25e9c7bebfSDarren Reed.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26e9c7bebfSDarren Reed.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27e9c7bebfSDarren Reed.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28e9c7bebfSDarren Reed.\" SUCH DAMAGE. 29e9c7bebfSDarren Reed.\" 3008aa4ea3SDarren Reed.\" $FreeBSD$ 31bf7f20c2SRuslan Ermilov.\" 32*b252313fSGleb Smirnoff.Dd January 28, 2019 33e9c7bebfSDarren Reed.Dt PFIL 9 34e9c7bebfSDarren Reed.Os 35e9c7bebfSDarren Reed.Sh NAME 36e9c7bebfSDarren Reed.Nm pfil , 3789a68827SSam Leffler.Nm pfil_head_register , 3889a68827SSam Leffler.Nm pfil_head_unregister , 39*b252313fSGleb Smirnoff.Nm pfil_link , 40*b252313fSGleb Smirnoff.Nm pfil_run_hooks 41e9c7bebfSDarren Reed.Nd packet filter interface 42e9c7bebfSDarren Reed.Sh SYNOPSIS 4332eef9aeSRuslan Ermilov.In sys/param.h 4432eef9aeSRuslan Ermilov.In sys/mbuf.h 4532eef9aeSRuslan Ermilov.In net/pfil.h 46*b252313fSGleb Smirnoff.Ft pfil_head_t 47*b252313fSGleb Smirnoff.Fn pfil_head_register "struct pfil_head_args *args" 484dab1a18SAlexander V. Chernikov.Ft void 49*b252313fSGleb Smirnoff.Fn pfil_head_unregister "struct pfil_head_t *head" 50*b252313fSGleb Smirnoff.Ft pfil_hook_t 51*b252313fSGleb Smirnoff.Fn pfil_add_hook "struct pfil_hook_args *" 524dab1a18SAlexander V. Chernikov.Ft void 53*b252313fSGleb Smirnoff.Fn pfil_remove_hook "pfil_hook_t" 54*b252313fSGleb Smirnoff.Ft int 55*b252313fSGleb Smirnoff.Fn pfil_link "struct pfil_link_args *args" 56*b252313fSGleb Smirnoff.Ft int 57*b252313fSGleb Smirnoff.Fn pfil_run_hooks "phil_head_t *" "pfil_packet_t" "struct ifnet *" "int" "struct inpcb *" 58e9c7bebfSDarren Reed.Sh DESCRIPTION 59e9c7bebfSDarren ReedThe 60e9c7bebfSDarren Reed.Nm 61*b252313fSGleb Smirnoffframework allows for a specified function or a list of functions 62*b252313fSGleb Smirnoffto be invoked for every incoming or outgoing packet for a particular 63*b252313fSGleb Smirnoffnetwork I/O stream. 6489a68827SSam LefflerThese hooks may be used to implement a firewall or perform packet 6589a68827SSam Lefflertransformations. 66e9c7bebfSDarren Reed.Pp 67*b252313fSGleb SmirnoffPacket filtering points, for historical reasons named 68*b252313fSGleb Smirnoff.Em heads , 69*b252313fSGleb Smirnoffare registered with 7089a68827SSam Leffler.Fn pfil_head_register . 71*b252313fSGleb SmirnoffThe function is supplied with special versioned 72*b252313fSGleb Smirnoff.Vt struct pfil_head_args 73*b252313fSGleb Smirnoffstructure that specifies type and features of the head as well as 74*b252313fSGleb Smirnoffhuman readable name. 75*b252313fSGleb SmirnoffIf the filtering point to be ever destroyed, the subsystem that 76*b252313fSGleb Smirnoffcreated it must unregister it with call to 77*b252313fSGleb Smirnoff.Fn pfil_head_unregister . 7889a68827SSam Leffler.Pp 79*b252313fSGleb SmirnoffPacket filtering systems may register arbitrary number of filters, 80*b252313fSGleb Smirnofffor historical reasons named 81*b252313fSGleb Smirnoff.Em hooks . 82*b252313fSGleb SmirnoffTo register a new hook 8389a68827SSam Leffler.Fn pfil_add_hook 84*b252313fSGleb Smirnoffwith special versioned 85*b252313fSGleb Smirnoff.Vt struct pfil_hook_args 86*b252313fSGleb Smirnoffstructure is called. 87*b252313fSGleb SmirnoffThe structure specifies type and features of the hook, pointer to 88*b252313fSGleb Smirnoffthe actual filtering function and user readable name of the filtering 89*b252313fSGleb Smirnoffmodule and ruleset name. 90*b252313fSGleb SmirnoffLater hooks can be removed with 9189a68827SSam Leffler.Fn pfil_remove_hook 924dab1a18SAlexander V. Chernikovfunctions. 9354202ab3SAlexander V. Chernikov.Pp 94*b252313fSGleb SmirnoffTo connect existing 95*b252313fSGleb Smirnoff.Em hook 96*b252313fSGleb Smirnoffto an existing 97*b252313fSGleb Smirnoff.Em head 98*b252313fSGleb Smirnofffunction 99*b252313fSGleb Smirnoff.Fn pfil_link 100*b252313fSGleb Smirnoffshall be used. 101*b252313fSGleb SmirnoffThe function is supplied with versioned 102*b252313fSGleb Smirnoff.Vt struct pfil_link_args 103*b252313fSGleb Smirnoffstructure that specifies either literal names of hook and head or 104*b252313fSGleb Smirnoffpointers to them. 105*b252313fSGleb SmirnoffTypically 106*b252313fSGleb Smirnoff.Fn pfil_link 107*b252313fSGleb Smirnoffis called by filtering modules to autoregister their default ruleset 108*b252313fSGleb Smirnoffand default filtering points. 109*b252313fSGleb SmirnoffIt also serves on the kernel side of 110*b252313fSGleb Smirnoff.Xr ioctl 2 111*b252313fSGleb Smirnoffwhen user changes 112*b252313fSGleb Smirnoff.Nm 113*b252313fSGleb Smirnoffconfiguration with help of 114*b252313fSGleb Smirnoff.Xr pfilctl 8 115*b252313fSGleb Smirnoffutility. 116*b252313fSGleb Smirnoff.Pp 117*b252313fSGleb SmirnoffFor every packet traveling through a 118*b252313fSGleb Smirnoff.Em head 119*b252313fSGleb Smirnoffthe latter shall invoke 120*b252313fSGleb Smirnoff.Fn pfil_run_hooks . 121*b252313fSGleb SmirnoffThe function can accept either 122*b252313fSGleb Smirnoff.Vt struct mbuf * 123*b252313fSGleb Smirnoffpointer or a 124*b252313fSGleb Smirnoff.Vt void * 125*b252313fSGleb Smirnoffpointer and length. 126*b252313fSGleb SmirnoffIn case if a hooked filtering module cannot understand 127*b252313fSGleb Smirnoff.Vt void * 128*b252313fSGleb Smirnoffpointer 129*b252313fSGleb Smirnoff.Nm 130*b252313fSGleb Smirnoffwill provide it with a fake one. 131*b252313fSGleb SmirnoffAll calls to 132*b252313fSGleb Smirnoff.Fn pfil_run_hooks 133*b252313fSGleb Smirnoffare performed in network 134*b252313fSGleb Smirnoff.Xr epoch 9 . 135*b252313fSGleb Smirnoff.Sh HEADS (filtering points) 136*b252313fSGleb SmirnoffBy default kernel creates the following heads: 137*b252313fSGleb Smirnoff.Bl -tag -width "ethernet" 138*b252313fSGleb Smirnoff.It inet 13921d172a3SGleb SmirnoffIPv4 packets. 140*b252313fSGleb Smirnoff.It inet6 14121d172a3SGleb SmirnoffIPv6 packets. 142*b252313fSGleb Smirnoff.It ethernet 14354202ab3SAlexander V. ChernikovLink-layer packets. 14454202ab3SAlexander V. Chernikov.El 14589a68827SSam Leffler.Pp 146*b252313fSGleb SmirnoffDefault rulesets are automatically linked to these heads to preserve 147*b252313fSGleb Smirnoffhistorical behavavior. 1489cbda590SRuslan Ermilov.Sh SEE ALSO 149*b252313fSGleb Smirnoff.Xr ipfilter 4 , 150*b252313fSGleb Smirnoff.Xr ipfw 4 , 151*b252313fSGleb Smirnoff.Xr pf 4 , 152*b252313fSGleb Smirnoff.Xr pfilctl 8 153e9c7bebfSDarren Reed.Sh HISTORY 154e9c7bebfSDarren ReedThe 155e9c7bebfSDarren Reed.Nm 156e9c7bebfSDarren Reedinterface first appeared in 157e9c7bebfSDarren Reed.Nx 1.3 . 158e9c7bebfSDarren ReedThe 159e9c7bebfSDarren Reed.Nm 160*b252313fSGleb Smirnoffinterface was imported into 1610e87afb6SSimon L. B. Nielsen.Fx 5.2 . 162*b252313fSGleb SmirnoffIn 163*b252313fSGleb Smirnoff.Fx 13.0 164*b252313fSGleb Smirnoffthe interface was significantly rewritten. 165