2 * The olsr.org Optimized Link-State Routing daemon (olsrd)
4 * (c) by the OLSR project
6 * See our Git repository to find out who worked on this file
7 * and thus is a copyright holder on it.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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
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.
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.
38 * Visit http://www.olsr.org for more information.
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.
46 #ifndef _OLSR_LQ_PACKET_H
47 #define _OLSR_LQ_PACKET_H
49 #include "olsr_types.h"
54 #define LQ_HELLO_MESSAGE 201
55 #define LQ_TC_MESSAGE 202
57 /* deserialized OLSR header */
63 union olsr_ip_addr orig;
69 /* serialized IPv4 OLSR header */
71 struct olsr_header_v4 {
81 /* serialized IPv6 OLSR header */
83 struct olsr_header_v6 {
87 unsigned char orig[16];
93 /* deserialized LQ_HELLO */
95 struct lq_hello_neighbor {
98 union olsr_ip_addr addr;
99 struct lq_hello_neighbor *next;
100 uint32_t linkquality[0];
103 struct lq_hello_message {
104 struct olsr_common comm;
107 struct lq_hello_neighbor *neigh;
110 /* serialized LQ_HELLO */
111 struct lq_hello_info_header {
117 struct lq_hello_header {
123 /* deserialized LQ_TC */
124 struct lq_tc_message {
125 struct olsr_common comm;
126 union olsr_ip_addr from;
128 struct tc_mpr_addr *neigh;
131 /* serialized LQ_TC */
133 struct lq_tc_header {
135 uint8_t lower_border;
136 uint8_t upper_border;
140 pkt_get_u8(const uint8_t ** p, uint8_t * var)
142 *var = *(const uint8_t *)(*p);
143 *p += sizeof(uint8_t);
146 pkt_get_u16(const uint8_t ** p, uint16_t * var)
148 *var = ntohs(**((const uint16_t **)p));
149 *p += sizeof(uint16_t);
152 pkt_get_u32(const uint8_t ** p, uint32_t * var)
154 *var = ntohl(**((const uint32_t **)p));
155 *p += sizeof(uint32_t);
158 pkt_get_s8(const uint8_t ** p, int8_t * var)
160 *var = *(const int8_t *)(*p);
161 *p += sizeof(int8_t);
164 pkt_get_s16(const uint8_t ** p, int16_t * var)
166 *var = ntohs(**((const int16_t **)p));
167 *p += sizeof(int16_t);
170 pkt_get_s32(const uint8_t ** p, int32_t * var)
172 *var = ntohl(**((const int32_t **)p));
173 *p += sizeof(int32_t);
176 pkt_get_reltime(const uint8_t ** p, olsr_reltime * var)
178 *var = me_to_reltime(**p);
179 *p += sizeof(uint8_t);
182 pkt_get_ipaddress(const uint8_t ** p, union olsr_ip_addr *var)
184 memcpy(var, *p, olsr_cnf->ipsize);
185 *p += olsr_cnf->ipsize;
188 pkt_get_prefixlen(const uint8_t ** p, uint8_t * var)
190 *var = netmask_to_prefix(*p, olsr_cnf->ipsize);
191 *p += olsr_cnf->ipsize;
195 pkt_ignore_u8(const uint8_t ** p)
197 *p += sizeof(uint8_t);
200 pkt_ignore_u16(const uint8_t ** p)
202 *p += sizeof(uint16_t);
205 pkt_ignore_u32(const uint8_t ** p)
207 *p += sizeof(uint32_t);
210 pkt_ignore_s8(const uint8_t ** p)
212 *p += sizeof(int8_t);
215 pkt_ignore_s16(const uint8_t ** p)
217 *p += sizeof(int16_t);
220 pkt_ignore_s32(const uint8_t ** p)
222 *p += sizeof(int32_t);
225 pkt_ignore_ipaddress(const uint8_t ** p)
227 *p += olsr_cnf->ipsize;
230 pkt_ignore_prefixlen(const uint8_t ** p)
232 *p += olsr_cnf->ipsize;
236 pkt_put_u8(uint8_t ** p, uint8_t var)
238 **((uint8_t **)p) = var;
239 *p += sizeof(uint8_t);
242 pkt_put_u16(uint8_t ** p, uint16_t var)
244 **((uint16_t **)p) = htons(var);
245 *p += sizeof(uint16_t);
248 pkt_put_u32(uint8_t ** p, uint32_t var)
250 **((uint32_t **)p) = htonl(var);
251 *p += sizeof(uint32_t);
254 pkt_put_s8(uint8_t ** p, int8_t var)
256 **((int8_t **)p) = var;
257 *p += sizeof(int8_t);
260 pkt_put_s16(uint8_t ** p, int16_t var)
262 **((int16_t **)p) = htons(var);
263 *p += sizeof(int16_t);
266 pkt_put_s32(uint8_t ** p, int32_t var)
268 **((int32_t **)p) = htonl(var);
269 *p += sizeof(int32_t);
272 pkt_put_reltime(uint8_t ** p, olsr_reltime var)
274 **p = reltime_to_me(var);
275 *p += sizeof(uint8_t);
278 pkt_put_ipaddress(uint8_t ** p, const union olsr_ip_addr *var)
280 memcpy(*p, var, olsr_cnf->ipsize);
281 *p += olsr_cnf->ipsize;
284 void olsr_output_lq_hello(void *para);
286 void olsr_output_lq_tc(void *para);
288 void olsr_input_lq_hello(union olsr_message *ser, struct interface_olsr *inif, union olsr_ip_addr *from);
290 extern bool lq_tc_pending;
292 #endif /* _OLSR_LQ_PACKET_H */
297 * indent-tabs-mode: nil