]> git.proxmox.com Git - mirror_frr.git/blob - vrrpd/vrrp_packet.c
vrrpd: initial commit
[mirror_frr.git] / vrrpd / vrrp_packet.c
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
25 #include "vrrp_packet.h"
26
27 /*
28 * Builds a VRRP packet.
29 */
30 struct vrrp_pkt *vrrp_pkt_build(uint8_t vrid, uint8_t prio,
31 uint16_t max_adver_int, bool v6, uint8_t numip,
32 void **ips)
33 {
34 size_t addrsz = v6 ? sizeof(struct in6_addr) : sizeof(struct in_addr);
35 struct vrrp_pkt *pkt =
36 XCALLOC(MTYPE_TMP, sizeof(struct vrrp_pkt) + addrsz * numip);
37
38 pkt->version = VRRP_VERSION;
39 pkt->type = VRRP_TYPE_ADVERTISEMENT;
40 pkt->vrid = vrid;
41 pkt->priority = prio;
42 pkt->rsvd = 0;
43 pkt->max_adver_int = max_adver_int;
44 for (uint8_t i = 0; i < numip; i++)
45 memcpy(&pkt->addrs[i].v4, ips[i], addrsz);
46 /* FIXME */
47 pkt->cksum = 0;
48
49 return pkt;
50 }