]> git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp_packet.h
vrrpd: ipv6 support
[mirror_frr.git] / vrrpd / vrrp_packet.h
1 /*
2 * VRRPD packet crafting
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 #include <zebra.h>
21
22 #include "memory.h"
23 #include "ipaddr.h"
24 #include "prefix.h"
25
26 #define VRRP_VERSION 3
27 #define VRRP_TYPE_ADVERTISEMENT 1
28
29 /*
30 * Shared header for VRRPv2/v3 packets.
31 */
32 struct vrrp_hdr {
33 /*
34 * H L H L
35 * 0000 0000
36 * ver type
37 */
38 uint8_t vertype;
39 uint8_t vrid;
40 uint8_t priority;
41 uint8_t naddr;
42 union {
43 struct {
44 uint8_t auth_type;
45 /* advertisement interval (in sec) */
46 uint8_t adver_int;
47 } v2;
48 struct {
49 /*
50 * advertisement interval (in centiseconds)
51 * H L H L
52 * 0000 000000000000
53 * rsvd adver_int
54 */
55 uint16_t adver_int;
56 } v3;
57 };
58 uint16_t chksum;
59 };
60
61 struct vrrp_pkt {
62 struct vrrp_hdr hdr;
63 union {
64 struct in_addr v4;
65 struct in6_addr v6;
66 } addrs[];
67 } __attribute((packed, aligned(1)));
68
69 /*
70 * Builds a VRRP packet.
71 *
72 * pkt
73 * Pointer to store pointer to result buffer in
74 *
75 * vrid
76 * Virtual Router Identifier
77 *
78 * prio
79 * Virtual Router Priority
80 *
81 * max_adver_int
82 * time between ADVERTISEMENTs
83 *
84 * v6
85 * whether 'ips' is an array of v4 or v6 addresses
86 *
87 * numip
88 * number of IPvX addresses in 'ips'
89 *
90 * ips
91 * array of pointer to either struct in_addr (v6 = false) or struct in6_addr
92 * (v6 = true)
93 */
94 ssize_t vrrp_pkt_build(struct vrrp_pkt **pkt, uint8_t vrid, uint8_t prio,
95 uint16_t max_adver_int, uint8_t numip,
96 struct ipaddr **ips);