1.\" $OpenBSD: pfsync.4,v 1.38 2023/10/18 07:56:45 benno 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: October 18 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 "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.Pp 134.Nm 135will increase the 136.Xr carp 4 137demotion counter for any interface groups associated with the interface 138by 32 during initialisation, and by 1 if the 139.Nm 140link is down or if a bulk update fails. 141.Sh EXAMPLES 142.Nm 143and 144.Xr carp 4 145can be used together to provide automatic failover of a pair of firewalls 146configured in parallel. 147One firewall will handle all traffic until it dies, is shut down, or is 148manually demoted, at which point the second firewall will take over 149automatically. 150.Pp 151Both firewalls in this example have three 152.Xr sis 4 153interfaces. 154sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 155internal interface, on the 192.168.0.0/24 subnet; and sis2 is the 156.Nm 157interface, using the 192.168.254.0/24 subnet. 158A crossover cable connects the two firewalls via their sis2 interfaces. 159On all three interfaces, firewall A uses the .254 address, while firewall B 160uses .253. 161The interfaces are configured as follows (firewall A unless otherwise 162indicated): 163.Pp 164.Pa /etc/hostname.sis0 : 165.Dl inet 10.0.0.254 255.255.255.0 NONE 166.Pp 167.Pa /etc/hostname.sis1 : 168.Dl inet 192.168.0.254 255.255.255.0 NONE 169.Pp 170.Pa /etc/hostname.sis2 : 171.Dl inet 192.168.254.254 255.255.255.0 NONE 172.Pp 173.Pa /etc/hostname.carp0 : 174.Bd -literal -offset indent -compact 175inet 10.0.0.1 255.255.255.0 10.0.0.255 \e 176 vhid 1 carpdev sis0 pass foo 177.Ed 178.Pp 179.Pa /etc/hostname.carp1 : 180.Bd -literal -offset indent -compact 181inet 192.168.0.1 255.255.255.0 192.168.0.255 \e 182 vhid 2 carpdev sis1 pass bar 183.Ed 184.Pp 185.Pa /etc/hostname.pfsync0 : 186.Bd -literal -offset indent -compact 187syncdev sis2 188up 189.Ed 190.Pp 191.Xr pf 4 192must also be configured to allow 193.Nm 194and 195.Xr carp 4 196traffic through. 197The following should be added to the top of 198.Pa /etc/pf.conf : 199.Bd -literal -offset indent 200pass quick on { sis2 } proto pfsync keep state (no-sync) 201pass on { sis0 sis1 } proto carp keep state (no-sync) 202.Ed 203.Pp 204It is preferable that one firewall handle the forwarding of all the traffic, 205therefore the 206.Ar advskew 207on the backup firewall's 208.Xr carp 4 209interfaces should be set to something higher than 210the primary's. 211For example, if firewall B is the backup, its 212.Pa /etc/hostname.carp1 213would look like this: 214.Bd -literal -offset indent 215inet 192.168.0.1 255.255.255.0 192.168.0.255 \e 216 vhid 2 pass bar advskew 100 217.Ed 218.Pp 219The following must also be added to 220.Pa /etc/sysctl.conf : 221.Bd -literal -offset indent 222net.inet.carp.preempt=1 223.Ed 224.Sh SEE ALSO 225.Xr bpf 4 , 226.Xr carp 4 , 227.\" .Xr enc 4 , 228.Xr inet 4 , 229.Xr inet6 4 , 230.\" .Xr ipsec 4 , 231.Xr netintro 4 , 232.Xr pf 4 , 233.Xr hostname.if 5 , 234.Xr pf.conf 5 , 235.Xr protocols 5 , 236.Xr ifconfig 8 , 237.Xr ifstated 8 , 238.Xr tcpdump 8 239.Sh HISTORY 240The 241.Nm 242device first appeared in 243.Ox 3.3 . 244.Pp 245The 246.Nm 247protocol and kernel implementation were significantly modified between 248.Ox 4.4 249and 250.Ox 4.5 . 251The two protocols are incompatible and will not interoperate. 252.Sh BUGS 253.Nm 254does not currently work with 255.Xr ipsec 4 . 256