-
Notifications
You must be signed in to change notification settings - Fork 9
/
vrrp.h
140 lines (119 loc) · 3.09 KB
/
vrrp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* vrrp.h - define main struct vrrp (VRRP instance) and some
* constants
*
* Copyright (C) 2014 Arnaud Andre
*
* This file is part of uvrrpd.
*
* uvrrpd is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* uvrrpd is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with uvrrpd. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _VRRP_H_
#define _VRRP_H_
#include <stdint.h>
#include "common.h"
#include "vrrp_net.h"
#include "vrrp_timer.h"
#include "vrrp_state.h"
#include "vrrp_ctrl.h"
/* MAX values */
#define VRID_MAX 255
#define VRRP_PRIO_MAX 255
#define ADVINT_MAX 4095 /* RFC5798 */
#define PRIO_OWNER VRRP_PRIO_MAX
/* DEFAULT values */
#define PREEMPT_DFL TRUE
#define PRIO_DFL 100
/* External script */
#define VRRP_SCRIPT stringify(PATH) "/vrrp_switch.sh"
#define VRRP_SCRIPT_MAX sysconf(_SC_ARG_MAX)
/* preemption */
#define STR_PREEMPT(s) (s == TRUE ? "true" : "false")
/**
* vrrp_version - VRRP version protocol
* @RFC2338 : VRRPv2 (deprecated)
* @RFC3768 : VRRPv2
* @RFC5798 : VRRPv3
*/
typedef enum {
RFC2338 = 2,
RFC3768 = 2,
RFC5798 = 3
} vrrp_version;
/**
* vrrp_authtype - Authentication type
* (from VRRPv2 / rfc2332)
*/
#define VRRP_AUTH_PASS_LEN 8
typedef enum {
NOAUTH,
SIMPLE,
HMAC /* not supported */
} vrrp_authtype;
/**
* vrrp - Main structure defining VRRP instance
*/
struct vrrp {
vrrp_version version; /* VRRP version */
uint8_t vrid; /* VRID 1 - 255 */
uint8_t priority; /* PRIO 0 - 255 */
uint8_t naddr; /* count ip addresses */
/* Advertisement interval
*
* VRRPv2 :
* - delay in s
* - default 1s
* - 8 bits field
*
* VRRPv3 :
* - delay in centisecond
* - default 100cs (1s)
* - 12 bits field
*/
uint16_t adv_int;
/* Start delay */
uint16_t start_delay;
/* Master advertisement interval
* only in VRRPv3 / rfc5798
*/
uint16_t master_adv_int;
vrrp_authtype auth_type;
char *auth_data;
vrrp_state state;
bool preempt;
char *scriptname;
char **argv;
/* control cmd fifo */
struct vrrp_ctrl ctrl;
struct vrrp_timer adv_timer;
struct vrrp_timer masterdown_timer;
};
/**
* enum vrrp_ret - Return code used in vrrp_net_listen
*/
enum _vrrp_event_type {
VRID_MISMATCH = -2, /* vrid mismatch */
INVALID = -1, /* invalid pkt */
PKT, /* valid packet */
SIGNAL, /* signal catch */
CTRL_FIFO, /* ctrl cmd event */
TIMER /* timer expired */
};
typedef enum _vrrp_event_type vrrp_event_t;
/* funcs */
void vrrp_init(struct vrrp *vrrp);
void vrrp_cleanup(struct vrrp *vrrp);
int vrrp_process(struct vrrp *vrrp, struct vrrp_net *vnet);
vrrp_event_t vrrp_listen(struct vrrp *vrrp, struct vrrp_net *vnet);
#endif /* _VRRP_H_ */