---
name: "pf"
section: "4"
platform: "openbsd"
package: "man"
version: "8.0-current-20261101"
release: "OpenBSD 8.0-current (2026-11-01)"
platforms: ["linux", "freebsd", "openbsd"]
url: "https://new.carta.tech/pf"
---

# pf(4)

packet filter

## NAME

**pf** – packet filter

## SYNOPSIS

**pseudo-device pf**

## DESCRIPTION

Packet filtering takes place in the kernel. A pseudo-device, */dev/pf*, allows userland processes to control the behavior of the packet filter through an [ioctl(2)](/ioctl/2.md) interface. There are commands to enable and disable the filter, load rulesets, add and remove individual rules or state table entries, and retrieve statistics. The most commonly used functions are covered by [pfctl(8)](/pfctl/8.md).

Operations loading or reading a ruleset that involve more than a single [ioctl(2)](/ioctl/2.md) call require a so-called **ticket**, which allows **pf** to deal with concurrent operations. For certain [ioctl(2)](/ioctl/2.md) commands (currently DIOCGETRULES) the number of tickets a program can get is limited. The programs must explicitly release their tickets using the DIOCXEND command to avoid hitting the limit. All tickets which are not freed by DIOCXEND are released when the program closes */dev/pf*.

Fields of [ioctl(2)](/ioctl/2.md) parameter structures that refer to packet data (like addresses and ports) are generally expected in network byte-order.

Rules and address tables are contained in so-called *anchors*. When servicing an [ioctl(2)](/ioctl/2.md) request, if the anchor field of the argument structure is empty, the kernel will use the default anchor (i.e., the main ruleset) in operations. Anchors are specified by name and may be nested, with components separated by ‘/’ characters, similar to how file system hierarchies are laid out. The final component of the anchor path is the anchor under which operations will be performed. Anchor names with characters after the terminating null byte are considered invalid; if used in an ioctl, EINVAL will be returned.

## IOCTL INTERFACE

**pf** supports the following [ioctl(2)](/ioctl/2.md) commands, available through ⟨net/pfvar.h⟩:

- DIOCSTART

  Start the packet filter.

- DIOCSTOP

  Stop the packet filter.

- DIOCADDRULE *struct pfioc\_rule \*pr*

  ```
  struct pfioc_rule {
  	u_int32_t	action;
  	u_int32_t	ticket;
  	u_int32_t	nr;
  	char		anchor[PATH_MAX];
  	char		anchor_call[PATH_MAX];
  	struct pf_rule	rule;
  };
  ```

  Add *rule* at the end of the inactive ruleset. This call requires a *ticket* obtained through a preceding DIOCXBEGIN call. The optional *anchor* name indicates the anchor in which to append the rule. *nr* and *action* are ignored.

- DIOCADDQUEUE *struct pfioc\_queue \*q*

  Add a queue.

  ```
  struct pfioc_queue {
  	u_int32_t		ticket;
  	u_int			nr;
  	struct pf_queuespec	queue;
  };
  ```

- DIOCGETRULES *struct pfioc\_rule \*pr*

  Get a *ticket* for subsequent DIOCGETRULE calls and the number *nr* of rules in the active ruleset. The ticket should be released by the DIOCXEND command.

- DIOCGETRULE *struct pfioc\_rule \*pr*

  Get a *rule* by its number *nr* using the *ticket* obtained through a preceding DIOCGETRULES call. If *action* is set to PF\_GET\_CLR\_CNTR, the per-rule statistics on the requested rule are cleared.

- DIOCGETQUEUES *struct pfioc\_queue \*pq*

  Get a *ticket* for subsequent DIOCGETQUEUE calls and the number *nr* of queues in the active list.

- DIOCGETQUEUE *struct pfioc\_queue \*pq*

  Get the queueing discipline by its number *nr* using the *ticket* obtained through a preceding DIOCGETQUEUES call.

- DIOCGETQSTATS *struct pfioc\_qstats \*pq*

  Get the statistics on a queue.

  ```
  struct pfioc_qstats {
  	u_int32_t	 	 ticket;
  	u_int32_t	 	 nr;
  	struct pf_queuespec	 queue;
  	void			*buf;
  	int		 	 nbytes;
  };
  ```

  This call fills in a pointer to the buffer of statistics *buf*, of length *nbytes*, for the queue specified by *nr*.

- DIOCGETRULESETS *struct pfioc\_ruleset \*pr*

  ```
  struct pfioc_ruleset {
  	u_int32_t	 nr;
  	char		 path[PATH_MAX];
  	char		 name[PF_ANCHOR_NAME_SIZE];
  };
  ```

  Get the number *nr* of rulesets (i.e., anchors) directly attached to the anchor named by *path* for use in subsequent DIOCGETRULESET calls. Nested anchors, since they are not directly attached to the given anchor, will not be included. This ioctl returns EINVAL if the given anchor does not exist.

- DIOCGETRULESET *struct pfioc\_ruleset \*pr*

  Get a ruleset (i.e., an anchor) *name* by its number *nr* from the given anchor *path*, the maximum number of which can be obtained from a preceding DIOCGETRULESETS call. This ioctl returns EINVAL if the given anchor does not exist or EBUSY if another process is concurrently updating a ruleset.

- DIOCADDSTATE *struct pfioc\_state \*ps*

  Add a state entry.

  ```
  struct pfioc_state {
  	struct pfsync_state	state;
  };
  ```

- DIOCGETSTATE *struct pfioc\_state \*ps*

  Extract the entry identified by the *id* and *creatorid* fields of the *state* structure from the state table.

- DIOCKILLSTATES *struct pfioc\_state\_kill \*psk*

  Remove matching entries from the state table. This ioctl returns the number of killed states in *psk\_killed*.

  ```
  struct pfioc_state_kill {
  	struct pf_state_cmp	psk_pfcmp;
  	sa_family_t		psk_af;
  	int			psk_proto;
  	struct pf_rule_addr	psk_src;
  	struct pf_rule_addr	psk_dst;
  	char			psk_ifname[IFNAMSIZ];
  	char			psk_label[PF_RULE_LABEL_SIZE];
  	u_int			psk_killed;
  	u_int16_t		psk_rdomain;
  };
  ```

- DIOCCLRSTATES *struct pfioc\_state\_kill \*psk*

  Clear all states. It works like DIOCKILLSTATES, but ignores all fields of the *pfioc\_state\_kill* structure, except *psk\_ifname*.

- DIOCGETSTATUS *struct pf\_status \*s*

  Get the internal packet filter statistics.

  ```
  struct pf_status {
  	u_int64_t	counters[PFRES_MAX];
  	u_int64_t	lcounters[LCNT_MAX];	/* limit counters */
  	u_int64_t	fcounters[FCNT_MAX];
  	u_int64_t	scounters[SCNT_MAX];
  	u_int64_t	pcounters[2][2][3];
  	u_int64_t	bcounters[2][2];
  	u_int64_t	stateid;
  	u_int64_t	syncookies_inflight[2]; /* unACKed SYNcookies */
  	time_t		since;
  	u_int32_t	running;
  	u_int32_t	states;
  	u_int32_t	states_halfopen;
  	u_int32_t	src_nodes;
  	u_int32_t	debug;
  	u_int32_t	hostid;
  	u_int32_t	reass;			/* reassembly */
  	u_int8_t	syncookies_active;
  	u_int8_t	syncookies_mode;	/* never/always/adaptive */
  	u_int8_t	pad[2];
  	char		ifname[IFNAMSIZ];
  	u_int8_t	pf_chksum[PF_MD5_DIGEST_LENGTH];
  };
  ```

- DIOCCLRSTATUS

  Clear the internal packet filter statistics.

- DIOCNATLOOK *struct pfioc\_natlook \*pnl*

  Look up a state table entry by source and destination addresses and ports.

  ```
  struct pfioc_natlook {
  	struct pf_addr	 saddr;
  	struct pf_addr	 daddr;
  	struct pf_addr	 rsaddr;
  	struct pf_addr	 rdaddr;
  	u_int16_t	 rdomain;
  	u_int16_t	 rrdomain;
  	u_int16_t	 sport;
  	u_int16_t	 dport;
  	u_int16_t	 rsport;
  	u_int16_t	 rdport;
  	sa_family_t	 af;
  	u_int8_t	 proto;
  	u_int8_t	 direction;
  };
  ```

  This was primarily used to support transparent proxies with rdr-to rules. New proxies should use divert-to rules instead. These do not require access to the privileged */dev/pf* device and preserve the original destination address for [getsockname(2)](/getsockname/2.md). For SOCK\_DGRAM sockets, the [ip(4)](/ip/4.md) socket options IP\_RECVDSTADDR and IP\_RECVDSTPORT can be used to retrieve the destination address and port.

- DIOCSETDEBUG *u\_int32\_t \*level*

  Set the debug level. See the [syslog(3)](/syslog/3.md) man page for a list of valid debug levels.

- DIOCGETSTATES *struct pfioc\_states \*ps*

  Get state table entries.

  ```
  struct pfioc_states {
  	size_t	ps_len;
  	union {
  		caddr_t		     psu_buf;
  		struct pfsync_state *psu_states;
  	} ps_u;
  #define ps_buf		ps_u.psu_buf
  #define ps_states	ps_u.psu_states
  };
  ```

  If *ps\_len* is non-zero on entry, as many states as possible that can fit into this size will be copied into the supplied buffer *ps\_states*. On exit, *ps\_len* is always set to the total size required to hold all state table entries (i.e., it is set to sizeof(struct pfsync\_state) \* nr).

- DIOCCHANGERULE *struct pfioc\_rule \*pcr*

  Add or remove the *rule* in the ruleset specified by *rule.action*.

  The type of operation to be performed is indicated by *action*, which can be any of the following:

  ```
  enum	{ PF_CHANGE_NONE, PF_CHANGE_ADD_HEAD, PF_CHANGE_ADD_TAIL,
  	  PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER,
  	  PF_CHANGE_REMOVE, PF_CHANGE_GET_TICKET };
  ```

  *ticket* must be set to the value obtained with PF\_CHANGE\_GET\_TICKET for all actions except PF\_CHANGE\_GET\_TICKET. *anchor* indicates to which anchor the operation applies. *nr* indicates the rule number against which PF\_CHANGE\_ADD\_BEFORE, PF\_CHANGE\_ADD\_AFTER, or PF\_CHANGE\_REMOVE actions are applied.

- DIOCSETTIMEOUT *struct pfioc\_tm \*pt*

  ```
  struct pfioc_tm {
  	int		 timeout;
  	int		 seconds;
  };
  ```

  Set the state timeout of *timeout* to *seconds*. The old value will be placed into *seconds*. For possible values of *timeout*, consult the PFTM\_\* values in ⟨net/pfvar.h⟩.

- DIOCGETTIMEOUT *struct pfioc\_tm \*pt*

  Get the state timeout of *timeout*. The value will be placed into the *seconds* field.

- DIOCSETLIMIT *struct pfioc\_limit \*pl*

  Set the hard limits on the memory pools used by the packet filter.

  ```
  struct pfioc_limit {
  	int		index;
  	unsigned	limit;
  };
  enum	{ PF_LIMIT_STATES, PF_LIMIT_SRC_NODES, PF_LIMIT_FRAGS,
  	  PF_LIMIT_TABLES, PF_LIMIT_TABLE_ENTRIES, PF_LIMIT_PKTDELAY_PKTS,
  	  PF_LIMIT_ANCHORS, PF_LIMIT_MAX };
  ```

- DIOCGETLIMIT *struct pfioc\_limit \*pl*

  Get the hard *limit* for the memory pool indicated by *index*.

- DIOCRCLRTABLES *struct pfioc\_table \*io*

  Clear all tables. All the ioctls that manipulate radix tables use the same structure described below. For DIOCRCLRTABLES, *pfrio\_ndel* contains on exit the number of tables deleted.

  ```
  struct pfioc_table {
  	struct pfr_table	 pfrio_table;
  	void			*pfrio_buffer;
  	int			 pfrio_esize;
  	int			 pfrio_size;
  	int			 pfrio_size2;
  	int			 pfrio_nadd;
  	int			 pfrio_ndel;
  	int			 pfrio_nchange;
  	int			 pfrio_flags;
  	u_int32_t		 pfrio_ticket;
  };
  #define pfrio_exists    pfrio_nadd
  #define pfrio_nzero     pfrio_nadd
  #define pfrio_nmatch    pfrio_nadd
  #define pfrio_naddr     pfrio_size2
  #define pfrio_setflag   pfrio_size2
  #define pfrio_clrflag   pfrio_nadd
  ```

- DIOCRADDTABLES *struct pfioc\_table \*io*

  Create one or more tables. On entry, *pfrio\_buffer* must point to an array of *struct* *pfr\_table* containing at least *pfrio\_size* elements. *pfrio\_esize* must be the size of *struct* *pfr\_table*. On exit, *pfrio\_nadd* contains the number of tables effectively created.

  ```
  struct pfr_table {
  	char		pfrt_anchor[PATH_MAX];
  	char		pfrt_name[PF_TABLE_NAME_SIZE];
  	u_int32_t	pfrt_flags;
  	u_int8_t	pfrt_fback;
  };
  ```

- DIOCRDELTABLES *struct pfioc\_table \*io*

  Delete one or more tables. On entry, *pfrio\_buffer* must point to an array of *struct* *pfr\_table* containing at least *pfrio\_size* elements. *pfrio\_esize* must be the size of *struct* *pfr\_table*. On exit, *pfrio\_ndel* contains the number of tables effectively deleted.

- DIOCRGETTABLES *struct pfioc\_table \*io*

  Get the list of all tables. On entry, *pfrio\_buffer\[pfrio\_size\]* contains a valid writeable buffer for *pfr\_table* structures. On exit, *pfrio\_size* contains the number of tables written into the buffer. If the buffer is too small, the kernel does not store anything but just returns the required buffer size, without error.

- DIOCRGETTSTATS *struct pfioc\_table \*io*

  This call is like DIOCRGETTABLES but is used to get an array of *pfr\_tstats* structures.

  ```
  struct pfr_tstats {
  	struct pfr_table pfrts_t;
  	u_int64_t	 pfrts_packets
  			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
  	u_int64_t	 pfrts_bytes
  			     [PFR_DIR_MAX][PFR_OP_TABLE_MAX];
  	u_int64_t	 pfrts_match;
  	u_int64_t	 pfrts_nomatch;
  	time_t		 pfrts_tzero;
  	int		 pfrts_cnt;
  	int		 pfrts_refcnt[PFR_REFCNT_MAX];
  };
  #define pfrts_name	 pfrts_t.pfrt_name
  #define pfrts_flags	 pfrts_t.pfrt_flags
  ```

- DIOCRCLRTSTATS *struct pfioc\_table \*io*

  Clear the statistics of one or more tables. On entry, *pfrio\_buffer* must point to an array of *struct* *pfr\_table* containing at least *pfrio\_size* elements. *pfrio\_esize* must be the size of *struct* *pfr\_table*. On exit, *pfrio\_nzero* contains the number of tables effectively cleared.

- DIOCRCLRADDRS *struct pfioc\_table \*io*

  Clear all addresses in a table. On entry, *pfrio\_table* contains the table to clear. On exit, *pfrio\_ndel* contains the number of addresses removed.

- DIOCRADDADDRS *struct pfioc\_table \*io*

  Add one or more addresses to a table. On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer* must point to an array of *struct* *pfr\_addr* containing at least *pfrio\_size* elements to add to the table. *pfrio\_esize* must be the size of *struct* *pfr\_addr*. On exit, *pfrio\_nadd* contains the number of addresses effectively added.

  ```
  struct pfr_addr {
  	union {
  		struct in_addr	 _pfra_ip4addr;
  		struct in6_addr	 _pfra_ip6addr;
  	}		 pfra_u;
  	char		 pfra_ifname[IFNAMSIZ];
  	u_int32_t	 pfra_states;
  	u_int16_t	 pfra_weight;
  	u_int8_t	 pfra_af;
  	u_int8_t	 pfra_net;
  	u_int8_t	 pfra_not;
  	u_int8_t	 pfra_fback;
  	u_int8_t	 pfra_type;
  	u_int8_t	 pad[7];
  };
  #define pfra_ip4addr    pfra_u._pfra_ip4addr
  #define pfra_ip6addr    pfra_u._pfra_ip6addr
  ```

- DIOCRDELADDRS *struct pfioc\_table \*io*

  Delete one or more addresses from a table. On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer* must point to an array of *struct* *pfr\_addr* containing at least *pfrio\_size* elements to delete from the table. *pfrio\_esize* must be the size of *struct* *pfr\_addr*. On exit, *pfrio\_ndel* contains the number of addresses effectively deleted.

- DIOCRSETADDRS *struct pfioc\_table \*io*

  Replace the content of a table by a new address list. This is the most complicated command, which uses all the structure members.

  On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer* must point to an array of *struct* *pfr\_addr* containing at least *pfrio\_size* elements which become the new contents of the table. *pfrio\_esize* must be the size of *struct* *pfr\_addr*. Additionally, if *pfrio\_size2* is non-zero, *pfrio\_buffer\[pfrio\_size..pfrio\_size2\]* must be a writeable buffer, into which the kernel can copy the addresses that have been deleted during the replace operation. On exit, *pfrio\_ndel*, *pfrio\_nadd*, and *pfrio\_nchange* contain the number of addresses deleted, added, and changed by the kernel. If *pfrio\_size2* was set on entry, *pfrio\_size2* will point to the size of the buffer used, exactly like DIOCRGETADDRS.

- DIOCRGETADDRS *struct pfioc\_table \*io*

  Get all the addresses of a table. On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer\[pfrio\_size\]* contains a valid writeable buffer for *pfr\_addr* structures. On exit, *pfrio\_size* contains the number of addresses written into the buffer. If the buffer was too small, the kernel does not store anything but just returns the required buffer size, without returning an error.

- DIOCRGETASTATS *struct pfioc\_table \*io*

  This call is like DIOCRGETADDRS but is used to get an array of *pfr\_astats* structures.

  ```
  struct pfr_astats {
  	struct pfr_addr	 pfras_a;
  	u_int64_t	 pfras_packets
  			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
  	u_int64_t	 pfras_bytes
  			     [PFR_DIR_MAX][PFR_OP_ADDR_MAX];
  	time_t		 pfras_tzero;
  };
  ```

- DIOCRCLRASTATS *struct pfioc\_table \*io*

  Clear the statistics of one or more addresses. On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer* must point to an array of *struct* *pfr\_addr* containing at least *pfrio\_size* elements to be cleared from the table. *pfrio\_esize* must be the size of *struct* *pfr\_addr*. On exit, *pfrio\_nzero* contains the number of addresses effectively cleared.

- DIOCRTSTADDRS *struct pfioc\_table \*io*

  Test if the given addresses match a table. On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer* must point to an array of *struct* *pfr\_addr* containing at least *pfrio\_size* elements, each of which will be tested for a match in the table. *pfrio\_esize* must be the size of *struct* *pfr\_addr*. On exit, the kernel updates the *pfr\_addr* array by setting the *pfra\_fback* member appropriately.

- DIOCRSETTFLAGS *struct pfioc\_table \*io*

  Change the PFR\_TFLAG\_CONST or PFR\_TFLAG\_PERSIST flags of a table. On entry, *pfrio\_buffer* must point to an array of *struct* *pfr\_table* containing at least *pfrio\_size* elements. *pfrio\_esize* must be the size of *struct* *pfr\_table*. *pfrio\_setflag* must contain the flags to add, while *pfrio\_clrflag* must contain the flags to remove. On exit, *pfrio\_nchange* and *pfrio\_ndel* contain the number of tables altered or deleted by the kernel. Yes, tables can be deleted if one removes the PFR\_TFLAG\_PERSIST flag of an unreferenced table.

- DIOCRINADEFINE *struct pfioc\_table \*io*

  Defines a table in the inactive set. On entry, *pfrio\_table* contains the table ID and *pfrio\_buffer\[pfrio\_size\]* contains an array of *pfr\_addr* structures to put in the table. A valid ticket must also be supplied to *pfrio\_ticket*. On exit, *pfrio\_nadd* contains 0 if the table was already defined in the inactive list or 1 if a new table has been created. *pfrio\_naddr* contains the number of addresses effectively put in the table.

- DIOCXBEGIN *struct pfioc\_trans \*io*

  ```
  struct pfioc_trans {
  	int		 size;	/* number of elements */
  	int		 esize;	/* size of each element in bytes */
  	struct pfioc_trans_e {
  		int		type;
  		char		anchor[PATH_MAX];
  		u_int32_t	ticket;
  	}		*array;
  };
  ```

  Clear all the inactive rulesets specified in the *pfioc\_trans\_e* array. For each ruleset, a ticket is returned for subsequent "add rule" ioctls, as well as for the DIOCXCOMMIT and DIOCXROLLBACK calls.

  Ruleset types, identified by *type*, can be one of the following:

  - PF\_TRANS\_RULESET

    Filter rules.

  - PF\_TRANS\_TABLE

    Address tables.

- DIOCXCOMMIT *struct pfioc\_trans \*io*

  Atomically switch a vector of inactive rulesets to the active rulesets. This call is implemented as a standard two-phase commit, which will either fail for all rulesets or completely succeed. All tickets need to be valid. This ioctl returns EBUSY if another process is concurrently updating some of the same rulesets.

- DIOCXROLLBACK *struct pfioc\_trans \*io*

  Clean up the kernel by undoing all changes that have taken place on the inactive rulesets since the last DIOCXBEGIN. DIOCXROLLBACK will silently ignore rulesets for which the ticket is invalid.

- DIOCXEND *u\_int32\_t \*ticket*

  Release the ticket obtained by the DIOCGETRULES command.

- DIOCSETHOSTID *u\_int32\_t \*hostid*

  Set the host ID, which is used by [pfsync(4)](/pfsync/4.md) to identify which host created state table entries.

- DIOCOSFPFLUSH

  Flush the passive OS fingerprint table.

- DIOCOSFPADD *struct pf\_osfp\_ioctl \*io*

  ```
  struct pf_osfp_ioctl {
  	struct pf_osfp_entry	fp_os;
  	pf_tcpopts_t		fp_tcpopts;	/* packed TCP options */
  	u_int16_t		fp_wsize;	/* TCP window size */
  	u_int16_t		fp_psize;	/* ip->ip_len */
  	u_int16_t		fp_mss;		/* TCP MSS */
  	u_int16_t		fp_flags;
  	u_int8_t		fp_optcnt;	/* TCP option count */
  	u_int8_t		fp_wscale;	/* TCP window scaling */
  	u_int8_t		fp_ttl;		/* IPv4 TTL */
  	int			fp_getnum;	/* DIOCOSFPGET number */
  };
  struct pf_osfp_entry {
  	SLIST_ENTRY(pf_osfp_entry) fp_entry;
  	pf_osfp_t		fp_os;
  	int			fp_enflags;
  #define PF_OSFP_EXPANDED	0x001		/* expanded entry */
  #define PF_OSFP_GENERIC		0x002		/* generic signature */
  #define PF_OSFP_NODETAIL	0x004		/* no p0f details */
  #define PF_OSFP_LEN	32
  	u_char			fp_class_nm[PF_OSFP_LEN];
  	u_char			fp_version_nm[PF_OSFP_LEN];
  	u_char			fp_subtype_nm[PF_OSFP_LEN];
  };
  ```

  Add a passive OS fingerprint to the table. Set *fp\_os.fp\_os* to the packed fingerprint, *fp\_os.fp\_class\_nm* to the name of the class (Linux, Windows, etc), *fp\_os.fp\_version\_nm* to the name of the version (NT, 95, 98), and *fp\_os.fp\_subtype\_nm* to the name of the subtype or patchlevel. The members *fp\_mss*, *fp\_wsize*, *fp\_psize*, *fp\_ttl*, *fp\_optcnt*, and *fp\_wscale* are set to the TCP MSS, the TCP window size, the IP length, the IP TTL, the number of TCP options, and the TCP window scaling constant of the TCP SYN packet, respectively.

  The *fp\_flags* member is filled according to the ⟨net/pfvar.h⟩ include file PF\_OSFP\_\* defines. The *fp\_tcpopts* member contains packed TCP options. Each option uses PF\_OSFP\_TCPOPT\_BITS bits in the packed value. Options include any of PF\_OSFP\_TCPOPT\_NOP, PF\_OSFP\_TCPOPT\_SACK, PF\_OSFP\_TCPOPT\_WSCALE, PF\_OSFP\_TCPOPT\_MSS, or PF\_OSFP\_TCPOPT\_TS.

  The *fp\_getnum* member is not used with this ioctl.

  The structure's slack space must be zeroed for correct operation; [memset(3)](/memset/3.md) the whole structure to zero before filling and sending to the kernel.

- DIOCOSFPGET *struct pf\_osfp\_ioctl \*io*

  Get the passive OS fingerprint number *fp\_getnum* from the kernel's fingerprint list. The rest of the structure members will come back filled. Get the whole list by repeatedly incrementing the *fp\_getnum* number until the ioctl returns EBUSY.

- DIOCGETSRCNODES *struct pfioc\_src\_nodes \*psn*

  ```
  struct pfioc_src_nodes {
  	size_t	psn_len;
  	union {
  		caddr_t		psu_buf;
  		struct pf_src_node	*psu_src_nodes;
  	} psn_u;
  #define psn_buf		psn_u.psu_buf
  #define psn_src_nodes	psn_u.psu_src_nodes
  };
  ```

  Get the list of source nodes kept by sticky addresses and source tracking. The ioctl must be called once with *psn\_len* set to 0. If the ioctl returns without error, *psn\_len* will be set to the size of the buffer required to hold all the *pf\_src\_node* structures held in the table. A buffer of this size should then be allocated, and a pointer to this buffer placed in *psn\_buf*. The ioctl must then be called again to fill this buffer with the actual source node data. After that call, *psn\_len* will be set to the length of the buffer actually used.

- DIOCCLRSRCNODES

  Clear the tree of source tracking nodes.

- DIOCIGETIFACES *struct pfioc\_iface \*io*

  Get the list of interfaces and interface groups known to **pf**. All the ioctls that manipulate interfaces use the same structure described below:

  ```
  struct pfioc_iface {
  	char			 pfiio_name[IFNAMSIZ];
  	void			*pfiio_buffer;
  	int			 pfiio_esize;
  	int			 pfiio_size;
  	int			 pfiio_nzero;
  	int			 pfiio_flags;
  };
  ```

  If not empty, *pfiio\_name* can be used to restrict the search to a specific interface or group. *pfiio\_buffer\[pfiio\_size\]* is the user-supplied buffer for returning the data. On entry, *pfiio\_size* contains the number of *pfi\_kif* entries that can fit into the buffer. The kernel will replace this value by the real number of entries it wants to return. *pfiio\_esize* should be set to sizeof(struct pfi\_kif).

  The data is returned in the *pfi\_kif* structure described below:

  ```
  struct pfi_kif {
  	char				 pfik_name[IFNAMSIZ];
  	RB_ENTRY(pfi_kif)		 pfik_tree;
  	u_int64_t			 pfik_packets[2][2][2];
  	u_int64_t			 pfik_bytes[2][2][2];
  	time_t				 pfik_tzero;
  	int				 pfik_flags;
  	int				 pfik_flags_new;
  	void				*pfik_ah_cookie;
  	struct ifnet			*pfik_ifp;
  	struct ifg_group		*pfik_group;
  	int				 pfik_states;
  	int				 pfik_rules;
  	int				 pfik_routes;
  	int				 pfik_srcnodes;
  	int				 pfik_flagrefs;
  	TAILQ_HEAD(, pfi_dynaddr)	 pfik_dynaddrs;
  };
  ```

- DIOCSETSTATUSIF *struct pfioc\_iface \*pi*

  Specify the interface for which statistics are accumulated.

- DIOCSETIFFLAG *struct pfioc\_iface \*io*

  Set the user settable flags (described above) of the **pf** internal interface description. The filtering process is the same as for DIOCIGETIFACES.

  ```
  #define PFI_IFLAG_SKIP	0x0100	/* skip filtering on interface */
  ```

- DIOCCLRIFFLAG *struct pfioc\_iface \*io*

  Works as DIOCSETIFFLAG above but clears the flags.

- DIOCKILLSRCNODES *struct pfioc\_src\_node\_kill \*psnk*

  Explicitly remove source tracking nodes.

  ```
  struct pfioc_src_node_kill {
  	sa_family_t		 psnk_af;
  	struct pf_rule_addr	 psnk_src;
  	struct pf_rule_addr	 psnk_dst;
  	u_int			 psnk_killed;
  };
  ```

## FILES

- */dev/pf*

  packet filtering device.

## EXAMPLES

The following example demonstrates how to use the DIOCGETLIMIT command to show the hard limit of a memory pool used by the packet filter:

```
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <netinet/in.h>
#include <net/if.h>
#include <net/pfvar.h>
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const struct {
	const char	*name;
	int		index;
} pf_limits[] = {
	{ "states",		PF_LIMIT_STATES },
	{ "src-nodes",		PF_LIMIT_SRC_NODES },
	{ "frags",		PF_LIMIT_FRAGS },
	{ "tables",		PF_LIMIT_TABLES },
	{ "table-entries",	PF_LIMIT_TABLE_ENTRIES },
	{ "anchors",		PF_LIMIT_ANCHORS },
	{ NULL,			0 }
};
void
usage(void)
{
	int i;
	fprintf(stderr, "usage: %s [", getprogname());
	for (i = 0; pf_limits[i].name; i++)
		fprintf(stderr, "%s%s", (i > 0 ? "|" : ""), pf_limits[i].name);
	fprintf(stderr, "]\n");
	exit(1);
}
int
main(int argc, char *argv[])
{
	struct pfioc_limit pl;
	int i, dev;
	int pool_index = -1;
	if (argc != 2)
		usage();
	for (i = 0; pf_limits[i].name; i++)
		if (strcmp(argv[1], pf_limits[i].name) == 0) {
			pool_index = pf_limits[i].index;
			break;
		}
	if (pool_index == -1) {
		warnx("no such memory pool: %s", argv[1]);
		usage();
	}
	dev = open("/dev/pf", O_RDWR);
	if (dev == -1)
		err(1, "open(\"/dev/pf\") failed");
	memset(&pl, 0, sizeof(struct pfioc_limit));
	pl.index = pool_index;
	if (ioctl(dev, DIOCGETLIMIT, &pl) == -1)
		err(1, "DIOCGETLIMIT");
	printf("The %s memory pool has ", pf_limits[i].name);
	if (pl.limit == UINT_MAX)
		printf("unlimited entries.\n");
	else
		printf("a hard limit of %u entries.\n", pl.limit);
	return 0;
}
```

## SEE ALSO

[ioctl(2)](/ioctl/2.md), [bridge(4)](/bridge/4.md), [pflog(4)](/pflog/4.md), [pflow(4)](/pflow/4.md), [pfsync(4)](/pfsync/4.md), [pf.conf(5)](/pf.conf/5.md), [pfctl(8)](/pfctl/8.md)

## HISTORY

The **pf** packet filtering mechanism first appeared in OpenBSD 3.0.
