]> git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp.h
vrrpd: clean up configuration code, fix skew bug
[mirror_frr.git] / vrrpd / vrrp.h
1 /*
2 * VRRPD global definitions and state machine
3 * Copyright (C) 2018 Cumulus Networks, Inc.
4 * Quentin Young
5 *
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)
9 * any later version.
10 *
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
14 * more details.
15 *
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
19 */
20 #ifndef _VRRP_H
21 #define _VRRP_H
22
23 #include <zebra.h>
24
25 #include "lib/hash.h"
26 #include "lib/hook.h"
27 #include "lib/if.h"
28 #include "lib/linklist.h"
29 #include "lib/privs.h"
30 #include "lib/thread.h"
31
32 /* Global definitions */
33 #define VRRP_DEFAULT_ADVINT 100
34 #define VRRP_DEFAULT_PRIORITY 100
35 #define VRRP_PRIO_MASTER 255
36 #define VRRP_MCAST_GROUP "224.0.0.18"
37 #define VRRP_MCAST_GROUP_HEX 0xe0000012
38 #define IPPROTO_VRRP 112
39
40 /* threadmaster */
41 extern struct thread_master *master;
42
43 /* privileges */
44 extern struct zebra_privs_t vrrp_privs;
45
46 /* Global hash of all Virtual Routers */
47 struct hash *vrrp_vrouters_hash;
48
49 /*
50 * VRRP Virtual Router
51 */
52 struct vrrp_vrouter {
53 /* Socket */
54 int sock;
55
56 /* Interface */
57 struct interface *ifp;
58
59 /* Virtual Router Identifier */
60 uint32_t vrid;
61
62 /* One or more IPv4 addresses associated with this Virtual Router. */
63 struct list *v4;
64
65 /*
66 * One ore more IPv6 addresses associated with this Virtual Router. The
67 * first address must be the Link-Local address associated with the
68 * virtual router.
69 */
70 struct list *v6;
71
72 /* Whether this VRRP Router is currently the master */
73 bool is_master;
74
75 /* Priority */
76 uint8_t priority;
77
78 /*
79 * Time interval between ADVERTISEMENTS (centiseconds). Default is 100
80 * centiseconds (1 second).
81 */
82 uint16_t advertisement_interval;
83 /*
84 * Advertisement interval contained in ADVERTISEMENTS received from the
85 * Master (centiseconds)
86 */
87 uint16_t master_adver_interval;
88
89 /*
90 * Time to skew Master_Down_Interval in centiseconds. Calculated as:
91 * (((256 - priority) * Master_Adver_Interval) / 256)
92 */
93 uint16_t skew_time;
94
95 /*
96 * Time interval for Backup to declare Master down (centiseconds).
97 * Calculated as:
98 * (3 * Master_Adver_Interval) + Skew_time
99 */
100 uint16_t master_down_interval;
101
102 /*
103 * Controls whether a (starting or restarting) higher-priority Backup
104 * router preempts a lower-priority Master router. Values are True to
105 * allow preemption and False to prohibit preemption. Default is True.
106 */
107 bool preempt_mode;
108
109 /*
110 * Controls whether a virtual router in Master state will accept
111 * packets addressed to the address owner's IPvX address as its own if
112 * it is not the IPvX address owner. The default is False.
113 */
114 bool accept_mode;
115
116 /*
117 * The MAC address used for the source MAC address in VRRP
118 * advertisements and advertised in ARP responses as the MAC address to
119 * use for IP_Addresses.
120 */
121 struct ethaddr vr_mac_v4;
122 struct ethaddr vr_mac_v6;
123
124 struct thread *t_master_down_timer;
125 struct thread *t_adver_timer;
126
127 struct {
128 int state;
129 } fsm;
130 };
131
132 /*
133 * Initialize VRRP global datastructures.
134 */
135 void vrrp_init(void);
136
137
138 /* Creation and destruction ------------------------------------------------ */
139
140 /*
141 * Create and register a new VRRP Virtual Router.
142 *
143 * ifp
144 * Base interface to configure VRRP on
145 *
146 * vrid
147 * Virtual Router Identifier
148 */
149 struct vrrp_vrouter *vrrp_vrouter_create(struct interface *ifp, uint8_t vrid);
150
151 /*
152 * Destroy a VRRP Virtual Router.
153 */
154 void vrrp_vrouter_destroy(struct vrrp_vrouter *vr);
155
156
157 /* Configuration controllers ----------------------------------------------- */
158
159 /*
160 * Change the priority of a VRRP Virtual Router.
161 *
162 * Also recalculates timers using new priority.
163 *
164 * vr
165 * Virtual Router to change priority of
166 *
167 * priority
168 * New priority
169 */
170 void vrrp_set_priority(struct vrrp_vrouter *vr, uint8_t priority);
171
172 /*
173 * Set Advertisement Interval on this Virtual Router.
174 *
175 * vr
176 * Virtual Router to change priority of
177 *
178 * advertisement_interval
179 * New advertisement interval
180 */
181 void vrrp_set_advertisement_interval(struct vrrp_vrouter *vr,
182 uint16_t advertisement_interval);
183
184 /*
185 * Add IPv4 address to a VRRP Virtual Router.
186 *
187 * vr
188 * Virtual Router to add IPv4 address to
189 *
190 * v4
191 * Address to add
192 */
193 void vrrp_add_ip(struct vrrp_vrouter *vr, struct in_addr v4);
194
195
196 /* State machine ----------------------------------------------------------- */
197
198 #define VRRP_STATE_INITIALIZE 1
199 #define VRRP_STATE_MASTER 2
200 #define VRRP_STATE_BACKUP 3
201 #define VRRP_EVENT_STARTUP 1
202 #define VRRP_EVENT_SHUTDOWN 2
203
204 /*
205 * This hook called whenever the state of a Virtual Router changes, after the
206 * specific internal state handlers have run.
207 *
208 * Use this if you need to react to state changes to perform non-critical
209 * tasks. Critical tasks should go in the internal state change handlers.
210 */
211 DECLARE_HOOK(vrrp_change_state_hook, (struct vrrp_vrouter *vr, int to), (vr, to));
212
213 /*
214 * Trigger a VRRP event on a given Virtual Router..
215 *
216 * vr
217 * Virtual Router to operate on
218 *
219 * event
220 * Event to kick off. All event related processing will have completed upon
221 * return of this function.
222 *
223 * Returns:
224 * < 0 if the event created an error
225 * 0 otherwise
226 */
227 int vrrp_event(struct vrrp_vrouter *vr, int event);
228
229
230 /* Other ------------------------------------------------------------------- */
231
232 /*
233 * Find VRRP Virtual Router by Virtual Router ID
234 */
235 struct vrrp_vrouter *vrrp_lookup(uint8_t vrid);
236
237 #endif /* _VRRP_H */