14696a7e0SJan Lentfer.\" $OpenBSD: pfsync.4,v 1.27 2008/06/03 19:51:02 jmc Exp $ 2f1e85027SSimon Schubert.\" 3f1e85027SSimon Schubert.\" Copyright (c) 2002 Michael Shalayeff 470224baaSJan Lentfer.\" Copyright (c) 2003-2004 Ryan McBride 5f1e85027SSimon Schubert.\" All rights reserved. 6f1e85027SSimon Schubert.\" 7f1e85027SSimon Schubert.\" Redistribution and use in source and binary forms, with or without 8f1e85027SSimon Schubert.\" modification, are permitted provided that the following conditions 9f1e85027SSimon Schubert.\" are met: 10f1e85027SSimon Schubert.\" 1. Redistributions of source code must retain the above copyright 11f1e85027SSimon Schubert.\" notice, this list of conditions and the following disclaimer. 12f1e85027SSimon Schubert.\" 2. Redistributions in binary form must reproduce the above copyright 13f1e85027SSimon Schubert.\" notice, this list of conditions and the following disclaimer in the 14f1e85027SSimon Schubert.\" documentation and/or other materials provided with the distribution. 15f1e85027SSimon Schubert.\" 16f1e85027SSimon Schubert.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17f1e85027SSimon Schubert.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18f1e85027SSimon Schubert.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19f1e85027SSimon Schubert.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20f1e85027SSimon Schubert.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21f1e85027SSimon Schubert.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF MIND, 22f1e85027SSimon Schubert.\" USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23f1e85027SSimon Schubert.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24f1e85027SSimon Schubert.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25f1e85027SSimon Schubert.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26f1e85027SSimon Schubert.\" 27*755d70b8SSascha Wildner.Dd April 21, 2018 28f1e85027SSimon Schubert.Dt PFSYNC 4 29f1e85027SSimon Schubert.Os 30f1e85027SSimon Schubert.Sh NAME 31f1e85027SSimon Schubert.Nm pfsync 3270224baaSJan Lentfer.Nd packet filter state table logging interface 33f1e85027SSimon Schubert.Sh SYNOPSIS 34f1e85027SSimon Schubert.Cd "device pfsync" 35f1e85027SSimon Schubert.Sh DESCRIPTION 36f1e85027SSimon SchubertThe 37f1e85027SSimon Schubert.Nm 38f1e85027SSimon Schubertinterface is a pseudo-device which exposes certain changes to the state 39f1e85027SSimon Schuberttable used by 40f1e85027SSimon Schubert.Xr pf 4 . 41f1e85027SSimon SchubertState changes can be viewed by invoking 42b958492bSSascha Wildner.Xr tcpdump 1 43f1e85027SSimon Schuberton the 44f1e85027SSimon Schubert.Nm 45f1e85027SSimon Schubertinterface. 46f1e85027SSimon SchubertIf configured with a physical synchronisation interface, 47f1e85027SSimon Schubert.Nm 48f1e85027SSimon Schubertwill also send state changes out on that interface using IP multicast, 49f1e85027SSimon Schubertand insert state changes received on that interface from other systems 50f1e85027SSimon Schubertinto the state table. 51f1e85027SSimon Schubert.Pp 52f1e85027SSimon SchubertBy default, all local changes to the state table are exposed via 53f1e85027SSimon Schubert.Nm . 54f1e85027SSimon SchubertHowever, state changes from packets received by 55f1e85027SSimon Schubert.Nm 56f1e85027SSimon Schubertover the network are not rebroadcast. 57f1e85027SSimon SchubertStates created by a rule marked with the 58f1e85027SSimon Schubert.Ar no-sync 59f1e85027SSimon Schubertkeyword are omitted from the 60f1e85027SSimon Schubert.Nm 61f1e85027SSimon Schubertinterface (see 62f1e85027SSimon Schubert.Xr pf.conf 5 63f1e85027SSimon Schubertfor details). 64f1e85027SSimon Schubert.Pp 65f1e85027SSimon SchubertThe 66f1e85027SSimon Schubert.Nm 67f1e85027SSimon Schubertinterface will attempt to collapse multiple updates of the same 68f1e85027SSimon Schubertstate into one message where possible. 69f1e85027SSimon SchubertThe maximum number of times this can be done before the update is sent out 70f1e85027SSimon Schubertis controlled by the 71f1e85027SSimon Schubert.Ar maxupd 7270224baaSJan Lentferparameter to ifconfig 73f1e85027SSimon Schubert(see 74f1e85027SSimon Schubert.Xr ifconfig 8 7570224baaSJan Lentferand the example below for more details). 76f1e85027SSimon Schubert.Pp 77f1e85027SSimon SchubertEach packet retrieved on this interface has a header associated 78f1e85027SSimon Schubertwith it of length 79f1e85027SSimon Schubert.Dv PFSYNC_HDRLEN . 80f1e85027SSimon SchubertThe header indicates the version of the protocol, address family, 8170224baaSJan Lentferaction taken on the following states, and the number of state 82f1e85027SSimon Schuberttable entries attached in this packet. 8370224baaSJan LentferThis structure is defined in 8470224baaSJan Lentfer.Aq Pa net/pf/if_pfsync.h 8570224baaSJan Lentferas: 86f1e85027SSimon Schubert.Bd -literal -offset indent 87f1e85027SSimon Schubertstruct pfsync_header { 88f1e85027SSimon Schubert u_int8_t version; 89f1e85027SSimon Schubert u_int8_t af; 90f1e85027SSimon Schubert u_int8_t action; 91f1e85027SSimon Schubert u_int8_t count; 92f1e85027SSimon Schubert}; 93f1e85027SSimon Schubert.Ed 94f1e85027SSimon Schubert.Sh NETWORK SYNCHRONISATION 95f1e85027SSimon SchubertStates can be synchronised between two or more firewalls using this 96f1e85027SSimon Schubertinterface, by specifying a synchronisation interface using 97f1e85027SSimon Schubert.Xr ifconfig 8 . 98f1e85027SSimon SchubertFor example, the following command sets fxp0 as the synchronisation 9970224baaSJan Lentferinterface: 100f1e85027SSimon Schubert.Bd -literal -offset indent 10170224baaSJan Lentfer# ifconfig pfsync0 syncdev fxp0 102f1e85027SSimon Schubert.Ed 103f1e85027SSimon Schubert.Pp 10470224baaSJan LentferBy default, state change messages are sent out on the synchronisation 105f1e85027SSimon Schubertinterface using IP multicast packets. 106f1e85027SSimon SchubertThe protocol is IP protocol 240, PFSYNC, and the multicast group 107f1e85027SSimon Schubertused is 224.0.0.240. 108*755d70b8SSascha WildnerAn alternative destination address for 109*755d70b8SSascha Wildner.Nm 110*755d70b8SSascha Wildnerpackets can be specified using the 11170224baaSJan Lentfer.Ic syncpeer 112*755d70b8SSascha Wildnerkeyword. 113f1e85027SSimon Schubert.Pp 11470224baaSJan LentferIt is important that the pfsync traffic be well secured 11570224baaSJan Lentferas there is no authentication on the protocol and it would 116f1e85027SSimon Schubertbe trivial to spoof packets which create states, bypassing the pf ruleset. 11770224baaSJan LentferEither run the pfsync protocol on a trusted network \- ideally a network 118*755d70b8SSascha Wildnerdedicated to pfsync messages such as a crossover cable between two firewalls. 119f1e85027SSimon Schubert.Pp 120f1e85027SSimon SchubertThere is a one-to-one correspondence between packets seen by 121f1e85027SSimon Schubert.Xr bpf 4 122f1e85027SSimon Schuberton the 123f1e85027SSimon Schubert.Nm 124f1e85027SSimon Schubertinterface, and packets sent out on the synchronisation interface, i.e.\& 125f1e85027SSimon Schuberta packet with 4 state deletion messages on 126f1e85027SSimon Schubert.Nm 127f1e85027SSimon Schubertmeans that the same 4 deletions were sent out on the synchronisation 128f1e85027SSimon Schubertinterface. 129f1e85027SSimon SchubertHowever, the actual packet contents may differ as the messages 130f1e85027SSimon Schubertsent over the network are "compressed" where possible, containing 131f1e85027SSimon Schubertonly the necessary information. 132f1e85027SSimon Schubert.Sh EXAMPLES 133f1e85027SSimon Schubert.Bd -literal -offset indent 134f1e85027SSimon Schubert# ifconfig pfsync0 up syncif fxp0 maxupd 64 135f1e85027SSimon Schubert# tcpdump -s1500 -evtni pfsync0 136f1e85027SSimon Schubert.Ed 1370d16ba1dSMatthew Dillon.Sh USING PFSYNC WITH CARP 1380d16ba1dSMatthew Dillon.Nm 1390d16ba1dSMatthew Dillonand 1400d16ba1dSMatthew Dillon.Xr carp 4 1410d16ba1dSMatthew Dilloncan be used together to provide automatic failover of a pair of firewalls 1420d16ba1dSMatthew Dillonconfigured in parallel. 1430d16ba1dSMatthew DillonOne firewall handles all traffic \- if it dies or 1440d16ba1dSMatthew Dillonis shut down, the second firewall takes over automatically. 1450d16ba1dSMatthew Dillon.Pp 1460d16ba1dSMatthew DillonBoth firewalls in this example have three 1470d16ba1dSMatthew Dillon.Xr sis 4 1480d16ba1dSMatthew Dilloninterfaces. 1490d16ba1dSMatthew Dillonsis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the 1500d16ba1dSMatthew Dilloninternal interface, on the 192.168.0.0/24 subnet; and sis2 is the 1510d16ba1dSMatthew Dillon.Nm 1520d16ba1dSMatthew Dilloninterface, using the 192.168.254.0/24 subnet. 1530d16ba1dSMatthew DillonA crossover cable connects the two firewalls via their sis2 interfaces. 1540d16ba1dSMatthew DillonOn all three interfaces, firewall A uses the .254 address, while firewall B 1550d16ba1dSMatthew Dillonuses .253. 1560d16ba1dSMatthew DillonThe interfaces are configured as follows (firewall A unless otherwise 1570d16ba1dSMatthew Dillonindicated): 1580d16ba1dSMatthew Dillon.Pp 1590d16ba1dSMatthew DillonInterfaces configuration in 1600d16ba1dSMatthew Dillon.Pa /etc/rc.conf : 1610d16ba1dSMatthew Dillon.Bd -literal -offset indent 1620d16ba1dSMatthew Dillonnetwork_interfaces="lo0 sis0 sis1 sis2" 1630d16ba1dSMatthew Dilloncloned_interfaces="carp0 carp1" 1640d16ba1dSMatthew Dillonifconfig_sis0="10.0.0.254/24" 1650d16ba1dSMatthew Dillonifconfig_sis1="192.168.0.254/24" 1660d16ba1dSMatthew Dillonifconfig_sis2="192.168.254.254/24" 1670d16ba1dSMatthew Dillonifconfig_carp0="vhid 1 pass foo 10.0.0.1/24" 1680d16ba1dSMatthew Dillonifconfig_carp1="vhid 2 pass bar 192.168.0.1/24" 1690d16ba1dSMatthew Dillonpfsync_enable="YES" 1700d16ba1dSMatthew Dillonpfsync_syncdev="sis2" 1710d16ba1dSMatthew Dillon.Ed 1720d16ba1dSMatthew Dillon.Pp 1730d16ba1dSMatthew Dillon.Xr pf 4 1740d16ba1dSMatthew Dillonmust also be configured to allow 1750d16ba1dSMatthew Dillon.Nm 1760d16ba1dSMatthew Dillonand 1770d16ba1dSMatthew Dillon.Xr carp 4 1780d16ba1dSMatthew Dillontraffic through. 1790d16ba1dSMatthew DillonThe following should be added to the top of 1800d16ba1dSMatthew Dillon.Pa /etc/pf.conf : 1810d16ba1dSMatthew Dillon.Bd -literal -offset indent 1824696a7e0SJan Lentferpass quick on { sis2 } proto pfsync keep state (no-sync) 1834696a7e0SJan Lentferpass on { sis0 sis1 } proto carp keep state (no-sync) 1840d16ba1dSMatthew Dillon.Ed 1850d16ba1dSMatthew Dillon.Pp 1860d16ba1dSMatthew DillonIf it is preferable that one firewall handle the traffic, 1870d16ba1dSMatthew Dillonthe 1880d16ba1dSMatthew Dillon.Ar advskew 1890d16ba1dSMatthew Dillonon the backup firewall's 1900d16ba1dSMatthew Dillon.Xr carp 4 1910d16ba1dSMatthew Dilloninterfaces should be set to something higher than 1920d16ba1dSMatthew Dillonthe primary's. 1930d16ba1dSMatthew DillonFor example, if firewall B is the backup, its 1940d16ba1dSMatthew Dilloncarp1 configuration would look like this: 1950d16ba1dSMatthew Dillon.Bd -literal -offset indent 1960d16ba1dSMatthew Dillonifconfig_carp1="vhid 2 pass bar advskew 100 192.168.0.1/24" 1970d16ba1dSMatthew Dillon.Ed 1980d16ba1dSMatthew Dillon.Pp 1990d16ba1dSMatthew DillonThe following must also be added to 2000d16ba1dSMatthew Dillon.Pa /etc/sysctl.conf : 2010d16ba1dSMatthew Dillon.Bd -literal -offset indent 2020d16ba1dSMatthew Dillonnet.inet.carp.preempt=1 2030d16ba1dSMatthew Dillon.Ed 204f1e85027SSimon Schubert.Sh SEE ALSO 205b31f0f40SSascha Wildner.Xr tcpdump 1 , 206f1e85027SSimon Schubert.Xr bpf 4 , 2079bf37d9dSSascha Wildner.Xr carp 4 , 208f1e85027SSimon Schubert.Xr inet 4 , 209f1e85027SSimon Schubert.Xr inet6 4 , 210f1e85027SSimon Schubert.Xr netintro 4 , 211f1e85027SSimon Schubert.Xr pf 4 , 212f1e85027SSimon Schubert.Xr pf.conf 5 , 213f1e85027SSimon Schubert.Xr protocols 5 , 214b31f0f40SSascha Wildner.Xr ifconfig 8 215b31f0f40SSascha Wildner.\".Xr ifstated 8 , 216f1e85027SSimon Schubert.Sh HISTORY 217f1e85027SSimon SchubertThe 218f1e85027SSimon Schubert.Nm 219f1e85027SSimon Schubertdevice first appeared in 220f1e85027SSimon Schubert.Ox 3.3 221f1e85027SSimon Schubertand was imported into 222f1e85027SSimon Schubert.Dx 1.1 223f1e85027SSimon Schubertby Devon H. O'Dell and Simon Schubert. 224