xref: /openbsd-src/share/man/man4/pfsync.4 (revision 5a38ef86d0b61900239c7913d24a05e7b88a58f0)
1.\"	$OpenBSD: pfsync.4,v 1.37 2021/02/01 16:39:19 sthen 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: February 1 2021 $
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.Dl up syncdev sis2
187.Pp
188.Xr pf 4
189must also be configured to allow
190.Nm
191and
192.Xr carp 4
193traffic through.
194The following should be added to the top of
195.Pa /etc/pf.conf :
196.Bd -literal -offset indent
197pass quick on { sis2 } proto pfsync keep state (no-sync)
198pass on { sis0 sis1 } proto carp keep state (no-sync)
199.Ed
200.Pp
201It is preferable that one firewall handle the forwarding of all the traffic,
202therefore the
203.Ar advskew
204on the backup firewall's
205.Xr carp 4
206interfaces should be set to something higher than
207the primary's.
208For example, if firewall B is the backup, its
209.Pa /etc/hostname.carp1
210would look like this:
211.Bd -literal -offset indent
212inet 192.168.0.1 255.255.255.0 192.168.0.255 \e
213	vhid 2 pass bar advskew 100
214.Ed
215.Pp
216The following must also be added to
217.Pa /etc/sysctl.conf :
218.Bd -literal -offset indent
219net.inet.carp.preempt=1
220.Ed
221.Sh SEE ALSO
222.Xr bpf 4 ,
223.Xr carp 4 ,
224.\" .Xr enc 4 ,
225.Xr inet 4 ,
226.Xr inet6 4 ,
227.\" .Xr ipsec 4 ,
228.Xr netintro 4 ,
229.Xr pf 4 ,
230.Xr hostname.if 5 ,
231.Xr pf.conf 5 ,
232.Xr protocols 5 ,
233.Xr ifconfig 8 ,
234.Xr ifstated 8 ,
235.Xr tcpdump 8
236.Sh HISTORY
237The
238.Nm
239device first appeared in
240.Ox 3.3 .
241.Pp
242The
243.Nm
244protocol and kernel implementation were significantly modified between
245.Ox 4.4
246and
247.Ox 4.5 .
248The two protocols are incompatible and will not interoperate.
249.Sh BUGS
250.Nm
251does not currently work with
252.Xr ipsec 4 .
253