xref: /openbsd-src/share/man/man4/pfsync.4 (revision 8cc14bf3942d71092d2a797fce78c4c1dc9adcff)
1.\"	$OpenBSD: pfsync.4,v 1.39 2024/01/31 06:50:16 jmc 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: January 31 2024 $
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.Xr ifconfig 8
73.Ar maxupd
74parameter.
75The sending out of a
76.Nm
77packet will be delayed by a maximum of one second.
78.Pp
79Where more than one firewall might actively handle packets, e.g. with certain
80.Xr ospfd 8 ,
81.Xr bgpd 8
82or
83.Xr carp 4
84configurations, it is beneficial to defer transmission of the initial
85packet of a connection.
86The
87.Nm
88state insert message is sent immediately; the packet is queued until
89either this message is acknowledged by another system, or a timeout has
90expired.
91This behaviour is enabled with the
92.Ar defer
93parameter to
94.Xr ifconfig 8 .
95.Sh NETWORK SYNCHRONISATION
96States can be synchronised between two or more firewalls using this
97interface, by specifying a synchronisation interface using
98.Xr ifconfig 8 .
99For example, the following command configures an address on fxp0 and
100sets it as the synchronisation interface:
101.Bd -literal -offset indent
102# ifconfig fxp0 inet 172.19.13.1/28
103# ifconfig pfsync0 syncdev fxp0
104.Ed
105.Pp
106By default, state change messages are sent out on the synchronisation
107interface using IP multicast packets to the 224.0.0.240 group address.
108An alternative destination address for
109.Nm
110packets can be specified using the
111.Ic syncpeer
112keyword.
113.\" This can be used in combination with
114.\" .Xr ipsec 4
115.\" to protect the synchronisation traffic.
116.\" In such a configuration, the syncdev should be set to the
117.\" .Xr enc 4
118.\" interface, as this is where the traffic arrives when it is decapsulated,
119.\" e.g.:
120.\" .Bd -literal -offset indent
121.\" # ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0
122.\" .Ed
123.Pp
124It is important that the pfsync traffic be well secured
125as there is no authentication on the protocol and it would
126be trivial to spoof packets which create states, bypassing the pf ruleset.
127Only run the pfsync protocol on a trusted network \- ideally a network
128dedicated to pfsync messages such as a crossover cable between two firewalls.
129.\" or specify a peer address and protect the traffic with
130.\" .Xr ipsec 4 .
131.Pp
132.Nm
133will increase the
134.Xr carp 4
135demotion counter for any interface groups associated with the interface
136by 32 during initialisation, and by 1 if the
137.Nm
138link is down or if a bulk update fails.
139.Sh EXAMPLES
140.Nm
141and
142.Xr carp 4
143can be used together to provide automatic failover of a pair of firewalls
144configured in parallel.
145One firewall will handle all traffic until it dies, is shut down, or is
146manually demoted, at which point the second firewall will take over
147automatically.
148.Pp
149Both firewalls in this example have three
150.Xr sis 4
151interfaces.
152sis0 is the external interface, on the 10.0.0.0/24 subnet; sis1 is the
153internal interface, on the 192.168.0.0/24 subnet; and sis2 is the
154.Nm
155interface, using the 192.168.254.0/24 subnet.
156A crossover cable connects the two firewalls via their sis2 interfaces.
157On all three interfaces, firewall A uses the .254 address, while firewall B
158uses .253.
159The interfaces are configured as follows (firewall A unless otherwise
160indicated):
161.Pp
162.Pa /etc/hostname.sis0 :
163.Dl inet 10.0.0.254 255.255.255.0 NONE
164.Pp
165.Pa /etc/hostname.sis1 :
166.Dl inet 192.168.0.254 255.255.255.0 NONE
167.Pp
168.Pa /etc/hostname.sis2 :
169.Dl inet 192.168.254.254 255.255.255.0 NONE
170.Pp
171.Pa /etc/hostname.carp0 :
172.Bd -literal -offset indent -compact
173inet 10.0.0.1 255.255.255.0 10.0.0.255 \e
174	vhid 1 carpdev sis0 pass foo
175.Ed
176.Pp
177.Pa /etc/hostname.carp1 :
178.Bd -literal -offset indent -compact
179inet 192.168.0.1 255.255.255.0 192.168.0.255 \e
180	vhid 2 carpdev sis1 pass bar
181.Ed
182.Pp
183.Pa /etc/hostname.pfsync0 :
184.Bd -literal -offset indent -compact
185syncdev sis2
186up
187.Ed
188.Pp
189.Xr pf 4
190must also be configured to allow
191.Nm
192and
193.Xr carp 4
194traffic through.
195The following should be added to the top of
196.Pa /etc/pf.conf :
197.Bd -literal -offset indent
198pass quick on { sis2 } proto pfsync keep state (no-sync)
199pass on { sis0 sis1 } proto carp keep state (no-sync)
200.Ed
201.Pp
202It is preferable that one firewall handle the forwarding of all the traffic,
203therefore the
204.Ar advskew
205on the backup firewall's
206.Xr carp 4
207interfaces should be set to something higher than
208the primary's.
209For example, if firewall B is the backup, its
210.Pa /etc/hostname.carp1
211would look like this:
212.Bd -literal -offset indent
213inet 192.168.0.1 255.255.255.0 192.168.0.255 \e
214	vhid 2 pass bar advskew 100
215.Ed
216.Pp
217The following must also be added to
218.Pa /etc/sysctl.conf :
219.Bd -literal -offset indent
220net.inet.carp.preempt=1
221.Ed
222.Sh SEE ALSO
223.Xr bpf 4 ,
224.Xr carp 4 ,
225.\" .Xr enc 4 ,
226.Xr inet 4 ,
227.Xr inet6 4 ,
228.\" .Xr ipsec 4 ,
229.Xr netintro 4 ,
230.Xr pf 4 ,
231.Xr hostname.if 5 ,
232.Xr pf.conf 5 ,
233.Xr protocols 5 ,
234.Xr ifconfig 8 ,
235.Xr ifstated 8 ,
236.Xr tcpdump 8
237.Sh HISTORY
238The
239.Nm
240device first appeared in
241.Ox 3.3 .
242.Pp
243The
244.Nm
245protocol and kernel implementation were significantly modified between
246.Ox 4.4
247and
248.Ox 4.5 .
249The two protocols are incompatible and will not interoperate.
250.Sh BUGS
251.Nm
252does not currently work with
253.Xr ipsec 4 .
254