Index:
CPU_ELAN(4)CPU_SOEKRIS(4)
aac(4)
acd(4)
acpi(4)
acpi_asus(4)
acpi_panasonic(4)
acpi_thermal(4)
acpi_toshiba(4)
acpi_video(4)
ad(4)
adv(4)
adw(4)
afd(4)
agp(4)
agpgart(4)
aha(4)
ahb(4)
ahc(4)
ahd(4)
aic(4)
aio(4)
alpm(4)
altq(4)
amd(4)
amdpm(4)
amr(4)
an(4)
apm(4)
ar(4)
arcmsr(4)
arl(4)
arp(4)
asr(4)
ast(4)
ata(4)
atapicam(4)
ath(4)
ath_hal(4)
atkbd(4)
atkbdc(4)
aue(4)
awi(4)
axe(4)
bfe(4)
bge(4)
bktr(4)
blackhole(4)
bpf(4)
bridge(4)
brooktree(4)
bt(4)
cam(4)
card(4)
cardbus(4)
carp(4)
cbb(4)
ccd(4)
cd(4)
cdce(4)
ch(4)
ciss(4)
cm(4)
cnw(4)
cp(4)
cpufreq(4)
crypto(4)
cryptodev(4)
cs(4)
ct(4)
ctau(4)
cue(4)
cx(4)
cy(4)
da(4)
dc(4)
dcons(4)
dcons_crom(4)
ddb(4)
de(4)
devctl(4)
digi(4)
disc(4)
divert(4)
dpt(4)
dummynet(4)
ed(4)
ef(4)
ehci(4)
el(4)
em(4)
en(4)
ep(4)
esp(4)
ex(4)
exca(4)
faith(4)
fast_ipsec(4)
fatm(4)
fd(4)
fdc(4)
fe(4)
fea(4)
firewire(4)
fla(4)
fpa(4)
fwe(4)
fwip(4)
fwohci(4)
fxp(4)
gbde(4)
gdb(4)
gem(4)
geom(4)
gif(4)
gre(4)
gx(4)
harp(4)
hatm(4)
hfa(4)
hifn(4)
hme(4)
hptmv(4)
i4b(4)
i4bcapi(4)
i4bctl(4)
i4bing(4)
i4bipr(4)
i4bisppp(4)
i4bq921(4)
i4bq931(4)
i4brbch(4)
i4btel(4)
i4btrc(4)
iavc(4)
ichsmb(4)
ichwd(4)
icmp(4)
icmp6(4)
ida(4)
idt(4)
ie(4)
ieee80211(4)
if_an(4)
if_aue(4)
if_awi(4)
if_axe(4)
if_bfe(4)
if_bge(4)
if_cue(4)
if_dc(4)
if_de(4)
if_disc(4)
if_ed(4)
if_ef(4)
if_em(4)
if_en(4)
if_faith(4)
if_fatm(4)
if_fwe(4)
if_fwip(4)
if_fxp(4)
if_gem(4)
if_gif(4)
if_gre(4)
if_gx(4)
if_hatm(4)
if_hme(4)
if_idt(4)
if_kue(4)
if_lge(4)
if_my(4)
if_ndis(4)
if_nge(4)
if_oltr(4)
if_patm(4)
if_pcn(4)
if_ppp(4)
if_re(4)
if_rl(4)
if_rue(4)
if_sbni(4)
if_sbsh(4)
if_sf(4)
if_sis(4)
if_sk(4)
if_sl(4)
if_sn(4)
if_ste(4)
if_stf(4)
if_tap(4)
if_ti(4)
if_tl(4)
if_tun(4)
if_tx(4)
if_txp(4)
if_udav(4)
if_vge(4)
if_vlan(4)
if_vr(4)
if_wb(4)
if_wi(4)
if_xe(4)
if_xl(4)
ifmib(4)
ifpi(4)
ifpi2(4)
ifpnp(4)
ihfc(4)
iic(4)
iicbb(4)
iicbus(4)
iicsmb(4)
iir(4)
imm(4)
inet(4)
inet6(4)
intpm(4)
intro(4)
io(4)
ip(4)
ip6(4)
ipaccounting(4)
ipacct(4)
ipf(4)
ipfirewall(4)
ipfw(4)
ipl(4)
ipnat(4)
ips(4)
ipsec(4)
isic(4)
isp(4)
ispfw(4)
itjc(4)
iwic(4)
ixgb(4)
joy(4)
kame(4)
keyboard(4)
kld(4)
kmem(4)
ktr(4)
kue(4)
led(4)
lge(4)
linux(4)
lnc(4)
lo(4)
longrun(4)
loop(4)
lp(4)
lpbb(4)
lpt(4)
mac(4)
mac_biba(4)
mac_bsdextended(4)
mac_ifoff(4)
mac_lomac(4)
mac_mls(4)
mac_none(4)
mac_partition(4)
mac_portacl(4)
mac_seeotheruids(4)
mac_stub(4)
mac_test(4)
mcd(4)
md(4)
mem(4)
meteor(4)
miibus(4)
mlx(4)
mly(4)
mouse(4)
mpt(4)
mse(4)
mtio(4)
multicast(4)
my(4)
natm(4)
natmip(4)
ncr(4)
ncv(4)
ndis(4)
net(4)
netgraph(4)
netintro(4)
networking(4)
ng_UI(4)
ng_async(4)
ng_atm(4)
ng_atmllc(4)
ng_atmpif(4)
ng_bluetooth(4)
ng_bpf(4)
ng_bridge(4)
ng_bt3c(4)
ng_btsocket(4)
ng_ccatm(4)
ng_cisco(4)
ng_device(4)
ng_echo(4)
ng_eiface(4)
ng_etf(4)
ng_ether(4)
ng_fec(4)
ng_frame_relay(4)
ng_gif(4)
ng_gif_demux(4)
ng_h4(4)
ng_hci(4)
ng_hole(4)
ng_hub(4)
ng_iface(4)
ng_ip_input(4)
ng_ksocket(4)
ng_l2cap(4)
ng_l2tp(4)
ng_lmi(4)
ng_mppc(4)
ng_netflow(4)
ng_one2many(4)
ng_ppp(4)
ng_pppoe(4)
ng_pptpgre(4)
ng_rfc1490(4)
ng_socket(4)
ng_split(4)
ng_sppp(4)
ng_sscfu(4)
ng_sscop(4)
ng_tee(4)
ng_tty(4)
ng_ubt(4)
ng_uni(4)
ng_vjc(4)
ng_vlan(4)
nge(4)
nmdm(4)
npx(4)
nsp(4)
null(4)
ohci(4)
oldcard(4)
oltr(4)
opie(4)
orm(4)
pae(4)
pass(4)
patm(4)
pccard(4)
pccbb(4)
pcf(4)
pci(4)
pcic(4)
pcm(4)
pcn(4)
pcvt(4)
perfmon(4)
pf(4)
pflog(4)
pfsync(4)
pim(4)
plip(4)
pnp(4)
pnpbios(4)
polling(4)
ppbus(4)
ppc(4)
ppi(4)
ppp(4)
psm(4)
pst(4)
pt(4)
pty(4)
puc(4)
random(4)
rawip(4)
ray(4)
rc(4)
re(4)
rl(4)
rndtest(4)
route(4)
rp(4)
rue(4)
sa(4)
sab(4)
safe(4)
sbni(4)
sbp(4)
sbp_targ(4)
sbsh(4)
sc(4)
scbus(4)
scd(4)
sched_4bsd(4)
sched_ule(4)
screen(4)
screensaver(4)
scsi(4)
sem(4)
ses(4)
sf(4)
si(4)
sio(4)
sis(4)
sk(4)
skey(4)
sl(4)
smapi(4)
smb(4)
smbus(4)
smp(4)
sn(4)
snc(4)
snd(4)
snd_ad1816(4)
snd_als4000(4)
snd_cmi(4)
snd_cs4281(4)
snd_csa(4)
snd_ds1(4)
snd_emu10k1(4)
snd_es137x(4)
snd_ess(4)
snd_fm801(4)
snd_gusc(4)
snd_ich(4)
snd_maestro(4)
snd_maestro3(4)
snd_neomagic(4)
snd_sbc(4)
snd_solo(4)
snd_uaudio(4)
snd_via8233(4)
snd_via82c686(4)
snd_vibes(4)
snp(4)
sound(4)
speaker(4)
spic(4)
spkr(4)
splash(4)
sppp(4)
sr(4)
stderr(4)
stdin(4)
stdout(4)
ste(4)
stf(4)
stg(4)
streams(4)
svr4(4)
sym(4)
syncache(4)
syncer(4)
syncookies(4)
syscons(4)
sysmouse(4)
tap(4)
targ(4)
tcp(4)
tdfx(4)
termios(4)
ti(4)
tl(4)
trm(4)
ttcp(4)
tty(4)
tun(4)
twa(4)
twe(4)
tx(4)
txp(4)
uart(4)
ubsa(4)
ubsec(4)
ubser(4)
ubtbcmfw(4)
ucom(4)
udav(4)
udbp(4)
udp(4)
ufm(4)
uftdi(4)
ugen(4)
uhci(4)
uhid(4)
uhidev(4)
ukbd(4)
ulpt(4)
umass(4)
umct(4)
umodem(4)
ums(4)
unix(4)
uplcom(4)
urio(4)
usb(4)
uscanner(4)
utopia(4)
uvisor(4)
uvscom(4)
vga(4)
vge(4)
viapm(4)
vinum(4)
vinumdebug(4)
vlan(4)
vn(4)
vpd(4)
vpo(4)
vr(4)
vt(4)
vx(4)
watchdog(4)
wb(4)
wd(4)
wdc(4)
wi(4)
witness(4)
wl(4)
wlan(4)
worm(4)
xe(4)
xl(4)
xpt(4)
zero(4)
pf(4)
NAME
pf -- packet filter
SYNOPSIS
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) 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). Manipulations like loading a ruleset that involve more than a single ioctl call require a so-called ticket, which prevents the occurrence of multiple concurrent manipulations. Fields of ioctl parameter structures that refer to packet data (like addresses and ports) are generally expected in network byte-order.
FILES
/dev/pf packet filtering device.
IOCTL INTERFACE
pf supports the following ioctl(2) commands: DIOCSTART Starts the packet filter. DIOCSTOP Stops the packet filter. DIOCSTARTALTQ Starts the ALTQ bandwidth control system. DIOCSTOPALTQ Stops the ALTQ bandwidth control system. DIOCBEGINADDRS struct pfioc_pooladdr struct pfioc_pooladdr { u_int32_t action; u_int32_t ticket; u_int32_t nr; u_int32_t r_num; u_int8_t r_action; u_int8_t r_last; u_int8_t af; char anchor[PF_ANCHOR_NAME_SIZE]; char ruleset[PF_RULESET_NAME_SIZE]; struct pf_pooladdr addr; }; Clears the buffer address pool and returns a ticket for subse- quent DIOCADDADDR, DIOCADDRULE and DIOCCHANGERULE calls. struct pfioc_rule { u_int32_t action; u_int32_t ticket; u_int32_t pool_ticket; u_int32_t nr; char anchor[PF_ANCHOR_NAME_SIZE]; char ruleset[PF_RULESET_NAME_SIZE]; struct pf_rule rule; }; Adds rule at the end of the inactive ruleset. Requires ticket obtained through preceding DIOCXBEGIN call, and pool_ticket obtained through DIOCBEGINADDRS call. DIOCADDADDR must also be called if any pool addresses are required. The optional anchor and ruleset names indicate the anchor and ruleset in which to append the rule. nr and action are ignored. DIOCADDALTQ struct pfioc_altq Adds struct pfioc_altq { u_int32_t action; u_int32_t ticket; u_int32_t nr; struct pf_altq altq; }; DIOCGETRULES struct pfioc_rule Returns ticket for subsequent DIOCGETRULE calls and nr of rules in the active ruleset. DIOCGETRULE struct pfioc_rule Returns rule number nr using ticket obtained through a preceding DIOCGETRULES call. DIOCGETADDRS struct pfioc_pooladdr Returns ticket for subsequent DIOCGETADDR calls and nr of pool addresses in the rule specified with r_action, r_num, anchor and ruleset. DIOCGETADDR struct pfioc_pooladdr Returns pool address addr number nr from the rule specified with r_action, r_num, anchor and ruleset using ticket obtained through a preceding DIOCGETADDRS call. DIOCGETALTQS struct pfioc_altq Returns ticket for subsequent DIOCGETALTQ calls and nr of queues in the active list. DIOCGETALTQ struct pfioc_altq Returns altq number nr using ticket obtained through a preceding DIOCGETALTQS call. DIOCGETQSTATS struct pfioc_qstats Returns statistics on a queue. struct pfioc_qstats { u_int32_t ticket; DIOCADDSTATE struct pfioc_state Adds a state entry. DIOCGETSTATE struct pfioc_state struct pfioc_state { u_int32_t nr; struct pf_state state; }; Extracts the entry with the specified number from the state ta- ble. DIOCKILLSTATES struct pfioc_state_kill Removes matching entries from the state table. Returns the num- ber of killed states in psk_af. struct pfioc_state_kill { int psk_af; int psk_proto; struct pf_rule_addr psk_src; struct pf_rule_addr psk_dst; char psk_ifname[IFNAMSIZ]; }; DIOCCLRSTATES struct pfioc_state_kill Clears all states. It works like DIOCKILLSTATES, but ignores the psk_af, psk_proto, psk_src and psk_dst fields of the pfioc_state_kill structure. DIOCSETSTATUSIF struct pfioc_if struct pfioc_if { char ifname[IFNAMSIZ]; }; Specifies the interface for which statistics are accumulated. DIOCGETSTATUS struct pf_status struct pf_status { u_int64_t counters[PFRES_MAX]; 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_int32_t running; u_int32_t states; u_int32_t src_nodes; u_int32_t since; u_int32_t debug; u_int32_t hostid; char ifname[IFNAMSIZ]; }; Gets the internal packet filter statistics. struct pfioc_natlook { struct pf_addr saddr; struct pf_addr daddr; struct pf_addr rsaddr; struct pf_addr rdaddr; 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; }; DIOCSETDEBUG u_int32_t Sets the debug level. enum { PF_DEBUG_NONE=0, PF_DEBUG_URGENT=1, PF_DEBUG_MISC=2 }; DIOCGETSTATES struct pfioc_states struct pfioc_states { int ps_len; union { caddr_t psu_buf; struct pf_state *psu_states; } ps_u; #define ps_buf ps_u.psu_buf #define ps_states ps_u.psu_states }; DIOCCHANGERULE struct pfioc_rule Adds or removes the rule in the ruleset specified by rule.action. enum { PF_CHANGE_ADD_HEAD=1, PF_CHANGE_ADD_TAIL=2, PF_CHANGE_ADD_BEFORE=3, PF_CHANGE_ADD_AFTER=4, PF_CHANGE_REMOVE=5, PF_CHANGE_GET_TICKET=6 }; The type of operation to be performed is indicated by action. ticket must be set to the value obtained with PF_CHANGE_GET_TICKET for all actions except PF_CHANGE_GET_TICKET. pool_ticket must be set to the value obtained with the DIOCBEGI- NADDRS call for all actions except PF_CHANGE_REMOVE and PF_CHANGE_GET_TICKET. anchor and ruleset indicate which anchor and ruleset the opera- tion applies to. nr indicates the rule number against which PF_CHANGE_ADD_BEFORE, PF_CHANGE_ADD_AFTER or PF_CHANGE_REMOVE actions are applied. DIOCCHANGEADDR struct pfioc_pooladdr Adds or removes a pool address addr from a rule specified with r_action, r_num, anchor and ruleset. DIOCSETTIMEOUT struct pfioc_tm struct pfioc_tm { DIOCSETLIMIT struct pfioc_limit Sets hard limits on the memory pools used by the packet filter. struct pfioc_limit { int index; unsigned limit; }; DIOCGETLIMIT struct pfioc_limit DIOCRCLRTABLES struct pfioc_table 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; int 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 Creates one or more tables. On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table structures. On exit, pfrio_nadd contains the number of tables effectively created. struct pfr_table { char pfrt_anchor[PF_ANCHOR_NAME_SIZE]; char pfrt_ruleset[PF_RULESET_NAME_SIZE]; char pfrt_name[PF_TABLE_NAME_SIZE]; u_int32_t pfrt_flags; u_int8_t pfrt_fback; }; DIOCRDELTABLES struct pfioc_table Deletes one or more tables. On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table structures. On exit, pfrio_nadd contains the number of tables effectively deleted. DIOCRGETTABLES struct pfioc_table 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 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; long 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 Clears the statistics of one or more tables. On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table struc- tures. On exit, pfrio_nzero contains the number of tables effec- tively cleared. DIOCRCLRADDRS struct pfioc_table 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 Add one or more addresses to a table. On entry, pfrio_table con- tains the table id and pfrio_buffer[pfrio_size] contains the list of pfr_addr structures to add. 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; u_int8_t pfra_af; u_int8_t pfra_net; u_int8_t pfra_not; u_int8_t pfra_fback; }; #define pfra_ip4addr pfra_u._pfra_ip4addr #define pfra_ip6addr pfra_u._pfra_ip6addr DIOCRDELADDRS struct pfioc_table Delete one or more addresses from a table. On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size] contains the list of pfr_addr structures to delete. On exit, pfrio_ndel con- tains the number of addresses effectively deleted. DIOCRSETADDRS struct pfioc_table Replace the content of a table by a new address list. This is the most complicated command, which uses all the structure mem- bers. On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size] contains the new list of pfr_addr struc- tures. In addition to that, if size2 is nonzero, pfrio_buffer[pfrio_size..pfrio_size2] must be a writeable buffer, into which the kernel can copy the addresses that have been the table id and pfrio_buffer[pfrio_size] contains a valid write- able buffer for pfr_addr structures. On exit, pfrio_size con- tains the number of addresses written into the buffer. If the buffer was too small, the kernel does not store anything but just return the required buffer size, without returning an error. DIOCRGETASTATS struct pfioc_table Like DIOCRGETADDRS, but returns an array of pfr_astats struc- tures. 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]; long pfras_tzero; }; DIOCRCLRASTATS struct pfioc_table Clears the statistics of one or more addresses. On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size] contains a table of pfr_addr structures to clear. On exit, pfrio_nzero contains the number of addresses effectively cleared. DIOCRTSTADDRS struct pfioc_table Test if the given addresses match a table. On entry, pfrio_table contains the table id and pfrio_buffer[pfrio_size] contains a ta- ble of pfr_addr structures to test. On exit, the kernel updates the pfr_addr table by setting the pfra_fback member appropri- ately. DIOCRSETTFLAGS struct pfioc_table Change the const or persist flag of a table. On entry, pfrio_buffer[pfrio_size] contains a table of pfr_table struc- tures, and pfrio_setflag contains the flags to add, while pfrio_clrflag contains 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 persist flag of an unreferenced table. DIOCRINADEFINE struct pfioc_table Defines a table in the inactive set. On entry, pfrio_table con- tains the table id and pfrio_buffer[pfrio_size] contains the list 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 #define PF_RULESET_ALTQ (PF_RULESET_MAX) #define PF_RULESET_TABLE (PF_RULESET_MAX+1) struct pfioc_trans { int size; /* number of elements */ int esize; /* size of each element in bytes */ struct pfioc_trans_e { 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. DIOCXCOMMIT struct pfioc_trans Atomically switch a vector of inactive rulesets to the active rulesets. Implemented as a standard 2-phase commit, which will either fail for all rulesets or completely succeed. All tickets need to be valid. Returns EBUSY if a concurrent process is try- ing to update some of the same rulesets concurrently. DIOCXROLLBACK struct pfioc_trans 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. DIOCFPFLUSH Flush the passive OS fingerprint table. DIOCFPADD struct pf_osfp_ioctl struct pf_osfp_ioctl { struct pf_osfp_entry { SLIST_ENTRY(pf_osfp_entry) fp_entry; pf_osfp_t fp_os; char fp_class_nm[PF_OSFP_LEN]; char fp_version_nm[PF_OSFP_LEN]; char fp_subtype_nm[PF_OSFP_LEN]; } fp_os; u_int16_t fp_mss; u_int16_t fp_wsize; u_int16_t fp_psize; u_int8_t fp_ttl; u_int8_t fp_wscale; u_int8_t fp_flags; int fp_getnum; }; 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, and fp_wscale are set to the TCP MSS, the TCP window size, the IP length and the IP TTL 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_getnum is not used with this ioctl. The structure's slack space must be zeroed for correct operation; memset the whole structure to zero before filling and sending to the kernel. DIOCFPGET struct pf_osfp_ioctl struct pf_osfp_ioctl { struct pf_osfp_entry { u_int16_t fp_psize; u_int8_t fp_ttl; u_int8_t fp_wscale; u_int8_t fp_flags; int fp_getnum; }; 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 struct pfioc_src_nodes { int 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 the sticky-address and source-track options. 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 the ioctl call psn_len will be set to the length of the buffer actually used. DIOCCLRSRCNODES struct pfioc_table Clear the tree of source tracking nodes. DIOCIGETIFACES struct pfioc_iface Gets the list of interfaces and interface drivers 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; }; #define PFI_FLAG_GROUP 0x0001 /* gets groups of interfaces */ #define PFI_FLAG_INSTANCE 0x0002 /* gets single interfaces */ #define PFI_FLAG_ALLMASK 0x0003 If not empty, pfiio_name can be used to restrict the search to a specific interface or driver. pfiio_buffer[pfiio_size] is the user-supplied buffer for returning the data. On entry, struct pfi_if { char pfif_name[IFNAMSIZ]; u_int64_t pfif_packets[2][2][2]; u_int64_t pfif_bytes[2][2][2]; u_int64_t pfif_addcnt; u_int64_t pfif_delcnt; long pfif_tzero; int pfif_states; int pfif_rules; int pfif_flags; }; #define PFI_IFLAG_GROUP 0x0001 /* group of interfaces */ #define PFI_IFLAG_INSTANCE 0x0002 /* single instance */ #define PFI_IFLAG_CLONABLE 0x0010 /* clonable group */ #define PFI_IFLAG_DYNAMIC 0x0020 /* dynamic group */ #define PFI_IFLAG_ATTACHED 0x0040 /* interface attached */ #define PFI_IFLAG_REFERENCED 0x0080 /* referenced by rules */ DIOCICLRISTATS struct pfioc_iface Clear the statistics counters of one or more interfaces. pfiio_name and pfrio_flags can be used to select which interfaces need to be cleared. The filtering process is the same as for DIOCIGETIFACES. pfiio_nzero will be set by the kernel to the number of interfaces and drivers that have been cleared.
EXAMPLES
The following example demonstrates how to use the DIOCNATLOOK command to find the internal host/port of a NATed connection. #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <sys/fcntl.h> #include <net/if.h> #include <netinet/in.h> #include <net/pfvar.h> #include <err.h> #include <stdio.h> #include <stdlib.h> u_int32_t read_address(const char *s) { int a, b, c, d; sscanf(s, "%i.%i.%i.%i", &a, &b, &c, &d); return htonl(a << 24 | b << 16 | c << 8 | d); } void print_address(u_int32_t a) { a = ntohl(a); printf("%d.%d.%d.%d", a >> 24 & 255, a >> 16 & 255, a >> 8 & 255, a & 255); } printf("%s <gwy addr> <gwy port> <ext addr> <ext port>\n", argv[0]); return 1; } dev = open("/dev/pf", O_RDWR); if (dev == -1) err(1, "open(\"/dev/pf\") failed"); memset(&nl, 0, sizeof(struct pfioc_natlook)); nl.saddr.v4.s_addr = read_address(argv[1]); nl.sport = htons(atoi(argv[2])); nl.daddr.v4.s_addr = read_address(argv[3]); nl.dport = htons(atoi(argv[4])); nl.af = AF_INET; nl.proto = IPPROTO_TCP; nl.direction = PF_IN; if (ioctl(dev, DIOCNATLOOK, &nl)) err(1, "DIOCNATLOOK"); printf("internal host "); print_address(nl.rsaddr.v4.s_addr); printf(":%u\n", ntohs(nl.rsport)); return 0; }
SEE ALSO
ioctl(2), altq(4), bridge(4), pflog(4), pfsync(4), pfctl(8)
HISTORY
The pf packet filtering mechanism first appeared in OpenBSD 3.0. FreeBSD 5.4 February 7, 2005 FreeBSD 5.4
SPONSORED LINKS
Man(1) output converted with man2html , sed , awk