1*86d7f5d3SJohn Marino.\" 2*86d7f5d3SJohn Marino.\" Copyright (c) 2003, Ryan McBride. All rights reserved. 3*86d7f5d3SJohn Marino.\" 4*86d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without 5*86d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions 6*86d7f5d3SJohn Marino.\" are met: 7*86d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 8*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer. 9*86d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 10*86d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 11*86d7f5d3SJohn Marino.\" documentation and/or other materials provided with the distribution. 12*86d7f5d3SJohn Marino.\" 13*86d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 14*86d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*86d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*86d7f5d3SJohn Marino.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 17*86d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*86d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*86d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*86d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*86d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*86d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*86d7f5d3SJohn Marino.\" SUCH DAMAGE. 24*86d7f5d3SJohn Marino.\" 25*86d7f5d3SJohn Marino.\" $OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $ 26*86d7f5d3SJohn Marino.\" $FreeBSD: src/share/man/man4/carp.4,v 1.10 2006/06/07 10:26:51 glebius Exp $ 27*86d7f5d3SJohn Marino.\" $DragonFly: src/share/man/man4/carp.4,v 1.4 2008/10/17 12:41:38 swildner Exp $ 28*86d7f5d3SJohn Marino.\" 29*86d7f5d3SJohn Marino.Dd April 9, 2007 30*86d7f5d3SJohn Marino.Dt CARP 4 31*86d7f5d3SJohn Marino.Os 32*86d7f5d3SJohn Marino.Sh NAME 33*86d7f5d3SJohn Marino.Nm carp 34*86d7f5d3SJohn Marino.Nd Common Address Redundancy Protocol 35*86d7f5d3SJohn Marino.Sh SYNOPSIS 36*86d7f5d3SJohn Marino.Cd "options CARP" 37*86d7f5d3SJohn Marino.Cd "pseudo-device carp" 38*86d7f5d3SJohn Marino.Sh DESCRIPTION 39*86d7f5d3SJohn MarinoThe 40*86d7f5d3SJohn Marino.Nm 41*86d7f5d3SJohn Marinointerface is a pseudo-device that implements and controls the 42*86d7f5d3SJohn MarinoCARP protocol. 43*86d7f5d3SJohn MarinoCARP allows multiple hosts on the same local network to share a set of IP addresses. 44*86d7f5d3SJohn MarinoIts primary purpose is to ensure that these 45*86d7f5d3SJohn Marinoaddresses are always available, but in some configurations 46*86d7f5d3SJohn Marino.Nm 47*86d7f5d3SJohn Marinocan also provide load balancing functionality. 48*86d7f5d3SJohn Marino.Pp 49*86d7f5d3SJohn MarinoA 50*86d7f5d3SJohn Marino.Nm 51*86d7f5d3SJohn Marinointerface can be created at runtime using the 52*86d7f5d3SJohn Marino.Nm ifconfig Li carp Ns Ar N Cm create 53*86d7f5d3SJohn Marinocommand or by configuring 54*86d7f5d3SJohn Marinoit via 55*86d7f5d3SJohn Marino.Va cloned_interfaces 56*86d7f5d3SJohn Marinoin the 57*86d7f5d3SJohn Marino.Pa /etc/rc.conf 58*86d7f5d3SJohn Marinofile. 59*86d7f5d3SJohn Marino.Pp 60*86d7f5d3SJohn MarinoTo use 61*86d7f5d3SJohn Marino.Nm , 62*86d7f5d3SJohn Marinothe administrator needs to configure at minimum a common virtual host ID (VHID) 63*86d7f5d3SJohn Marinoand virtual host IP address on each machine which is to take part in the virtual 64*86d7f5d3SJohn Marinogroup. 65*86d7f5d3SJohn MarinoAdditional parameters can also be set on a per-interface basis: 66*86d7f5d3SJohn Marino.Cm advbase 67*86d7f5d3SJohn Marinoand 68*86d7f5d3SJohn Marino.Cm advskew , 69*86d7f5d3SJohn Marinowhich are used to control how frequently the host sends advertisements when it 70*86d7f5d3SJohn Marinois the master for a virtual host, and 71*86d7f5d3SJohn Marino.Cm pass 72*86d7f5d3SJohn Marinowhich is used to authenticate 73*86d7f5d3SJohn Marino.Nm 74*86d7f5d3SJohn Marinoadvertisements. 75*86d7f5d3SJohn MarinoThe 76*86d7f5d3SJohn Marino.Cm advbase 77*86d7f5d3SJohn Marinoparameter stands for 78*86d7f5d3SJohn Marino.Dq "advertisement base" . 79*86d7f5d3SJohn MarinoIt is measured in seconds and specifies the base of the advertisement interval. 80*86d7f5d3SJohn MarinoThe 81*86d7f5d3SJohn Marino.Cm advskew 82*86d7f5d3SJohn Marinoparameter stands for 83*86d7f5d3SJohn Marino.Dq "advertisement skew" . 84*86d7f5d3SJohn MarinoIt is measured in 1/256 of seconds. 85*86d7f5d3SJohn MarinoIt is added to the base advertisement interval to make one host advertise 86*86d7f5d3SJohn Marinoa bit slower than the other does. 87*86d7f5d3SJohn MarinoBoth 88*86d7f5d3SJohn Marino.Cm advbase 89*86d7f5d3SJohn Marinoand 90*86d7f5d3SJohn Marino.Cm advskew 91*86d7f5d3SJohn Marinoare put inside CARP advertisements. 92*86d7f5d3SJohn MarinoThese configurations can be done using 93*86d7f5d3SJohn Marino.Xr ifconfig 8 , 94*86d7f5d3SJohn Marinoor through the 95*86d7f5d3SJohn Marino.Dv SIOCSVH 96*86d7f5d3SJohn Marino.Xr ioctl 2 . 97*86d7f5d3SJohn Marino.Pp 98*86d7f5d3SJohn MarinoAdditionally, there are a number of global parameters which can be set using 99*86d7f5d3SJohn Marino.Xr sysctl 8 : 100*86d7f5d3SJohn Marino.Bl -tag -width ".Va net.inet.carp.arpbalance" 101*86d7f5d3SJohn Marino.It Va net.inet.carp.allow 102*86d7f5d3SJohn MarinoAccept incoming 103*86d7f5d3SJohn Marino.Nm 104*86d7f5d3SJohn Marinopackets. 105*86d7f5d3SJohn MarinoEnabled by default. 106*86d7f5d3SJohn Marino.It Va net.inet.carp.preempt 107*86d7f5d3SJohn MarinoAllow virtual hosts to preempt each other. 108*86d7f5d3SJohn MarinoIt is also used to failover 109*86d7f5d3SJohn Marino.Nm 110*86d7f5d3SJohn Marinointerfaces as a group. 111*86d7f5d3SJohn MarinoWhen the option is enabled and one of the 112*86d7f5d3SJohn Marino.Nm 113*86d7f5d3SJohn Marinoenabled physical interfaces 114*86d7f5d3SJohn Marinogoes down, 115*86d7f5d3SJohn Marino.Cm advskew 116*86d7f5d3SJohn Marinois changed to 240 on all 117*86d7f5d3SJohn Marino.Nm 118*86d7f5d3SJohn Marinointerfaces. 119*86d7f5d3SJohn MarinoSee also the first example. 120*86d7f5d3SJohn MarinoDisabled by default. 121*86d7f5d3SJohn Marino.It Va net.inet.carp.log 122*86d7f5d3SJohn MarinoValue of 0 disables any logging. 123*86d7f5d3SJohn MarinoValue of 1 enables logging of bad 124*86d7f5d3SJohn Marino.Nm 125*86d7f5d3SJohn Marinopackets. 126*86d7f5d3SJohn MarinoValues above 1 enable logging state changes of 127*86d7f5d3SJohn Marino.Nm 128*86d7f5d3SJohn Marinointerfaces. 129*86d7f5d3SJohn MarinoDefault value is 1. 130*86d7f5d3SJohn Marino.It Va net.inet.carp.arpbalance 131*86d7f5d3SJohn MarinoBalance local traffic using ARP (see below). 132*86d7f5d3SJohn MarinoDisabled by default. 133*86d7f5d3SJohn Marino.It Va net.inet.carp.suppress_preempt 134*86d7f5d3SJohn MarinoA read only value showing the status of preemption suppression. 135*86d7f5d3SJohn MarinoPreemption can be suppressed if link on an interface is down 136*86d7f5d3SJohn Marinoor when 137*86d7f5d3SJohn Marino.Xr pfsync 4 138*86d7f5d3SJohn Marinointerface is not synchronized. 139*86d7f5d3SJohn MarinoValue of 0 means that preemption is not suppressed, since no 140*86d7f5d3SJohn Marinoproblems are detected. 141*86d7f5d3SJohn MarinoEvery problem increments suppression counter. 142*86d7f5d3SJohn Marino.El 143*86d7f5d3SJohn Marino.Sh ARP LEVEL LOAD BALANCING 144*86d7f5d3SJohn MarinoThe 145*86d7f5d3SJohn Marino.Nm 146*86d7f5d3SJohn Marinohas limited abilities for load balancing the incoming connections 147*86d7f5d3SJohn Marinobetween hosts in Ethernet network. 148*86d7f5d3SJohn MarinoFor load balancing operation, one needs several CARP interfaces that 149*86d7f5d3SJohn Marinoare configured to the same IP address, but to a different VHIDs. 150*86d7f5d3SJohn MarinoOnce an ARP request is received, the CARP protocol will use a hashing 151*86d7f5d3SJohn Marinofunction against the source IP address in the ARP request to determine 152*86d7f5d3SJohn Marinowhich VHID should this request belong to. 153*86d7f5d3SJohn MarinoIf the corresponding CARP interface is in master state, the ARP request 154*86d7f5d3SJohn Marinowill be replied, otherwise it will be ignored. 155*86d7f5d3SJohn MarinoSee the 156*86d7f5d3SJohn Marino.Sx EXAMPLES 157*86d7f5d3SJohn Marinosection for a practical example of load balancing. 158*86d7f5d3SJohn Marino.Pp 159*86d7f5d3SJohn MarinoThe ARP load balancing has some limitations. 160*86d7f5d3SJohn MarinoFirst, ARP balancing only works on the local network segment. 161*86d7f5d3SJohn MarinoIt cannot balance traffic that crosses a router, because the 162*86d7f5d3SJohn Marinorouter itself will always be balanced to the same virtual host. 163*86d7f5d3SJohn MarinoSecond, ARP load balancing can lead to asymmetric routing 164*86d7f5d3SJohn Marinoof incoming and outgoing traffic, and thus combining it with 165*86d7f5d3SJohn Marino.Xr pfsync 4 166*86d7f5d3SJohn Marinois dangerous, because this creates a race condition between 167*86d7f5d3SJohn Marinobalanced routers and a host they are serving. 168*86d7f5d3SJohn MarinoImagine an incoming packet creating state on the first router, being 169*86d7f5d3SJohn Marinoforwarded to its destination, and destination replying faster 170*86d7f5d3SJohn Marinothan the state information is packed and synced with the second router. 171*86d7f5d3SJohn MarinoIf the reply would be load balanced to second router, it will be 172*86d7f5d3SJohn Marinodropped due to no state. 173*86d7f5d3SJohn Marino.Sh EXAMPLES 174*86d7f5d3SJohn MarinoFor firewalls and routers with multiple interfaces, it is desirable to 175*86d7f5d3SJohn Marinofailover all of the 176*86d7f5d3SJohn Marino.Nm 177*86d7f5d3SJohn Marinointerfaces together, when one of the physical interfaces goes down. 178*86d7f5d3SJohn MarinoThis is achieved by the preempt option. 179*86d7f5d3SJohn MarinoEnable it on both host A and B: 180*86d7f5d3SJohn Marino.Pp 181*86d7f5d3SJohn Marino.Dl sysctl net.inet.carp.preempt=1 182*86d7f5d3SJohn Marino.Pp 183*86d7f5d3SJohn MarinoAssume that host A is the preferred master and 192.168.1.x/24 is 184*86d7f5d3SJohn Marinoconfigured on one physical interface and 192.168.2.y/24 on another. 185*86d7f5d3SJohn MarinoThis is the setup for host A: 186*86d7f5d3SJohn Marino.Bd -literal -offset indent 187*86d7f5d3SJohn Marinoifconfig carp0 create 188*86d7f5d3SJohn Marinoifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1/24 189*86d7f5d3SJohn Marinoifconfig carp1 create 190*86d7f5d3SJohn Marinoifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1/24 191*86d7f5d3SJohn Marino.Ed 192*86d7f5d3SJohn Marino.Pp 193*86d7f5d3SJohn MarinoThe setup for host B is identical, but it has a higher 194*86d7f5d3SJohn Marino.Cm advskew : 195*86d7f5d3SJohn Marino.Bd -literal -offset indent 196*86d7f5d3SJohn Marinoifconfig carp0 create 197*86d7f5d3SJohn Marinoifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24 198*86d7f5d3SJohn Marinoifconfig carp1 create 199*86d7f5d3SJohn Marinoifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24 200*86d7f5d3SJohn Marino.Ed 201*86d7f5d3SJohn Marino.Pp 202*86d7f5d3SJohn MarinoBecause of the preempt option, when one of the physical interfaces of 203*86d7f5d3SJohn Marinohost A fails, 204*86d7f5d3SJohn Marino.Cm advskew 205*86d7f5d3SJohn Marinois adjusted to 240 on all its 206*86d7f5d3SJohn Marino.Nm 207*86d7f5d3SJohn Marinointerfaces. 208*86d7f5d3SJohn MarinoThis will cause host B to preempt on both interfaces instead of 209*86d7f5d3SJohn Marinojust the failed one. 210*86d7f5d3SJohn Marino.Pp 211*86d7f5d3SJohn MarinoIn order to set up an ARP balanced virtual host, it is necessary to configure 212*86d7f5d3SJohn Marinoone virtual host for each physical host which would respond to ARP requests 213*86d7f5d3SJohn Marinoand thus handle the traffic. 214*86d7f5d3SJohn MarinoIn the following example, two virtual hosts are configured on two hosts to 215*86d7f5d3SJohn Marinoprovide balancing and failover for the IP address 192.168.1.10. 216*86d7f5d3SJohn Marino.Pp 217*86d7f5d3SJohn MarinoFirst the 218*86d7f5d3SJohn Marino.Nm 219*86d7f5d3SJohn Marinointerfaces on host A are configured. 220*86d7f5d3SJohn MarinoThe 221*86d7f5d3SJohn Marino.Cm advskew 222*86d7f5d3SJohn Marinoof 100 on the second virtual host means that its advertisements will be sent 223*86d7f5d3SJohn Marinoout slightly less frequently. 224*86d7f5d3SJohn Marino.Bd -literal -offset indent 225*86d7f5d3SJohn Marinoifconfig carp0 create 226*86d7f5d3SJohn Marinoifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24 227*86d7f5d3SJohn Marinoifconfig carp1 create 228*86d7f5d3SJohn Marinoifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24 229*86d7f5d3SJohn Marino.Ed 230*86d7f5d3SJohn Marino.Pp 231*86d7f5d3SJohn MarinoThe configuration for host B is identical, except the 232*86d7f5d3SJohn Marino.Cm advskew 233*86d7f5d3SJohn Marinois on virtual host 1 rather than virtual host 2. 234*86d7f5d3SJohn Marino.Bd -literal -offset indent 235*86d7f5d3SJohn Marinoifconfig carp0 create 236*86d7f5d3SJohn Marinoifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24 237*86d7f5d3SJohn Marinoifconfig carp1 create 238*86d7f5d3SJohn Marinoifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24 239*86d7f5d3SJohn Marino.Ed 240*86d7f5d3SJohn Marino.Pp 241*86d7f5d3SJohn MarinoFinally, the ARP balancing feature must be enabled on both hosts: 242*86d7f5d3SJohn Marino.Pp 243*86d7f5d3SJohn Marino.Dl sysctl net.inet.carp.arpbalance=1 244*86d7f5d3SJohn Marino.Pp 245*86d7f5d3SJohn MarinoWhen the hosts receive an ARP request for 192.168.1.10, the source IP address 246*86d7f5d3SJohn Marinoof the request is used to compute which virtual host should answer the request. 247*86d7f5d3SJohn MarinoThe host which is master of the selected virtual host will reply to the 248*86d7f5d3SJohn Marinorequest, the other(s) will ignore it. 249*86d7f5d3SJohn Marino.Pp 250*86d7f5d3SJohn MarinoThis way, locally connected systems will receive different ARP replies and 251*86d7f5d3SJohn Marinosubsequent IP traffic will be balanced among the hosts. 252*86d7f5d3SJohn MarinoIf one of the hosts fails, the other will take over the virtual MAC address, 253*86d7f5d3SJohn Marinoand begin answering ARP requests on its behalf. 254*86d7f5d3SJohn Marino.Sh SEE ALSO 255*86d7f5d3SJohn Marino.Xr inet 4 , 256*86d7f5d3SJohn Marino.Xr pfsync 4 , 257*86d7f5d3SJohn Marino.Xr rc.conf 5 , 258*86d7f5d3SJohn Marino.Xr ifconfig 8 , 259*86d7f5d3SJohn Marino.Xr sysctl 8 260*86d7f5d3SJohn Marino.Sh HISTORY 261*86d7f5d3SJohn MarinoThe 262*86d7f5d3SJohn Marino.Nm 263*86d7f5d3SJohn Marinodevice first appeared in 264*86d7f5d3SJohn Marino.Ox 3.5 . 265*86d7f5d3SJohn MarinoIt was imported into 266*86d7f5d3SJohn Marino.Dx 1.11 . 267