1.\" $NetBSD: pfsync.4,v 1.3 2009/09/14 11:45:01 degroote 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 (it is not supported at the moment on 129.Nx 130due to the lack of any encapsulation pseudo-device). 131.Pp 132There is a one-to-one correspondence between packets seen by 133.Xr bpf 4 134on the 135.Nm 136interface, and packets sent out on the synchronisation interface, i.e.\& 137a packet with 4 state deletion messages on 138.Nm 139means that the same 4 deletions were sent out on the synchronisation 140interface. 141However, the actual packet contents may differ as the messages 142sent over the network are "compressed" where possible, containing 143only the necessary information. 144.Sh EXAMPLES 145.Nm 146and 147.Xr carp 4 148can be used together to provide automatic failover of a pair of firewalls 149configured in parallel. 150One firewall handles all traffic \- if it dies or 151is shut down, the second firewall takes over automatically. 152.Pp 153Both firewalls in this example have three 154.Xr sis 4 155interfaces. 156sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 157internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 158.Nm 159interface, using the 192.168.254.0/24 subnet. 160A crossover cable connects the two firewalls via their sis2 interfaces. 161On all three interfaces, firewall A uses the .254 address, while firewall B 162uses .253. 163The interfaces are configured as follows (firewall A unless otherwise 164indicated): 165.Pp 166.Pa /etc/ifconfig.sis0 : 167.Bd -literal -offset indent 168inet 10.0.0.254 255.255.255.0 NONE 169.Ed 170.Pp 171.Pa /etc/ifconfig.sis1 : 172.Bd -literal -offset indent 173inet 192.168.0.254 255.255.255.0 NONE 174.Ed 175.Pp 176.Pa /etc/ifconfig.sis2 : 177.Bd -literal -offset indent 178inet 192.168.254.254 255.255.255.0 NONE 179.Ed 180.Pp 181.Pa /etc/ifconfig.carp0 : 182.Bd -literal -offset indent 183inet 10.0.0.1 255.255.255.0 10.0.0.255 vhid 1 pass foo 184.Ed 185.Pp 186.Pa /etc/ifconfig.carp1 : 187.Bd -literal -offset indent 188inet 192.168.0.1 255.255.255.0 192.168.0.255 vhid 2 pass bar 189.Ed 190.Pp 191.Pa /etc/ifconfig.pfsync0 : 192.Bd -literal -offset indent 193up syncdev sis2 194.Ed 195.Pp 196.Xr pf 4 197must also be configured to allow 198.Nm 199and 200.Xr carp 4 201traffic through. 202The following should be added to the top of 203.Pa /etc/pf.conf : 204.Bd -literal -offset indent 205pass quick on { sis2 } proto pfsync 206pass on { sis0 sis1 } proto carp 207.Ed 208.Pp 209If it is preferable that one firewall handle the traffic, 210the 211.Ar advskew 212on the backup firewall's 213.Xr carp 4 214interfaces should be set to something higher than 215the primary's. 216For example, if firewall B is the backup, its 217.Pa /etc/ifconfig.carp1 218would look like this: 219.Bd -literal -offset indent 220inet 192.168.0.1 255.255.255.0 192.168.0.255 vhid 2 pass bar \e 221 advskew 100 222.Ed 223.Pp 224The following must also be added to 225.Pa /etc/sysctl.conf : 226.Bd -literal -offset indent 227net.inet.carp.preempt=1 228.Ed 229.Sh SEE ALSO 230.Xr bpf 4 , 231.Xr carp 4 , 232.Xr inet 4 , 233.Xr inet6 4 , 234.Xr ipsec 4 , 235.Xr netintro 4 , 236.Xr pf 4 , 237.Xr ifconfig.if 5 , 238.Xr pf.conf 5 , 239.Xr protocols 5 , 240.\" enc 8, 241.Xr ifconfig 8 , 242.Xr tcpdump 8 243.Sh HISTORY 244The 245.Nm 246device first appeared in 247.Ox 3.3 . 248