xref: /freebsd/share/man/man4/pfsync.4 (revision 0957b409)
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.\" $FreeBSD$
28.\"
29.Dd December 6, 2018
30.Dt PFSYNC 4
31.Os
32.Sh NAME
33.Nm pfsync
34.Nd packet filter state table sychronisation interface
35.Sh SYNOPSIS
36.Cd "device pfsync"
37.Sh DESCRIPTION
38The
39.Nm
40interface is a pseudo-device which exposes certain changes to the state
41table used by
42.Xr pf 4 .
43State changes can be viewed by invoking
44.Xr tcpdump 1
45on the
46.Nm
47interface.
48If configured with a physical synchronisation interface,
49.Nm
50will also send state changes out on that interface,
51and insert state changes received on that interface from other systems
52into the state table.
53.Pp
54By default, all local changes to the state table are exposed via
55.Nm .
56State changes from packets received by
57.Nm
58over the network are not rebroadcast.
59Updates to states created by a rule marked with the
60.Ar no-sync
61keyword are ignored by the
62.Nm
63interface (see
64.Xr pf.conf 5
65for details).
66.Pp
67The
68.Nm
69interface will attempt to collapse multiple state updates into a single
70packet where possible.
71The maximum number of times a single state can be updated before a
72.Nm
73packet will be sent out is controlled by the
74.Ar maxupd
75parameter to ifconfig
76(see
77.Xr ifconfig 8
78and the example below for more details).
79The sending out of a
80.Nm
81packet will be delayed by a maximum of one second.
82.Sh NETWORK SYNCHRONISATION
83States can be synchronised between two or more firewalls using this
84interface, by specifying a synchronisation interface using
85.Xr ifconfig 8 .
86For example, the following command sets fxp0 as the synchronisation
87interface:
88.Bd -literal -offset indent
89# ifconfig pfsync0 syncdev fxp0
90.Ed
91.Pp
92By default, state change messages are sent out on the synchronisation
93interface using IP multicast packets to the 224.0.0.240 group address.
94An alternative destination address for
95.Nm
96packets can be specified using the
97.Ic syncpeer
98keyword.
99This can be used in combination with
100.Xr ipsec 4
101to protect the synchronisation traffic.
102In such a configuration, the syncdev should be set to the
103.Xr enc 4
104interface, as this is where the traffic arrives when it is decapsulated,
105e.g.:
106.Bd -literal -offset indent
107# ifconfig pfsync0 syncpeer 10.0.0.2 syncdev enc0
108.Ed
109.Pp
110It is important that the pfsync traffic be well secured
111as there is no authentication on the protocol and it would
112be trivial to spoof packets which create states, bypassing the pf ruleset.
113Either run the pfsync protocol on a trusted network \- ideally a network
114dedicated to pfsync messages such as a crossover cable between two firewalls,
115or specify a peer address and protect the traffic with
116.Xr ipsec 4 .
117.Pp
118.Nm
119has the following
120.Xr sysctl 8
121tunables:
122.Bl -tag -width ".Va net.pfsync"
123.It Va net.pfsync.carp_demotion_factor
124Value added to
125.Va net.inet.carp.demotion
126while
127.Nm
128tries to perform its bulk update.
129See
130.Xr carp 4
131for more information.
132Default value is 240.
133.It Va net.pfsync.pfsync_buckets
134The number of
135.Nm
136buckets.
137This affects the performance and memory tradeoff.
138Defaults to twice the number of CPUs.
139Change only if benchmarks show this helps on your workload.
140.El
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
164Interfaces configuration in
165.Pa /etc/rc.conf :
166.Bd -literal -offset indent
167network_interfaces="lo0 sis0 sis1 sis2"
168ifconfig_sis0="10.0.0.254/24"
169ifconfig_sis0_alias0="inet 10.0.0.1/24 vhid 1 pass foo"
170ifconfig_sis1="192.168.0.254/24"
171ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar"
172ifconfig_sis2="192.168.254.254/24"
173pfsync_enable="YES"
174pfsync_syncdev="sis2"
175.Ed
176.Pp
177.Xr pf 4
178must also be configured to allow
179.Nm
180and
181.Xr carp 4
182traffic through.
183The following should be added to the top of
184.Pa /etc/pf.conf :
185.Bd -literal -offset indent
186pass quick on { sis2 } proto pfsync keep state (no-sync)
187pass on { sis0 sis1 } proto carp keep state (no-sync)
188.Ed
189.Pp
190It is preferable that one firewall handle the forwarding of all the traffic,
191therefore the
192.Ar advskew
193on the backup firewall's
194.Xr carp 4
195vhids should be set to something higher than
196the primary's.
197For example, if firewall B is the backup, its
198carp1 configuration would look like this:
199.Bd -literal -offset indent
200ifconfig_sis1_alias0="inet 192.168.0.1/24 vhid 2 pass bar advskew 100"
201.Ed
202.Pp
203The following must also be added to
204.Pa /etc/sysctl.conf :
205.Bd -literal -offset indent
206net.inet.carp.preempt=1
207.Ed
208.Sh SEE ALSO
209.Xr tcpdump 1 ,
210.Xr bpf 4 ,
211.Xr carp 4 ,
212.Xr enc 4 ,
213.Xr inet 4 ,
214.Xr inet6 4 ,
215.Xr ipsec 4 ,
216.Xr netintro 4 ,
217.Xr pf 4 ,
218.Xr pf.conf 5 ,
219.Xr protocols 5 ,
220.Xr rc.conf 5 ,
221.Xr ifconfig 8
222.Sh HISTORY
223The
224.Nm
225device first appeared in
226.Ox 3.3 .
227It was first imported to
228.Fx 5.3 .
229.Pp
230The
231.Nm
232protocol and kernel implementation were significantly modified in
233.Fx 9.0 .
234The newer protocol is not compatible with older one and will not interoperate
235with it.
236