1.\" $OpenBSD: pfsync.4,v 1.28 2009/02/17 10:05:18 dlg 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 December 6, 2018 28.Dt PFSYNC 4 29.Os 30.Sh NAME 31.Nm pfsync 32.Nd packet filter state table sychronisation interface 33.Sh SYNOPSIS 34.Cd "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 1 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.Sh NETWORK SYNCHRONISATION 81States can be synchronised between two or more firewalls using this 82interface, by specifying a synchronisation interface using 83.Xr ifconfig 8 . 84For example, the following command sets fxp0 as the synchronisation 85interface: 86.Bd -literal -offset indent 87# ifconfig pfsync0 syncdev fxp0 88.Ed 89.Pp 90By default, state change messages are sent out on the synchronisation 91interface using IP multicast packets to the 224.0.0.240 group address. 92An alternative destination address for 93.Nm 94packets can be specified using the 95.Ic syncpeer 96keyword. 97This can be used in combination with 98.Xr ipsec 4 99to protect the synchronisation traffic. 100In such a configuration, the syncdev should be set to the 101.Xr enc 4 102interface, as this is where the traffic arrives when it is decapsulated, 103e.g.: 104.Bd -literal -offset indent 105# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0 106.Ed 107.Pp 108It is important that the pfsync traffic be well secured 109as there is no authentication on the protocol and it would 110be trivial to spoof packets which create states, bypassing the pf ruleset. 111Either run the pfsync protocol on a trusted network \- ideally a network 112dedicated to pfsync messages such as a crossover cable between two firewalls, 113or specify a peer address and protect the traffic with 114.Xr ipsec 4 . 115.Pp 116.Nm 117has the following 118.Xr sysctl 8 119tunables: 120.Bl -tag -width ".Va net.pfsync" 121.It Va net.pfsync.carp_demotion_factor 122Value added to 123.Va net.inet.carp.demotion 124while 125.Nm 126tries to perform its bulk update. 127See 128.Xr carp 4 129for more information. 130Default value is 240. 131.It Va net.pfsync.pfsync_buckets 132The number of 133.Nm 134buckets. 135This affects the performance and memory tradeoff. 136Defaults to twice the number of CPUs. 137Change only if benchmarks show this helps on your workload. 138.El 139.Sh EXAMPLES 140.Nm 141and 142.Xr carp 4 143can be used together to provide automatic failover of a pair of firewalls 144configured in parallel. 145One firewall will handle all traffic until it dies, is shut down, or is 146manually demoted, at which point the second firewall will take over 147automatically. 148.Pp 149Both firewalls in this example have three 150.Xr sis 4 151interfaces. 152sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 153internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 154.Nm 155interface, using the 192.168.254.0/24 subnet. 156A crossover cable connects the two firewalls via their sis2 interfaces. 157On all three interfaces, firewall A uses the .254 address, while firewall B 158uses .253. 159The interfaces are configured as follows (firewall A unless otherwise 160indicated): 161.Pp 162Interfaces configuration in 163.Pa /etc/rc.conf : 164.Bd -literal -offset indent 165network_interfaces="lo0 sis0 sis1 sis2" 166ifconfig_sis0="10.0.0.254/24" 167ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo" 168ifconfig_sis1="192.168.0.254/24" 169ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar" 170ifconfig_sis2="192.168.254.254/24" 171pfsync_enable="YES" 172pfsync_syncdev="sis2" 173.Ed 174.Pp 175.Xr pf 4 176must also be configured to allow 177.Nm 178and 179.Xr carp 4 180traffic through. 181The following should be added to the top of 182.Pa /etc/pf.conf : 183.Bd -literal -offset indent 184pass quick on { sis2 } proto pfsync keep state (no-sync) 185pass on { sis0 sis1 } proto carp keep state (no-sync) 186.Ed 187.Pp 188It is preferable that one firewall handle the forwarding of all the traffic, 189therefore the 190.Ar advskew 191on the backup firewall's 192.Xr carp 4 193vhids should be set to something higher than 194the primary's. 195For example, if firewall B is the backup, its 196carp1 configuration would look like this: 197.Bd -literal -offset indent 198ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100" 199.Ed 200.Pp 201The following must also be added to 202.Pa /etc/sysctl.conf : 203.Bd -literal -offset indent 204net.inet.carp.preempt=1 205.Ed 206.Sh SEE ALSO 207.Xr tcpdump 1 , 208.Xr bpf 4 , 209.Xr carp 4 , 210.Xr enc 4 , 211.Xr inet 4 , 212.Xr inet6 4 , 213.Xr ipsec 4 , 214.Xr netintro 4 , 215.Xr pf 4 , 216.Xr pf.conf 5 , 217.Xr protocols 5 , 218.Xr rc.conf 5 , 219.Xr ifconfig 8 220.Sh HISTORY 221The 222.Nm 223device first appeared in 224.Ox 3.3 . 225It was first imported to 226.Fx 5.3 . 227.Pp 228The 229.Nm 230protocol and kernel implementation were significantly modified in 231.Fx 9.0 . 232The newer protocol is not compatible with older one and will not interoperate 233with it. 234