2 * The olsr.org Optimized Link-State Routing daemon(olsrd)
3 * Copyright (c) 2004, Thomas Lopatic (thomas@lopatic.de)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of olsr.org, olsrd nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
33 * Visit http://www.olsr.org for more information.
35 * If you find this software useful feel free to make a donation
36 * to the project. For more information see the website or contact
37 * the copyright holders.
41 #ifndef _OLSR_LQ_PACKET_H
42 #define _OLSR_LQ_PACKET_H
44 #include "olsr_types.h"
49 #define LQ_HELLO_MESSAGE 201
50 #define LQ_TC_MESSAGE 202
52 // deserialized OLSR header
59 union olsr_ip_addr orig;
65 // serialized IPv4 OLSR header
78 // serialized IPv6 OLSR header
85 unsigned char orig[16];
91 // deserialized LQ_HELLO
93 struct lq_hello_neighbor
99 fpm neigh_link_quality;
102 double neigh_link_quality;
104 union olsr_ip_addr addr;
105 struct lq_hello_neighbor *next;
108 struct lq_hello_message
110 struct olsr_common comm;
113 struct lq_hello_neighbor *neigh;
116 // serialized LQ_HELLO
118 struct lq_hello_info_header
125 struct lq_hello_header
132 // deserialized LQ_TC
135 struct olsr_common comm;
136 union olsr_ip_addr from;
138 struct tc_mpr_addr *neigh;
149 static INLINE void pkt_get_u8(const olsr_u8_t **p, olsr_u8_t *var) { *var = *(const olsr_u8_t *)(*p); *p += sizeof(olsr_u8_t); }
150 static INLINE void pkt_get_u16(const olsr_u8_t **p, olsr_u16_t *var) { *var = ntohs(*(const olsr_u16_t *)(*p)); *p += sizeof(olsr_u16_t); }
151 static INLINE void pkt_get_u32(const olsr_u8_t **p, olsr_u32_t *var) { *var = ntohl(*(const olsr_u32_t *)(p)); *p += sizeof(olsr_u32_t); }
152 static INLINE void pkt_get_s8(const olsr_u8_t **p, olsr_8_t *var) { *var = *(const olsr_8_t *)(*p); *p += sizeof(olsr_8_t); }
153 static INLINE void pkt_get_s16(const olsr_u8_t **p, olsr_16_t *var) { *var = ntohs(*(const olsr_16_t *)(*p)); *p += sizeof(olsr_16_t); }
154 static INLINE void pkt_get_s32(const olsr_u8_t **p, olsr_32_t *var) { *var = ntohl(*(const olsr_32_t *)(*p)); *p += sizeof(olsr_32_t); }
155 static INLINE void pkt_get_double(const olsr_u8_t **p, double *var) { *var = me_to_double(**p); *p += sizeof(olsr_u8_t); }
156 static INLINE void pkt_get_ipaddress(const olsr_u8_t **p, union olsr_ip_addr *var) { memcpy(var, *p, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
157 static INLINE void pkt_get_prefixlen(const olsr_u8_t **p, olsr_u8_t *var) { *var = netmask_to_prefix(*p, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
159 static INLINE void pkt_get_lq(const olsr_u8_t **p, fpm *var) { *var = fpmidiv(itofpm(**p), 255); *p += sizeof(olsr_u8_t); }
161 static INLINE void pkt_get_lq(const olsr_u8_t **p, double *var) { *var = (const double)**p / 255.0; *p += sizeof(olsr_u8_t); }
164 static INLINE void pkt_ignore_u8(const olsr_u8_t **p) { *p += sizeof(olsr_u8_t); }
165 static INLINE void pkt_ignore_u16(const olsr_u8_t **p) { *p += sizeof(olsr_u16_t); }
166 static INLINE void pkt_ignore_u32(const olsr_u8_t **p) { *p += sizeof(olsr_u32_t); }
167 static INLINE void pkt_ignore_s8(const olsr_u8_t **p) { *p += sizeof(olsr_8_t); }
168 static INLINE void pkt_ignore_s16(const olsr_u8_t **p) { *p += sizeof(olsr_16_t); }
169 static INLINE void pkt_ignore_s32(const olsr_u8_t **p) { *p += sizeof(olsr_32_t); }
170 static INLINE void pkt_ignore_ipaddress(const olsr_u8_t **p) { *p += olsr_cnf->ipsize; }
171 static INLINE void pkt_ignore_prefixlen(const olsr_u8_t **p) { *p += olsr_cnf->ipsize; }
173 static INLINE void pkt_put_u8(olsr_u8_t **p, olsr_u8_t var) { *(olsr_u8_t *)(*p) = var; *p += sizeof(olsr_u8_t); }
174 static INLINE void pkt_put_u16(olsr_u8_t **p, olsr_u16_t var) { *(olsr_u16_t *)(*p) = htons(var); *p += sizeof(olsr_u16_t); }
175 static INLINE void pkt_put_u32(olsr_u8_t **p, olsr_u32_t var) { *(olsr_u32_t *)(*p) = htonl(var); *p += sizeof(olsr_u32_t); }
176 static INLINE void pkt_put_s8(olsr_u8_t **p, olsr_8_t var) { *(olsr_8_t *)(*p) = var; *p += sizeof(olsr_8_t); }
177 static INLINE void pkt_put_s16(olsr_u8_t **p, olsr_16_t var) { *(olsr_16_t *)(*p) = htons(var); *p += sizeof(olsr_16_t); }
178 static INLINE void pkt_put_s32(olsr_u8_t **p, olsr_32_t var) { *(olsr_32_t *)(*p) = htonl(var); *p += sizeof(olsr_32_t); }
179 static INLINE void pkt_put_double(olsr_u8_t **p, double var) { **p = double_to_me(var); *p += sizeof(olsr_u8_t); }
180 static INLINE void pkt_put_ipaddress(olsr_u8_t **p, const union olsr_ip_addr *var) { memcpy(*p, var, olsr_cnf->ipsize); *p += olsr_cnf->ipsize; }
181 static INLINE void pkt_put_prefixlen(olsr_u8_t **p, olsr_u8_t var) { prefix_to_netmask(*p, olsr_cnf->ipsize, var); *p += olsr_cnf->ipsize; }
182 static INLINE void pkt_put_lq(olsr_u8_t **p, double var) { **p = var * 255.0; *p += sizeof(olsr_u8_t); }
184 void olsr_output_lq_hello(void *para);
186 void olsr_output_lq_tc(void *para);
188 void olsr_input_lq_hello(union olsr_message *ser, struct interface *inif,
189 union olsr_ip_addr *from);
191 extern olsr_bool lq_tc_pending;