]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - share/man/man4/carp.4
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / share / man / man4 / carp.4
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 .\"
5 .\" Redistribution and use in source and binary forms, with or without
6 .\" modification, are permitted provided that the following conditions
7 .\" are met:
8 .\" 1. Redistributions of source code must retain the above copyright
9 .\"    notice, this list of conditions and the following disclaimer.
10 .\" 2. Redistributions in binary form must reproduce the above copyright
11 .\"    notice, this list of conditions and the following disclaimer in the
12 .\"    documentation and/or other materials provided with the distribution.
13 .\"
14 .\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
15 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
18 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 .\" SUCH DAMAGE.
25 .\"
26 .\" $FreeBSD$
27 .\"
28 .Dd August 15, 2011
29 .Dt CARP 4
30 .Os
31 .Sh NAME
32 .Nm carp
33 .Nd Common Address Redundancy Protocol
34 .Sh SYNOPSIS
35 .Cd "device carp"
36 .Sh DESCRIPTION
37 The
38 .Nm
39 interface is a pseudo-device that implements and controls the
40 CARP protocol.
41 CARP allows multiple hosts on the same local network to share a set of IP addresses.
42 Its primary purpose is to ensure that these
43 addresses are always available, but in some configurations
44 .Nm
45 can also provide load balancing functionality.
46 .Pp
47 A
48 .Nm
49 interface can be created at runtime using the
50 .Nm ifconfig Li carp Ns Ar N Cm create
51 command or by configuring
52 it via
53 .Va cloned_interfaces
54 in the
55 .Pa /etc/rc.conf
56 file.
57 .Pp
58 To use
59 .Nm ,
60 the administrator needs to configure at minimum a common virtual host ID (VHID)
61 and virtual host IP address on each machine which is to take part in the virtual
62 group.
63 Additional parameters can also be set on a per-interface basis:
64 .Cm advbase
65 and
66 .Cm advskew ,
67 which are used to control how frequently the host sends advertisements when it
68 is the master for a virtual host, and
69 .Cm pass
70 which is used to authenticate
71 .Nm
72 advertisements.
73 The
74 .Cm advbase
75 parameter stands for
76 .Dq "advertisement base" .
77 It is measured in seconds and specifies the base of the advertisement interval.
78 The
79 .Cm advskew
80 parameter stands for
81 .Dq "advertisement skew" .
82 It is measured in 1/256 of seconds.
83 It is added to the base advertisement interval to make one host advertise
84 a bit slower that the other does.
85 Both
86 .Cm advbase
87 and
88 .Cm advskew
89 are put inside CARP advertisements.
90 These configurations can be done using
91 .Xr ifconfig 8 ,
92 or through the
93 .Dv SIOCSVH
94 .Xr ioctl 2 .
95 .Pp
96 Additionally, there are a number of global parameters which can be set using
97 .Xr sysctl 8 :
98 .Bl -tag -width ".Va net.inet.carp.arpbalance"
99 .It Va net.inet.carp.allow
100 Accept incoming
101 .Nm
102 packets.
103 Enabled by default.
104 .It Va net.inet.carp.preempt
105 Allow virtual hosts to preempt each other.
106 It is also used to failover
107 .Nm
108 interfaces as a group.
109 When the option is enabled and one of the
110 .Nm
111 enabled physical interfaces
112 goes down,
113 .Cm advskew
114 is changed to 240 on all
115 .Nm
116 interfaces.
117 See also the first example.
118 Disabled by default.
119 .It Va net.inet.carp.log
120 Value of 0 disables any logging.
121 Value of 1 enables logging state changes of
122 .Nm
123 interfaces.
124 Values above 1 enable logging of bad
125 .Nm
126 packets.
127 Default value is 1.
128 .It Va net.inet.carp.arpbalance
129 Balance local traffic using ARP (see below).
130 Disabled by default.
131 .It Va net.inet.carp.suppress_preempt
132 A read only value showing the status of preemption suppression.
133 Preemption can be suppressed if link on an interface is down
134 or when
135 .Xr pfsync 4
136 interface is not synchronized.
137 Value of 0 means that preemption is not suppressed, since no
138 problems are detected.
139 Every problem increments suppression counter.
140 .El
141 .Sh ARP level load balancing
142 The
143 .Nm
144 has limited abilities for load balancing the incoming connections
145 between hosts in Ethernet network.
146 For load balancing operation, one needs several CARP interfaces that
147 are configured to the same IP address, but to a different VHIDs.
148 Once an ARP request is received, the CARP protocol will use a hashing
149 function against the source IP address in the ARP request to determine
150 which VHID should this request belong to.
151 If the corresponding CARP interface is in master state, the ARP request
152 will be replied, otherwise it will be ignored.
153 See the
154 .Sx EXAMPLES
155 section for a practical example of load balancing.
156 .Pp
157 The ARP load balancing has some limitations.
158 First, ARP balancing only works on the local network segment.
159 It cannot balance traffic that crosses a router, because the
160 router itself will always be balanced to the same virtual host.
161 Second, ARP load balancing can lead to asymmetric routing
162 of incoming and outgoing traffic, and thus combining it with
163 .Xr pfsync 4
164 is dangerous, because this creates a race condition between
165 balanced routers and a host they are serving.
166 Imagine an incoming packet creating state on the first router, being
167 forwarded to its destination, and destination replying faster
168 than the state information is packed and synced with the second router.
169 If the reply would be load balanced to second router, it will be
170 dropped due to no state.
171 .Sh STATE CHANGE NOTIFICATIONS
172 Sometimes it is useful to get notified about
173 .Nm
174 status change events.
175 This can be accomplished by using
176 .Xr devd 8
177 hooks.
178 Master/slave events are signalled as
179 .Nm
180 interface
181 .Dv LINK_UP
182 or
183 .Dv LINK_DOWN
184 event.
185 Please see
186 .Xr devd.conf 5
187 and
188 .Sx EXAMPLES
189 section for more information.
190 .Sh EXAMPLES
191 For firewalls and routers with multiple interfaces, it is desirable to
192 failover all of the
193 .Nm
194 interfaces together, when one of the physical interfaces goes down.
195 This is achieved by the preempt option.
196 Enable it on both host A and B:
197 .Pp
198 .Dl sysctl net.inet.carp.preempt=1
199 .Pp
200 Assume that host A is the preferred master and 192.168.1.x/24 is
201 configured on one physical interface and 192.168.2.y/24 on another.
202 This is the setup for host A:
203 .Bd -literal -offset indent
204 ifconfig carp0 create
205 ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.1/24
206 ifconfig carp1 create
207 ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.2.1/24
208 .Ed
209 .Pp
210 The setup for host B is identical, but it has a higher
211 .Cm advskew :
212 .Bd -literal -offset indent
213 ifconfig carp0 create
214 ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.1/24
215 ifconfig carp1 create
216 ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.2.1/24
217 .Ed
218 .Pp
219 Because of the preempt option, when one of the physical interfaces of
220 host A fails,
221 .Cm advskew
222 is adjusted to 240 on all its
223 .Nm
224 interfaces.
225 This will cause host B to preempt on both interfaces instead of
226 just the failed one.
227 .Pp
228 In order to set up an ARP balanced virtual host, it is necessary to configure
229 one virtual host for each physical host which would respond to ARP requests
230 and thus handle the traffic.
231 In the following example, two virtual hosts are configured on two hosts to
232 provide balancing and failover for the IP address 192.168.1.10.
233 .Pp
234 First the
235 .Nm
236 interfaces on host A are configured.
237 The
238 .Cm advskew
239 of 100 on the second virtual host means that its advertisements will be sent
240 out slightly less frequently.
241 .Bd -literal -offset indent
242 ifconfig carp0 create
243 ifconfig carp0 vhid 1 pass mekmitasdigoat 192.168.1.10/24
244 ifconfig carp1 create
245 ifconfig carp1 vhid 2 advskew 100 pass mekmitasdigoat 192.168.1.10/24
246 .Ed
247 .Pp
248 The configuration for host B is identical, except the
249 .Cm advskew
250 is on virtual host 1 rather than virtual host 2.
251 .Bd -literal -offset indent
252 ifconfig carp0 create
253 ifconfig carp0 vhid 1 advskew 100 pass mekmitasdigoat 192.168.1.10/24
254 ifconfig carp1 create
255 ifconfig carp1 vhid 2 pass mekmitasdigoat 192.168.1.10/24
256 .Ed
257 .Pp
258 Finally, the ARP balancing feature must be enabled on both hosts:
259 .Pp
260 .Dl sysctl net.inet.carp.arpbalance=1
261 .Pp
262 When the hosts receive an ARP request for 192.168.1.10, the source IP address
263 of the request is used to compute which virtual host should answer the request.
264 The host which is master of the selected virtual host will reply to the
265 request, the other(s) will ignore it.
266 .Pp
267 This way, locally connected systems will receive different ARP replies and
268 subsequent IP traffic will be balanced among the hosts.
269 If one of the hosts fails, the other will take over the virtual MAC address,
270 and begin answering ARP requests on its behalf.
271 .Pp
272 Processing of
273 .Nm
274 status change events can be set up by using the following devd.conf rules:
275 .Bd -literal -offset indent
276 notify 0 {
277         match "system"          "IFNET";
278         match "type"            "LINK_UP";
279         match "subsystem"       "carp*";
280         action "/root/carpcontrol.sh $type $subsystem";
281 };
282
283 notify 0 {
284         match "system"          "IFNET";
285         match "type"            "LINK_DOWN";
286         match "subsystem"       "carp*";
287         action "/root/carpcontrol.sh $type $subsystem";
288 };
289 .Ed
290 .Sh SEE ALSO
291 .Xr inet 4 ,
292 .Xr pfsync 4 ,
293 .Xr rc.conf 5 ,
294 .Xr devd.conf 5 ,
295 .Xr ifconfig 8 ,
296 .Xr sysctl 8
297 .Sh HISTORY
298 The
299 .Nm
300 device first appeared in
301 .Ox 3.5 .
302 The
303 .Nm
304 device was imported into
305 .Fx 5.4 .