xref: /freebsd/share/man/man4/pfsync.4 (revision e5b786625f7f82a1fa91e41823332459ea5550f9)
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 October 17, 2023
28.Dt PFSYNC 4
29.Os
30.Sh NAME
31.Nm pfsync
32.Nd packet filter state table sychronisation interface
33.Sh SYNOPSIS
34.Cd "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 1
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.Sh NETWORK SYNCHRONISATION
81States can be synchronised between two or more firewalls using this
82interface, by specifying a synchronisation interface using
83.Xr ifconfig 8 .
84For example, the following command sets fxp0 as the synchronisation
85interface:
86.Bd -literal -offset indent
87# ifconfig pfsync0 syncdev fxp0
88.Ed
89.Pp
90By default, state change messages are sent out on the synchronisation
91interface using IP multicast packets to the 224.0.0.240 group address.
92An alternative destination address for
93.Nm
94packets can be specified using the
95.Ic syncpeer
96keyword.
97This can be used in combination with
98.Xr ipsec 4
99to protect the synchronisation traffic.
100In such a configuration, the syncdev should be set to the
101.Xr enc 4
102interface, as this is where the traffic arrives when it is decapsulated,
103e.g.:
104.Bd -literal -offset indent
105# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0
106.Ed
107.Pp
108It is important that the pfsync traffic be well secured
109as there is no authentication on the protocol and it would
110be trivial to spoof packets which create states, bypassing the pf ruleset.
111Either run the pfsync protocol on a trusted network \- ideally a network
112dedicated to pfsync messages such as a crossover cable between two firewalls,
113or specify a peer address and protect the traffic with
114.Xr ipsec 4 .
115.Pp
116When new features are introduced to
117.Xr pf 4
118the format of messages used by
119.Nm
120might change.
121.Nm
122will by default use the latest format.
123If synchronization with a peer running an older version of FreeBSD is needed the
124.Ar version
125parameter can be used.
126E.g.:
127.Bd -literal -offset indent
128# ifconfig pfsync0 version 1301
129.Ed
130.Pp
131.Bd
132Currently the following versions are supported:
133.Bl -tag -width indent
134.It Cm 1301
135FreeBSD releases 13.2 and older.
136Compatibility with FreeBSD 13.1 has been verified.
137.It Cm 1400
138FreeBSD release 14.0.
139.El
140.Ed
141.Pp
142.Nm
143has the following
144.Xr sysctl 8
145tunables:
146.Bl -tag -width ".Va net.pfsync"
147.It Va net.pfsync.carp_demotion_factor
148Value added to
149.Va net.inet.carp.demotion
150while
151.Nm
152tries to perform its bulk update.
153See
154.Xr carp 4
155for more information.
156Default value is 240.
157.It Va net.pfsync.pfsync_buckets
158The number of
159.Nm
160buckets.
161This affects the performance and memory tradeoff.
162Defaults to twice the number of CPUs.
163Change only if benchmarks show this helps on your workload.
164.El
165.Sh EXAMPLES
166.Nm
167and
168.Xr carp 4
169can be used together to provide automatic failover of a pair of firewalls
170configured in parallel.
171One firewall will handle all traffic until it dies, is shut down, or is
172manually demoted, at which point the second firewall will take over
173automatically.
174.Pp
175Both firewalls in this example have three
176.Xr sis 4
177interfaces.
178sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the
179internal interface, on the 192.168.0.0/24 subnet; and sis2 is the
180.Nm
181interface, using the 192.168.254.0/24 subnet.
182A crossover cable connects the two firewalls via their sis2 interfaces.
183On all three interfaces, firewall A uses the .254 address, while firewall B
184uses .253.
185The interfaces are configured as follows (firewall A unless otherwise
186indicated):
187.Pp
188Interfaces configuration in
189.Pa /etc/rc.conf :
190.Bd -literal -offset indent
191network_interfaces="lo0 sis0 sis1 sis2"
192ifconfig_sis0="10.0.0.254/24"
193ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo"
194ifconfig_sis1="192.168.0.254/24"
195ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar"
196ifconfig_sis2="192.168.254.254/24"
197pfsync_enable="YES"
198pfsync_syncdev="sis2"
199.Ed
200.Pp
201.Xr pf 4
202must also be configured to allow
203.Nm
204and
205.Xr carp 4
206traffic through.
207The following should be added to the top of
208.Pa /etc/pf.conf :
209.Bd -literal -offset indent
210pass quick on { sis2 } proto pfsync keep state (no-sync)
211pass on { sis0 sis1 } proto carp keep state (no-sync)
212.Ed
213.Pp
214It is preferable that one firewall handle the forwarding of all the traffic,
215therefore the
216.Ar advskew
217on the backup firewall's
218.Xr carp 4
219vhids should be set to something higher than
220the primary's.
221For example, if firewall B is the backup, its
222carp1 configuration would look like this:
223.Bd -literal -offset indent
224ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100"
225.Ed
226.Pp
227The following must also be added to
228.Pa /etc/sysctl.conf :
229.Bd -literal -offset indent
230net.inet.carp.preempt=1
231.Ed
232.Sh SEE ALSO
233.Xr tcpdump 1 ,
234.Xr bpf 4 ,
235.Xr carp 4 ,
236.Xr enc 4 ,
237.Xr inet 4 ,
238.Xr inet6 4 ,
239.Xr ipsec 4 ,
240.Xr netintro 4 ,
241.Xr pf 4 ,
242.Xr pf.conf 5 ,
243.Xr protocols 5 ,
244.Xr rc.conf 5 ,
245.Xr ifconfig 8
246.Sh HISTORY
247The
248.Nm
249device first appeared in
250.Ox 3.3 .
251It was first imported to
252.Fx 5.3 .
253.Pp
254The
255.Nm
256protocol and kernel implementation were significantly modified in
257.Fx 9.0 .
258The newer protocol is not compatible with older one and will not interoperate
259with it.
260