18e925890SGleb Smirnoff.\" $OpenBSD: carp.4,v 1.16 2004/12/07 23:41:35 jmc Exp $ 28e925890SGleb Smirnoff.\" 38e925890SGleb Smirnoff.\" Copyright (c) 2003, Ryan McBride. All rights reserved. 4*08b68b0eSGleb Smirnoff.\" Copyright (c) 2011, Gleb Smirnoff <glebius@FreeBSD.org> 58e925890SGleb Smirnoff.\" 68e925890SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without 78e925890SGleb Smirnoff.\" modification, are permitted provided that the following conditions 88e925890SGleb Smirnoff.\" are met: 98e925890SGleb Smirnoff.\" 1. Redistributions of source code must retain the above copyright 108e925890SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer. 118e925890SGleb Smirnoff.\" 2. Redistributions in binary form must reproduce the above copyright 128e925890SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer in the 138e925890SGleb Smirnoff.\" documentation and/or other materials provided with the distribution. 148e925890SGleb Smirnoff.\" 158e925890SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 168e925890SGleb Smirnoff.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 178e925890SGleb Smirnoff.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 188e925890SGleb Smirnoff.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 198e925890SGleb Smirnoff.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 208e925890SGleb Smirnoff.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 218e925890SGleb Smirnoff.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 228e925890SGleb Smirnoff.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 238e925890SGleb Smirnoff.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 248e925890SGleb Smirnoff.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 258e925890SGleb Smirnoff.\" SUCH DAMAGE. 268e925890SGleb Smirnoff.\" 278e925890SGleb Smirnoff.\" $FreeBSD$ 288e925890SGleb Smirnoff.\" 29*08b68b0eSGleb Smirnoff.Dd December 16, 2011 308e925890SGleb Smirnoff.Dt CARP 4 318e925890SGleb Smirnoff.Os 328e925890SGleb Smirnoff.Sh NAME 338e925890SGleb Smirnoff.Nm carp 348e925890SGleb Smirnoff.Nd Common Address Redundancy Protocol 358e925890SGleb Smirnoff.Sh SYNOPSIS 368e925890SGleb Smirnoff.Cd "device carp" 378e925890SGleb Smirnoff.Sh DESCRIPTION 38*08b68b0eSGleb SmirnoffThe CARP allows multiple hosts on the same local network to share a set of 39*08b68b0eSGleb SmirnoffIPv4 and/or IPv6 addresses. 408e925890SGleb SmirnoffIts primary purpose is to ensure that these 41*08b68b0eSGleb Smirnoffaddresses are always available. 428e925890SGleb Smirnoff.Pp 438e925890SGleb SmirnoffTo use 448e925890SGleb Smirnoff.Nm , 45*08b68b0eSGleb Smirnoffthe administrator needs to configure at minimum a common virtual host ID 46*08b68b0eSGleb Smirnoff(vhid) and attach at least one IP address to this vhid on each machine which 47*08b68b0eSGleb Smirnoffis to take part in the virtual group. 48*08b68b0eSGleb SmirnoffAdditional parameters can also be set on a per-vhid basis: 498e925890SGleb Smirnoff.Cm advbase 508e925890SGleb Smirnoffand 518e925890SGleb Smirnoff.Cm advskew , 528e925890SGleb Smirnoffwhich are used to control how frequently the host sends advertisements when it 538e925890SGleb Smirnoffis the master for a virtual host, and 548e925890SGleb Smirnoff.Cm pass 553e630869SGleb Smirnoffwhich is used to authenticate 563e630869SGleb Smirnoff.Nm 573e630869SGleb Smirnoffadvertisements. 58762ce3e6SGleb SmirnoffThe 59762ce3e6SGleb Smirnoff.Cm advbase 60762ce3e6SGleb Smirnoffparameter stands for 61a4be0b3cSRuslan Ermilov.Dq "advertisement base" . 621a1fa3bdSGiorgos KeramidasIt is measured in seconds and specifies the base of the advertisement interval. 63762ce3e6SGleb SmirnoffThe 64762ce3e6SGleb Smirnoff.Cm advskew 65762ce3e6SGleb Smirnoffparameter stands for 66a4be0b3cSRuslan Ermilov.Dq "advertisement skew" . 67762ce3e6SGleb SmirnoffIt is measured in 1/256 of seconds. 68762ce3e6SGleb SmirnoffIt is added to the base advertisement interval to make one host advertise 69762ce3e6SGleb Smirnoffa bit slower that the other does. 70762ce3e6SGleb SmirnoffBoth 71762ce3e6SGleb Smirnoff.Cm advbase 72762ce3e6SGleb Smirnoffand 73762ce3e6SGleb Smirnoff.Cm advskew 74a4be0b3cSRuslan Ermilovare put inside CARP advertisements. 758e925890SGleb SmirnoffThese configurations can be done using 768e925890SGleb Smirnoff.Xr ifconfig 8 , 778e925890SGleb Smirnoffor through the 788e925890SGleb Smirnoff.Dv SIOCSVH 793e630869SGleb Smirnoff.Xr ioctl 2 . 808e925890SGleb Smirnoff.Pp 81*08b68b0eSGleb SmirnoffCARP virtual hosts can be configured on multicast capable interfaces: Ethernet, 82*08b68b0eSGleb Smirnofflayer 2 VLAN, FDDI and Token Ring. 83*08b68b0eSGleb SmirnoffAn arbitrary number of virtual host IDs can be configured on an interface. 84*08b68b0eSGleb SmirnoffAn arbitrary number of IPv4 or IPv6 addresses can be attached to a particular 85*08b68b0eSGleb Smirnoffvhid. 86*08b68b0eSGleb SmirnoffIt is important that all hosts participating in a vhid have the same list 87*08b68b0eSGleb Smirnoffof prefixes configured on the vhid, since all prefixes are included in the 88*08b68b0eSGleb Smirnoffcryptographic checksum supplied in each advertisement. 89*08b68b0eSGleb SmirnoffMultiple vhids running on one interface participate in master/backup 90*08b68b0eSGleb Smirnoffelections independently. 91*08b68b0eSGleb Smirnoff.Pp 928e925890SGleb SmirnoffAdditionally, there are a number of global parameters which can be set using 938e925890SGleb Smirnoff.Xr sysctl 8 : 94*08b68b0eSGleb Smirnoff.Bl -tag -width ".Va net.inet.carp.preempt" 953e630869SGleb Smirnoff.It Va net.inet.carp.allow 968e925890SGleb SmirnoffAccept incoming 978e925890SGleb Smirnoff.Nm 988e925890SGleb Smirnoffpackets. 998e925890SGleb SmirnoffEnabled by default. 1003e630869SGleb Smirnoff.It Va net.inet.carp.preempt 1018e925890SGleb SmirnoffAllow virtual hosts to preempt each other. 1028e925890SGleb SmirnoffIt is also used to failover 1038e925890SGleb Smirnoff.Nm 1048e925890SGleb Smirnoffinterfaces as a group. 1058e925890SGleb SmirnoffWhen the option is enabled and one of the 1068e925890SGleb Smirnoff.Nm 1078e925890SGleb Smirnoffenabled physical interfaces 1083e630869SGleb Smirnoffgoes down, 1093e630869SGleb Smirnoff.Cm advskew 1103e630869SGleb Smirnoffis changed to 240 on all 1118e925890SGleb Smirnoff.Nm 1128e925890SGleb Smirnoffinterfaces. 1138e925890SGleb SmirnoffSee also the first example. 1148e925890SGleb SmirnoffDisabled by default. 1153e630869SGleb Smirnoff.It Va net.inet.carp.log 116442af10aSGleb SmirnoffValue of 0 disables any logging. 117acc0fee0SRuslan ErmilovValue of 1 enables logging state changes of 118442af10aSGleb Smirnoff.Nm 119442af10aSGleb Smirnoffinterfaces. 120acc0fee0SRuslan ErmilovValues above 1 enable logging of bad 121acc0fee0SRuslan Ermilov.Nm 122acc0fee0SRuslan Ermilovpackets. 123442af10aSGleb SmirnoffDefault value is 1. 1241771f872SGleb Smirnoff.It Va net.inet.carp.suppress_preempt 1251771f872SGleb SmirnoffA read only value showing the status of preemption suppression. 1261771f872SGleb SmirnoffPreemption can be suppressed if link on an interface is down 1271771f872SGleb Smirnoffor when 1281771f872SGleb Smirnoff.Xr pfsync 4 1291771f872SGleb Smirnoffinterface is not synchronized. 1301771f872SGleb SmirnoffValue of 0 means that preemption is not suppressed, since no 1311771f872SGleb Smirnoffproblems are detected. 1321771f872SGleb SmirnoffEvery problem increments suppression counter. 1338e925890SGleb Smirnoff.El 134*08b68b0eSGleb Smirnoff.\".Sh ARP level load balancing 135*08b68b0eSGleb Smirnoff.\"The 136*08b68b0eSGleb Smirnoff.\".Nm 137*08b68b0eSGleb Smirnoff.\"has limited abilities for load balancing the incoming connections 138*08b68b0eSGleb Smirnoff.\"between hosts in Ethernet network. 139*08b68b0eSGleb Smirnoff.\"For load balancing operation, one needs several CARP interfaces that 140*08b68b0eSGleb Smirnoff.\"are configured to the same IP address, but to a different vhids. 141*08b68b0eSGleb Smirnoff.\"Once an ARP request is received, the CARP protocol will use a hashing 142*08b68b0eSGleb Smirnoff.\"function against the source IP address in the ARP request to determine 143*08b68b0eSGleb Smirnoff.\"which vhid should this request belong to. 144*08b68b0eSGleb Smirnoff.\"If the corresponding CARP interface is in master state, the ARP request 145*08b68b0eSGleb Smirnoff.\"will be replied, otherwise it will be ignored. 146*08b68b0eSGleb Smirnoff.\"See the 147*08b68b0eSGleb Smirnoff.\".Sx EXAMPLES 148*08b68b0eSGleb Smirnoff.\"section for a practical example of load balancing. 149*08b68b0eSGleb Smirnoff.\".Pp 150*08b68b0eSGleb Smirnoff.\"The ARP load balancing has some limitations. 151*08b68b0eSGleb Smirnoff.\"First, ARP balancing only works on the local network segment. 152*08b68b0eSGleb Smirnoff.\"It cannot balance traffic that crosses a router, because the 153*08b68b0eSGleb Smirnoff.\"router itself will always be balanced to the same virtual host. 154*08b68b0eSGleb Smirnoff.\"Second, ARP load balancing can lead to asymmetric routing 155*08b68b0eSGleb Smirnoff.\"of incoming and outgoing traffic, and thus combining it with 156*08b68b0eSGleb Smirnoff.\".Xr pfsync 4 157*08b68b0eSGleb Smirnoff.\"is dangerous, because this creates a race condition between 158*08b68b0eSGleb Smirnoff.\"balanced routers and a host they are serving. 159*08b68b0eSGleb Smirnoff.\"Imagine an incoming packet creating state on the first router, being 160*08b68b0eSGleb Smirnoff.\"forwarded to its destination, and destination replying faster 161*08b68b0eSGleb Smirnoff.\"than the state information is packed and synced with the second router. 162*08b68b0eSGleb Smirnoff.\"If the reply would be load balanced to second router, it will be 163*08b68b0eSGleb Smirnoff.\"dropped due to no state. 164cc8b2291SGleb Smirnoff.Sh STATE CHANGE NOTIFICATIONS 165cc8b2291SGleb SmirnoffSometimes it is useful to get notified about 166cc8b2291SGleb Smirnoff.Nm 167cc8b2291SGleb Smirnoffstatus change events. 168cc8b2291SGleb SmirnoffThis can be accomplished by using 169cc8b2291SGleb Smirnoff.Xr devd 8 170cc8b2291SGleb Smirnoffhooks. 171*08b68b0eSGleb SmirnoffMaster/slave events are signalled under system 172*08b68b0eSGleb Smirnoff.Dv CARP . 173*08b68b0eSGleb SmirnoffSubsystem specifies vhid and name of interface, where event occured. 174*08b68b0eSGleb SmirnoffType of the message displays new state of vhid. 175cc8b2291SGleb SmirnoffPlease see 176cc8b2291SGleb Smirnoff.Xr devd.conf 5 177cc8b2291SGleb Smirnoffand 178cc8b2291SGleb Smirnoff.Sx EXAMPLES 179cc8b2291SGleb Smirnoffsection for more information. 1808e925890SGleb Smirnoff.Sh EXAMPLES 1818e925890SGleb SmirnoffFor firewalls and routers with multiple interfaces, it is desirable to 1828e925890SGleb Smirnofffailover all of the 1838e925890SGleb Smirnoff.Nm 1848e925890SGleb Smirnoffinterfaces together, when one of the physical interfaces goes down. 1858e925890SGleb SmirnoffThis is achieved by the preempt option. 1868e925890SGleb SmirnoffEnable it on both host A and B: 1878e925890SGleb Smirnoff.Pp 1883e630869SGleb Smirnoff.Dl sysctl net.inet.carp.preempt=1 1898e925890SGleb Smirnoff.Pp 190*08b68b0eSGleb SmirnoffAssume that host A is the preferred master and we are running the 191*08b68b0eSGleb Smirnoff192.168.1.0/24 prefix on em0 and 192.168.2.0/24 on em1. 1928e925890SGleb SmirnoffThis is the setup for host A: 1938e925890SGleb Smirnoff.Bd -literal -offset indent 194*08b68b0eSGleb Smirnoffifconfig em0 vhid 1 pass mekmitasdigoat 192.168.1.1/24 195*08b68b0eSGleb Smirnoffifconfig em1 vhid 2 pass mekmitasdigoat 192.168.2.1/24 1968e925890SGleb Smirnoff.Ed 1978e925890SGleb Smirnoff.Pp 1983e630869SGleb SmirnoffThe setup for host B is identical, but it has a higher 1993e630869SGleb Smirnoff.Cm advskew : 2008e925890SGleb Smirnoff.Bd -literal -offset indent 201*08b68b0eSGleb Smirnoffifconfig em0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24 202*08b68b0eSGleb Smirnoffifconfig em1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24 2038e925890SGleb Smirnoff.Ed 2048e925890SGleb Smirnoff.Pp 2058e925890SGleb SmirnoffBecause of the preempt option, when one of the physical interfaces of 2063e630869SGleb Smirnoffhost A fails, 2073e630869SGleb Smirnoff.Cm advskew 2083e630869SGleb Smirnoffis adjusted to 240 on all its 2098e925890SGleb Smirnoff.Nm 2108e925890SGleb Smirnoffinterfaces. 2118e925890SGleb SmirnoffThis will cause host B to preempt on both interfaces instead of 2128e925890SGleb Smirnoffjust the failed one. 213*08b68b0eSGleb Smirnoff.\".Pp 214*08b68b0eSGleb Smirnoff.\"In order to set up an ARP balanced virtual host, it is necessary to configure 215*08b68b0eSGleb Smirnoff.\"one virtual host for each physical host which would respond to ARP requests 216*08b68b0eSGleb Smirnoff.\"and thus handle the traffic. 217*08b68b0eSGleb Smirnoff.\"In the following example, two virtual hosts are configured on two hosts to 218*08b68b0eSGleb Smirnoff.\"provide balancing and failover for the IP address 192.168.1.10. 219*08b68b0eSGleb Smirnoff.\".Pp 220*08b68b0eSGleb Smirnoff.\"First the 221*08b68b0eSGleb Smirnoff.\".Nm 222*08b68b0eSGleb Smirnoff.\"interfaces on host A are configured. 223*08b68b0eSGleb Smirnoff.\"The 224*08b68b0eSGleb Smirnoff.\".Cm advskew 225*08b68b0eSGleb Smirnoff.\"of 100 on the second virtual host means that its advertisements will be sent 226*08b68b0eSGleb Smirnoff.\"out slightly less frequently. 227*08b68b0eSGleb Smirnoff.\".Bd -literal -offset indent 228*08b68b0eSGleb Smirnoff.\"ifconfig carp0 create 229*08b68b0eSGleb Smirnoff.\"ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24 230*08b68b0eSGleb Smirnoff.\"ifconfig carp1 create 231*08b68b0eSGleb Smirnoff.\"ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24 232*08b68b0eSGleb Smirnoff.\".Ed 233*08b68b0eSGleb Smirnoff.\".Pp 234*08b68b0eSGleb Smirnoff.\"The configuration for host B is identical, except the 235*08b68b0eSGleb Smirnoff.\".Cm advskew 236*08b68b0eSGleb Smirnoff.\"is on virtual host 1 rather than virtual host 2. 237*08b68b0eSGleb Smirnoff.\".Bd -literal -offset indent 238*08b68b0eSGleb Smirnoff.\"ifconfig carp0 create 239*08b68b0eSGleb Smirnoff.\"ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24 240*08b68b0eSGleb Smirnoff.\"ifconfig carp1 create 241*08b68b0eSGleb Smirnoff.\"ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24 242*08b68b0eSGleb Smirnoff.\".Ed 243*08b68b0eSGleb Smirnoff.\".Pp 244*08b68b0eSGleb Smirnoff.\"Finally, the ARP balancing feature must be enabled on both hosts: 245*08b68b0eSGleb Smirnoff.\".Pp 246*08b68b0eSGleb Smirnoff.\".Dl sysctl net.inet.carp.arpbalance=1 247*08b68b0eSGleb Smirnoff.\".Pp 248*08b68b0eSGleb Smirnoff.\"When the hosts receive an ARP request for 192.168.1.10, the source IP address 249*08b68b0eSGleb Smirnoff.\"of the request is used to compute which virtual host should answer the request. 250*08b68b0eSGleb Smirnoff.\"The host which is master of the selected virtual host will reply to the 251*08b68b0eSGleb Smirnoff.\"request, the other(s) will ignore it. 252*08b68b0eSGleb Smirnoff.\".Pp 253*08b68b0eSGleb Smirnoff.\"This way, locally connected systems will receive different ARP replies and 254*08b68b0eSGleb Smirnoff.\"subsequent IP traffic will be balanced among the hosts. 255*08b68b0eSGleb Smirnoff.\"If one of the hosts fails, the other will take over the virtual MAC address, 256*08b68b0eSGleb Smirnoff.\"and begin answering ARP requests on its behalf. 257cc8b2291SGleb Smirnoff.Pp 258cc8b2291SGleb SmirnoffProcessing of 259cc8b2291SGleb Smirnoff.Nm 260*08b68b0eSGleb Smirnoffstatus change events can be set up by using the following devd.conf rule: 261cc8b2291SGleb Smirnoff.Bd -literal -offset indent 262cc8b2291SGleb Smirnoffnotify 0 { 263*08b68b0eSGleb Smirnoff match "system" "CARP"; 264*08b68b0eSGleb Smirnoff match "subsystem" "[0-9]+@"; 265*08b68b0eSGleb Smirnoff match "type" "(MASTER|BACKUP)"; 266*08b68b0eSGleb Smirnoff action "/root/carpcontrol.sh $subsystem $type"; 267cc8b2291SGleb Smirnoff}; 268cc8b2291SGleb Smirnoff.Ed 2698e925890SGleb Smirnoff.Sh SEE ALSO 2708e925890SGleb Smirnoff.Xr inet 4 , 2711771f872SGleb Smirnoff.Xr pfsync 4 , 2721771f872SGleb Smirnoff.Xr rc.conf 5 , 2731eefdc3bSGleb Smirnoff.Xr devd.conf 5 , 274a4be0b3cSRuslan Ermilov.Xr ifconfig 8 , 2758e925890SGleb Smirnoff.Xr sysctl 8 2768e925890SGleb Smirnoff.Sh HISTORY 2778e925890SGleb SmirnoffThe 2788e925890SGleb Smirnoff.Nm 2798e925890SGleb Smirnoffdevice first appeared in 2808e925890SGleb Smirnoff.Ox 3.5 . 2818e925890SGleb SmirnoffThe 2828e925890SGleb Smirnoff.Nm 2833e630869SGleb Smirnoffdevice was imported into 2848e925890SGleb Smirnoff.Fx 5.4 . 285*08b68b0eSGleb SmirnoffIn 286*08b68b0eSGleb Smirnoff.Fx 10 287*08b68b0eSGleb Smirnoffthe 288*08b68b0eSGleb Smirnoff.Nm 289*08b68b0eSGleb Smirnoffwas significantly rewritten, and is no longer a pseudo-interface. 290