1.\" $OpenBSD: pfsync.4,v 1.36 2016/08/30 13:56:14 jmc 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: August 30 2016 $ 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. 115.\" This can be used in combination with 116.\" .Xr ipsec 4 117.\" to protect the synchronisation traffic. 118.\" In such a configuration, the syncdev should be set to the 119.\" .Xr enc 4 120.\" interface, as this is where the traffic arrives when it is decapsulated, 121.\" e.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. 129Only run the pfsync protocol on a trusted network \- ideally a network 130dedicated to pfsync messages such as a crossover cable between two firewalls. 131.\" or 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.Dl inet 10.0.0.254 255.255.255.0 NONE 158.Pp 159.Pa /etc/hostname.sis1 : 160.Dl inet 192.168.0.254 255.255.255.0 NONE 161.Pp 162.Pa /etc/hostname.sis2 : 163.Dl inet 192.168.254.254 255.255.255.0 NONE 164.Pp 165.Pa /etc/hostname.carp0 : 166.Bd -literal -offset indent -compact 167inet 10.0.0.1 255.255.255.0 10.0.0.255 \e 168 vhid 1 carpdev sis0 pass foo 169.Ed 170.Pp 171.Pa /etc/hostname.carp1 : 172.Bd -literal -offset indent -compact 173inet 192.168.0.1 255.255.255.0 192.168.0.255 \e 174 vhid 2 carpdev sis1 pass bar 175.Ed 176.Pp 177.Pa /etc/hostname.pfsync0 : 178.Dl up syncdev sis2 179.Pp 180.Xr pf 4 181must also be configured to allow 182.Nm 183and 184.Xr carp 4 185traffic through. 186The following should be added to the top of 187.Pa /etc/pf.conf : 188.Bd -literal -offset indent 189pass quick on { sis2 } proto pfsync keep state (no-sync) 190pass on { sis0 sis1 } proto carp keep state (no-sync) 191.Ed 192.Pp 193It is preferable that one firewall handle the forwarding of all the traffic, 194therefore the 195.Ar advskew 196on the backup firewall's 197.Xr carp 4 198interfaces should be set to something higher than 199the primary's. 200For example, if firewall B is the backup, its 201.Pa /etc/hostname.carp1 202would look like this: 203.Bd -literal -offset indent 204inet 192.168.0.1 255.255.255.0 192.168.0.255 \e 205 vhid 2 pass bar advskew 100 206.Ed 207.Pp 208The following must also be added to 209.Pa /etc/sysctl.conf : 210.Bd -literal -offset indent 211net.inet.carp.preempt=1 212.Ed 213.Sh SEE ALSO 214.Xr bpf 4 , 215.Xr carp 4 , 216.\" .Xr enc 4 , 217.Xr inet 4 , 218.Xr inet6 4 , 219.\" .Xr ipsec 4 , 220.Xr netintro 4 , 221.Xr pf 4 , 222.Xr hostname.if 5 , 223.Xr pf.conf 5 , 224.Xr protocols 5 , 225.Xr ifconfig 8 , 226.Xr ifstated 8 , 227.Xr tcpdump 8 228.Sh HISTORY 229The 230.Nm 231device first appeared in 232.Ox 3.3 . 233.Pp 234The 235.Nm 236protocol and kernel implementation were significantly modified between 237.Ox 4.4 238and 239.Ox 4.5 . 240The two protocols are incompatible and will not interoperate. 241.Sh BUGS 242.Nm 243does not currently work with 244.Xr ipsec 4 . 245