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