xref: /freebsd/share/man/man4/carp.4 (revision 0d446a4303a8444c5ba9c7d4a3caee846579d101)
1.\"	$OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $
2.\"
3.\" Copyright (c) 2003, Ryan McBride.  All rights reserved.
4.\" Copyright (c) 2011, Gleb Smirnoff <glebius@FreeBSD.org>
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
16.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
19.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25.\" SUCH DAMAGE.
26.\"
27.Dd April 12, 2024
28.Dt CARP 4
29.Os
30.Sh NAME
31.Nm carp
32.Nd Common Address Redundancy Protocol
33.Sh SYNOPSIS
34.Cd "device carp"
35.Sh DESCRIPTION
36The CARP allows multiple hosts on the same local network to share a set of
37IPv4 and/or IPv6 addresses.
38Its primary purpose is to ensure that these
39addresses are always available.
40.Pp
41To use
42.Nm ,
43the administrator needs to configure at a minimum a common virtual host ID
44(vhid), and attach at least one IP address to this vhid on each machine which
45is to take part in the virtual group.
46Additional parameters can also be set on a per-vhid basis:
47.Cm advbase
48and
49.Cm advskew ,
50which are used to control how frequently the host sends advertisements when it
51is the master for a virtual host, and
52.Cm pass
53which is used to authenticate
54.Nm
55advertisements.
56The
57.Cm advbase
58parameter stands for
59.Dq "advertisement base" .
60It is measured in seconds and specifies the base of the advertisement interval.
61The
62.Cm advskew
63parameter stands for
64.Dq "advertisement skew" .
65It is measured in 1/256 of seconds.
66It is added to the base advertisement interval to make one host advertise
67a bit slower that the other does.
68Both
69.Cm advbase
70and
71.Cm advskew
72are put inside CARP advertisements.
73These values can be configured using
74.Xr ifconfig 8 ,
75or through the
76.Dv SIOCSVH
77.Xr ioctl 2 .
78.Pp
79CARP defaults to using multicast messages, but can be configured to unicast
80announcements to peers using the
81.Cm peer
82and
83.Cm peer6
84parameters. Default addresses can be restored using
85.Cm mcast
86and
87.Cm mcast6 .
88Note that TTL verification is disabled if the peer address is not a multicast
89address.
90These values can be configured using
91.Xr ifconfig 8 ,
92or through the
93.Dv SIOCSPEER
94.Xr ioctl 2 .
95.Pp
96.Xr carp 4
97can be configured to use either the non-standard CARP protocol, or VRRPv3 (RFC 5798).
98Use the
99.Cm carpver
100parameter to select either 2 (CARP) or 3 (VRRPv3).
101VRRPv3 specific parameters can be configured using the
102.Cm vrrpprio
103and
104.Cm vrrpinterval
105parameters.
106.Pp
107CARP virtual hosts can be configured on multicast-capable interfaces: Ethernet,
108layer 2 VLAN, FDDI and Token Ring.
109An arbitrary number of virtual host IDs can be configured on an interface.
110An arbitrary number of IPv4 or IPv6 addresses can be attached to a particular
111vhid.
112It is important that all hosts participating in a vhid have the same list
113of prefixes configured on the vhid, since all the prefixes are included in the
114cryptographic checksum supplied in each advertisement.
115Multiple vhids running on one interface participate in master/backup
116elections independently.
117.Pp
118Additionally, there are a number of global parameters which can be set using
119.Xr sysctl 8 :
120.Bl -tag -width ".Va net.inet.carp.ifdown_demotion_factor"
121.It Va net.inet.carp.allow
122Allow
123.Nm
124operation.
125When disabled, virtual hosts remain in initial state, neither sending nor
126receiving announcements or traffic.
127Enabled by default.
128.It Va net.inet.carp.preempt
129Allow virtual hosts to preempt each other.
130When enabled, a vhid in a backup state would preempt a master that
131is announcing itself with a lower advskew.
132Disabled by default.
133.It Va net.inet.carp.dscp
134DSCP value in carp packet.
135Valid Values are 0 to 63.
136A value of 4 is equivalent to the old standard of TOS LOW_DELAY.
137TOS values were deprecated and replaced by DSCP in 1998.
138The default value is 56 (CS7/Network Control).
139.It Va net.inet.carp.log
140Determines what events relating to
141.Nm
142vhids are logged.
143A value of 0 disables any logging.
144A value of 1 enables logging state changes of
145.Nm
146vhids.
147Values above 1 enable logging of bad
148.Nm
149packets.
150The default value is 1.
151.It Va net.inet.carp.demotion
152This value shows the current level of CARP demotion.
153The value is added to the actual advskew sent in announcements for
154all vhids.
155During normal system operation the demotion factor is zero.
156However, problematic conditions raise its level: when
157.Nm
158experiences problem with sending announcements, when an interface
159running a vhid goes down, or while the
160.Xr pfsync 4
161interface is not synchronized.
162The demotion factor can be adjusted writing to the sysctl oid.
163The signed value supplied to the
164.Xr sysctl 8
165command is added to current demotion factor.
166This allows to control
167.Nm
168behaviour depending on some external conditions, for example on the status
169of some daemon utility.
170.It Va net.inet.carp.ifdown_demotion_factor
171This value is added to
172.Va net.inet.carp.demotion
173when an interface running a vhid goes down.
174The default value is 240 (the maximum advskew value).
175.It Va net.inet.carp.senderr_demotion_factor
176This value is added to
177.Va net.inet.carp.demotion
178when
179.Nm
180experiences errors sending its announcements.
181The default value is 240 (the maximum advskew value).
182.El
183.\".Sh ARP level load balancing
184.\"A
185.\".Nm
186.\"interface has limited abilities for load balancing incoming connections
187.\"between hosts in an Ethernet network.
188.\"For load-balancing operation, one needs several CARP interfaces that
189.\"are configured to the same IP address, but to a different vhids.
190.\"Once an ARP request is received, the CARP protocol will use a hashing
191.\"function against the source IP address in the ARP request to determine
192.\"which vhid the request will be assigned to.
193.\"If the corresponding CARP interface is the current
194.\"master interface, a reply will
195.\"be sent to the ARP request;
196.\"otherwise it will be ignored.
197.\"See the
198.\".Sx EXAMPLES
199.\"section for a practical example of load balancing.
200.\".Pp
201.\"The ARP load balancing implemented in
202.\".Nm
203.\"has some limitations.
204.\"First, ARP balancing only works on the local network segment.
205.\"It cannot balance traffic that crosses a router, because the
206.\"router itself will always be balanced to the same virtual host.
207.\"Second, ARP load balancing can lead to asymmetric routing
208.\"of incoming and outgoing traffic, and thus combining it with
209.\".Xr pfsync 4
210.\"is dangerous, because this creates a race condition between
211.\"balanced routers and a host they are serving.
212.\"Imagine an incoming packet creating state on the first router, being
213.\"forwarded to its destination, and the destination replying faster
214.\"than the state information is packed and synced with the second router.
215.\"If the reply would be load balanced to second router, it will be
216.\"dropped since the second router has not yet received information about
217.\"the connection state.
218.Sh STATE CHANGE NOTIFICATIONS
219Sometimes it is useful to get notified about
220.Nm
221status change events.
222This can be accomplished by using
223.Xr devd 8
224hooks.
225Master/slave events are signalled under system
226.Dv CARP .
227The subsystem specifies the vhid and name of the interface where
228the master/slave event occurred.
229The type of the message displays the new state of the vhid.
230Please see
231.Xr devd.conf 5
232and the
233.Sx EXAMPLES
234section for more information.
235.Sh EXAMPLES
236For firewalls and routers with multiple interfaces, it is desirable to
237failover all of the addresses running
238.Nm
239together, when one of the physical interfaces goes down.
240This is achieved by the use of the preempt option.
241Enable it on both hosts A and B:
242.Pp
243.Dl sysctl net.inet.carp.preempt=1
244.Pp
245Assume that host A is the preferred master and we are running the
246192.168.1.0/24 prefix on em0 and 192.168.2.0/24 on em1.
247This is the setup for host A (advskew is above 0 so it could be overwritten
248in the emergency situation from the other host):
249.Bd -literal -offset indent
250ifconfig em0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24
251ifconfig em1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24
252.Ed
253.Pp
254The setup for host B is identical, but it has a higher
255.Cm advskew :
256.Bd -literal -offset indent
257ifconfig em0 vhid 1 advskew 200 pass mekmitasdigoat 192.168.1.1/24
258ifconfig em1 vhid 2 advskew 200 pass mekmitasdigoat 192.168.2.1/24
259.Ed
260.Pp
261When one of the physical interfaces of host A fails,
262.Cm advskew
263is demoted to a configured value on all its
264.Nm
265vhids.
266Due to the preempt option, host B would start announcing itself, and thus
267preempt host A on both interfaces instead of just the failed one.
268.\".Pp
269.\"In order to set up an ARP balanced virtual host, it is necessary to configure
270.\"one virtual host for each physical host which would respond to ARP requests
271.\"and thus handle the traffic.
272.\"In the following example, two virtual hosts are configured on two hosts to
273.\"provide balancing and failover for the IP address 192.168.1.10.
274.\".Pp
275.\"First the
276.\".Nm
277.\"interfaces on host A are configured.
278.\"The
279.\".Cm advskew
280.\"of 100 on the second virtual host means that its advertisements will be sent
281.\"out slightly less frequently.
282.\".Bd -literal -offset indent
283.\"ifconfig carp0 create
284.\"ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24
285.\"ifconfig carp1 create
286.\"ifconfig carp1 vhid 2 advskew 200 pass mekmitasdigoat 192.168.1.10/24
287.\".Ed
288.\".Pp
289.\"The configuration for host B is identical, except the
290.\".Cm advskew
291.\"is on virtual host 1 rather than virtual host 2.
292.\".Bd -literal -offset indent
293.\"ifconfig carp0 create
294.\"ifconfig carp0 vhid 1 advskew 200 pass mekmitasdigoat 192.168.1.10/24
295.\"ifconfig carp1 create
296.\"ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24
297.\".Ed
298.\".Pp
299.\"Finally, the ARP balancing feature must be enabled on both hosts:
300.\".Pp
301.\".Dl sysctl net.inet.carp.arpbalance=1
302.\".Pp
303.\"When the hosts receive an ARP request for 192.168.1.10, the source IP address
304.\"of the request is used to compute which virtual host should answer the request.
305.\"The host which is master of the selected virtual host will reply to the
306.\"request, the other(s) will ignore it.
307.\".Pp
308.\"This way, locally connected systems will receive different ARP replies and
309.\"subsequent IP traffic will be balanced among the hosts.
310.\"If one of the hosts fails, the other will take over the virtual MAC address,
311.\"and begin answering ARP requests on its behalf.
312.Pp
313Processing of
314.Nm
315status change events can be set up by using the following devd.conf rule:
316.Bd -literal -offset indent
317notify 0 {
318	match "system"          "CARP";
319	match "subsystem"       "[0-9]+@[0-9a-z\.]+";
320	match "type"            "(MASTER|BACKUP)";
321	action "/root/carpcontrol.sh $subsystem $type";
322};
323.Ed
324.Pp
325To see
326.Nm
327packets decoded in
328.Xr tcpdump 1
329output, one needs to specify the
330.Fl T Ar carp
331option, otherwise
332.Xr tcpdump 1
333will interpret them as VRRP packets:
334.Bd -literal -offset indent
335tcpdump -npi vlan0 -T carp
336.Ed
337.Sh SEE ALSO
338.Xr tcpdump 1 ,
339.Xr inet 4 ,
340.Xr pfsync 4 ,
341.Xr devd.conf 5 ,
342.Xr rc.conf 5 ,
343.Xr ifconfig 8 ,
344.Xr sysctl 8
345.Sh HISTORY
346The
347.Nm
348device first appeared in
349.Ox 3.5 .
350The
351.Nm
352device was imported into
353.Fx 5.4 .
354In
355.Fx 10.0 ,
356.Nm
357was significantly rewritten, and is no longer a pseudo-interface.
358