]>
git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp.h
2 * VRRPD global definitions and state machine
3 * Copyright (C) 2018 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_PRIO_MASTER 255
38 #define VRRP_MCASTV4_GROUP_STR "224.0.0.18"
39 #define VRRP_MCASTV6_GROUP_STR "ff02:0:0:0:0:0:0:12"
40 #define VRRP_MCASTV4_GROUP 0xe0000012
41 #define VRRP_MCASTV6_GROUP 0xff020000000000000000000000000012
42 #define IPPROTO_VRRP 112
44 #define VRRP_LOGPFX_VRID "[VRID: %u] "
47 extern struct thread_master
*master
;
50 extern struct zebra_privs_t vrrp_privs
;
52 /* Global hash of all Virtual Routers */
53 struct hash
*vrrp_vrouters_hash
;
58 * This struct contains all state for a particular VRRP Router operating in a
59 * Virtual Router for either IPv4 or IPv6.
63 * Whether this VRRP Router is active.
67 /* Rx socket: Rx from parent of mvl_ifp */
69 /* Tx socket; Tx from mvl_ifp */
72 /* macvlan interface */
73 struct interface
*mvl_ifp
;
75 /* Socket read buffer */
76 uint8_t ibuf
[IP_MAXPACKET
];
79 * Address family of this Virtual Router.
80 * Either AF_INET or AF_INET6.
85 * Virtual Router this VRRP Router is participating in.
87 struct vrrp_vrouter
*vr
;
90 * One or more IPvX addresses associated with this Virtual
91 * Router. The first address must be the "primary" address this
92 * Virtual Router is backing up in the case of IPv4. In the case of
93 * IPv6 it must be the link-local address of vr->ifp.
95 * Type: struct ipaddr *
101 * => vr->priority if we are Backup
102 * => 255 if we are Master
107 * Advertisement interval contained in ADVERTISEMENTS received from the
108 * Master (centiseconds)
110 uint16_t master_adver_interval
;
113 * Time to skew Master_Down_Interval in centiseconds. Calculated as:
114 * (((256 - priority) * Master_Adver_Interval) / 256)
119 * Time interval for Backup to declare Master down (centiseconds).
121 * (3 * Master_Adver_Interval) + Skew_time
123 uint16_t master_down_interval
;
126 * The MAC address used for the source MAC address in VRRP
127 * advertisements, advertised in ARP requests/responses, and advertised
128 * in ND Neighbor Advertisements.
136 struct thread
*t_master_down_timer
;
137 struct thread
*t_adver_timer
;
138 struct thread
*t_read
;
139 struct thread
*t_write
;
143 * VRRP Virtual Router.
145 * This struct contains all state and configuration for a given Virtual Router
146 * Identifier on a given interface, both v4 and v6.
148 * RFC5798 s. 1 states:
149 * "Within a VRRP router, the virtual routers in each of the IPv4 and IPv6
150 * address families are a domain unto themselves and do not overlap."
152 * This implementation has chosen the tuple (interface, VRID) as the key for a
153 * particular VRRP Router, and the rest of the program is designed around this
154 * assumption. Additionally, base protocol configuration parameters such as the
155 * advertisement interval and (configured) priority are shared between v4 and
156 * v6 instances. This corresponds to the choice made by other industrial
159 struct vrrp_vrouter
{
161 struct interface
*ifp
;
166 /* Virtual Router Identifier */
169 /* Configured priority */
173 * Time interval between ADVERTISEMENTS (centiseconds). Default is 100
174 * centiseconds (1 second).
176 uint16_t advertisement_interval
;
179 * Controls whether a (starting or restarting) higher-priority Backup
180 * router preempts a lower-priority Master router. Values are True to
181 * allow preemption and False to prohibit preemption. Default is True.
186 * Controls whether a virtual router in Master state will accept
187 * packets addressed to the address owner's IPvX address as its own if
188 * it is not the IPvX address owner. The default is False.
192 struct vrrp_router
*v4
;
193 struct vrrp_router
*v6
;
197 * Initialize VRRP global datastructures.
199 void vrrp_init(void);
202 /* Creation and destruction ------------------------------------------------ */
205 * Create and register a new VRRP Virtual Router.
208 * Base interface to configure VRRP on
211 * Virtual Router Identifier
213 struct vrrp_vrouter
*vrrp_vrouter_create(struct interface
*ifp
, uint8_t vrid
);
216 * Destroy a VRRP Virtual Router.
218 void vrrp_vrouter_destroy(struct vrrp_vrouter
*vr
);
221 /* Configuration controllers ----------------------------------------------- */
224 * Change the configured priority of a VRRP Virtual Router.
226 * Note that this only changes the configured priority of the Virtual Router.
227 * The currently effective priority will not be changed; to change the
228 * effective priority, the Virtual Router must be restarted by issuing a
229 * VRRP_EVENT_SHUTDOWN followed by a VRRP_EVENT_STARTUP.
232 * Virtual Router to change priority of
237 void vrrp_set_priority(struct vrrp_vrouter
*vr
, uint8_t priority
);
240 * Set Advertisement Interval on this Virtual Router.
243 * Virtual Router to change priority of
245 * advertisement_interval
246 * New advertisement interval
248 void vrrp_set_advertisement_interval(struct vrrp_vrouter
*vr
,
249 uint16_t advertisement_interval
);
252 * Add an IPvX address to a VRRP Virtual Router.
255 * Virtual Router to add IPvx address to
260 void vrrp_add_ip(struct vrrp_vrouter
*vr
, struct ipaddr ip
);
263 * Add an IPv4 address to a VRRP Virtual Router.
266 * Virtual Router to add IPv4 address to
271 void vrrp_add_ipv4(struct vrrp_vrouter
*vr
, struct in_addr v4
);
274 * Add an IPv6 address to a VRRP Virtual Router.
277 * Virtual Router to add IPv6 address to
282 void vrrp_add_ipv6(struct vrrp_vrouter
*vr
, struct in6_addr v6
);
285 /* State machine ----------------------------------------------------------- */
287 #define VRRP_STATE_INITIALIZE 0
288 #define VRRP_STATE_MASTER 1
289 #define VRRP_STATE_BACKUP 2
290 #define VRRP_EVENT_STARTUP 0
291 #define VRRP_EVENT_SHUTDOWN 1
293 extern const char *vrrp_state_names
[3];
294 extern const char *vrrp_event_names
[2];
297 * This hook called whenever the state of a Virtual Router changes, after the
298 * specific internal state handlers have run.
300 * Use this if you need to react to state changes to perform non-critical
301 * tasks. Critical tasks should go in the internal state change handlers.
303 DECLARE_HOOK(vrrp_change_state_hook
, (struct vrrp_router
* r
, int to
), (r
, to
));
306 * Trigger a VRRP event on a given Virtual Router..
309 * Virtual Router to operate on
312 * Event to kick off. All event related processing will have completed upon
313 * return of this function.
316 * < 0 if the event created an error
319 int vrrp_event(struct vrrp_router
*r
, int event
);
322 /* Other ------------------------------------------------------------------- */
325 * Find VRRP Virtual Router by Virtual Router ID
327 struct vrrp_vrouter
*vrrp_lookup(uint8_t vrid
);