1.\" $NetBSD: npfd.8,v 1.3 2017/01/08 13:59:53 wiz Exp $ 2.\" $OpenBSD: pflogd.8,v 1.35 2007/05/31 19:19:47 jmc Exp $ 3.\" 4.\" Copyright (c) 2001 Can Erkin Acar. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. The name of the author may not be used to endorse or promote products 15.\" derived from this software without specific prior written permission. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27.\" 28.\" 29.Dd January 5, 2017 30.Dt NPFD 8 31.Os 32.Sh NAME 33.Nm npfd 34.Nd packet filter logging and state synchronization daemon 35.Sh SYNOPSIS 36.Nm npfd 37.Op Fl D 38.Op Fl d Ar delay 39.Op Fl f Ar filename 40.Op Fl i Ar interface 41.Op Fl p Ar pidfile 42.Op Fl s Ar snaplen 43.Op Ar expression 44.Sh DESCRIPTION 45.Nm 46is a background daemon which reads packets logged by 47.Xr npf 7 48to an 49.\" .Xr npflog 4 50npflog 51interface, normally 52.Pa npflog0 , 53and writes the packets to a logfile (normally 54.Pa /var/log/npflog0.pcap ) 55in 56.Xr pcap 3 57format, which can be read by 58.Xr tcpdump 8 . 59These logs can be reviewed later using the 60.Fl r 61option of 62.Xr tcpdump 8 , 63hopefully offline in case there are bugs in the packet parsing code of 64.Xr tcpdump 8 . 65.Pp 66.Nm 67closes and then re-opens the log file when it receives 68.Dv SIGHUP , 69permitting 70.Xr newsyslog 8 71to rotate logfiles automatically. 72.Dv SIGALRM 73causes 74.Nm 75to flush the current logfile buffers to the disk, thus making the most 76recent logs available. 77The buffers are also flushed every 78.Ar delay 79seconds. 80.Pp 81If the log file contains data after a restart or a 82.Dv SIGHUP , 83new logs are appended to the existing file. 84If the existing log file was created with a different snaplen, 85.Nm 86temporarily uses the old snaplen to keep the log file consistent. 87.Pp 88.Nm 89tries to preserve the integrity of the log file against I/O errors. 90Furthermore, integrity of an existing log file is verified before 91appending. 92If there is an invalid log file or an I/O error, the log file is moved 93out of the way and a new one is created. 94If a new file cannot be created, logging is suspended until a 95.Dv SIGHUP 96or a 97.Dv SIGALRM 98is received. 99.Pp 100If 101.Dv SIGINFO 102is received, then 103.Nm 104logs capture statistics to 105.Xr syslogd 8 . 106.Pp 107The options are as follows: 108.Bl -tag -width Ds 109.It Fl D 110Debugging mode. 111.Nm 112does not disassociate from the controlling terminal. 113.It Fl d Ar delay 114Time in seconds to delay between automatic flushes of the file. 115This may be specified with a value between 5 and 3600 seconds. 116If not specified, the default is 60 seconds. 117.It Fl f Ar filename 118Log output filename. 119Default is 120.Pa /var/log/npflog0.pcap . 121.It Fl i Ar interface 122Specifies the 123npflog 124.\" .Xr if_npflog 4 125interface to use. 126By default, 127.Nm 128will use 129.Ar npflog0 . 130.It Fl p Ar pidfile 131Writes a file containing the process ID of the program. 132The file name has the form 133.Pa /var/run/npfd.pid . 134If the option is not given, 135.Ar pidfile 136defaults to 137.Pa npfd . 138.It Fl s Ar snaplen 139Analyze at most the first 140.Ar snaplen 141bytes of data from each packet rather than the default of 116. 142The default of 116 is adequate for IP, ICMP, TCP, and UDP headers but may 143truncate protocol information for other protocols. 144Other file parsers may desire a higher snaplen. 145.\" .It Fl x 146.\" Check the integrity of an existing log file, and return. 147.It Ar expression 148Selects which packets will be dumped, using the regular language of 149.Xr tcpdump 8 . 150.El 151.Sh FILES 152.Bl -tag -width /var/run/npflog0.pcap -compact 153.It Pa /var/run/npfd.pid 154Process ID of the currently running 155.Nm . 156.It Pa /var/log/npflog0.pcap 157Default log file. 158.El 159.Sh EXAMPLES 160Log specific tcp packets to a different log file with a large snaplen 161(useful with a log-all rule to dump complete sessions): 162.Bd -literal -offset indent 163# npfd -s 1600 -f suspicious.log port 80 and host evilhost 164.Ed 165.Pp 166Log from another 167.\" .Xr pflog 4 168npflog 169interface, excluding specific packets: 170.Bd -literal -offset indent 171# npfd -i npflog3 -f network3.log "not (tcp and port 23)" 172.Ed 173.Pp 174Display binary logs: 175.Bd -literal -offset indent 176# tcpdump -n -e -ttt -r /var/log/npflog0.pcap 177.Ed 178.Pp 179Display the logs in real time (this does not interfere with the 180operation of 181.Nm ) : 182.Bd -literal -offset indent 183# tcpdump -n -e -ttt -i npflog0.pcap 184.Ed 185.Pp 186Tcpdump has been extended to be able to filter on the 187.Ox 188pfloghdr 189structure defined in 190.Ar sys/net/npf/if_npflog.h . 191Tcpdump can restrict the output 192to packets logged on a specified interface, a rule number, a reason, 193a direction, an IP family or an action. 194.Pp 195.Bl -tag -width "ruleset rules " -compact 196.It ip 197Address family equals IPv4. 198.It ip6 199Address family equals IPv6. 200.It ifname kue0 201Interface name equals "kue0". 202.It on kue0 203Interface name equals "kue0". 204.It ruleset rules 205Ruleset name equals "rules". 206.It rulenum 10 207Rule number equals 10. 208.It reason match 209Reason equals match. 210.\" Also accepts "bad-offset", "fragment", "bad-timestamp", "short", 211.\" "normalize", "memory", "congestion", "ip-option", "proto-cksum", 212.\" "state-mismatch", "state-insert", "state-limit", "src-limit", 213.\" and "synproxy". 214.It action pass 215Action equals pass. 216Also accepts "block". 217.It inbound 218The direction was inbound. 219.It outbound 220The direction was outbound. 221.El 222.Pp 223Display the logs in real time of inbound packets that were blocked on 224the wi0 interface: 225.Bd -literal -offset indent 226# tcpdump -n -e -ttt -i npflog0 inbound and action block and on wi0 227.Ed 228.Pp 229Each 230.Xr npf 7 231rule is marked with an id number, shown using: 232.Bd -literal -offset indent 233# npfctl show 234... 235 block final all apply "log" # id="45" 236... 237.Ed 238.Pp 239This id is the rule id shown by tcpdump: 240.Bd -literal -offset indent 241# tcpdump -enr /var/log/npflog0.pcap 242... 24311:26:02.288199 rule 45.rules.0/0(match): block in on sk0: \e 2441.2.3.4.46063 > 5.6.7.8.23231: Flags [S], seq 1, win 8192, \e 245options [mss 1440], length 0 246... 247.Ed 248.Sh SEE ALSO 249.Xr pcap 3 , 250\" .Xr if_npflog 4 , 251.Xr npf.conf 5 , 252.Xr npf 7 , 253.Xr newsyslog 8 , 254.Xr npfctl 8 , 255.Xr tcpdump 8 256.Sh HISTORY 257The 258.Nm 259command appeared in 260.Nx 8.0 . 261.Sh AUTHORS 262This manual page was written by 263.An Can Erkin Acar Aq Mt canacar@openbsd.org . 264