-
Notifications
You must be signed in to change notification settings - Fork 9
/
vrrp_adv.h
96 lines (83 loc) · 2.71 KB
/
vrrp_adv.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
/*
* vrrp_adv.h - VRRP advertisement
*
* 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_ADV_H_
#define _VRRP_ADV_H_
int vrrp_adv_init(struct vrrp_net *vnet, const struct vrrp *vrrp);
void vrrp_adv_cleanup(struct vrrp_net *vnet);
int vrrp_adv_send(struct vrrp_net *vnet);
int vrrp_adv_send_zero(struct vrrp_net *vnet);
uint16_t vrrp_adv_chksum(struct vrrp_net *vnet, struct vrrphdr *pkt,
uint32_t saddr, uint32_t daddr);
#ifdef HAVE_IP6
uint16_t vrrp_adv_ip6_chksum(struct vrrp_net *vnet, struct vrrphdr *pkt,
struct in6_addr *saddr, struct in6_addr *daddr);
#endif /* HAVE_IP6 */
/**
* vrrp_adv_get_version() - get version_type from received adv pkt
*/
static inline int vrrp_adv_get_version(const struct vrrp_net *vnet)
{
return vnet->__pkt.adv.version_type;
}
/**
* vrrp_adv_get_priority() - get priority from received adv priority
*/
static inline int vrrp_adv_get_priority(const struct vrrp_net *vnet)
{
return vnet->__pkt.adv.priority;
}
/**
* vrrp_adv_set_priority() - set priority in emitted adv pkt
*/
static inline void vrrp_adv_set_priority(struct vrrp_net *vnet, uint8_t prio)
{
struct vrrphdr *pkt = vnet->__adv[2].iov_base;
pkt->priority = prio;
/* recompute chksum */
pkt->chksum = vnet->adv_checksum(vnet, pkt, NULL, NULL);
log_notice("vrid %d :: new prio %d applied", vnet->vrid, pkt->priority);
}
/**
* vrrp_adv_addr_to_str() - return source ip from received adv pkt
* in string format
*/
static inline const char *vrrp_adv_addr_to_str(struct vrrp_net *vnet, char *dst)
{
return vnet->ipx_to_str(&vnet->__pkt.s_ipx, dst);
}
/**
* vrrp_adv_get_compare() - compare received adv pkt addr to local
* primary address
*/
static inline int vrrp_adv_addr_cmp(struct vrrp_net *vnet)
{
return vnet->ipx_cmp(&vnet->__pkt.s_ipx, &vnet->vif.ipx);
}
/**
* vrrp_adv_get_advint() - get adv interval
*/
static inline uint16_t vrrp_adv_get_advint(const struct vrrp_net *vnet)
{
if (vnet->__pkt.adv.version_type >> 4 == RFC5798)
return ntohs(vnet->__pkt.adv.max_adv_int);
return vnet->__pkt.adv.adv_int;
}
#endif /* _VRRP_ADV_H_ */