13b3a8eb9SGleb Smirnoff.\" $OpenBSD: pfsync.4,v 1.28 2009/02/17 10:05:18 dlg Exp $ 23b3a8eb9SGleb Smirnoff.\" 33b3a8eb9SGleb Smirnoff.\" Copyright (c) 2002 Michael Shalayeff 43b3a8eb9SGleb Smirnoff.\" Copyright (c) 2003-2004 Ryan McBride 53b3a8eb9SGleb Smirnoff.\" All rights reserved. 63b3a8eb9SGleb Smirnoff.\" 73b3a8eb9SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without 83b3a8eb9SGleb Smirnoff.\" modification, are permitted provided that the following conditions 93b3a8eb9SGleb Smirnoff.\" are met: 103b3a8eb9SGleb Smirnoff.\" 1. Redistributions of source code must retain the above copyright 113b3a8eb9SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer. 123b3a8eb9SGleb Smirnoff.\" 2. Redistributions in binary form must reproduce the above copyright 133b3a8eb9SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer in the 143b3a8eb9SGleb Smirnoff.\" documentation and/or other materials provided with the distribution. 153b3a8eb9SGleb Smirnoff.\" 163b3a8eb9SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 173b3a8eb9SGleb Smirnoff.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 183b3a8eb9SGleb Smirnoff.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 193b3a8eb9SGleb Smirnoff.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 203b3a8eb9SGleb Smirnoff.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 213b3a8eb9SGleb Smirnoff.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND, 223b3a8eb9SGleb Smirnoff.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 233b3a8eb9SGleb Smirnoff.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 243b3a8eb9SGleb Smirnoff.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 253b3a8eb9SGleb Smirnoff.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 263b3a8eb9SGleb Smirnoff.\" 273b3a8eb9SGleb Smirnoff.\" $FreeBSD$ 283b3a8eb9SGleb Smirnoff.\" 290b3504fdSChristian Brueffer.Dd December 20, 2011 303b3a8eb9SGleb Smirnoff.Dt PFSYNC 4 313b3a8eb9SGleb Smirnoff.Os 323b3a8eb9SGleb Smirnoff.Sh NAME 333b3a8eb9SGleb Smirnoff.Nm pfsync 343b3a8eb9SGleb Smirnoff.Nd packet filter state table sychronisation interface 353b3a8eb9SGleb Smirnoff.Sh SYNOPSIS 363b3a8eb9SGleb Smirnoff.Cd "device pfsync" 373b3a8eb9SGleb Smirnoff.Sh DESCRIPTION 383b3a8eb9SGleb SmirnoffThe 393b3a8eb9SGleb Smirnoff.Nm 403b3a8eb9SGleb Smirnoffinterface is a pseudo-device which exposes certain changes to the state 413b3a8eb9SGleb Smirnofftable used by 423b3a8eb9SGleb Smirnoff.Xr pf 4 . 433b3a8eb9SGleb SmirnoffState changes can be viewed by invoking 443b3a8eb9SGleb Smirnoff.Xr tcpdump 1 453b3a8eb9SGleb Smirnoffon the 463b3a8eb9SGleb Smirnoff.Nm 473b3a8eb9SGleb Smirnoffinterface. 483b3a8eb9SGleb SmirnoffIf configured with a physical synchronisation interface, 493b3a8eb9SGleb Smirnoff.Nm 503b3a8eb9SGleb Smirnoffwill also send state changes out on that interface, 513b3a8eb9SGleb Smirnoffand insert state changes received on that interface from other systems 523b3a8eb9SGleb Smirnoffinto the state table. 533b3a8eb9SGleb Smirnoff.Pp 543b3a8eb9SGleb SmirnoffBy default, all local changes to the state table are exposed via 553b3a8eb9SGleb Smirnoff.Nm . 563b3a8eb9SGleb SmirnoffState changes from packets received by 573b3a8eb9SGleb Smirnoff.Nm 583b3a8eb9SGleb Smirnoffover the network are not rebroadcast. 593b3a8eb9SGleb SmirnoffUpdates to states created by a rule marked with the 603b3a8eb9SGleb Smirnoff.Ar no-sync 613b3a8eb9SGleb Smirnoffkeyword are ignored by the 623b3a8eb9SGleb Smirnoff.Nm 633b3a8eb9SGleb Smirnoffinterface (see 643b3a8eb9SGleb Smirnoff.Xr pf.conf 5 653b3a8eb9SGleb Smirnofffor details). 663b3a8eb9SGleb Smirnoff.Pp 673b3a8eb9SGleb SmirnoffThe 683b3a8eb9SGleb Smirnoff.Nm 693b3a8eb9SGleb Smirnoffinterface will attempt to collapse multiple state updates into a single 703b3a8eb9SGleb Smirnoffpacket where possible. 713b3a8eb9SGleb SmirnoffThe maximum number of times a single state can be updated before a 723b3a8eb9SGleb Smirnoff.Nm 733b3a8eb9SGleb Smirnoffpacket will be sent out is controlled by the 743b3a8eb9SGleb Smirnoff.Ar maxupd 753b3a8eb9SGleb Smirnoffparameter to ifconfig 763b3a8eb9SGleb Smirnoff(see 773b3a8eb9SGleb Smirnoff.Xr ifconfig 8 783b3a8eb9SGleb Smirnoffand the example below for more details). 793b3a8eb9SGleb SmirnoffThe sending out of a 803b3a8eb9SGleb Smirnoff.Nm 813b3a8eb9SGleb Smirnoffpacket will be delayed by a maximum of one second. 823b3a8eb9SGleb Smirnoff.Sh NETWORK SYNCHRONISATION 833b3a8eb9SGleb SmirnoffStates can be synchronised between two or more firewalls using this 843b3a8eb9SGleb Smirnoffinterface, by specifying a synchronisation interface using 853b3a8eb9SGleb Smirnoff.Xr ifconfig 8 . 863b3a8eb9SGleb SmirnoffFor example, the following command sets fxp0 as the synchronisation 873b3a8eb9SGleb Smirnoffinterface: 883b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 893b3a8eb9SGleb Smirnoff# ifconfig pfsync0 syncdev fxp0 903b3a8eb9SGleb Smirnoff.Ed 913b3a8eb9SGleb Smirnoff.Pp 923b3a8eb9SGleb SmirnoffBy default, state change messages are sent out on the synchronisation 933b3a8eb9SGleb Smirnoffinterface using IP multicast packets to the 244.0.0.240 group address. 943b3a8eb9SGleb SmirnoffAn alternative destination address for 953b3a8eb9SGleb Smirnoff.Nm 963b3a8eb9SGleb Smirnoffpackets can be specified using the 973b3a8eb9SGleb Smirnoff.Ic syncpeer 983b3a8eb9SGleb Smirnoffkeyword. 993b3a8eb9SGleb SmirnoffThis can be used in combination with 1003b3a8eb9SGleb Smirnoff.Xr ipsec 4 1013b3a8eb9SGleb Smirnoffto protect the synchronisation traffic. 1023b3a8eb9SGleb SmirnoffIn such a configuration, the syncdev should be set to the 1033b3a8eb9SGleb Smirnoff.Xr enc 4 1043b3a8eb9SGleb Smirnoffinterface, as this is where the traffic arrives when it is decapsulated, 1053b3a8eb9SGleb Smirnoffe.g.: 1063b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 1073b3a8eb9SGleb Smirnoff# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0 1083b3a8eb9SGleb Smirnoff.Ed 1093b3a8eb9SGleb Smirnoff.Pp 1103b3a8eb9SGleb SmirnoffIt is important that the pfsync traffic be well secured 1113b3a8eb9SGleb Smirnoffas there is no authentication on the protocol and it would 1123b3a8eb9SGleb Smirnoffbe trivial to spoof packets which create states, bypassing the pf ruleset. 1133b3a8eb9SGleb SmirnoffEither run the pfsync protocol on a trusted network \- ideally a network 1143b3a8eb9SGleb Smirnoffdedicated to pfsync messages such as a crossover cable between two firewalls, 1153b3a8eb9SGleb Smirnoffor specify a peer address and protect the traffic with 1163b3a8eb9SGleb Smirnoff.Xr ipsec 4 . 1173b3a8eb9SGleb Smirnoff.Pp 1183b3a8eb9SGleb Smirnoff.Nm 1193b3a8eb9SGleb Smirnoffhas the following 1203b3a8eb9SGleb Smirnoff.Xr sysctl 8 1213b3a8eb9SGleb Smirnofftunables: 1223b3a8eb9SGleb Smirnoff.Bl -tag -width ".Va net.pfsync" 1233b3a8eb9SGleb Smirnoff.It Va net.pfsync.carp_demotion_factor 1243b3a8eb9SGleb SmirnoffValue added to 1253b3a8eb9SGleb Smirnoff.Va net.inet.carp.demotion 1263b3a8eb9SGleb Smirnoffwhile 1273b3a8eb9SGleb Smirnoff.Nm 1283b3a8eb9SGleb Smirnofftries to perform its bulk update. 1293b3a8eb9SGleb SmirnoffSee 1303b3a8eb9SGleb Smirnoff.Xr carp 4 1313b3a8eb9SGleb Smirnofffor more information. 1323b3a8eb9SGleb SmirnoffDefault value is 240. 1333b3a8eb9SGleb Smirnoff.El 1343b3a8eb9SGleb Smirnoff.Sh EXAMPLES 1353b3a8eb9SGleb Smirnoff.Nm 1363b3a8eb9SGleb Smirnoffand 1373b3a8eb9SGleb Smirnoff.Xr carp 4 1383b3a8eb9SGleb Smirnoffcan be used together to provide automatic failover of a pair of firewalls 1393b3a8eb9SGleb Smirnoffconfigured in parallel. 1403b3a8eb9SGleb SmirnoffOne firewall will handle all traffic until it dies, is shut down, or is 1413b3a8eb9SGleb Smirnoffmanually demoted, at which point the second firewall will take over 1423b3a8eb9SGleb Smirnoffautomatically. 1433b3a8eb9SGleb Smirnoff.Pp 1443b3a8eb9SGleb SmirnoffBoth firewalls in this example have three 1453b3a8eb9SGleb Smirnoff.Xr sis 4 1463b3a8eb9SGleb Smirnoffinterfaces. 1473b3a8eb9SGleb Smirnoffsis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 1483b3a8eb9SGleb Smirnoffinternal interface, on the 192.168.0.0/24 subnet; and sis2 is the 1493b3a8eb9SGleb Smirnoff.Nm 1503b3a8eb9SGleb Smirnoffinterface, using the 192.168.254.0/24 subnet. 1513b3a8eb9SGleb SmirnoffA crossover cable connects the two firewalls via their sis2 interfaces. 1523b3a8eb9SGleb SmirnoffOn all three interfaces, firewall A uses the .254 address, while firewall B 1533b3a8eb9SGleb Smirnoffuses .253. 1543b3a8eb9SGleb SmirnoffThe interfaces are configured as follows (firewall A unless otherwise 1553b3a8eb9SGleb Smirnoffindicated): 1563b3a8eb9SGleb Smirnoff.Pp 1573b3a8eb9SGleb SmirnoffInterfaces configuration in 1583b3a8eb9SGleb Smirnoff.Pa /etc/rc.conf : 1593b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 1603b3a8eb9SGleb Smirnoffnetwork_interfaces="lo0 sis0 sis1 sis2" 1613b3a8eb9SGleb Smirnoffifconfig_sis0="10.0.0.254/24" 1623b3a8eb9SGleb Smirnoffifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo" 1633b3a8eb9SGleb Smirnoffifconfig_sis1="192.168.0.254/24" 1643b3a8eb9SGleb Smirnoffifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar" 1653b3a8eb9SGleb Smirnoffifconfig_sis2="192.168.254.254/24" 1663b3a8eb9SGleb Smirnoffpfsync_enable="YES" 1673b3a8eb9SGleb Smirnoffpfsync_syncdev="sis2" 1683b3a8eb9SGleb Smirnoff.Ed 1693b3a8eb9SGleb Smirnoff.Pp 1703b3a8eb9SGleb Smirnoff.Xr pf 4 1713b3a8eb9SGleb Smirnoffmust also be configured to allow 1723b3a8eb9SGleb Smirnoff.Nm 1733b3a8eb9SGleb Smirnoffand 1743b3a8eb9SGleb Smirnoff.Xr carp 4 1753b3a8eb9SGleb Smirnofftraffic through. 1763b3a8eb9SGleb SmirnoffThe following should be added to the top of 1773b3a8eb9SGleb Smirnoff.Pa /etc/pf.conf : 1783b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 1793b3a8eb9SGleb Smirnoffpass quick on { sis2 } proto pfsync keep state (no-sync) 1803b3a8eb9SGleb Smirnoffpass on { sis0 sis1 } proto carp keep state (no-sync) 1813b3a8eb9SGleb Smirnoff.Ed 1823b3a8eb9SGleb Smirnoff.Pp 1833b3a8eb9SGleb SmirnoffIt is preferable that one firewall handle the forwarding of all the traffic, 1843b3a8eb9SGleb Smirnofftherefore the 1853b3a8eb9SGleb Smirnoff.Ar advskew 1863b3a8eb9SGleb Smirnoffon the backup firewall's 1873b3a8eb9SGleb Smirnoff.Xr carp 4 1883b3a8eb9SGleb Smirnoffvhids should be set to something higher than 1893b3a8eb9SGleb Smirnoffthe primary's. 1903b3a8eb9SGleb SmirnoffFor example, if firewall B is the backup, its 1913b3a8eb9SGleb Smirnoffcarp1 configuration would look like this: 1923b3a8eb9SGleb Smirnoffwould look like this: 1933b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 1943b3a8eb9SGleb Smirnoffifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100" 1953b3a8eb9SGleb Smirnoff.Ed 1963b3a8eb9SGleb Smirnoff.Pp 1973b3a8eb9SGleb SmirnoffThe following must also be added to 1983b3a8eb9SGleb Smirnoff.Pa /etc/sysctl.conf : 1993b3a8eb9SGleb Smirnoff.Bd -literal -offset indent 2003b3a8eb9SGleb Smirnoffnet.inet.carp.preempt=1 2013b3a8eb9SGleb Smirnoff.Ed 2023b3a8eb9SGleb Smirnoff.Sh SEE ALSO 203*923544aaSBaptiste Daroussin.Xr tcpdump 1 , 2043b3a8eb9SGleb Smirnoff.Xr bpf 4 , 2053b3a8eb9SGleb Smirnoff.Xr carp 4 , 2063b3a8eb9SGleb Smirnoff.Xr enc 4 , 2073b3a8eb9SGleb Smirnoff.Xr inet 4 , 2083b3a8eb9SGleb Smirnoff.Xr inet6 4 , 2093b3a8eb9SGleb Smirnoff.Xr ipsec 4 , 2103b3a8eb9SGleb Smirnoff.Xr netintro 4 , 2113b3a8eb9SGleb Smirnoff.Xr pf 4 , 2123b3a8eb9SGleb Smirnoff.Xr pf.conf 5 , 2133b3a8eb9SGleb Smirnoff.Xr protocols 5 , 2143b3a8eb9SGleb Smirnoff.Xr rc.conf 5 , 215*923544aaSBaptiste Daroussin.Xr ifconfig 8 2163b3a8eb9SGleb Smirnoff.Sh HISTORY 2173b3a8eb9SGleb SmirnoffThe 2183b3a8eb9SGleb Smirnoff.Nm 2193b3a8eb9SGleb Smirnoffdevice first appeared in 2203b3a8eb9SGleb Smirnoff.Ox 3.3 . 2213b3a8eb9SGleb SmirnoffIt was first imported to 2223b3a8eb9SGleb Smirnoff.Fx 5.3 . 2233b3a8eb9SGleb Smirnoff.Pp 2243b3a8eb9SGleb SmirnoffThe 2253b3a8eb9SGleb Smirnoff.Nm 2263b3a8eb9SGleb Smirnoffprotocol and kernel implementation were significantly modified in 2273b3a8eb9SGleb Smirnoff.Fx 9.0 . 2283b3a8eb9SGleb SmirnoffThe newer protocol is not compatible with older one and will not interoperate 2293b3a8eb9SGleb Smirnoffwith it. 230