xref: /dflybsd-src/share/man/man4/carp.4 (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
186d7f5d3SJohn Marino.\"
286d7f5d3SJohn Marino.\" Copyright (c) 2003, Ryan McBride.  All rights reserved.
386d7f5d3SJohn Marino.\"
486d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without
586d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions
686d7f5d3SJohn Marino.\" are met:
786d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright
886d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer.
986d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright
1086d7f5d3SJohn Marino.\"    notice, this list of conditions and the following disclaimer in the
1186d7f5d3SJohn Marino.\"    documentation and/or other materials provided with the distribution.
1286d7f5d3SJohn Marino.\"
1386d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1486d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1586d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1686d7f5d3SJohn Marino.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
1786d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1886d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1986d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2086d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2186d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2286d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2386d7f5d3SJohn Marino.\" SUCH DAMAGE.
2486d7f5d3SJohn Marino.\"
2586d7f5d3SJohn Marino.\" $OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $
2686d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man4/carp.4,v 1.10 2006/06/07 10:26:51 glebius Exp $
2786d7f5d3SJohn Marino.\" $DragonFly: src/share/man/man4/carp.4,v 1.4 2008/10/17 12:41:38 swildner Exp $
2886d7f5d3SJohn Marino.\"
2986d7f5d3SJohn Marino.Dd April 9, 2007
3086d7f5d3SJohn Marino.Dt CARP 4
3186d7f5d3SJohn Marino.Os
3286d7f5d3SJohn Marino.Sh NAME
3386d7f5d3SJohn Marino.Nm carp
3486d7f5d3SJohn Marino.Nd Common Address Redundancy Protocol
3586d7f5d3SJohn Marino.Sh SYNOPSIS
3686d7f5d3SJohn Marino.Cd "options CARP"
3786d7f5d3SJohn Marino.Cd "pseudo-device carp"
3886d7f5d3SJohn Marino.Sh DESCRIPTION
3986d7f5d3SJohn MarinoThe
4086d7f5d3SJohn Marino.Nm
4186d7f5d3SJohn Marinointerface is a pseudo-device that implements and controls the
4286d7f5d3SJohn MarinoCARP protocol.
4386d7f5d3SJohn MarinoCARP allows multiple hosts on the same local network to share a set of IP addresses.
4486d7f5d3SJohn MarinoIts primary purpose is to ensure that these
4586d7f5d3SJohn Marinoaddresses are always available, but in some configurations
4686d7f5d3SJohn Marino.Nm
4786d7f5d3SJohn Marinocan also provide load balancing functionality.
4886d7f5d3SJohn Marino.Pp
4986d7f5d3SJohn MarinoA
5086d7f5d3SJohn Marino.Nm
5186d7f5d3SJohn Marinointerface can be created at runtime using the
5286d7f5d3SJohn Marino.Nm ifconfig Li carp Ns Ar N Cm create
5386d7f5d3SJohn Marinocommand or by configuring
5486d7f5d3SJohn Marinoit via
5586d7f5d3SJohn Marino.Va cloned_interfaces
5686d7f5d3SJohn Marinoin the
5786d7f5d3SJohn Marino.Pa /etc/rc.conf
5886d7f5d3SJohn Marinofile.
5986d7f5d3SJohn Marino.Pp
6086d7f5d3SJohn MarinoTo use
6186d7f5d3SJohn Marino.Nm ,
6286d7f5d3SJohn Marinothe administrator needs to configure at minimum a common virtual host ID (VHID)
6386d7f5d3SJohn Marinoand virtual host IP address on each machine which is to take part in the virtual
6486d7f5d3SJohn Marinogroup.
6586d7f5d3SJohn MarinoAdditional parameters can also be set on a per-interface basis:
6686d7f5d3SJohn Marino.Cm advbase
6786d7f5d3SJohn Marinoand
6886d7f5d3SJohn Marino.Cm advskew ,
6986d7f5d3SJohn Marinowhich are used to control how frequently the host sends advertisements when it
7086d7f5d3SJohn Marinois the master for a virtual host, and
7186d7f5d3SJohn Marino.Cm pass
7286d7f5d3SJohn Marinowhich is used to authenticate
7386d7f5d3SJohn Marino.Nm
7486d7f5d3SJohn Marinoadvertisements.
7586d7f5d3SJohn MarinoThe
7686d7f5d3SJohn Marino.Cm advbase
7786d7f5d3SJohn Marinoparameter stands for
7886d7f5d3SJohn Marino.Dq "advertisement base" .
7986d7f5d3SJohn MarinoIt is measured in seconds and specifies the base of the advertisement interval.
8086d7f5d3SJohn MarinoThe
8186d7f5d3SJohn Marino.Cm advskew
8286d7f5d3SJohn Marinoparameter stands for
8386d7f5d3SJohn Marino.Dq "advertisement skew" .
8486d7f5d3SJohn MarinoIt is measured in 1/256 of seconds.
8586d7f5d3SJohn MarinoIt is added to the base advertisement interval to make one host advertise
8686d7f5d3SJohn Marinoa bit slower than the other does.
8786d7f5d3SJohn MarinoBoth
8886d7f5d3SJohn Marino.Cm advbase
8986d7f5d3SJohn Marinoand
9086d7f5d3SJohn Marino.Cm advskew
9186d7f5d3SJohn Marinoare put inside CARP advertisements.
9286d7f5d3SJohn MarinoThese configurations can be done using
9386d7f5d3SJohn Marino.Xr ifconfig 8 ,
9486d7f5d3SJohn Marinoor through the
9586d7f5d3SJohn Marino.Dv SIOCSVH
9686d7f5d3SJohn Marino.Xr ioctl 2 .
9786d7f5d3SJohn Marino.Pp
9886d7f5d3SJohn MarinoAdditionally, there are a number of global parameters which can be set using
9986d7f5d3SJohn Marino.Xr sysctl 8 :
10086d7f5d3SJohn Marino.Bl -tag -width ".Va net.inet.carp.arpbalance"
10186d7f5d3SJohn Marino.It Va net.inet.carp.allow
10286d7f5d3SJohn MarinoAccept incoming
10386d7f5d3SJohn Marino.Nm
10486d7f5d3SJohn Marinopackets.
10586d7f5d3SJohn MarinoEnabled by default.
10686d7f5d3SJohn Marino.It Va net.inet.carp.preempt
10786d7f5d3SJohn MarinoAllow virtual hosts to preempt each other.
10886d7f5d3SJohn MarinoIt is also used to failover
10986d7f5d3SJohn Marino.Nm
11086d7f5d3SJohn Marinointerfaces as a group.
11186d7f5d3SJohn MarinoWhen the option is enabled and one of the
11286d7f5d3SJohn Marino.Nm
11386d7f5d3SJohn Marinoenabled physical interfaces
11486d7f5d3SJohn Marinogoes down,
11586d7f5d3SJohn Marino.Cm advskew
11686d7f5d3SJohn Marinois changed to 240 on all
11786d7f5d3SJohn Marino.Nm
11886d7f5d3SJohn Marinointerfaces.
11986d7f5d3SJohn MarinoSee also the first example.
12086d7f5d3SJohn MarinoDisabled by default.
12186d7f5d3SJohn Marino.It Va net.inet.carp.log
12286d7f5d3SJohn MarinoValue of 0 disables any logging.
12386d7f5d3SJohn MarinoValue of 1 enables logging of bad
12486d7f5d3SJohn Marino.Nm
12586d7f5d3SJohn Marinopackets.
12686d7f5d3SJohn MarinoValues above 1 enable logging state changes of
12786d7f5d3SJohn Marino.Nm
12886d7f5d3SJohn Marinointerfaces.
12986d7f5d3SJohn MarinoDefault value is 1.
13086d7f5d3SJohn Marino.It Va net.inet.carp.arpbalance
13186d7f5d3SJohn MarinoBalance local traffic using ARP (see below).
13286d7f5d3SJohn MarinoDisabled by default.
13386d7f5d3SJohn Marino.It Va net.inet.carp.suppress_preempt
13486d7f5d3SJohn MarinoA read only value showing the status of preemption suppression.
13586d7f5d3SJohn MarinoPreemption can be suppressed if link on an interface is down
13686d7f5d3SJohn Marinoor when
13786d7f5d3SJohn Marino.Xr pfsync 4
13886d7f5d3SJohn Marinointerface is not synchronized.
13986d7f5d3SJohn MarinoValue of 0 means that preemption is not suppressed, since no
14086d7f5d3SJohn Marinoproblems are detected.
14186d7f5d3SJohn MarinoEvery problem increments suppression counter.
14286d7f5d3SJohn Marino.El
14386d7f5d3SJohn Marino.Sh ARP LEVEL LOAD BALANCING
14486d7f5d3SJohn MarinoThe
14586d7f5d3SJohn Marino.Nm
14686d7f5d3SJohn Marinohas limited abilities for load balancing the incoming connections
14786d7f5d3SJohn Marinobetween hosts in Ethernet network.
14886d7f5d3SJohn MarinoFor load balancing operation, one needs several CARP interfaces that
14986d7f5d3SJohn Marinoare configured to the same IP address, but to a different VHIDs.
15086d7f5d3SJohn MarinoOnce an ARP request is received, the CARP protocol will use a hashing
15186d7f5d3SJohn Marinofunction against the source IP address in the ARP request to determine
15286d7f5d3SJohn Marinowhich VHID should this request belong to.
15386d7f5d3SJohn MarinoIf the corresponding CARP interface is in master state, the ARP request
15486d7f5d3SJohn Marinowill be replied, otherwise it will be ignored.
15586d7f5d3SJohn MarinoSee the
15686d7f5d3SJohn Marino.Sx EXAMPLES
15786d7f5d3SJohn Marinosection for a practical example of load balancing.
15886d7f5d3SJohn Marino.Pp
15986d7f5d3SJohn MarinoThe ARP load balancing has some limitations.
16086d7f5d3SJohn MarinoFirst, ARP balancing only works on the local network segment.
16186d7f5d3SJohn MarinoIt cannot balance traffic that crosses a router, because the
16286d7f5d3SJohn Marinorouter itself will always be balanced to the same virtual host.
16386d7f5d3SJohn MarinoSecond, ARP load balancing can lead to asymmetric routing
16486d7f5d3SJohn Marinoof incoming and outgoing traffic, and thus combining it with
16586d7f5d3SJohn Marino.Xr pfsync 4
16686d7f5d3SJohn Marinois dangerous, because this creates a race condition between
16786d7f5d3SJohn Marinobalanced routers and a host they are serving.
16886d7f5d3SJohn MarinoImagine an incoming packet creating state on the first router, being
16986d7f5d3SJohn Marinoforwarded to its destination, and destination replying faster
17086d7f5d3SJohn Marinothan the state information is packed and synced with the second router.
17186d7f5d3SJohn MarinoIf the reply would be load balanced to second router, it will be
17286d7f5d3SJohn Marinodropped due to no state.
17386d7f5d3SJohn Marino.Sh EXAMPLES
17486d7f5d3SJohn MarinoFor firewalls and routers with multiple interfaces, it is desirable to
17586d7f5d3SJohn Marinofailover all of the
17686d7f5d3SJohn Marino.Nm
17786d7f5d3SJohn Marinointerfaces together, when one of the physical interfaces goes down.
17886d7f5d3SJohn MarinoThis is achieved by the preempt option.
17986d7f5d3SJohn MarinoEnable it on both host A and B:
18086d7f5d3SJohn Marino.Pp
18186d7f5d3SJohn Marino.Dl sysctl net.inet.carp.preempt=1
18286d7f5d3SJohn Marino.Pp
18386d7f5d3SJohn MarinoAssume that host A is the preferred master and 192.168.1.x/24 is
18486d7f5d3SJohn Marinoconfigured on one physical interface and 192.168.2.y/24 on another.
18586d7f5d3SJohn MarinoThis is the setup for host A:
18686d7f5d3SJohn Marino.Bd -literal -offset indent
18786d7f5d3SJohn Marinoifconfig carp0 create
18886d7f5d3SJohn Marinoifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1/24
18986d7f5d3SJohn Marinoifconfig carp1 create
19086d7f5d3SJohn Marinoifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1/24
19186d7f5d3SJohn Marino.Ed
19286d7f5d3SJohn Marino.Pp
19386d7f5d3SJohn MarinoThe setup for host B is identical, but it has a higher
19486d7f5d3SJohn Marino.Cm advskew :
19586d7f5d3SJohn Marino.Bd -literal -offset indent
19686d7f5d3SJohn Marinoifconfig carp0 create
19786d7f5d3SJohn Marinoifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24
19886d7f5d3SJohn Marinoifconfig carp1 create
19986d7f5d3SJohn Marinoifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24
20086d7f5d3SJohn Marino.Ed
20186d7f5d3SJohn Marino.Pp
20286d7f5d3SJohn MarinoBecause of the preempt option, when one of the physical interfaces of
20386d7f5d3SJohn Marinohost A fails,
20486d7f5d3SJohn Marino.Cm advskew
20586d7f5d3SJohn Marinois adjusted to 240 on all its
20686d7f5d3SJohn Marino.Nm
20786d7f5d3SJohn Marinointerfaces.
20886d7f5d3SJohn MarinoThis will cause host B to preempt on both interfaces instead of
20986d7f5d3SJohn Marinojust the failed one.
21086d7f5d3SJohn Marino.Pp
21186d7f5d3SJohn MarinoIn order to set up an ARP balanced virtual host, it is necessary to configure
21286d7f5d3SJohn Marinoone virtual host for each physical host which would respond to ARP requests
21386d7f5d3SJohn Marinoand thus handle the traffic.
21486d7f5d3SJohn MarinoIn the following example, two virtual hosts are configured on two hosts to
21586d7f5d3SJohn Marinoprovide balancing and failover for the IP address 192.168.1.10.
21686d7f5d3SJohn Marino.Pp
21786d7f5d3SJohn MarinoFirst the
21886d7f5d3SJohn Marino.Nm
21986d7f5d3SJohn Marinointerfaces on host A are configured.
22086d7f5d3SJohn MarinoThe
22186d7f5d3SJohn Marino.Cm advskew
22286d7f5d3SJohn Marinoof 100 on the second virtual host means that its advertisements will be sent
22386d7f5d3SJohn Marinoout slightly less frequently.
22486d7f5d3SJohn Marino.Bd -literal -offset indent
22586d7f5d3SJohn Marinoifconfig carp0 create
22686d7f5d3SJohn Marinoifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24
22786d7f5d3SJohn Marinoifconfig carp1 create
22886d7f5d3SJohn Marinoifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24
22986d7f5d3SJohn Marino.Ed
23086d7f5d3SJohn Marino.Pp
23186d7f5d3SJohn MarinoThe configuration for host B is identical, except the
23286d7f5d3SJohn Marino.Cm advskew
23386d7f5d3SJohn Marinois on virtual host 1 rather than virtual host 2.
23486d7f5d3SJohn Marino.Bd -literal -offset indent
23586d7f5d3SJohn Marinoifconfig carp0 create
23686d7f5d3SJohn Marinoifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24
23786d7f5d3SJohn Marinoifconfig carp1 create
23886d7f5d3SJohn Marinoifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24
23986d7f5d3SJohn Marino.Ed
24086d7f5d3SJohn Marino.Pp
24186d7f5d3SJohn MarinoFinally, the ARP balancing feature must be enabled on both hosts:
24286d7f5d3SJohn Marino.Pp
24386d7f5d3SJohn Marino.Dl sysctl net.inet.carp.arpbalance=1
24486d7f5d3SJohn Marino.Pp
24586d7f5d3SJohn MarinoWhen the hosts receive an ARP request for 192.168.1.10, the source IP address
24686d7f5d3SJohn Marinoof the request is used to compute which virtual host should answer the request.
24786d7f5d3SJohn MarinoThe host which is master of the selected virtual host will reply to the
24886d7f5d3SJohn Marinorequest, the other(s) will ignore it.
24986d7f5d3SJohn Marino.Pp
25086d7f5d3SJohn MarinoThis way, locally connected systems will receive different ARP replies and
25186d7f5d3SJohn Marinosubsequent IP traffic will be balanced among the hosts.
25286d7f5d3SJohn MarinoIf one of the hosts fails, the other will take over the virtual MAC address,
25386d7f5d3SJohn Marinoand begin answering ARP requests on its behalf.
25486d7f5d3SJohn Marino.Sh SEE ALSO
25586d7f5d3SJohn Marino.Xr inet 4 ,
25686d7f5d3SJohn Marino.Xr pfsync 4 ,
25786d7f5d3SJohn Marino.Xr rc.conf 5 ,
25886d7f5d3SJohn Marino.Xr ifconfig 8 ,
25986d7f5d3SJohn Marino.Xr sysctl 8
26086d7f5d3SJohn Marino.Sh HISTORY
26186d7f5d3SJohn MarinoThe
26286d7f5d3SJohn Marino.Nm
26386d7f5d3SJohn Marinodevice first appeared in
26486d7f5d3SJohn Marino.Ox 3.5 .
26586d7f5d3SJohn MarinoIt was imported into
26686d7f5d3SJohn Marino.Dx 1.11 .
267