1.\" $NetBSD: npfd.8,v 1.7 2020/10/30 09:23:36 abs 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 August 7, 2018 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 writes to a file in 47.Xr pcap 3 48format logged packets read from an npflog interface. 49The npflog interface is used by 50.Xr npf 7 51to log packets as defined in 52.Xr npf.conf 5 . 53The generated 54.Xr pcap 3 55files can then be analysed using tools such as 56.Xr tcpdump 8 . 57.Pp 58.Nm 59closes and then re-opens the log file when it receives 60.Dv SIGHUP , 61permitting 62.Xr newsyslog 8 63to rotate logfiles automatically. 64.Dv SIGALRM 65causes 66.Nm 67to flush the current logfile buffers to the disk, thus making the most 68recent logs available. 69The buffers are also flushed every 70.Ar delay 71seconds. 72.Pp 73If the log file contains data after a restart or a 74.Dv SIGHUP , 75new logs are appended to the existing file. 76If the existing log file was created with a different snaplen, 77.Nm 78temporarily uses the old snaplen to keep the log file consistent. 79.Pp 80.Nm 81tries to preserve the integrity of the log file against I/O errors. 82Furthermore, integrity of an existing log file is verified before 83appending. 84If there is an invalid log file or an I/O error, the log file is moved 85out of the way and a new one is created. 86If a new file cannot be created, logging is suspended until a 87.Dv SIGHUP 88or a 89.Dv SIGALRM 90is received. 91.Pp 92If 93.Dv SIGINFO 94is received, then 95.Nm 96logs capture statistics to 97.Xr syslogd 8 . 98.Pp 99The options are as follows: 100.Bl -tag -width Ds 101.It Fl D 102Debugging mode. 103.Nm 104does not disassociate from the controlling terminal. 105.It Fl d Ar delay 106Time in seconds to delay between automatic flushes of the file. 107This may be specified with a value between 5 and 3600 seconds. 108If not specified, the default is 60 seconds. 109.It Fl f Ar filename 110Log output filename. 111Default is 112.Pa /var/log/npflog0.pcap . 113.It Fl i Ar interface 114Specifies the 115npflog 116.\" .Xr if_npflog 4 117interface to use. 118By default, 119.Nm 120will use 121.Ar npflog0 . 122.It Fl p Ar pidfile 123Writes a file containing the process ID of the program. 124The file name has the form 125.Pa /var/run/npfd.pid . 126If the option is not given, 127.Ar pidfile 128defaults to 129.Pa npfd . 130.It Fl s Ar snaplen 131Analyze at most the first 132.Ar snaplen 133bytes of data from each packet rather than the default of 116. 134The default of 116 is adequate for IP, ICMP, TCP, and UDP headers but may 135truncate protocol information for other protocols. 136Other file parsers may desire a higher snaplen. 137.\" .It Fl x 138.\" Check the integrity of an existing log file, and return. 139.It Ar expression 140Selects which packets will be dumped, using the regular language of 141.Xr tcpdump 8 . 142.El 143.Sh FILES 144.Bl -tag -width /var/run/npflog0.pcap -compact 145.It Pa /var/run/npfd.pid 146Process ID of the currently running 147.Nm . 148.It Pa /var/log/npflog0.pcap 149Default log file. 150.El 151.Sh EXAMPLES 152Log specific tcp packets to a different log file with a large snaplen 153(useful with a log-all rule to dump complete sessions): 154.Bd -literal -offset indent 155# npfd -s 1600 -f suspicious.log port 80 and host evilhost 156.Ed 157.Pp 158Log from another 159npflog 160interface, excluding specific packets: 161.Bd -literal -offset indent 162# npfd -i npflog3 -f network3.log "not (tcp and port 23)" 163.Ed 164.Pp 165Display binary logs: 166.Bd -literal -offset indent 167# tcpdump -n -e -ttt -r /var/log/npflog0.pcap 168.Ed 169.Pp 170Display the logs in real time (this does not interfere with the 171operation of 172.Nm ) : 173.Bd -literal -offset indent 174# tcpdump -n -e -ttt -i npflog0 175.Ed 176.Pp 177Tcpdump has been extended to be able to filter on the 178.Ox 179pfloghdr 180structure defined in 181.Ar sys/net/npf/if_npflog.h . 182Tcpdump can restrict the output 183to packets logged on a specified interface, a rule number, a reason, 184a direction, an IP family or an action. 185.Pp 186.Bl -tag -width "ruleset rules " -compact 187.It ip 188Address family equals IPv4. 189.It ip6 190Address family equals IPv6. 191.It ifname kue0 192Interface name equals "kue0". 193.It on kue0 194Interface name equals "kue0". 195.It ruleset rules 196Ruleset name equals "rules". 197.It rulenum 10 198Rule number equals 10. 199.It reason match 200Reason equals match. 201.\" Also accepts "bad-offset", "fragment", "bad-timestamp", "short", 202.\" "normalize", "memory", "congestion", "ip-option", "proto-cksum", 203.\" "state-mismatch", "state-insert", "state-limit", "src-limit", 204.\" and "synproxy". 205.It action pass 206Action equals pass. 207Also accepts "block". 208.It inbound 209The direction was inbound. 210.It outbound 211The direction was outbound. 212.El 213.Pp 214Display the logs in real time of inbound packets that were blocked on 215the wi0 interface: 216.Bd -literal -offset indent 217# tcpdump -n -e -ttt -i npflog0 inbound and action block and on wi0 218.Ed 219.Pp 220Each 221.Xr npf 7 222rule is marked with an id number, shown using: 223.Bd -literal -offset indent 224# npfctl show 225\&... 226 block final all apply "log" # id="45" 227\&... 228.Ed 229.Pp 230This id is the rule id shown by tcpdump: 231.Bd -literal -offset indent 232# tcpdump -enr /var/log/npflog0.pcap 233\&... 23411:26:02.288199 rule 45.rules.0/0(match): block in on sk0: \e 2351.2.3.4.46063 > 5.6.7.8.23231: Flags [S], seq 1, win 8192, \e 236options [mss 1440], length 0 237\&... 238.Ed 239.Sh SEE ALSO 240.Xr pcap 3 , 241.Xr npf.conf 5 , 242.Xr npf 7 , 243.Xr newsyslog 8 , 244.Xr npfctl 8 , 245.Xr tcpdump 8 246.Sh HISTORY 247The 248.Nm 249command appeared in 250.Nx 8.0 . 251.Sh AUTHORS 252This manual page was written by 253.An Can Erkin Acar Aq Mt canacar@openbsd.org . 254.Sh CAVEATS 255Offline analysis of captured data is advised to alleviate issues with 256malicious data intended to exploit bugs in the packet parsing code of 257.Xr tcpdump 8 . 258