]> git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_msg.c
pimd: Remove unnecessary QuaggaId
[mirror_frr.git] / pimd / pim_msg.c
1 /*
2 PIM for Quagga
3 Copyright (C) 2008 Everton da Silva Marques
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 MA 02110-1301 USA
19
20 */
21
22 #include <zebra.h>
23
24 #include "if.h"
25
26 #include "pimd.h"
27 #include "pim_pim.h"
28 #include "pim_msg.h"
29 #include "pim_util.h"
30
31 void pim_msg_build_header(uint8_t *pim_msg, int pim_msg_size,
32 uint8_t pim_msg_type)
33 {
34 uint16_t checksum;
35
36 zassert(pim_msg_size >= PIM_PIM_MIN_LEN);
37
38 /*
39 * Write header
40 */
41
42 *(uint8_t *) PIM_MSG_HDR_OFFSET_VERSION(pim_msg) = (PIM_PROTO_VERSION << 4) | pim_msg_type;
43 *(uint8_t *) PIM_MSG_HDR_OFFSET_RESERVED(pim_msg) = 0;
44
45 /*
46 * Compute checksum
47 */
48
49 *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) = 0;
50 checksum = in_cksum(pim_msg, pim_msg_size);
51 *(uint16_t *) PIM_MSG_HDR_OFFSET_CHECKSUM(pim_msg) = checksum;
52 }
53
54 uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf,
55 int buf_size,
56 struct in_addr addr)
57 {
58 const int ENCODED_IPV4_UCAST_SIZE = 6;
59
60 if (buf_size < ENCODED_IPV4_UCAST_SIZE) {
61 return 0;
62 }
63
64 buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */
65 buf[1] = '\0'; /* native encoding */
66 memcpy(buf+2, &addr, sizeof(struct in_addr));
67
68 return buf + ENCODED_IPV4_UCAST_SIZE;
69 }
70
71 uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf,
72 int buf_size,
73 struct in_addr addr)
74 {
75 const int ENCODED_IPV4_GROUP_SIZE = 8;
76
77 if (buf_size < ENCODED_IPV4_GROUP_SIZE) {
78 return 0;
79 }
80
81 buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */
82 buf[1] = '\0'; /* native encoding */
83 buf[2] = '\0'; /* reserved */
84 buf[3] = 32; /* mask len */
85 memcpy(buf+4, &addr, sizeof(struct in_addr));
86
87 return buf + ENCODED_IPV4_GROUP_SIZE;
88 }
89
90 uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf,
91 int buf_size,
92 struct in_addr addr)
93 {
94 const int ENCODED_IPV4_SOURCE_SIZE = 8;
95
96 if (buf_size < ENCODED_IPV4_SOURCE_SIZE) {
97 return 0;
98 }
99
100 buf[0] = PIM_MSG_ADDRESS_FAMILY_IPV4; /* addr family */
101 buf[1] = '\0'; /* native encoding */
102 buf[2] = 4; /* reserved = 0 | S bit = 1 | W bit = 0 | R bit = 0 */
103 buf[3] = 32; /* mask len */
104 memcpy(buf+4, &addr, sizeof(struct in_addr));
105
106 return buf + ENCODED_IPV4_SOURCE_SIZE;
107 }