]>
git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp.h
2 * VRRP global definitions and state machine.
3 * Copyright (C) 2018-2019 Cumulus Networks, Inc.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <netinet/ip.h>
29 #include "lib/linklist.h"
30 #include "lib/privs.h"
31 #include "lib/stream.h"
32 #include "lib/thread.h"
34 /* Global definitions */
35 #define VRRP_DEFAULT_ADVINT 100
36 #define VRRP_DEFAULT_PRIORITY 100
37 #define VRRP_RADV_INT 16
38 #define VRRP_PRIO_MASTER 255
39 #define VRRP_MCASTV4_GROUP_STR "224.0.0.18"
40 #define VRRP_MCASTV6_GROUP_STR "ff02:0:0:0:0:0:0:12"
41 #define VRRP_MCASTV4_GROUP 0xe0000012
42 #define VRRP_MCASTV6_GROUP 0xff020000000000000000000000000012
43 #define IPPROTO_VRRP 112
45 #define VRRP_LOGPFX_VRID "[VRID: %u] "
48 extern struct thread_master
*master
;
51 extern struct zebra_privs_t vrrp_privs
;
53 /* Global hash of all Virtual Routers */
54 struct hash
*vrrp_vrouters_hash
;
59 * This struct contains all state for a particular VRRP Router operating in a
60 * Virtual Router for either IPv4 or IPv6.
64 * Whether this VRRP Router is active.
68 /* Whether we are the address owner */
71 /* Rx socket: Rx from parent of mvl_ifp */
73 /* Tx socket; Tx from mvl_ifp */
76 /* macvlan interface */
77 struct interface
*mvl_ifp
;
79 /* Source address for advertisements */
82 /* Socket read buffer */
83 uint8_t ibuf
[IP_MAXPACKET
];
86 * Address family of this Virtual Router.
87 * Either AF_INET or AF_INET6.
92 * Virtual Router this VRRP Router is participating in.
94 struct vrrp_vrouter
*vr
;
97 * One or more IPvX addresses associated with this Virtual
98 * Router. The first address must be the "primary" address this
99 * Virtual Router is backing up in the case of IPv4. In the case of
100 * IPv6 it must be the link-local address of vr->ifp.
102 * Type: struct ipaddr *
108 * => vr->priority if we are Backup
109 * => 255 if we are Master
114 * Advertisement interval contained in ADVERTISEMENTS received from the
115 * Master (centiseconds)
117 uint16_t master_adver_interval
;
120 * Time to skew Master_Down_Interval in centiseconds. Calculated as:
121 * (((256 - priority) * Master_Adver_Interval) / 256)
126 * Time interval for Backup to declare Master down (centiseconds).
128 * (3 * Master_Adver_Interval) + Skew_time
130 uint16_t master_down_interval
;
133 * The MAC address used for the source MAC address in VRRP
134 * advertisements, advertised in ARP requests/responses, and advertised
135 * in ND Neighbor Advertisements.
143 struct thread
*t_master_down_timer
;
144 struct thread
*t_adver_timer
;
145 struct thread
*t_read
;
146 struct thread
*t_write
;
150 * VRRP Virtual Router.
152 * This struct contains all state and configuration for a given Virtual Router
153 * Identifier on a given interface, both v4 and v6.
155 * RFC5798 s. 1 states:
156 * "Within a VRRP router, the virtual routers in each of the IPv4 and IPv6
157 * address families are a domain unto themselves and do not overlap."
159 * This implementation has chosen the tuple (interface, VRID) as the key for a
160 * particular VRRP Router, and the rest of the program is designed around this
161 * assumption. Additionally, base protocol configuration parameters such as the
162 * advertisement interval and (configured) priority are shared between v4 and
163 * v6 instances. This corresponds to the choice made by other industrial
166 struct vrrp_vrouter
{
168 struct interface
*ifp
;
173 /* Virtual Router Identifier */
176 /* Configured priority */
180 * Time interval between ADVERTISEMENTS (centiseconds). Default is 100
181 * centiseconds (1 second).
183 uint16_t advertisement_interval
;
186 * Controls whether a (starting or restarting) higher-priority Backup
187 * router preempts a lower-priority Master router. Values are True to
188 * allow preemption and False to prohibit preemption. Default is True.
193 * Controls whether a virtual router in Master state will accept
194 * packets addressed to the address owner's IPvX address as its own if
195 * it is not the IPvX address owner. The default is False.
199 struct vrrp_router
*v4
;
200 struct vrrp_router
*v6
;
204 * Initialize VRRP global datastructures.
206 void vrrp_init(void);
209 /* Creation and destruction ------------------------------------------------ */
212 * Create and register a new VRRP Virtual Router.
215 * Base interface to configure VRRP on
218 * Virtual Router Identifier
220 struct vrrp_vrouter
*vrrp_vrouter_create(struct interface
*ifp
, uint8_t vrid
);
223 * Destroy a VRRP Virtual Router, freeing all its resources.
225 * If there are any running VRRP instances, these are stopped and destroyed.
227 void vrrp_vrouter_destroy(struct vrrp_vrouter
*vr
);
230 /* Configuration controllers ----------------------------------------------- */
233 * Change the configured priority of a VRRP Virtual Router.
235 * Note that this only changes the configured priority of the Virtual Router.
236 * The currently effective priority will not be changed; to change the
237 * effective priority, the Virtual Router must be restarted by issuing a
238 * VRRP_EVENT_SHUTDOWN followed by a VRRP_EVENT_STARTUP.
241 * Virtual Router to change priority of
246 void vrrp_set_priority(struct vrrp_vrouter
*vr
, uint8_t priority
);
249 * Set Advertisement Interval on this Virtual Router.
252 * Virtual Router to change priority of
254 * advertisement_interval
255 * New advertisement interval
257 void vrrp_set_advertisement_interval(struct vrrp_vrouter
*vr
,
258 uint16_t advertisement_interval
);
261 * Add an IPvX address to a VRRP Virtual Router.
264 * Virtual Router to add IPvx address to
270 * Whether to automatically start the VRRP router if this is the first IP
277 int vrrp_add_ip(struct vrrp_router
*r
, struct ipaddr
*ip
, bool activate
);
280 * Add an IPv4 address to a VRRP Virtual Router.
283 * Virtual Router to add IPv4 address to
289 * Whether to automatically start the VRRP router if this is the first IP
296 int vrrp_add_ipv4(struct vrrp_vrouter
*vr
, struct in_addr v4
, bool activate
);
299 * Add an IPv6 address to a VRRP Virtual Router.
302 * Virtual Router to add IPv6 address to
308 * Whether to automatically start the VRRP router if this is the first IP
315 int vrrp_add_ipv6(struct vrrp_vrouter
*vr
, struct in6_addr v6
, bool activate
);
318 * Remove an IP address from a VRRP Virtual Router.
321 * Virtual Router to remove IP address from
327 * Whether to automatically stop the VRRP router if removing v4 would leave
328 * us with an empty address list. If this is not true and ip is the only IP
329 * address backed up by this virtual router, this function will not remove
330 * the address and return failure.
336 int vrrp_del_ip(struct vrrp_router
*r
, struct ipaddr
*ip
, bool deactivate
);
339 * Remove an IPv4 address from a VRRP Virtual Router.
342 * Virtual Router to remove IPv4 address from
348 * Whether to automatically stop the VRRP router if removing v4 would leave
349 * us with an empty address list. If this is not true and v4 is the only
350 * IPv4 address backed up by this virtual router, this function will not
351 * remove the address and return failure.
357 int vrrp_del_ipv4(struct vrrp_vrouter
*vr
, struct in_addr v4
, bool deactivate
);
360 * Remove an IPv6 address from a VRRP Virtual Router.
363 * Virtual Router to remove IPv6 address from
369 * Whether to automatically stop the VRRP router if removing v5 would leave
370 * us with an empty address list. If this is not true and v4 is the only
371 * IPv6 address backed up by this virtual router, this function will not
372 * remove the address and return failure.
378 int vrrp_del_ipv6(struct vrrp_vrouter
*vr
, struct in6_addr v6
, bool deactivate
);
380 /* State machine ----------------------------------------------------------- */
382 #define VRRP_STATE_INITIALIZE 0
383 #define VRRP_STATE_MASTER 1
384 #define VRRP_STATE_BACKUP 2
385 #define VRRP_EVENT_STARTUP 0
386 #define VRRP_EVENT_SHUTDOWN 1
388 extern const char *vrrp_state_names
[3];
389 extern const char *vrrp_event_names
[2];
392 * This hook called whenever the state of a Virtual Router changes, after the
393 * specific internal state handlers have run.
395 * Use this if you need to react to state changes to perform non-critical
396 * tasks. Critical tasks should go in the internal state change handlers.
398 DECLARE_HOOK(vrrp_change_state_hook
, (struct vrrp_router
* r
, int to
), (r
, to
));
401 * Trigger a VRRP event on a given Virtual Router..
404 * Virtual Router to operate on
407 * Event to kick off. All event related processing will have completed upon
408 * return of this function.
411 * < 0 if the event created an error
414 int vrrp_event(struct vrrp_router
*r
, int event
);
417 /* Other ------------------------------------------------------------------- */
420 * Find VRRP Virtual Router by Virtual Router ID
422 struct vrrp_vrouter
*vrrp_lookup(struct interface
*ifp
, uint8_t vrid
);
424 #endif /* __VRRP_H__ */