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