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 November 08, 2023 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 "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 116Support for 117.Nm 118transport over IPv6 was introduced in 119.Fx 14.0 . 120To set up 121.Nm 122using multicast with IPv6 link-local addresses, the 123.Ic syncpeer 124must be set to the 125.Nm 126multicast address and the 127.Ic syncdev 128to the interface where 129.Nm 130traffic is expected. 131.Bd -literal -offset indent 132# ifconfig pfsync0 syncpeer ff12::f0 syncdev vtnet0 133.Ed 134.Pp 135When new features are introduced to 136.Xr pf 4 137the format of messages used by 138.Nm 139might change. 140.Nm 141will by default use the latest format. 142If synchronization with a peer running an older version of FreeBSD is needed the 143.Ar version 144parameter can be used. 145E.g.: 146.Bd -literal -offset indent 147# ifconfig pfsync0 version 1301 148.Ed 149.Pp 150Currently the following versions are supported: 151.Bl -tag -width indent 152.It Cm 1301 153FreeBSD releases 13.2 and older. 154Compatibility with FreeBSD 13.1 has been verified. 155.It Cm 1400 156FreeBSD release 14.0. 157.El 158.Pp 159.Nm 160has the following 161.Xr sysctl 8 162tunables: 163.Bl -tag -width ".Va net.pfsync" 164.It Va net.pfsync.carp_demotion_factor 165Value added to 166.Va net.inet.carp.demotion 167while 168.Nm 169tries to perform its bulk update. 170See 171.Xr carp 4 172for more information. 173Default value is 240. 174.It Va net.pfsync.pfsync_buckets 175The number of 176.Nm 177buckets. 178This affects the performance and memory tradeoff. 179Defaults to twice the number of CPUs. 180Change only if benchmarks show this helps on your workload. 181.El 182.Sh EXAMPLES 183.Nm 184and 185.Xr carp 4 186can be used together to provide automatic failover of a pair of firewalls 187configured in parallel. 188One firewall will handle all traffic until it dies, is shut down, or is 189manually demoted, at which point the second firewall will take over 190automatically. 191.Pp 192Both firewalls in this example have three 193.Xr sis 4 194interfaces. 195sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 196internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 197.Nm 198interface, using the 192.168.254.0/24 subnet. 199A crossover cable connects the two firewalls via their sis2 interfaces. 200On all three interfaces, firewall A uses the .254 address, while firewall B 201uses .253. 202The interfaces are configured as follows (firewall A unless otherwise 203indicated): 204.Pp 205Interfaces configuration in 206.Pa /etc/rc.conf : 207.Bd -literal -offset indent 208network_interfaces="lo0 sis0 sis1 sis2" 209ifconfig_sis0="10.0.0.254/24" 210ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo" 211ifconfig_sis1="192.168.0.254/24" 212ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar" 213ifconfig_sis2="192.168.254.254/24" 214pfsync_enable="YES" 215pfsync_syncdev="sis2" 216.Ed 217.Pp 218.Xr pf 4 219must also be configured to allow 220.Nm 221and 222.Xr carp 4 223traffic through. 224The following should be added to the top of 225.Pa /etc/pf.conf : 226.Bd -literal -offset indent 227pass quick on { sis2 } proto pfsync keep state (no-sync) 228pass on { sis0 sis1 } proto carp keep state (no-sync) 229.Ed 230.Pp 231It is preferable that one firewall handle the forwarding of all the traffic, 232therefore the 233.Ar advskew 234on the backup firewall's 235.Xr carp 4 236vhids should be set to something higher than 237the primary's. 238For example, if firewall B is the backup, its 239carp1 configuration would look like this: 240.Bd -literal -offset indent 241ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100" 242.Ed 243.Pp 244The following must also be added to 245.Pa /etc/sysctl.conf : 246.Bd -literal -offset indent 247net.inet.carp.preempt=1 248.Ed 249.Sh SEE ALSO 250.Xr tcpdump 1 , 251.Xr bpf 4 , 252.Xr carp 4 , 253.Xr enc 4 , 254.Xr inet 4 , 255.Xr inet6 4 , 256.Xr ipsec 4 , 257.Xr netintro 4 , 258.Xr pf 4 , 259.Xr pf.conf 5 , 260.Xr protocols 5 , 261.Xr rc.conf 5 , 262.Xr ifconfig 8 263.Sh HISTORY 264The 265.Nm 266device first appeared in 267.Ox 3.3 . 268It was first imported to 269.Fx 5.3 . 270.Pp 271The 272.Nm 273protocol and kernel implementation were significantly modified in 274.Fx 9.0 . 275The newer protocol is not compatible with older one and will not interoperate 276with it. 277