xref: /freebsd/share/man/man4/pfsync.4 (revision 046c625e9382e17da953767b881aaa782fa73af8)
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.It Cm 1500
166FreeBSD release 15.0.
167.El
168.Sh SYSCTL VARIABLES
169The following variables can be entered at the
170.Xr loader 8
171prompt, set in
172.Xr loader.conf 5 ,
173or changed at runtime with
174.Xr sysctl 8 :
175.Bl -tag -width indent
176.It Va net.pfsync.carp_demotion_factor
177Value added to
178.Va net.inet.carp.demotion
179while
180.Nm
181tries to perform its bulk update.
182See
183.Xr carp 4
184for more information.
185Default value is 240.
186.El
187.Sh LOADER TUNABLES
188The following tunable may be set in
189.Xr loader.conf 5
190or at the
191.Xr loader 8
192prompt:
193.Bl -tag -width indent
194.It Va net.pfsync.pfsync_buckets
195The number of
196.Nm
197buckets.
198This affects the performance and memory tradeoff.
199Defaults to twice the number of CPUs.
200Change only if benchmarks show this helps on your workload.
201.El
202.Sh EXAMPLES
203.Nm
204and
205.Xr carp 4
206can be used together to provide automatic failover of a pair of firewalls
207configured in parallel.
208One firewall will handle all traffic until it dies, is shut down, or is
209manually demoted, at which point the second firewall will take over
210automatically.
211.Pp
212Both firewalls in this example have three
213.Xr sis 4
214interfaces.
215sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the
216internal interface, on the 192.168.0.0/24 subnet; and sis2 is the
217.Nm
218interface, using the 192.168.254.0/24 subnet.
219A crossover cable connects the two firewalls via their sis2 interfaces.
220On all three interfaces, firewall A uses the .254 address, while firewall B
221uses .253.
222The interfaces are configured as follows (firewall A unless otherwise
223indicated):
224.Pp
225Interfaces configuration in
226.Pa /etc/rc.conf :
227.Bd -literal -offset indent
228network_interfaces="lo0 sis0 sis1 sis2"
229ifconfig_sis0="10.0.0.254/24"
230ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo"
231ifconfig_sis1="192.168.0.254/24"
232ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar"
233ifconfig_sis2="192.168.254.254/24"
234pfsync_enable="YES"
235pfsync_syncdev="sis2"
236.Ed
237.Pp
238.Xr pf 4
239must also be configured to allow
240.Nm
241and
242.Xr carp 4
243traffic through.
244The following should be added to the top of
245.Pa /etc/pf.conf :
246.Bd -literal -offset indent
247pass quick on { sis2 } proto pfsync keep state (no-sync)
248pass on { sis0 sis1 } proto carp keep state (no-sync)
249.Ed
250.Pp
251It is preferable that one firewall handle the forwarding of all the traffic,
252therefore the
253.Ar advskew
254on the backup firewall's
255.Xr carp 4
256vhids should be set to something higher than
257the primary's.
258For example, if firewall B is the backup, its
259carp1 configuration would look like this:
260.Bd -literal -offset indent
261ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100"
262.Ed
263.Pp
264The following must also be added to
265.Pa /etc/sysctl.conf :
266.Bd -literal -offset indent
267net.inet.carp.preempt=1
268.Ed
269.Sh SEE ALSO
270.Xr tcpdump 1 ,
271.Xr bpf 4 ,
272.Xr carp 4 ,
273.Xr enc 4 ,
274.Xr inet 4 ,
275.Xr inet6 4 ,
276.Xr ipsec 4 ,
277.Xr netintro 4 ,
278.Xr pf 4 ,
279.Xr pf.conf 5 ,
280.Xr protocols 5 ,
281.Xr rc.conf 5 ,
282.Xr ifconfig 8
283.Sh HISTORY
284The
285.Nm
286device first appeared in
287.Ox 3.3 .
288It was first imported to
289.Fx 5.3 .
290.Pp
291The
292.Nm
293protocol and kernel implementation were significantly modified in
294.Fx 9.0 .
295The newer protocol is not compatible with older one and will not interoperate
296with it.
297