1.\" $NetBSD: pfsync.4,v 1.5 2010/04/12 14:26:11 ahoka Exp $ 2.\" $OpenBSD: pfsync.4,v 1.25 2007/05/31 19:19:51 jmc Exp $ 3.\" 4.\" Copyright (c) 2002 Michael Shalayeff 5.\" Copyright (c) 2003-2004 Ryan McBride 6.\" All rights reserved. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 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 MIND, 23.\" USE, 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.Dd September 14, 2009 29.Dt PFSYNC 4 30.Os 31.Sh NAME 32.Nm pfsync 33.Nd packet filter state table logging interface 34.Sh SYNOPSIS 35.Cd "pseudo-device pfsync" 36.Sh DESCRIPTION 37The 38.Nm 39interface is a pseudo-device which exposes certain changes to the state 40table used by 41.Xr pf 4 . 42State changes can be viewed by invoking 43.Xr tcpdump 8 44on the 45.Nm 46interface. 47If configured with a physical synchronisation interface, 48.Nm 49will also send state changes out on that interface using IP multicast, 50and insert state changes received on that interface from other systems 51into the state table. 52.Pp 53By default, all local changes to the state table are exposed via 54.Nm . 55However, state changes from packets received by 56.Nm 57over the network are not rebroadcast. 58States created by a rule marked with the 59.Ar no-sync 60keyword are omitted from the 61.Nm 62interface (see 63.Xr pf.conf 5 64for details). 65.Pp 66The 67.Nm 68interface will attempt to collapse multiple updates of the same 69state into one message where possible. 70The maximum number of times this can be done before the update is sent out 71is controlled by the 72.Ar maxupd 73parameter to ifconfig 74(see 75.Xr ifconfig 8 76and the example below for more details). 77.Pp 78Each packet retrieved on this interface has a header associated 79with it of length 80.Dv PFSYNC_HDRLEN . 81The header indicates the version of the protocol, address family, 82action taken on the following states, and the number of state 83table entries attached in this packet. 84This structure is defined in 85.Aq Pa net/if_pfsync.h 86as: 87.Bd -literal -offset indent 88struct pfsync_header { 89 u_int8_t version; 90 u_int8_t af; 91 u_int8_t action; 92 u_int8_t count; 93}; 94.Ed 95.Sh NETWORK SYNCHRONISATION 96States can be synchronised between two or more firewalls using this 97interface, by specifying a synchronisation interface using 98.Xr ifconfig 8 . 99For example, the following command sets fxp0 as the synchronisation 100interface: 101.Bd -literal -offset indent 102# ifconfig pfsync0 syncdev fxp0 103.Ed 104.Pp 105By default, state change messages are sent out on the synchronisation 106interface using IP multicast packets. 107The protocol is IP protocol 240, PFSYNC, and the multicast group 108used is 224.0.0.240. 109When a peer address is specified using the 110.Ic syncpeer 111keyword, the peer address is used as a destination for the pfsync traffic. 112.\"and the traffic can then be protected using 113.\".Xr ipsec 4 . 114.\"In such a configuration, the syncdev should be set to the 115.\".Xr enc 4 116.\"interface, as this is where the traffic arrives when it is decapsulated, 117.\"e.g.: 118.\".Bd -literal -offset indent 119.\"# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0 120.\".Ed 121.Pp 122It is important that the pfsync traffic be well secured 123as there is no authentication on the protocol and it would 124be trivial to spoof packets which create states, bypassing the pf ruleset. 125Either run the pfsync protocol on a trusted network \- ideally a network 126dedicated to pfsync messages such as a crossover cable between two firewalls, 127or specify a peer address and protect the traffic with 128.Xr ipsec 4 129(it is not supported at the moment on 130.Nx 131due to the lack of any encapsulation pseudo-device). 132.Pp 133There is a one-to-one correspondence between packets seen by 134.Xr bpf 4 135on the 136.Nm 137interface, and packets sent out on the synchronisation interface, i.e.\& 138a packet with 4 state deletion messages on 139.Nm 140means that the same 4 deletions were sent out on the synchronisation 141interface. 142However, the actual packet contents may differ as the messages 143sent over the network are "compressed" where possible, containing 144only the necessary information. 145.Sh EXAMPLES 146.Nm 147and 148.Xr carp 4 149can be used together to provide automatic failover of a pair of firewalls 150configured in parallel. 151One firewall handles all traffic \- if it dies or 152is shut down, the second firewall takes over automatically. 153.Pp 154Both firewalls in this example have three 155.Xr sis 4 156interfaces. 157sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 158internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 159.Nm 160interface, using the 192.168.254.0/24 subnet. 161A crossover cable connects the two firewalls via their sis2 interfaces. 162On all three interfaces, firewall A uses the .254 address, while firewall B 163uses .253. 164The interfaces are configured as follows (firewall A unless otherwise 165indicated): 166.Pp 167.Pa /etc/ifconfig.sis0 : 168.Bd -literal -offset indent 169inet 10.0.0.254 255.255.255.0 NONE 170.Ed 171.Pp 172.Pa /etc/ifconfig.sis1 : 173.Bd -literal -offset indent 174inet 192.168.0.254 255.255.255.0 NONE 175.Ed 176.Pp 177.Pa /etc/ifconfig.sis2 : 178.Bd -literal -offset indent 179inet 192.168.254.254 255.255.255.0 NONE 180.Ed 181.Pp 182.Pa /etc/ifconfig.carp0 : 183.Bd -literal -offset indent 184inet 10.0.0.1 255.255.255.0 10.0.0.255 vhid 1 pass foo 185.Ed 186.Pp 187.Pa /etc/ifconfig.carp1 : 188.Bd -literal -offset indent 189inet 192.168.0.1 255.255.255.0 192.168.0.255 vhid 2 pass bar 190.Ed 191.Pp 192.Pa /etc/ifconfig.pfsync0 : 193.Bd -literal -offset indent 194up syncdev sis2 195.Ed 196.Pp 197.Xr pf 4 198must also be configured to allow 199.Nm 200and 201.Xr carp 4 202traffic through. 203The following should be added to the top of 204.Pa /etc/pf.conf : 205.Bd -literal -offset indent 206pass quick on { sis2 } proto pfsync 207pass on { sis0 sis1 } proto carp 208.Ed 209.Pp 210If it is preferable that one firewall handle the traffic, 211the 212.Ar advskew 213on the backup firewall's 214.Xr carp 4 215interfaces should be set to something higher than 216the primary's. 217For example, if firewall B is the backup, its 218.Pa /etc/ifconfig.carp1 219would look like this: 220.Bd -literal -offset indent 221inet 192.168.0.1 255.255.255.0 192.168.0.255 vhid 2 pass bar \e 222 advskew 100 223.Ed 224.Pp 225The following must also be added to 226.Pa /etc/sysctl.conf : 227.Bd -literal -offset indent 228net.inet.carp.preempt=1 229.Ed 230.Sh SEE ALSO 231.Xr bpf 4 , 232.Xr carp 4 , 233.Xr inet 4 , 234.Xr inet6 4 , 235.Xr ipsec 4 , 236.Xr netintro 4 , 237.Xr pf 4 , 238.Xr ifconfig.if 5 , 239.Xr pf.conf 5 , 240.Xr protocols 5 , 241.\" enc 8, 242.Xr ifconfig 8 , 243.Xr tcpdump 8 244.Sh HISTORY 245The 246.Nm 247device first appeared in 248.Ox 3.3 . 249.Sh CAVEATS 250.Nm 251is not available when using 252.Xr pf 4 253as a kernel module. 254