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. 48e925890SGleb Smirnoff.\" 58e925890SGleb Smirnoff.\" Redistribution and use in source and binary forms, with or without 68e925890SGleb Smirnoff.\" modification, are permitted provided that the following conditions 78e925890SGleb Smirnoff.\" are met: 88e925890SGleb Smirnoff.\" 1. Redistributions of source code must retain the above copyright 98e925890SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer. 108e925890SGleb Smirnoff.\" 2. Redistributions in binary form must reproduce the above copyright 118e925890SGleb Smirnoff.\" notice, this list of conditions and the following disclaimer in the 128e925890SGleb Smirnoff.\" documentation and/or other materials provided with the distribution. 138e925890SGleb Smirnoff.\" 148e925890SGleb Smirnoff.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 158e925890SGleb Smirnoff.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 168e925890SGleb Smirnoff.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 178e925890SGleb Smirnoff.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 188e925890SGleb Smirnoff.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 198e925890SGleb Smirnoff.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 208e925890SGleb Smirnoff.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 218e925890SGleb Smirnoff.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 228e925890SGleb Smirnoff.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 238e925890SGleb Smirnoff.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 248e925890SGleb Smirnoff.\" SUCH DAMAGE. 258e925890SGleb Smirnoff.\" 268e925890SGleb Smirnoff.\" $FreeBSD$ 278e925890SGleb Smirnoff.\" 281771f872SGleb Smirnoff.Dd May 15, 2005 298e925890SGleb Smirnoff.Dt CARP 4 308e925890SGleb Smirnoff.Os 318e925890SGleb Smirnoff.Sh NAME 328e925890SGleb Smirnoff.Nm carp 338e925890SGleb Smirnoff.Nd Common Address Redundancy Protocol 348e925890SGleb Smirnoff.Sh SYNOPSIS 358e925890SGleb Smirnoff.Cd "device carp" 368e925890SGleb Smirnoff.Sh DESCRIPTION 378e925890SGleb SmirnoffThe 388e925890SGleb Smirnoff.Nm 393e630869SGleb Smirnoffinterface is a pseudo-device that implements and controls the 408e925890SGleb SmirnoffCARP protocol. 413e630869SGleb SmirnoffCARP allows multiple hosts on the same local network to share a set of IP addresses. 428e925890SGleb SmirnoffIts primary purpose is to ensure that these 438e925890SGleb Smirnoffaddresses are always available, but in some configurations 448e925890SGleb Smirnoff.Nm 458e925890SGleb Smirnoffcan also provide load balancing functionality. 468e925890SGleb Smirnoff.Pp 478e925890SGleb SmirnoffA 488e925890SGleb Smirnoff.Nm 498e925890SGleb Smirnoffinterface can be created at runtime using the 503e630869SGleb Smirnoff.Nm ifconfig Li carp Ns Ar N Cm create 5158ce5a27SRalf S. Engelschallcommand or by configuring 5258ce5a27SRalf S. Engelschallit via 5358ce5a27SRalf S. Engelschall.Va cloned_interfaces 5458ce5a27SRalf S. Engelschallin the 558e925890SGleb Smirnoff.Pa /etc/rc.conf 568e925890SGleb Smirnofffile. 578e925890SGleb Smirnoff.Pp 588e925890SGleb SmirnoffTo use 598e925890SGleb Smirnoff.Nm , 608e925890SGleb Smirnoffthe administrator needs to configure at minimum a common virtual host ID and 618e925890SGleb Smirnoffvirtual host IP address on each machine which is to take part in the virtual 628e925890SGleb Smirnoffgroup. 638e925890SGleb SmirnoffAdditional parameters can also be set on a per-interface basis: 648e925890SGleb Smirnoff.Cm advbase 658e925890SGleb Smirnoffand 668e925890SGleb Smirnoff.Cm advskew , 678e925890SGleb Smirnoffwhich are used to control how frequently the host sends advertisements when it 688e925890SGleb Smirnoffis the master for a virtual host, and 698e925890SGleb Smirnoff.Cm pass 703e630869SGleb Smirnoffwhich is used to authenticate 713e630869SGleb Smirnoff.Nm 723e630869SGleb Smirnoffadvertisements. 73762ce3e6SGleb SmirnoffThe 74762ce3e6SGleb Smirnoff.Cm advbase 75762ce3e6SGleb Smirnoffparameter stands for 76762ce3e6SGleb Smirnoff.Qq advertisement base . 77762ce3e6SGleb SmirnoffIt is measured in seconds and specifies the base of the adverisement interval. 78762ce3e6SGleb SmirnoffThe 79762ce3e6SGleb Smirnoff.Cm advskew 80762ce3e6SGleb Smirnoffparameter stands for 81762ce3e6SGleb Smirnoff.Qq advertisement skew . 82762ce3e6SGleb SmirnoffIt is measured in 1/256 of seconds. 83762ce3e6SGleb SmirnoffIt is added to the base advertisement interval to make one host advertise 84762ce3e6SGleb Smirnoffa bit slower that the other does. 85762ce3e6SGleb SmirnoffBoth 86762ce3e6SGleb Smirnoff.Cm advbase 87762ce3e6SGleb Smirnoffand 88762ce3e6SGleb Smirnoff.Cm advskew 89762ce3e6SGleb Smirnoffare put inside CARP advertisments. 908e925890SGleb SmirnoffThese configurations can be done using 918e925890SGleb Smirnoff.Xr ifconfig 8 , 928e925890SGleb Smirnoffor through the 938e925890SGleb Smirnoff.Dv SIOCSVH 943e630869SGleb Smirnoff.Xr ioctl 2 . 958e925890SGleb Smirnoff.Pp 968e925890SGleb SmirnoffAdditionally, there are a number of global parameters which can be set using 978e925890SGleb Smirnoff.Xr sysctl 8 : 983e630869SGleb Smirnoff.Bl -tag -width ".Va net.inet.carp.arpbalance" 993e630869SGleb Smirnoff.It Va net.inet.carp.allow 1008e925890SGleb SmirnoffAccept incoming 1018e925890SGleb Smirnoff.Nm 1028e925890SGleb Smirnoffpackets. 1038e925890SGleb SmirnoffEnabled by default. 1043e630869SGleb Smirnoff.It Va net.inet.carp.preempt 1058e925890SGleb SmirnoffAllow virtual hosts to preempt each other. 1068e925890SGleb SmirnoffIt is also used to failover 1078e925890SGleb Smirnoff.Nm 1088e925890SGleb Smirnoffinterfaces as a group. 1098e925890SGleb SmirnoffWhen the option is enabled and one of the 1108e925890SGleb Smirnoff.Nm 1118e925890SGleb Smirnoffenabled physical interfaces 1123e630869SGleb Smirnoffgoes down, 1133e630869SGleb Smirnoff.Cm advskew 1143e630869SGleb Smirnoffis changed to 240 on all 1158e925890SGleb Smirnoff.Nm 1168e925890SGleb Smirnoffinterfaces. 1178e925890SGleb SmirnoffSee also the first example. 1188e925890SGleb SmirnoffDisabled by default. 1193e630869SGleb Smirnoff.It Va net.inet.carp.log 120442af10aSGleb SmirnoffValue of 0 disables any logging. 121442af10aSGleb SmirnoffValue of 1 enables logging of bad 1228e925890SGleb Smirnoff.Nm 1238e925890SGleb Smirnoffpackets. 124442af10aSGleb SmirnoffValues above 1 enable logging state changes of 125442af10aSGleb Smirnoff.Nm 126442af10aSGleb Smirnoffinterfaces. 127442af10aSGleb SmirnoffDefault value is 1. 1283e630869SGleb Smirnoff.It Va net.inet.carp.arpbalance 1298e925890SGleb SmirnoffBalance local traffic using ARP. 1308e925890SGleb SmirnoffDisabled by default. 1311771f872SGleb Smirnoff.It Va net.inet.carp.suppress_preempt 1321771f872SGleb SmirnoffA read only value showing the status of preemption suppression. 1331771f872SGleb SmirnoffPreemption can be suppressed if link on an interface is down 1341771f872SGleb Smirnoffor when 1351771f872SGleb Smirnoff.Xr pfsync 4 1361771f872SGleb Smirnoffinterface is not synchronized. 1371771f872SGleb SmirnoffValue of 0 means that preemption is not suppressed, since no 1381771f872SGleb Smirnoffproblems are detected. 1391771f872SGleb SmirnoffEvery problem increments suppression counter. 1408e925890SGleb Smirnoff.El 1418e925890SGleb Smirnoff.Sh EXAMPLES 1428e925890SGleb SmirnoffFor firewalls and routers with multiple interfaces, it is desirable to 1438e925890SGleb Smirnofffailover all of the 1448e925890SGleb Smirnoff.Nm 1458e925890SGleb Smirnoffinterfaces together, when one of the physical interfaces goes down. 1468e925890SGleb SmirnoffThis is achieved by the preempt option. 1478e925890SGleb SmirnoffEnable it on both host A and B: 1488e925890SGleb Smirnoff.Pp 1493e630869SGleb Smirnoff.Dl sysctl net.inet.carp.preempt=1 1508e925890SGleb Smirnoff.Pp 1518e925890SGleb SmirnoffAssume that host A is the preferred master and 192.168.1.x/24 is 1528e925890SGleb Smirnoffconfigured on one physical interface and 192.168.2.y/24 on another. 1538e925890SGleb SmirnoffThis is the setup for host A: 1548e925890SGleb Smirnoff.Bd -literal -offset indent 1553e630869SGleb Smirnoffifconfig carp0 create 1563cdec3edSGleb Smirnoffifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1/24 1573e630869SGleb Smirnoffifconfig carp1 create 1583cdec3edSGleb Smirnoffifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1/24 1598e925890SGleb Smirnoff.Ed 1608e925890SGleb Smirnoff.Pp 1613e630869SGleb SmirnoffThe setup for host B is identical, but it has a higher 1623e630869SGleb Smirnoff.Cm advskew : 1638e925890SGleb Smirnoff.Bd -literal -offset indent 1643e630869SGleb Smirnoffifconfig carp0 create 1653cdec3edSGleb Smirnoffifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24 1663e630869SGleb Smirnoffifconfig carp1 create 1673cdec3edSGleb Smirnoffifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24 1688e925890SGleb Smirnoff.Ed 1698e925890SGleb Smirnoff.Pp 1708e925890SGleb SmirnoffBecause of the preempt option, when one of the physical interfaces of 1713e630869SGleb Smirnoffhost A fails, 1723e630869SGleb Smirnoff.Cm advskew 1733e630869SGleb Smirnoffis adjusted to 240 on all its 1748e925890SGleb Smirnoff.Nm 1758e925890SGleb Smirnoffinterfaces. 1768e925890SGleb SmirnoffThis will cause host B to preempt on both interfaces instead of 1778e925890SGleb Smirnoffjust the failed one. 1788e925890SGleb Smirnoff.Pp 1798e925890SGleb SmirnoffIn order to set up an ARP balanced virtual host, it is necessary to configure 1808e925890SGleb Smirnoffone virtual host for each physical host which would respond to ARP requests 1818e925890SGleb Smirnoffand thus handle the traffic. 1828e925890SGleb SmirnoffIn the following example, two virtual hosts are configured on two hosts to 1838e925890SGleb Smirnoffprovide balancing and failover for the IP address 192.168.1.10. 1848e925890SGleb Smirnoff.Pp 1858e925890SGleb SmirnoffFirst the 1868e925890SGleb Smirnoff.Nm 1873e630869SGleb Smirnoffinterfaces on host A are configured. 1888e925890SGleb SmirnoffThe 1898e925890SGleb Smirnoff.Cm advskew 1908e925890SGleb Smirnoffof 100 on the second virtual host means that its advertisements will be sent 1918e925890SGleb Smirnoffout slightly less frequently. 1928e925890SGleb Smirnoff.Bd -literal -offset indent 1933e630869SGleb Smirnoffifconfig carp0 create 1943cdec3edSGleb Smirnoffifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24 1953e630869SGleb Smirnoffifconfig carp1 create 1963cdec3edSGleb Smirnoffifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24 1978e925890SGleb Smirnoff.Ed 1988e925890SGleb Smirnoff.Pp 1993e630869SGleb SmirnoffThe configuration for host B is identical, except the 2003e630869SGleb Smirnoff.Cm advskew 2013e630869SGleb Smirnoffis on virtual host 1 rather than virtual host 2. 2028e925890SGleb Smirnoff.Bd -literal -offset indent 2033e630869SGleb Smirnoffifconfig carp0 create 2043cdec3edSGleb Smirnoffifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24 2053e630869SGleb Smirnoffifconfig carp1 create 2063cdec3edSGleb Smirnoffifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24 2078e925890SGleb Smirnoff.Ed 2088e925890SGleb Smirnoff.Pp 2098e925890SGleb SmirnoffFinally, the ARP balancing feature must be enabled on both hosts: 2108e925890SGleb Smirnoff.Pp 2113e630869SGleb Smirnoff.Dl sysctl net.inet.carp.arpbalance=1 2128e925890SGleb Smirnoff.Pp 2138e925890SGleb SmirnoffWhen the hosts receive an ARP request for 192.168.1.10, the source IP address 2148e925890SGleb Smirnoffof the request is used to compute which virtual host should answer the request. 2158e925890SGleb SmirnoffThe host which is master of the selected virtual host will reply to the 2168e925890SGleb Smirnoffrequest, the other(s) will ignore it. 2178e925890SGleb Smirnoff.Pp 2188e925890SGleb SmirnoffThis way, locally connected systems will receive different ARP replies and 2198e925890SGleb Smirnoffsubsequent IP traffic will be balanced among the hosts. 2208e925890SGleb SmirnoffIf one of the hosts fails, the other will take over the virtual MAC address, 2218e925890SGleb Smirnoffand begin answering ARP requests on its behalf. 2228e925890SGleb Smirnoff.Pp 2238e925890SGleb SmirnoffNote: ARP balancing only works on the local network segment. 2248e925890SGleb SmirnoffIt cannot balance traffic that crosses a router, because the router 2258e925890SGleb Smirnoffitself will always be balanced to the same virtual host. 2268e925890SGleb Smirnoff.Sh SEE ALSO 2278e925890SGleb Smirnoff.Xr inet 4 , 2288e925890SGleb Smirnoff.Xr ifconfig 8 , 2291771f872SGleb Smirnoff.Xr pfsync 4 , 2301771f872SGleb Smirnoff.Xr rc.conf 5 , 2318e925890SGleb Smirnoff.Xr sysctl 8 2328e925890SGleb Smirnoff.Sh HISTORY 2338e925890SGleb SmirnoffThe 2348e925890SGleb Smirnoff.Nm 2358e925890SGleb Smirnoffdevice first appeared in 2368e925890SGleb Smirnoff.Ox 3.5 . 2378e925890SGleb SmirnoffThe 2388e925890SGleb Smirnoff.Nm 2393e630869SGleb Smirnoffdevice was imported into 2408e925890SGleb Smirnoff.Fx 5.4 . 241