]> git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp.h
vrrpd: initial commit
[mirror_frr.git] / vrrpd / vrrp.h
1 /*
2 * VRRPD global definitions
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 #include "linklist.h"
25 #include "hash.h"
26 #include "if.h"
27 #include "thread.h"
28 #include "hook.h"
29
30 /* Global definitions */
31 #define VRRP_DEFAULT_ADVINT 100
32 #define VRRP_DEFAULT_PRIORITY 100
33 #define VRRP_PRIO_MASTER 255
34 #define VRRP_MCAST_GROUP "224.0.0.18"
35 #define VRRP_MCAST_GROUP_HEX 0xe0000012
36 #define IPPROTO_VRRP 112
37
38 /* threadmaster */
39 extern struct thread_master *master;
40
41 /* Global hash of all Virtual Routers */
42 struct hash *vrrp_vrouters_hash;
43
44 /*
45 * VRRP Virtual Router
46 */
47 struct vrrp_vrouter {
48 /* Socket */
49 int sock;
50
51 /* Interface */
52 struct interface *ifp;
53
54 /* Virtual Router Identifier */
55 uint32_t vrid;
56
57 /* One or more IPv4 addresses associated with this Virtual Router. */
58 struct list *v4;
59
60 /*
61 * One ore more IPv6 addresses associated with this Virtual Router. The
62 * first address must be the Link-Local address associated with the
63 * virtual router.
64 */
65 struct list *v6;
66
67 /* Time between ADVERTISEMENTS (centiseconds) */
68 int advint;
69
70 /* Whether this VRRP Router is currently the master */
71 bool is_master;
72
73 /* Priority */
74 uint8_t priority;
75
76 /*
77 * Time interval between ADVERTISEMENTS (centiseconds). Default is 100
78 * centiseconds (1 second).
79 */
80 uint16_t advertisement_interval;
81 /*
82 * Advertisement interval contained in ADVERTISEMENTS received from the
83 * Master (centiseconds)
84 */
85 uint16_t master_adver_interval;
86
87 /*
88 * Time to skew Master_Down_Interval in centiseconds. Calculated as:
89 * (((256 - priority) * Master_Adver_Interval) / 256)
90 */
91 uint16_t skew_time;
92
93 /*
94 * Time interval for Backup to declare Master down (centiseconds).
95 * Calculated as:
96 * (3 * Master_Adver_Interval) + Skew_time
97 */
98 uint16_t master_down_interval;
99
100 /*
101 * Controls whether a (starting or restarting) higher-priority Backup
102 * router preempts a lower-priority Master router. Values are True to
103 * allow preemption and False to prohibit preemption. Default is True.
104 */
105 bool preempt_mode;
106
107 /*
108 * Controls whether a virtual router in Master state will accept
109 * packets addressed to the address owner's IPvX address as its own if
110 * it is not the IPvX address owner. The default is False.
111 */
112 bool accept_mode;
113
114 /*
115 * The MAC address used for the source MAC address in VRRP
116 * advertisements and advertised in ARP responses as the MAC address to
117 * use for IP_Addresses.
118 */
119 struct ethaddr vr_mac_v4;
120 struct ethaddr vr_mac_v6;
121
122 struct thread *t_master_down_timer;
123 struct thread *t_adver_timer;
124
125 struct {
126 int state;
127 } fsm;
128 };
129
130 /* State machine */
131 #define VRRP_STATE_INITIALIZE 1
132 #define VRRP_STATE_MASTER 2
133 #define VRRP_STATE_BACKUP 3
134 #define VRRP_EVENT_STARTUP 1
135 #define VRRP_EVENT_SHUTDOWN 2
136
137 DECLARE_HOOK(vrrp_change_state_hook, (struct vrrp_vrouter *vr, int to), (vr, to));
138 void vrrp_event(struct vrrp_vrouter *vr, int event);
139 /* End state machine */
140
141
142 /*
143 * Initialize VRRP global datastructures.
144 */
145 void vrrp_init(void);
146
147 /*
148 * Create and register a new VRRP Virtual Router.
149 */
150 struct vrrp_vrouter *vrrp_vrouter_create(struct interface *ifp, uint8_t vrid);
151
152 /*
153 * Find VRRP Virtual Router by Virtual Router ID
154 */
155 struct vrrp_vrouter *vrrp_lookup(uint8_t vrid);
156
157 /*
158 * Trigger VRRP event
159 */
160 void vrrp_event(struct vrrp_vrouter *vr, int event);
161
162 #endif