1 /*
2 * The olsr.org Optimized Link-State Routing daemon (olsrd)
3 *
4 * (c) by the OLSR project
5 *
6 * See our Git repository to find out who worked on this file
7 * and thus is a copyright holder on it.
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * * Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 * * Neither the name of olsr.org, olsrd nor the names of its
22 * contributors may be used to endorse or promote products derived
23 * from this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 * Visit http://www.olsr.org for more information.
39 *
40 * If you find this software useful feel free to make a donation
41 * to the project. For more information see the website or contact
42 * the copyright holders.
43 *
44 */
45
46 #ifndef _OLSR_LQ_PACKET_H
47 #define _OLSR_LQ_PACKET_H
48
49 #include "olsr_types.h"
50 #include "packet.h"
51 #include "mantissa.h"
52 #include "ipcalc.h"
53
54 #define LQ_HELLO_MESSAGE 201
55 #define LQ_TC_MESSAGE 202
56
57 /* deserialized OLSR header */
58
59 struct olsr_common {
60 uint8_t type;
61 olsr_reltime vtime;
62 uint16_t size;
63 union olsr_ip_addr orig;
64 uint8_t ttl;
65 uint8_t hops;
66 uint16_t seqno;
67 };
68
69 /* serialized IPv4 OLSR header */
70
71 struct olsr_header_v4 {
72 uint8_t type;
73 uint8_t vtime;
74 uint16_t size;
75 uint32_t orig;
76 uint8_t ttl;
77 uint8_t hops;
78 uint16_t seqno;
79 };
80
81 /* serialized IPv6 OLSR header */
82
83 struct olsr_header_v6 {
84 uint8_t type;
85 uint8_t vtime;
86 uint16_t size;
87 unsigned char orig[16];
88 uint8_t ttl;
89 uint8_t hops;
90 uint16_t seqno;
91 };
92
93 /* deserialized LQ_HELLO */
94
95 struct lq_hello_neighbor {
96 uint8_t link_type;
97 uint8_t neigh_type;
98 union olsr_ip_addr addr;
99 struct lq_hello_neighbor *next;
100 uint32_t linkquality[0];
101 };
102
103 struct lq_hello_message {
104 struct olsr_common comm;
105 olsr_reltime htime;
106 uint8_t will;
107 struct lq_hello_neighbor *neigh;
108 };
109
110 /* serialized LQ_HELLO */
111 struct lq_hello_info_header {
112 uint8_t link_code;
113 uint8_t reserved;
114 uint16_t size;
115 };
116
117 struct lq_hello_header {
118 uint16_t reserved;
119 uint8_t htime;
120 uint8_t will;
121 };
122
123 /* deserialized LQ_TC */
124 struct lq_tc_message {
125 struct olsr_common comm;
126 union olsr_ip_addr from;
127 uint16_t ansn;
128 struct tc_mpr_addr *neigh;
129 };
130
131 /* serialized LQ_TC */
132
133 struct lq_tc_header {
134 uint16_t ansn;
135 uint8_t lower_border;
136 uint8_t upper_border;
137 };
138
139 static INLINE void
pkt_get_u8(const uint8_t ** p,uint8_t * var)140 pkt_get_u8(const uint8_t ** p, uint8_t * var)
141 {
142 *var = *(const uint8_t *)(*p);
143 *p += sizeof(uint8_t);
144 }
145 static INLINE void
pkt_get_u16(const uint8_t ** p,uint16_t * var)146 pkt_get_u16(const uint8_t ** p, uint16_t * var)
147 {
148 *var = ntohs(**((const uint16_t **)p));
149 *p += sizeof(uint16_t);
150 }
151 static INLINE void
pkt_get_u32(const uint8_t ** p,uint32_t * var)152 pkt_get_u32(const uint8_t ** p, uint32_t * var)
153 {
154 *var = ntohl(**((const uint32_t **)p));
155 *p += sizeof(uint32_t);
156 }
157 static INLINE void
pkt_get_s8(const uint8_t ** p,int8_t * var)158 pkt_get_s8(const uint8_t ** p, int8_t * var)
159 {
160 *var = *(const int8_t *)(*p);
161 *p += sizeof(int8_t);
162 }
163 static INLINE void
pkt_get_s16(const uint8_t ** p,int16_t * var)164 pkt_get_s16(const uint8_t ** p, int16_t * var)
165 {
166 *var = ntohs(**((const int16_t **)p));
167 *p += sizeof(int16_t);
168 }
169 static INLINE void
pkt_get_s32(const uint8_t ** p,int32_t * var)170 pkt_get_s32(const uint8_t ** p, int32_t * var)
171 {
172 *var = ntohl(**((const int32_t **)p));
173 *p += sizeof(int32_t);
174 }
175 static INLINE void
pkt_get_reltime(const uint8_t ** p,olsr_reltime * var)176 pkt_get_reltime(const uint8_t ** p, olsr_reltime * var)
177 {
178 *var = me_to_reltime(**p);
179 *p += sizeof(uint8_t);
180 }
181 static INLINE void
pkt_get_ipaddress(const uint8_t ** p,union olsr_ip_addr * var)182 pkt_get_ipaddress(const uint8_t ** p, union olsr_ip_addr *var)
183 {
184 memcpy(var, *p, olsr_cnf->ipsize);
185 *p += olsr_cnf->ipsize;
186 }
187 static INLINE void
pkt_get_prefixlen(const uint8_t ** p,uint8_t * var)188 pkt_get_prefixlen(const uint8_t ** p, uint8_t * var)
189 {
190 *var = netmask_to_prefix(*p, olsr_cnf->ipsize);
191 *p += olsr_cnf->ipsize;
192 }
193
194 static INLINE void
pkt_ignore_u8(const uint8_t ** p)195 pkt_ignore_u8(const uint8_t ** p)
196 {
197 *p += sizeof(uint8_t);
198 }
199 static INLINE void
pkt_ignore_u16(const uint8_t ** p)200 pkt_ignore_u16(const uint8_t ** p)
201 {
202 *p += sizeof(uint16_t);
203 }
204 static INLINE void
pkt_ignore_u32(const uint8_t ** p)205 pkt_ignore_u32(const uint8_t ** p)
206 {
207 *p += sizeof(uint32_t);
208 }
209 static INLINE void
pkt_ignore_s8(const uint8_t ** p)210 pkt_ignore_s8(const uint8_t ** p)
211 {
212 *p += sizeof(int8_t);
213 }
214 static INLINE void
pkt_ignore_s16(const uint8_t ** p)215 pkt_ignore_s16(const uint8_t ** p)
216 {
217 *p += sizeof(int16_t);
218 }
219 static INLINE void
pkt_ignore_s32(const uint8_t ** p)220 pkt_ignore_s32(const uint8_t ** p)
221 {
222 *p += sizeof(int32_t);
223 }
224 static INLINE void
pkt_ignore_ipaddress(const uint8_t ** p)225 pkt_ignore_ipaddress(const uint8_t ** p)
226 {
227 *p += olsr_cnf->ipsize;
228 }
229 static INLINE void
pkt_ignore_prefixlen(const uint8_t ** p)230 pkt_ignore_prefixlen(const uint8_t ** p)
231 {
232 *p += olsr_cnf->ipsize;
233 }
234
235 static INLINE void
pkt_put_u8(uint8_t ** p,uint8_t var)236 pkt_put_u8(uint8_t ** p, uint8_t var)
237 {
238 **((uint8_t **)p) = var;
239 *p += sizeof(uint8_t);
240 }
241 static INLINE void
pkt_put_u16(uint8_t ** p,uint16_t var)242 pkt_put_u16(uint8_t ** p, uint16_t var)
243 {
244 **((uint16_t **)p) = htons(var);
245 *p += sizeof(uint16_t);
246 }
247 static INLINE void
pkt_put_u32(uint8_t ** p,uint32_t var)248 pkt_put_u32(uint8_t ** p, uint32_t var)
249 {
250 **((uint32_t **)p) = htonl(var);
251 *p += sizeof(uint32_t);
252 }
253 static INLINE void
pkt_put_s8(uint8_t ** p,int8_t var)254 pkt_put_s8(uint8_t ** p, int8_t var)
255 {
256 **((int8_t **)p) = var;
257 *p += sizeof(int8_t);
258 }
259 static INLINE void
pkt_put_s16(uint8_t ** p,int16_t var)260 pkt_put_s16(uint8_t ** p, int16_t var)
261 {
262 **((int16_t **)p) = htons(var);
263 *p += sizeof(int16_t);
264 }
265 static INLINE void
pkt_put_s32(uint8_t ** p,int32_t var)266 pkt_put_s32(uint8_t ** p, int32_t var)
267 {
268 **((int32_t **)p) = htonl(var);
269 *p += sizeof(int32_t);
270 }
271 static INLINE void
pkt_put_reltime(uint8_t ** p,olsr_reltime var)272 pkt_put_reltime(uint8_t ** p, olsr_reltime var)
273 {
274 **p = reltime_to_me(var);
275 *p += sizeof(uint8_t);
276 }
277 static INLINE void
pkt_put_ipaddress(uint8_t ** p,const union olsr_ip_addr * var)278 pkt_put_ipaddress(uint8_t ** p, const union olsr_ip_addr *var)
279 {
280 memcpy(*p, var, olsr_cnf->ipsize);
281 *p += olsr_cnf->ipsize;
282 }
283
284 void olsr_output_lq_hello(void *para);
285
286 void olsr_output_lq_tc(void *para);
287
288 void olsr_input_lq_hello(union olsr_message *ser, struct interface_olsr *inif, union olsr_ip_addr *from);
289
290 extern bool lq_tc_pending;
291
292 #endif /* _OLSR_LQ_PACKET_H */
293
294 /*
295 * Local Variables:
296 * c-basic-offset: 2
297 * indent-tabs-mode: nil
298 * End:
299 */
300