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.Pp 36In 37.Xr loader.conf 5 : 38.Cd net.pfsync.pfsync_buckets 39.Pp 40In 41.Xr sysctl.conf 5 : 42.Cd net.pfsync.carp_demotion_factor 43.Sh DESCRIPTION 44The 45.Nm 46interface is a pseudo-device which exposes certain changes to the state 47table used by 48.Xr pf 4 . 49State changes can be viewed by invoking 50.Xr tcpdump 1 51on the 52.Nm 53interface. 54If configured with a physical synchronisation interface, 55.Nm 56will also send state changes out on that interface, 57and insert state changes received on that interface from other systems 58into the state table. 59.Pp 60By default, all local changes to the state table are exposed via 61.Nm . 62State changes from packets received by 63.Nm 64over the network are not rebroadcast. 65Updates to states created by a rule marked with the 66.Ar no-sync 67keyword are ignored by the 68.Nm 69interface (see 70.Xr pf.conf 5 71for details). 72.Pp 73The 74.Nm 75interface will attempt to collapse multiple state updates into a single 76packet where possible. 77The maximum number of times a single state can be updated before a 78.Nm 79packet will be sent out is controlled by the 80.Ar maxupd 81parameter to ifconfig 82(see 83.Xr ifconfig 8 84and the example below for more details). 85The sending out of a 86.Nm 87packet will be delayed by a maximum of one second. 88.Sh NETWORK SYNCHRONISATION 89States can be synchronised between two or more firewalls using this 90interface, by specifying a synchronisation interface using 91.Xr ifconfig 8 . 92For example, the following command sets fxp0 as the synchronisation 93interface: 94.Bd -literal -offset indent 95# ifconfig pfsync0 syncdev fxp0 96.Ed 97.Pp 98By default, state change messages are sent out on the synchronisation 99interface using IP multicast packets to the 224.0.0.240 group address. 100An alternative destination address for 101.Nm 102packets can be specified using the 103.Ic syncpeer 104keyword. 105This can be used in combination with 106.Xr ipsec 4 107to protect the synchronisation traffic. 108In such a configuration, the syncdev should be set to the 109.Xr enc 4 110interface, as this is where the traffic arrives when it is decapsulated, 111e.g.: 112.Bd -literal -offset indent 113# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0 114.Ed 115.Pp 116It is important that the pfsync traffic be well secured 117as there is no authentication on the protocol and it would 118be trivial to spoof packets which create states, bypassing the pf ruleset. 119Either run the pfsync protocol on a trusted network \- ideally a network 120dedicated to pfsync messages such as a crossover cable between two firewalls, 121or specify a peer address and protect the traffic with 122.Xr ipsec 4 . 123.Pp 124Support for 125.Nm 126transport over IPv6 was introduced in 127.Fx 14.0 . 128To set up 129.Nm 130using multicast with IPv6 link-local addresses, the 131.Ic syncpeer 132must be set to the 133.Nm 134multicast address and the 135.Ic syncdev 136to the interface where 137.Nm 138traffic is expected. 139.Bd -literal -offset indent 140# ifconfig pfsync0 syncpeer ff12::f0 syncdev vtnet0 141.Ed 142.Pp 143When new features are introduced to 144.Xr pf 4 145the format of messages used by 146.Nm 147might change. 148.Nm 149will by default use the latest format. 150If synchronization with a peer running an older version of FreeBSD is needed the 151.Ar version 152parameter can be used. 153E.g.: 154.Bd -literal -offset indent 155# ifconfig pfsync0 version 1301 156.Ed 157.Pp 158Currently the following versions are supported: 159.Bl -tag -width indent 160.It Cm 1301 161FreeBSD releases 13.2 and older. 162Compatibility with FreeBSD 13.1 has been verified. 163.It Cm 1400 164FreeBSD release 14.0. 165.El 166.Sh SYSCTL VARIABLES 167The following variables can be entered at the 168.Xr loader 8 169prompt, set in 170.Xr loader.conf 5 , 171or changed at runtime with 172.Xr sysctl 8 : 173.Bl -tag -width indent 174.It Va net.pfsync.carp_demotion_factor 175Value added to 176.Va net.inet.carp.demotion 177while 178.Nm 179tries to perform its bulk update. 180See 181.Xr carp 4 182for more information. 183Default value is 240. 184.El 185.Sh LOADER TUNABLES 186The following tunable may be set in 187.Xr loader.conf 5 188or at the 189.Xr loader 8 190prompt: 191.Bl -tag -width indent 192.It Va net.pfsync.pfsync_buckets 193The number of 194.Nm 195buckets. 196This affects the performance and memory tradeoff. 197Defaults to twice the number of CPUs. 198Change only if benchmarks show this helps on your workload. 199.El 200.Sh EXAMPLES 201.Nm 202and 203.Xr carp 4 204can be used together to provide automatic failover of a pair of firewalls 205configured in parallel. 206One firewall will handle all traffic until it dies, is shut down, or is 207manually demoted, at which point the second firewall will take over 208automatically. 209.Pp 210Both firewalls in this example have three 211.Xr sis 4 212interfaces. 213sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 214internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 215.Nm 216interface, using the 192.168.254.0/24 subnet. 217A crossover cable connects the two firewalls via their sis2 interfaces. 218On all three interfaces, firewall A uses the .254 address, while firewall B 219uses .253. 220The interfaces are configured as follows (firewall A unless otherwise 221indicated): 222.Pp 223Interfaces configuration in 224.Pa /etc/rc.conf : 225.Bd -literal -offset indent 226network_interfaces="lo0 sis0 sis1 sis2" 227ifconfig_sis0="10.0.0.254/24" 228ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo" 229ifconfig_sis1="192.168.0.254/24" 230ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar" 231ifconfig_sis2="192.168.254.254/24" 232pfsync_enable="YES" 233pfsync_syncdev="sis2" 234.Ed 235.Pp 236.Xr pf 4 237must also be configured to allow 238.Nm 239and 240.Xr carp 4 241traffic through. 242The following should be added to the top of 243.Pa /etc/pf.conf : 244.Bd -literal -offset indent 245pass quick on { sis2 } proto pfsync keep state (no-sync) 246pass on { sis0 sis1 } proto carp keep state (no-sync) 247.Ed 248.Pp 249It is preferable that one firewall handle the forwarding of all the traffic, 250therefore the 251.Ar advskew 252on the backup firewall's 253.Xr carp 4 254vhids should be set to something higher than 255the primary's. 256For example, if firewall B is the backup, its 257carp1 configuration would look like this: 258.Bd -literal -offset indent 259ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100" 260.Ed 261.Pp 262The following must also be added to 263.Pa /etc/sysctl.conf : 264.Bd -literal -offset indent 265net.inet.carp.preempt=1 266.Ed 267.Sh SEE ALSO 268.Xr tcpdump 1 , 269.Xr bpf 4 , 270.Xr carp 4 , 271.Xr enc 4 , 272.Xr inet 4 , 273.Xr inet6 4 , 274.Xr ipsec 4 , 275.Xr netintro 4 , 276.Xr pf 4 , 277.Xr pf.conf 5 , 278.Xr protocols 5 , 279.Xr rc.conf 5 , 280.Xr ifconfig 8 281.Sh HISTORY 282The 283.Nm 284device first appeared in 285.Ox 3.3 . 286It was first imported to 287.Fx 5.3 . 288.Pp 289The 290.Nm 291protocol and kernel implementation were significantly modified in 292.Fx 9.0 . 293The newer protocol is not compatible with older one and will not interoperate 294with it. 295