1.\" $OpenBSD: pfsync.4,v 1.32 2015/02/01 08:33:48 jsg Exp $ 2.\" 3.\" Copyright (c) 2002 Michael Shalayeff 4.\" Copyright (c) 2003-2004 Ryan McBride 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND, 22.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26.\" 27.Dd $Mdocdate: February 1 2015 $ 28.Dt PFSYNC 4 29.Os 30.Sh NAME 31.Nm pfsync 32.Nd packet filter state table synchronisation interface 33.Sh SYNOPSIS 34.Cd "pseudo-device pfsync" 35.Sh DESCRIPTION 36The 37.Nm 38interface is a pseudo-device which exposes certain changes to the state 39table used by 40.Xr pf 4 . 41State changes can be viewed by invoking 42.Xr tcpdump 8 43on the 44.Nm 45interface. 46If configured with a physical synchronisation interface, 47.Nm 48will also send state changes out on that interface, 49and insert state changes received on that interface from other systems 50into the state table. 51.Pp 52By default, all local changes to the state table are exposed via 53.Nm . 54State changes from packets received by 55.Nm 56over the network are not rebroadcast. 57Updates to states created by a rule marked with the 58.Ar no-sync 59keyword are ignored by the 60.Nm 61interface (see 62.Xr pf.conf 5 63for details). 64.Pp 65The 66.Nm 67interface will attempt to collapse multiple state updates into a single 68packet where possible. 69The maximum number of times a single state can be updated before a 70.Nm 71packet will be sent out is controlled by the 72.Ar maxupd 73parameter to ifconfig 74(see 75.Xr ifconfig 8 76and the example below for more details). 77The sending out of a 78.Nm 79packet will be delayed by a maximum of one second. 80.Pp 81Where more than one firewall might actively handle packets, e.g. with certain 82.Xr ospfd 8 , 83.Xr bgpd 8 84or 85.Xr carp 4 86configurations, it is beneficial to defer transmission of the initial 87packet of a connection. 88The 89.Nm 90state insert message is sent immediately; the packet is queued until 91either this message is acknowledged by another system, or a timeout has 92expired. 93This behaviour is enabled with the 94.Ar defer 95parameter to 96.Xr ifconfig 8 . 97.Sh NETWORK SYNCHRONISATION 98States can be synchronised between two or more firewalls using this 99interface, by specifying a synchronisation interface using 100.Xr ifconfig 8 . 101For example, the following command configures an address on fxp0 and 102sets it as the synchronisation interface: 103.Bd -literal -offset indent 104# ifconfig fxp0 inet 172.19.13.1/28 105# ifconfig pfsync0 syncdev fxp0 106.Ed 107.Pp 108By default, state change messages are sent out on the synchronisation 109interface using IP multicast packets to the 224.0.0.240 group address. 110An alternative destination address for 111.Nm 112packets can be specified using the 113.Ic syncpeer 114keyword. 115This can be used in combination with 116.Xr ipsec 4 117to protect the synchronisation traffic. 118In such a configuration, the syncdev should be set to the 119.Xr enc 4 120interface, as this is where the traffic arrives when it is decapsulated, 121e.g.: 122.Bd -literal -offset indent 123# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0 124.Ed 125.Pp 126It is important that the pfsync traffic be well secured 127as there is no authentication on the protocol and it would 128be trivial to spoof packets which create states, bypassing the pf ruleset. 129Either run the pfsync protocol on a trusted network \- ideally a network 130dedicated to pfsync messages such as a crossover cable between two firewalls, 131or specify a peer address and protect the traffic with 132.Xr ipsec 4 . 133.Sh EXAMPLES 134.Nm 135and 136.Xr carp 4 137can be used together to provide automatic failover of a pair of firewalls 138configured in parallel. 139One firewall will handle all traffic until it dies, is shut down, or is 140manually demoted, at which point the second firewall will take over 141automatically. 142.Pp 143Both firewalls in this example have three 144.Xr sis 4 145interfaces. 146sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 147internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 148.Nm 149interface, using the 192.168.254.0/24 subnet. 150A crossover cable connects the two firewalls via their sis2 interfaces. 151On all three interfaces, firewall A uses the .254 address, while firewall B 152uses .253. 153The interfaces are configured as follows (firewall A unless otherwise 154indicated): 155.Pp 156.Pa /etc/hostname.sis0 : 157.Bd -literal -offset indent 158inet 10.0.0.254 255.255.255.0 NONE 159.Ed 160.Pp 161.Pa /etc/hostname.sis1 : 162.Bd -literal -offset indent 163inet 192.168.0.254 255.255.255.0 NONE 164.Ed 165.Pp 166.Pa /etc/hostname.sis2 : 167.Bd -literal -offset indent 168inet 192.168.254.254 255.255.255.0 NONE 169.Ed 170.Pp 171.Pa /etc/hostname.carp0 : 172.Bd -literal -offset indent 173inet 10.0.0.1 255.255.255.0 10.0.0.255 vhid 1 pass foo 174.Ed 175.Pp 176.Pa /etc/hostname.carp1 : 177.Bd -literal -offset indent 178inet 192.168.0.1 255.255.255.0 192.168.0.255 vhid 2 pass bar 179.Ed 180.Pp 181.Pa /etc/hostname.pfsync0 : 182.Bd -literal -offset indent 183up syncdev sis2 184.Ed 185.Pp 186.Xr pf 4 187must also be configured to allow 188.Nm 189and 190.Xr carp 4 191traffic through. 192The following should be added to the top of 193.Pa /etc/pf.conf : 194.Bd -literal -offset indent 195pass quick on { sis2 } proto pfsync keep state (no-sync) 196pass on { sis0 sis1 } proto carp keep state (no-sync) 197.Ed 198.Pp 199It is preferable that one firewall handle the forwarding of all the traffic, 200therefore the 201.Ar advskew 202on the backup firewall's 203.Xr carp 4 204interfaces should be set to something higher than 205the primary's. 206For example, if firewall B is the backup, its 207.Pa /etc/hostname.carp1 208would look like this: 209.Bd -literal -offset indent 210inet 192.168.0.1 255.255.255.0 192.168.0.255 vhid 2 pass bar \e 211 advskew 100 212.Ed 213.Pp 214The following must also be added to 215.Pa /etc/sysctl.conf : 216.Bd -literal -offset indent 217net.inet.carp.preempt=1 218.Ed 219.Sh SEE ALSO 220.Xr bpf 4 , 221.Xr carp 4 , 222.Xr enc 4 , 223.Xr inet 4 , 224.Xr inet6 4 , 225.Xr ipsec 4 , 226.Xr netintro 4 , 227.Xr pf 4 , 228.Xr hostname.if 5 , 229.Xr pf.conf 5 , 230.Xr protocols 5 , 231.Xr ifconfig 8 , 232.Xr ifstated 8 , 233.Xr tcpdump 8 234.Sh HISTORY 235The 236.Nm 237device first appeared in 238.Ox 3.3 . 239.Pp 240The 241.Nm 242protocol and kernel implementation were significantly modified between 243.Ox 4.4 244and 245.Ox 4.5 . 246The two protocols are incompatible and will not interoperate. 247