xref: /freebsd/share/man/man4/pfsync.4 (revision e0c4386e)
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.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
116Support for
117.Nm
118transport over IPv6 was introduced in
119.Fx 14.0 .
120To set up
121.Nm
122using multicast with IPv6 link-local addresses, the
123.Ic syncpeer
124must be set to the
125.Nm
126multicast address and the
127.Ic syncdev
128to the interface where
129.Nm
130traffic is expected.
131.Bd -literal -offset indent
132# ifconfig pfsync0 syncpeer ff12::f0 syncdev vtnet0
133.Ed
134.Pp
135When new features are introduced to
136.Xr pf 4
137the format of messages used by
138.Nm
139might change.
140.Nm
141will by default use the latest format.
142If synchronization with a peer running an older version of FreeBSD is needed the
143.Ar version
144parameter can be used.
145E.g.:
146.Bd -literal -offset indent
147# ifconfig pfsync0 version 1301
148.Ed
149.Pp
150.Bd
151Currently the following versions are supported:
152.Bl -tag -width indent
153.It Cm 1301
154FreeBSD releases 13.2 and older.
155Compatibility with FreeBSD 13.1 has been verified.
156.It Cm 1400
157FreeBSD release 14.0.
158.El
159.Ed
160.Pp
161.Nm
162has the following
163.Xr sysctl 8
164tunables:
165.Bl -tag -width ".Va net.pfsync"
166.It Va net.pfsync.carp_demotion_factor
167Value added to
168.Va net.inet.carp.demotion
169while
170.Nm
171tries to perform its bulk update.
172See
173.Xr carp 4
174for more information.
175Default value is 240.
176.It Va net.pfsync.pfsync_buckets
177The number of
178.Nm
179buckets.
180This affects the performance and memory tradeoff.
181Defaults to twice the number of CPUs.
182Change only if benchmarks show this helps on your workload.
183.El
184.Sh EXAMPLES
185.Nm
186and
187.Xr carp 4
188can be used together to provide automatic failover of a pair of firewalls
189configured in parallel.
190One firewall will handle all traffic until it dies, is shut down, or is
191manually demoted, at which point the second firewall will take over
192automatically.
193.Pp
194Both firewalls in this example have three
195.Xr sis 4
196interfaces.
197sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the
198internal interface, on the 192.168.0.0/24 subnet; and sis2 is the
199.Nm
200interface, using the 192.168.254.0/24 subnet.
201A crossover cable connects the two firewalls via their sis2 interfaces.
202On all three interfaces, firewall A uses the .254 address, while firewall B
203uses .253.
204The interfaces are configured as follows (firewall A unless otherwise
205indicated):
206.Pp
207Interfaces configuration in
208.Pa /etc/rc.conf :
209.Bd -literal -offset indent
210network_interfaces="lo0 sis0 sis1 sis2"
211ifconfig_sis0="10.0.0.254/24"
212ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo"
213ifconfig_sis1="192.168.0.254/24"
214ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar"
215ifconfig_sis2="192.168.254.254/24"
216pfsync_enable="YES"
217pfsync_syncdev="sis2"
218.Ed
219.Pp
220.Xr pf 4
221must also be configured to allow
222.Nm
223and
224.Xr carp 4
225traffic through.
226The following should be added to the top of
227.Pa /etc/pf.conf :
228.Bd -literal -offset indent
229pass quick on { sis2 } proto pfsync keep state (no-sync)
230pass on { sis0 sis1 } proto carp keep state (no-sync)
231.Ed
232.Pp
233It is preferable that one firewall handle the forwarding of all the traffic,
234therefore the
235.Ar advskew
236on the backup firewall's
237.Xr carp 4
238vhids should be set to something higher than
239the primary's.
240For example, if firewall B is the backup, its
241carp1 configuration would look like this:
242.Bd -literal -offset indent
243ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100"
244.Ed
245.Pp
246The following must also be added to
247.Pa /etc/sysctl.conf :
248.Bd -literal -offset indent
249net.inet.carp.preempt=1
250.Ed
251.Sh SEE ALSO
252.Xr tcpdump 1 ,
253.Xr bpf 4 ,
254.Xr carp 4 ,
255.Xr enc 4 ,
256.Xr inet 4 ,
257.Xr inet6 4 ,
258.Xr ipsec 4 ,
259.Xr netintro 4 ,
260.Xr pf 4 ,
261.Xr pf.conf 5 ,
262.Xr protocols 5 ,
263.Xr rc.conf 5 ,
264.Xr ifconfig 8
265.Sh HISTORY
266The
267.Nm
268device first appeared in
269.Ox 3.3 .
270It was first imported to
271.Fx 5.3 .
272.Pp
273The
274.Nm
275protocol and kernel implementation were significantly modified in
276.Fx 9.0 .
277The newer protocol is not compatible with older one and will not interoperate
278with it.
279