]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/pf/man/pf.4
This commit was generated by cvs2svn to compensate for changes in r133665,
[FreeBSD/FreeBSD.git] / contrib / pf / man / pf.4
1 .\"     $OpenBSD: pf.4,v 1.48 2004/03/27 17:15:30 henning Exp $
2 .\"
3 .\" Copyright (C) 2001, Kjell Wooding.  All rights reserved.
4 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\" 3. Neither the name of the project nor the names of its contributors
14 .\"    may be used to endorse or promote products derived from this software
15 .\"    without specific prior written permission.
16 .\"
17 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" SUCH DAMAGE.
28 .\"
29 .\" $FreeBSD$
30 .\"
31 .Dd June 24, 2001
32 .Dt PF 4
33 .Os
34 .Sh NAME
35 .Nm pf
36 .Nd packet filter
37 .Sh SYNOPSIS
38 .Cd "options PFIL_HOOKS"
39 .Cd "device pf"
40 .Sh DESCRIPTION
41 Packet filtering takes place in the kernel.
42 A pseudo-device,
43 .Pa /dev/pf ,
44 allows userland processes to control the
45 behavior of the packet filter through an
46 .Xr ioctl 2
47 interface.
48 There are commands to enable and disable the filter, load rulesets,
49 add and remove individual rules or state table entries,
50 and retrieve statistics.
51 The most commonly used functions are covered by
52 .Xr pfctl 8 .
53 .Pp
54 Manipulations like loading a ruleset that involve more than a single
55 ioctl call require a so-called ticket, which prevents the occurrence of
56 multiple concurrent manipulations.
57 .Pp
58 Fields of ioctl parameter structures that refer to packet data (like
59 addresses and ports) are generally expected in network byte-order.
60 .Sh FILES
61 .Bl -tag -width /dev/pf -compact
62 .It Pa /dev/pf
63 packet filtering device.
64 .El
65 .Sh IOCTL INTERFACE
66 pf supports the following
67 .Xr ioctl 2
68 commands:
69 .Bl -tag -width xxxxxx
70 .It Dv DIOCSTART
71 Starts the packet filter.
72 .It Dv DIOCSTOP
73 Stops the packet filter.
74 .It Dv DIOCSTARTALTQ
75 Starts the ALTQ bandwidth control system.
76 .It Dv DIOCSTOPALTQ
77 Stops the ALTQ bandwidth control system.
78 .It Dv DIOCBEGINADDRS  Fa "struct pfioc_pooladdr"
79 .Bd -literal
80 struct pfioc_pooladdr {
81         u_int32_t               action;
82         u_int32_t               ticket;
83         u_int32_t               nr;
84         u_int32_t               r_num;
85         u_int8_t                r_action;
86         u_int8_t                r_last;
87         u_int8_t                af;
88         char                    anchor[PF_ANCHOR_NAME_SIZE];
89         char                    ruleset[PF_RULESET_NAME_SIZE];
90         struct pf_pooladdr      addr;
91 };
92 .Ed
93 .Pp
94 Clears the buffer address pool
95 and returns a
96 .Va ticket
97 for subsequent DIOCADDADDR, DIOCADDRULE and DIOCCHANGERULE calls.
98 .It Dv DIOCADDADDR     Fa "struct pfioc_pooladdr"
99 .Pp
100 Adds pool address
101 .Va addr
102 to the buffer address pool to be used in the following
103 DIOCADDRULE or DIOCCHANGERULE call.
104 All other members of the structure are ignored.
105 .It Dv DIOCADDRULE     Fa "struct pfioc_rule"
106 .Bd -literal
107 struct pfioc_rule {
108         u_int32_t       action;
109         u_int32_t       ticket;
110         u_int32_t       pool_ticket;
111         u_int32_t       nr;
112         char            anchor[PF_ANCHOR_NAME_SIZE];
113         char            ruleset[PF_RULESET_NAME_SIZE];
114         struct pf_rule  rule;
115 };
116 .Ed
117 .Pp
118 Adds
119 .Va rule
120 at the end of the inactive ruleset.
121 Requires
122 .Va ticket
123 obtained through preceding DIOCXBEGIN call, and
124 .Va pool_ticket
125 obtained through DIOCBEGINADDRS call.
126 DIOCADDADDR must also be called if any pool addresses are required.
127 The optional
128 .Va anchor
129 and
130 .Va ruleset
131 names indicate the anchor and ruleset in which to append the rule.
132 .Va nr
133 and
134 .Va action
135 are ignored.
136 .It Dv DIOCADDALTQ     Fa "struct pfioc_altq"
137 Adds
138 .Bd -literal
139 struct pfioc_altq {
140         u_int32_t       action;
141         u_int32_t       ticket;
142         u_int32_t       nr;
143         struct pf_altq   altq;
144 };
145 .Ed
146 .It Dv DIOCGETRULES    Fa "struct pfioc_rule"
147 Returns
148 .Va ticket
149 for subsequent DIOCGETRULE calls and
150 .Va nr
151 of rules in the active ruleset.
152 .It Dv DIOCGETRULE     Fa "struct pfioc_rule"
153 Returns
154 .Va rule
155 number
156 .Va nr
157 using
158 .Va ticket
159 obtained through a preceding DIOCGETRULES call.
160 .It Dv DIOCGETADDRS    Fa "struct pfioc_pooladdr"
161 Returns
162 .Va ticket
163 for subsequent DIOCGETADDR calls and
164 .Va nr
165 of pool addresses in the rule specified with
166 .Va r_action ,
167 .Va r_num ,
168 .Va anchor
169 and
170 .Va ruleset .
171 .It Dv DIOCGETADDR     Fa "struct pfioc_pooladdr"
172 Returns pool address
173 .Va addr
174 number
175 .Va nr
176 from the rule specified with
177 .Va r_action ,
178 .Va r_num ,
179 .Va anchor
180 and
181 .Va ruleset
182 using
183 .Va ticket
184 obtained through a preceding DIOCGETADDRS call.
185 .It Dv DIOCGETALTQS    Fa "struct pfioc_altq"
186 Returns
187 .Va ticket
188 for subsequent DIOCGETALTQ calls and
189 .Va nr
190 of queues in the active list.
191 .It Dv DIOCGETALTQ     Fa "struct pfioc_altq"
192 Returns
193 .Va altq
194 number
195 .Va nr
196 using
197 .Va ticket
198 obtained through a preceding DIOCGETALTQS call.
199 .It Dv DIOCGETQSTATS   Fa "struct pfioc_qstats"
200 Returns statistics on a queue.
201 .Bd -literal
202 struct pfioc_qstats {
203         u_int32_t        ticket;
204         u_int32_t        nr;
205         void            *buf;
206         int              nbytes;
207         u_int8_t         scheduler;
208 };
209 .Ed
210 .Pp
211 A pointer to a buffer of statistics
212 .Va buf
213 of length
214 .Va nbytes
215 for the queue specified by
216 .Va nr .
217 .It Dv DIOCADDSTATE    Fa "struct pfioc_state"
218 Adds a state entry.
219 .It Dv DIOCGETSTATE    Fa "struct pfioc_state"
220 .Bd -literal
221 struct pfioc_state {
222         u_int32_t        nr;
223         struct pf_state  state;
224 };
225 .Ed
226 .Pp
227 Extracts the entry with the specified number from the state table.
228 .It Dv DIOCKILLSTATES  Fa "struct pfioc_state_kill"
229 Removes matching entries from the state table.
230 Returns the number of killed states in psk_af.
231 .Bd -literal
232 struct pfioc_state_kill {
233         int                     psk_af;
234         int                     psk_proto;
235         struct pf_rule_addr     psk_src;
236         struct pf_rule_addr     psk_dst;
237         char                    psk_ifname[IFNAMSIZ];
238 };
239 .Ed
240 .It Dv DIOCCLRSTATES  Fa "struct pfioc_state_kill"
241 Clears all states.
242 It works like
243 .Dv DIOCKILLSTATES ,
244 but ignores the psk_af, psk_proto, psk_src and psk_dst fields of the
245 .Fa pfioc_state_kill
246 structure.
247 .It Dv DIOCSETSTATUSIF Fa "struct pfioc_if"
248 .Bd -literal
249 struct pfioc_if {
250         char             ifname[IFNAMSIZ];
251 };
252 .Ed
253 .Pp
254 Specifies the interface for which statistics are accumulated.
255 .It Dv DIOCGETSTATUS   Fa "struct pf_status"
256 .Bd -literal
257 struct pf_status {
258         u_int64_t       counters[PFRES_MAX];
259         u_int64_t       fcounters[FCNT_MAX];
260         u_int64_t       scounters[SCNT_MAX];
261         u_int64_t       pcounters[2][2][3];
262         u_int64_t       bcounters[2][2];
263         u_int64_t       stateid;
264         u_int32_t       running;
265         u_int32_t       states;
266         u_int32_t       src_nodes;
267         u_int32_t       since;
268         u_int32_t       debug;
269         u_int32_t       hostid;
270         char            ifname[IFNAMSIZ];
271 };
272 .Ed
273 .Pp
274 Gets the internal packet filter statistics.
275 .It Dv DIOCCLRSTATUS
276 Clears the internal packet filter statistics.
277 .It Dv DIOCNATLOOK     Fa "struct pfioc_natlook"
278 Looks up a state table entry by source and destination addresses and ports.
279 .Bd -literal
280 struct pfioc_natlook {
281         struct pf_addr   saddr;
282         struct pf_addr   daddr;
283         struct pf_addr   rsaddr;
284         struct pf_addr   rdaddr;
285         u_int16_t        sport;
286         u_int16_t        dport;
287         u_int16_t        rsport;
288         u_int16_t        rdport;
289         sa_family_t      af;
290         u_int8_t         proto;
291         u_int8_t         direction;
292 };
293 .Ed
294 .It Dv DIOCSETDEBUG    Fa "u_int32_t"
295 Sets the debug level.
296 .Bd -literal
297 enum    { PF_DEBUG_NONE=0, PF_DEBUG_URGENT=1, PF_DEBUG_MISC=2 };
298 .Ed
299 .It Dv DIOCGETSTATES   Fa "struct pfioc_states"
300 .Bd -literal
301 struct pfioc_states {
302         int     ps_len;
303         union {
304                 caddr_t psu_buf;
305                 struct pf_state *psu_states;
306         } ps_u;
307 #define ps_buf          ps_u.psu_buf
308 #define ps_states       ps_u.psu_states
309 };
310 .Ed
311 .It Dv DIOCCHANGERULE  Fa "struct pfioc_rule"
312 Adds or removes the
313 .Va rule
314 in the ruleset specified by
315 .Va rule.action .
316 .Bd -literal
317 enum    { PF_CHANGE_ADD_HEAD=1, PF_CHANGE_ADD_TAIL=2,
318           PF_CHANGE_ADD_BEFORE=3, PF_CHANGE_ADD_AFTER=4,
319           PF_CHANGE_REMOVE=5, PF_CHANGE_GET_TICKET=6 };
320 .Ed
321 .Pp
322 The type of operation to be performed is indicated by
323 .Va action .
324 .Pp
325 .Va ticket
326 must be set to the value obtained with PF_CHANGE_GET_TICKET
327 for all actions except PF_CHANGE_GET_TICKET.
328 .Va pool_ticket
329 must be set to the value obtained with the DIOCBEGINADDRS call
330 for all actions except PF_CHANGE_REMOVE and PF_CHANGE_GET_TICKET.
331 .Pp
332 .Va anchor
333 and
334 .Va ruleset
335 indicate which anchor and ruleset the operation applies to.
336 .Va nr
337 indicates the rule number against which PF_CHANGE_ADD_BEFORE,
338 PF_CHANGE_ADD_AFTER or PF_CHANGE_REMOVE actions are applied.
339 .It Dv DIOCCHANGEADDR  Fa "struct pfioc_pooladdr"
340 Adds or removes a pool address
341 .Va addr
342 from a rule specified with
343 .Va r_action ,
344 .Va r_num ,
345 .Va anchor
346 and
347 .Va ruleset .
348 .It Dv DIOCSETTIMEOUT  Fa "struct pfioc_tm"
349 .Bd -literal
350 struct pfioc_tm {
351         int              timeout;
352         int              seconds;
353 };
354 .Ed
355 .It Dv DIOCGETTIMEOUT  Fa "struct pfioc_tm"
356 .It Dv DIOCCLRRULECTRS
357 Clear per-rule statistics.
358 .It Dv DIOCSETLIMIT   Fa "struct pfioc_limit"
359 Sets hard limits on the memory pools used by the packet filter.
360 .Bd -literal
361 struct pfioc_limit {
362         int             index;
363         unsigned        limit;
364 };
365 .Ed
366 .It Dv DIOCGETLIMIT   Fa "struct pfioc_limit"
367 .It Dv DIOCRCLRTABLES Fa "struct pfioc_table"
368 Clear all tables.
369 All the IOCTLs that manipulate radix tables
370 use the same structure described below.
371 For
372 .Dv DIOCRCLRTABLES, pfrio_ndel contains on exit the number
373 of tables deleted.
374 .Bd -literal
375 struct pfioc_table {
376         struct pfr_table         pfrio_table;
377         void                    *pfrio_buffer;
378         int                      pfrio_esize;
379         int                      pfrio_size;
380         int                      pfrio_size2;
381         int                      pfrio_nadd;
382         int                      pfrio_ndel;
383         int                      pfrio_nchange;
384         int                      pfrio_flags;
385         int                      pfrio_ticket;
386 };
387 #define pfrio_exists    pfrio_nadd
388 #define pfrio_nzero     pfrio_nadd
389 #define pfrio_nmatch    pfrio_nadd
390 #define pfrio_naddr     pfrio_size2
391 #define pfrio_setflag   pfrio_size2
392 #define pfrio_clrflag   pfrio_nadd
393 .Ed
394 .It Dv DIOCRADDTABLES Fa "struct pfioc_table"
395 Creates one or more tables.
396 On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table structures.
397 On exit, pfrio_nadd contains the number of tables effectively created.
398 .Bd -literal
399 struct pfr_table {
400         char                     pfrt_anchor[PF_ANCHOR_NAME_SIZE];
401         char                     pfrt_ruleset[PF_RULESET_NAME_SIZE];
402         char                     pfrt_name[PF_TABLE_NAME_SIZE];
403         u_int32_t                pfrt_flags;
404         u_int8_t                 pfrt_fback;
405 };
406 .Ed
407 .It Dv DIOCRDELTABLES Fa "struct pfioc_table"
408 Deletes one or more tables.
409 On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table structures.
410 On exit, pfrio_nadd contains the number of tables effectively deleted.
411 .It Dv DIOCRGETTABLES Fa "struct pfioc_table"
412 Get the list of all tables.
413 On entry, pfrio_buffer[pfrio_size] contains a valid writeable buffer for
414 pfr_table structures.
415 On exit, pfrio_size contains the number of tables written into the buffer.
416 If the buffer is too small, the kernel does not store anything but just
417 returns the required buffer size, without error.
418 .It Dv DIOCRGETTSTATS Fa "struct pfioc_table"
419 Like
420 .Dv DIOCRGETTABLES ,
421 but returns an array of pfr_tstats structures.
422 .Bd -literal
423 struct pfr_tstats {
424         struct pfr_table pfrts_t;
425         u_int64_t        pfrts_packets
426                              [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
427         u_int64_t        pfrts_bytes
428                              [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
429         u_int64_t        pfrts_match;
430         u_int64_t        pfrts_nomatch;
431         long             pfrts_tzero;
432         int              pfrts_cnt;
433         int              pfrts_refcnt[PFR_REFCNT_MAX];
434 };
435 #define pfrts_name      pfrts_t.pfrt_name
436 #define pfrts_flags     pfrts_t.pfrt_flags
437 .Ed
438 .It Dv DIOCRCLRTSTATS Fa "struct pfioc_table"
439 Clears the statistics of one or more tables.
440 On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table structures.
441 On exit, pfrio_nzero contains the number of tables effectively cleared.
442 .It Dv DIOCRCLRADDRS Fa "struct pfioc_table"
443 Clear all addresses in a table.
444 On entry, pfrio_table contains the table to clear.
445 On exit, pfrio_ndel contains the number of addresses removed.
446 .It Dv DIOCRADDADDRS Fa "struct pfioc_table"
447 Add one or more addresses to a table.
448 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
449 contains the list of pfr_addr structures to add.
450 On exit, pfrio_nadd contains the number of addresses effectively added.
451 .Bd -literal
452 struct pfr_addr {
453         union {
454                 struct in_addr   _pfra_ip4addr;
455                 struct in6_addr  _pfra_ip6addr;
456         }                pfra_u;
457         u_int8_t         pfra_af;
458         u_int8_t         pfra_net;
459         u_int8_t         pfra_not;
460         u_int8_t         pfra_fback;
461 };
462 #define pfra_ip4addr    pfra_u._pfra_ip4addr
463 #define pfra_ip6addr    pfra_u._pfra_ip6addr
464 .Ed
465 .It Dv DIOCRDELADDRS Fa "struct pfioc_table"
466 Delete one or more addresses from a table.
467 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
468 contains the list of pfr_addr structures to delete.
469 On exit, pfrio_ndel contains the number of addresses effectively deleted.
470 .It Dv DIOCRSETADDRS Fa "struct pfioc_table"
471 Replace the content of a table by a new address list.
472 This is the most complicated command, which uses all the structure members.
473 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
474 contains the new list of pfr_addr structures.
475 In addition to that, if size2 is nonzero, pfrio_buffer[pfrio_size..pfrio_size2]
476 must be a writeable buffer, into which the kernel can copy the addresses that
477 have been deleted during the replace operation.
478 On exit, pfrio_ndel, pfrio_nadd and pfrio_nchange contain the number of
479 addresses deleted, added and changed by the kernel.
480 If pfrio_size2 was set on
481 entry, pfrio_size2 will point to the size of the buffer used, exactly like
482 .Dv DIOCRGETADDRS .
483 .It Dv DIOCRGETADDRS Fa "struct pfioc_table"
484 Get all the addresses of a table.
485 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
486 contains a valid writeable buffer for pfr_addr structures.
487 On exit, pfrio_size contains the number of addresses written into the buffer.
488 If the buffer was too small, the kernel does not store anything but just
489 return the required buffer size, without returning an error.
490 .It Dv DIOCRGETASTATS Fa "struct pfioc_table"
491 Like
492 .Dv DIOCRGETADDRS ,
493 but returns an array of pfr_astats structures.
494 .Bd -literal
495 struct pfr_astats {
496         struct pfr_addr  pfras_a;
497         u_int64_t        pfras_packets
498                              [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
499         u_int64_t        pfras_bytes
500                              [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
501         long             pfras_tzero;
502 };
503 .Ed
504 .It Dv DIOCRCLRASTATS Fa "struct pfioc_table"
505 Clears the statistics of one or more addresses.
506 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
507 contains a table of pfr_addr structures to clear.
508 On exit, pfrio_nzero contains the number of addresses effectively cleared.
509 .It Dv DIOCRTSTADDRS Fa "struct pfioc_table"
510 Test if the given addresses match a table.
511 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
512 contains a table of pfr_addr structures to test.
513 On exit, the kernel updates the pfr_addr table by setting the pfra_fback
514 member appropriately.
515 .It Dv DIOCRSETTFLAGS Fa "struct pfioc_table"
516 Change the
517 .Va const
518 or
519 .Va persist
520 flag of a table.
521 On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table structures,
522 and pfrio_setflag contains the flags to add, while pfrio_clrflag contains the
523 flags to remove.
524 On exit, pfrio_nchange and pfrio_ndel contain the number of tables altered
525 or deleted by the kernel.
526 Yes, tables can be deleted if one removes the
527 .Va persist
528 flag of an unreferenced table.
529 .It Dv DIOCRINADEFINE Fa "struct pfioc_table"
530 Defines a table in the inactive set.
531 On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size]
532 contains the list of pfr_addr structures to put in the table.
533 A valid ticket must also be supplied to pfrio_ticket.
534 On exit, pfrio_nadd contains 0 if the table was already defined in the
535 inactive list, or 1 if a new table has been created.
536 pfrio_naddr contains the number of addresses effectively put in the table.
537 .It Dv DIOCXBEGIN Fa "struct pfioc_trans"
538 .Bd -literal
539 #define PF_RULESET_ALTQ         (PF_RULESET_MAX)
540 #define PF_RULESET_TABLE        (PF_RULESET_MAX+1)
541 struct pfioc_trans {
542         int              size;  /* number of elements */
543         int              esize; /* size of each element in bytes */
544         struct pfioc_trans_e {
545                 int             rs_num;
546                 char            anchor[PF_ANCHOR_NAME_SIZE];
547                 char            ruleset[PF_RULESET_NAME_SIZE];
548                 u_int32_t       ticket;
549         }               *array;
550 };
551 .Ed
552 .Pp
553 Clears all the inactive rulesets specified in the
554 .Fa "struct pfioc_trans_e"
555 array.
556 For each ruleset, a ticket is returned for subsequent "add rule" IOCTLs,
557 as well as for the
558 .Dv DIOCXCOMMIT
559 and
560 .Dv DIOCXROLLBACK
561 calls.
562 .It Dv DIOCXCOMMIT Fa "struct pfioc_trans"
563 Atomically switch a vector of inactive rulesets to the active rulesets.
564 Implemented as a standard 2-phase commit, which will either fail for all
565 rulesets or completely succeed.
566 All tickets need to be valid.
567 Returns
568 .Dv EBUSY
569 if a concurrent process is trying to update some of the same rulesets
570 concurrently.
571 .It Dv DIOCXROLLBACK Fa "struct pfioc_trans"
572 Clean up the kernel by undoing all changes that have taken place on the
573 inactive rulesets since the last
574 .Dv DIOCXBEGIN .
575 .Dv DIOCXROLLBACK
576 will silently ignore rulesets for which the ticket is invalid.
577 .It Dv DIOCFPFLUSH
578 Flush the passive OS fingerprint table.
579 .It Dv DIOCFPADD Fa "struct pf_osfp_ioctl"
580 .Bd -literal
581 struct pf_osfp_ioctl {
582         struct pf_osfp_entry {
583                 SLIST_ENTRY(pf_osfp_entry) fp_entry;
584                 pf_osfp_t               fp_os;
585                 char                    fp_class_nm[PF_OSFP_LEN];
586                 char                    fp_version_nm[PF_OSFP_LEN];
587                 char                    fp_subtype_nm[PF_OSFP_LEN];
588         }                       fp_os;
589         u_int16_t               fp_mss;
590         u_int16_t               fp_wsize;
591         u_int16_t               fp_psize;
592         u_int8_t                fp_ttl;
593         u_int8_t                fp_wscale;
594         u_int8_t                fp_flags;
595         int                     fp_getnum;
596 };
597 .Ed
598 .Pp
599 Add a passive OS fingerprint to the table.
600 Set
601 .Va fp_os.fp_os
602 to the packed fingerprint,
603 .Va fp_os.fp_class_nm
604 to the name of the class (Linux, Windows, etc),
605 .Va fp_os.fp_version_nm
606 to the name of the version (NT, 95, 98), and
607 .Va fp_os.fp_subtype_nm
608 to the name of the subtype or patchlevel.
609 The members
610 .Va fp_mss ,
611 .Va fp_wsize ,
612 .Va fp_psize ,
613 .Va fp_ttl ,
614 and
615 .Va fp_wscale
616 are set to the TCP MSS, the TCP window size, the IP length and the IP TTL of
617 the TCP SYN packet respectively.
618 The
619 .Va fp_flags
620 member is filled according to the net/pfvar.h include file PF_OSFP_* defines.
621 The
622 .Va fp_getnum
623 is not used with this ioctl.
624 .Pp
625 The structure's slack space must be zeroed for correct operation; memset
626 the whole structure to zero before filling and sending to the kernel.
627 .It Dv DIOCFPGET Fa "struct pf_osfp_ioctl"
628 .Bd -literal
629 struct pf_osfp_ioctl {
630         struct pf_osfp_entry {
631                 SLIST_ENTRY(pf_osfp_entry) fp_entry;
632                 pf_osfp_t               fp_os;
633                 char                    fp_class_nm[PF_OSFP_LEN];
634                 char                    fp_version_nm[PF_OSFP_LEN];
635                 char                    fp_subtype_nm[PF_OSFP_LEN];
636         }                       fp_os;
637         u_int16_t               fp_mss;
638         u_int16_t               fp_wsize;
639         u_int16_t               fp_psize;
640         u_int8_t                fp_ttl;
641         u_int8_t                fp_wscale;
642         u_int8_t                fp_flags;
643         int                     fp_getnum;
644 };
645 .Ed
646 .Pp
647 Get the passive OS fingerprint number
648 .Va fp_getnum
649 from the kernel's fingerprint list.
650 The rest of the structure members will come back filled.
651 Get the whole list by repeatedly incrementing the
652 .Va fp_getnum
653 number until the ioctl returns EBUSY.
654 .It Dv DIOCGETSRCNODES Fa "struct pfioc_src_nodes"
655 .Bd -literal
656 struct pfioc_src_nodes {
657         int     psn_len;
658         union {
659                 caddr_t          psu_buf;
660                 struct pf_src_node      *psu_src_nodes;
661         } psn_u;
662 #define psn_buf         psn_u.psu_buf
663 #define psn_src_nodes   psn_u.psu_src_nodes
664 };
665 .Ed
666 .Pp
667 Get the list of source nodes kept by the
668 .Ar sticky-address
669 and
670 .Ar source-track
671 options.
672 The ioctl must be called once with
673 .Va psn_len
674 set to 0.
675 If the ioctl returns without error,
676 .Va psn_len
677 will be set to the size of the buffer required to hold all the
678 .Va pf_src_node
679 structures held in the table.
680 A buffer of this size should then be allocated, and a pointer to this buffer
681 placed in
682 .Va psn_buf .
683 The ioctl must then be called again to fill this buffer with the actual
684 source node data.
685 After the ioctl call
686 .Va psn_len
687 will be set to the length of the buffer actually used.
688 .It Dv DIOCCLRSRCNODES Fa "struct pfioc_table"
689 Clear the tree of source tracking nodes.
690 .It Dv DIOCIGETIFACES Fa "struct pfioc_iface"
691 Gets the list of interfaces and interface drivers known to
692 .Nm .
693 All the IOCTLs that manipulate interfaces
694 use the same structure described below:
695 .Bd -literal
696 struct pfioc_iface {
697         char                     pfiio_name[IFNAMSIZ];
698         void                    *pfiio_buffer;
699         int                      pfiio_esize;
700         int                      pfiio_size;
701         int                      pfiio_nzero;
702         int                      pfiio_flags;
703 };
704
705 #define PFI_FLAG_GROUP     0x0001  /* gets groups of interfaces */
706 #define PFI_FLAG_INSTANCE  0x0002  /* gets single interfaces */
707 #define PFI_FLAG_ALLMASK   0x0003
708 .Ed
709 .Pp
710 If not empty,
711 .Va pfiio_name
712 can be used to restrict the search to a specific interface or driver.
713 .Va pfiio_buffer[pfiio_size]
714 is the user-supplied buffer for returning the data.
715 On entry,
716 .Va pfiio_size
717 represents the number of
718 .Va pfi_if
719 entries that can fit into the buffer.
720 The kernel will replace this value by the real number of entries it wants
721 to return.
722 .Va pfiio_esize
723 should be set to sizeof(struct pfi_if).
724 .Va pfiio_flags
725 should be set to
726 .Dv PFI_FLAG_GROUP , PFI_FLAG_INSTANCE ,
727 or both to tell the kernel to return a group of interfaces
728 (drivers, like "fxp"), real interface instances (like "fxp1") or both.
729 The data is returned in the
730 .Va pfi_if
731 structure described below:
732 .Bd -literal
733 struct pfi_if {
734         char                             pfif_name[IFNAMSIZ];
735         u_int64_t                        pfif_packets[2][2][2];
736         u_int64_t                        pfif_bytes[2][2][2];
737         u_int64_t                        pfif_addcnt;
738         u_int64_t                        pfif_delcnt;
739         long                             pfif_tzero;
740         int                              pfif_states;
741         int                              pfif_rules;
742         int                              pfif_flags;
743 };
744
745 #define PFI_IFLAG_GROUP         0x0001  /* group of interfaces */
746 #define PFI_IFLAG_INSTANCE      0x0002  /* single instance */
747 #define PFI_IFLAG_CLONABLE      0x0010  /* clonable group */
748 #define PFI_IFLAG_DYNAMIC       0x0020  /* dynamic group */
749 #define PFI_IFLAG_ATTACHED      0x0040  /* interface attached */
750 #define PFI_IFLAG_REFERENCED    0x0080  /* referenced by rules */
751 .Ed
752 .It Dv DIOCICLRISTATS Fa "struct pfioc_iface"
753 Clear the statistics counters of one or more interfaces.
754 .Va pfiio_name
755 and
756 .Va pfrio_flags
757 can be used to select which interfaces need to be cleared.
758 The filtering process is the same as for
759 .Dv DIOCIGETIFACES .
760 .Va pfiio_nzero
761 will be set by the kernel to the number of interfaces and drivers
762 that have been cleared.
763 .El
764 .Sh EXAMPLES
765 The following example demonstrates how to use the DIOCNATLOOK command
766 to find the internal host/port of a NATed connection.
767 .Bd -literal
768 #include <sys/types.h>
769 #include <sys/socket.h>
770 #include <sys/ioctl.h>
771 #include <sys/fcntl.h>
772 #include <net/if.h>
773 #include <netinet/in.h>
774 #include <net/pfvar.h>
775 #include <err.h>
776 #include <stdio.h>
777 #include <stdlib.h>
778
779 u_int32_t
780 read_address(const char *s)
781 {
782         int a, b, c, d;
783
784         sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d);
785         return htonl(a << 24 | b << 16 | c << 8 | d);
786 }
787
788 void
789 print_address(u_int32_t a)
790 {
791         a = ntohl(a);
792         printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255,
793             a >> 8 & 255, a & 255);
794 }
795
796 int
797 main(int argc, char *argv[])
798 {
799         struct pfioc_natlook nl;
800         int dev;
801
802         if (argc != 5) {
803                 printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\\n",
804                     argv[0]);
805                 return 1;
806         }
807
808         dev = open("/dev/pf", O_RDWR);
809         if (dev == -1)
810                 err(1, "open(\\"/dev/pf\\") failed");
811
812         memset(&nl, 0, sizeof(struct pfioc_natlook));
813         nl.saddr.v4.s_addr      = read_address(argv[1]);
814         nl.sport                = htons(atoi(argv[2]));
815         nl.daddr.v4.s_addr      = read_address(argv[3]);
816         nl.dport                = htons(atoi(argv[4]));
817         nl.af                   = AF_INET;
818         nl.proto                = IPPROTO_TCP;
819         nl.direction            = PF_IN;
820
821         if (ioctl(dev, DIOCNATLOOK, &nl))
822                 err(1, "DIOCNATLOOK");
823
824         printf("internal host ");
825         print_address(nl.rsaddr.v4.s_addr);
826         printf(":%u\\n", ntohs(nl.rsport));
827         return 0;
828 }
829 .Ed
830 .Sh SEE ALSO
831 .Xr ioctl 2 ,
832 .Xr bridge 4 ,
833 .Xr pflog 4 ,
834 .Xr pfsync 4 ,
835 .Xr pfctl 8
836 .Sh HISTORY
837 The
838 .Nm
839 packet filtering mechanism first appeared in
840 .Ox 3.0 .