]>
Commit | Line | Data |
---|---|---|
12e41d03 | 1 | /* |
896014f4 DL |
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 along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
12e41d03 DL |
19 | |
20 | #ifndef PIM_MSG_H | |
21 | #define PIM_MSG_H | |
22 | ||
23 | #include <netinet/in.h> | |
24 | ||
982bff89 | 25 | #include "pim_jp_agg.h" |
d57a8bbf | 26 | |
27 | #define PIM_HDR_LEN sizeof(struct pim_msg_header) | |
12e41d03 | 28 | /* |
d62a17ae | 29 | Number Description |
12e41d03 DL |
30 | ---------- ------------------ |
31 | 0 Reserved | |
32 | 1 IP (IP version 4) | |
33 | 2 IP6 (IP version 6) | |
34 | ||
35 | From: | |
36 | http://www.iana.org/assignments/address-family-numbers | |
37 | */ | |
34687162 | 38 | enum pim_msg_address_family { |
d62a17ae | 39 | PIM_MSG_ADDRESS_FAMILY_RESERVED, |
40 | PIM_MSG_ADDRESS_FAMILY_IPV4, | |
41 | PIM_MSG_ADDRESS_FAMILY_IPV6, | |
34687162 | 42 | }; |
12e41d03 | 43 | |
70ce34ae | 44 | /* |
be6a3245 | 45 | * pim_msg_hdr |
d57a8bbf | 46 | * ========================= |
47 | * PIM Header definition as per RFC 5059. N bit introduced to indicate | |
48 | * do-not-forward option in PIM Boot strap Message. | |
49 | * 0 1 2 3 | |
50 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
51 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
52 | * |PIM Ver| Type |N| Reserved | Checksum | | |
53 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
70ce34ae DS |
54 | */ |
55 | struct pim_msg_header { | |
be6a3245 | 56 | #if (BYTE_ORDER == LITTLE_ENDIAN) |
d62a17ae | 57 | uint8_t type : 4; |
58 | uint8_t ver : 4; | |
be6a3245 BA |
59 | uint8_t reserved : 7; |
60 | uint8_t Nbit : 1; /* No Fwd Bit */ | |
61 | #elif (BYTE_ORDER == BIG_ENDIAN) | |
62 | uint8_t ver : 4; | |
63 | uint8_t type : 4; | |
d57a8bbf | 64 | uint8_t Nbit : 1; /* No Fwd Bit */ |
65 | uint8_t reserved : 7; | |
be6a3245 BA |
66 | #else |
67 | #error"Please set byte order" | |
68 | #endif | |
d62a17ae | 69 | uint16_t checksum; |
70 | } __attribute__((packed)); | |
70ce34ae | 71 | |
74ac496f | 72 | struct pim_encoded_ipv4_unicast { |
d62a17ae | 73 | uint8_t family; |
74 | uint8_t reserved; | |
75 | struct in_addr addr; | |
76 | } __attribute__((packed)); | |
74ac496f | 77 | |
16763d77 DL |
78 | struct pim_encoded_ipv6_unicast { |
79 | uint8_t family; | |
80 | uint8_t reserved; | |
81 | struct in6_addr addr; | |
82 | } __attribute__((packed)); | |
83 | ||
71361a2c | 84 | /* |
85 | * Encoded Group format. RFC 4601 Sec 4.9.1 | |
86 | * 0 1 2 3 | |
87 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
88 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
89 | * | Addr Family | Encoding Type |B| Reserved |Z| Mask Len | | |
90 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
91 | * | Group multicast Address | |
92 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+... | |
93 | */ | |
74ac496f | 94 | struct pim_encoded_group_ipv4 { |
d62a17ae | 95 | uint8_t family; |
71361a2c | 96 | uint8_t ne; |
be6a3245 BA |
97 | #if (BYTE_ORDER == LITTLE_ENDIAN) |
98 | uint8_t sz : 1; /* scope zone bit */ | |
99 | uint8_t reserved : 6; /* Reserved */ | |
100 | uint8_t bidir : 1; /* Bidir bit */ | |
101 | #elif (BYTE_ORDER == BIG_ENDIAN) | |
d57a8bbf | 102 | uint8_t bidir : 1; /* Bidir bit */ |
103 | uint8_t reserved : 6; /* Reserved */ | |
104 | uint8_t sz : 1; /* scope zone bit */ | |
be6a3245 BA |
105 | #else |
106 | #error"Please set byte order" | |
107 | #endif | |
d62a17ae | 108 | uint8_t mask; |
109 | struct in_addr addr; | |
110 | } __attribute__((packed)); | |
74ac496f | 111 | |
16763d77 DL |
112 | struct pim_encoded_group_ipv6 { |
113 | uint8_t family; | |
114 | uint8_t ne; | |
115 | #if (BYTE_ORDER == LITTLE_ENDIAN) | |
116 | uint8_t sz : 1; /* scope zone bit */ | |
117 | uint8_t reserved : 6; /* Reserved */ | |
118 | uint8_t bidir : 1; /* Bidir bit */ | |
119 | #elif (BYTE_ORDER == BIG_ENDIAN) | |
120 | uint8_t bidir : 1; /* Bidir bit */ | |
121 | uint8_t reserved : 6; /* Reserved */ | |
122 | uint8_t sz : 1; /* scope zone bit */ | |
123 | #else | |
124 | #error "Please set byte order" | |
125 | #endif | |
126 | uint8_t mask; | |
127 | struct in6_addr addr; | |
128 | } __attribute__((packed)); | |
71361a2c | 129 | |
130 | /* | |
131 | * Encoded Source format. RFC 4601 Sec 4.9.1 | |
132 | * 0 1 2 3 | |
133 | * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | |
134 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
135 | * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len | | |
136 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |
137 | * | Source Address | |
138 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-... | |
139 | */ | |
74ac496f | 140 | struct pim_encoded_source_ipv4 { |
d62a17ae | 141 | uint8_t family; |
71361a2c | 142 | uint8_t ne; |
d62a17ae | 143 | uint8_t bits; |
144 | uint8_t mask; | |
145 | struct in_addr addr; | |
146 | } __attribute__((packed)); | |
74ac496f | 147 | |
16763d77 DL |
148 | struct pim_encoded_source_ipv6 { |
149 | uint8_t family; | |
150 | uint8_t ne; | |
151 | uint8_t bits; | |
152 | uint8_t mask; | |
153 | struct in6_addr addr; | |
154 | } __attribute__((packed)); | |
155 | ||
156 | /* clang-format off */ | |
157 | #if PIM_IPV == 4 | |
158 | typedef struct pim_encoded_ipv4_unicast pim_encoded_unicast; | |
159 | typedef struct pim_encoded_group_ipv4 pim_encoded_group; | |
160 | typedef struct pim_encoded_source_ipv4 pim_encoded_source; | |
161 | #else | |
162 | typedef struct pim_encoded_ipv6_unicast pim_encoded_unicast; | |
163 | typedef struct pim_encoded_group_ipv6 pim_encoded_group; | |
164 | typedef struct pim_encoded_source_ipv6 pim_encoded_source; | |
165 | #endif | |
166 | /* clang-format on */ | |
167 | ||
74ac496f | 168 | struct pim_jp_groups { |
16763d77 | 169 | pim_encoded_group g; |
d62a17ae | 170 | uint16_t joins; |
171 | uint16_t prunes; | |
16763d77 | 172 | pim_encoded_source s[1]; |
d62a17ae | 173 | } __attribute__((packed)); |
74ac496f DS |
174 | |
175 | struct pim_jp { | |
d62a17ae | 176 | struct pim_msg_header header; |
16763d77 | 177 | pim_encoded_unicast addr; |
d62a17ae | 178 | uint8_t reserved; |
179 | uint8_t num_groups; | |
180 | uint16_t holdtime; | |
181 | struct pim_jp_groups groups[1]; | |
182 | } __attribute__((packed)); | |
74ac496f | 183 | |
d62a17ae | 184 | void pim_msg_build_header(uint8_t *pim_msg, size_t pim_msg_size, |
d57a8bbf | 185 | uint8_t pim_msg_type, bool no_fwd); |
f8e7d799 DS |
186 | uint8_t *pim_msg_addr_encode_ipv4_ucast(uint8_t *buf, struct in_addr addr); |
187 | uint8_t *pim_msg_addr_encode_ipv4_group(uint8_t *buf, struct in_addr addr); | |
984c84f4 DS |
188 | |
189 | #define PIM_ENCODE_SPARSE_BIT 0x04 | |
190 | #define PIM_ENCODE_WC_BIT 0x02 | |
191 | #define PIM_ENCODE_RPT_BIT 0x01 | |
d62a17ae | 192 | uint8_t *pim_msg_addr_encode_ipv4_source(uint8_t *buf, struct in_addr addr, |
193 | uint8_t bits); | |
12e41d03 | 194 | |
16763d77 DL |
195 | uint8_t *pim_msg_addr_encode_ipv6_ucast(uint8_t *buf, struct in6_addr addr); |
196 | uint8_t *pim_msg_addr_encode_ipv6_group(uint8_t *buf, struct in6_addr addr); | |
197 | uint8_t *pim_msg_addr_encode_ipv6_source(uint8_t *buf, struct in6_addr addr, | |
198 | uint8_t bits); | |
199 | ||
200 | uint8_t *pim_msg_addr_encode_ucast(uint8_t *buf, pim_addr addr); | |
201 | uint8_t *pim_msg_addr_encode_group(uint8_t *buf, pim_addr addr); | |
202 | uint8_t *pim_msg_addr_encode_source(uint8_t *buf, pim_addr addr, uint8_t bits); | |
346cffe3 | 203 | |
d62a17ae | 204 | size_t pim_msg_get_jp_group_size(struct list *sources); |
205 | size_t pim_msg_build_jp_groups(struct pim_jp_groups *grp, | |
206 | struct pim_jp_agg_group *sgs, size_t size); | |
12e41d03 | 207 | #endif /* PIM_MSG_H */ |