]> The Tcpdump Group git mirrors - tcpdump/blob - print-olsr.c
Don't require IPv6 library support in order to support IPv6 addresses.
[tcpdump] / print-olsr.c
1 /*
2 * Copyright (c) 1998-2007 The TCPDUMP project
3 * Copyright (c) 2009 Florian Forster
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code
7 * distributions retain the above copyright notice and this paragraph
8 * in its entirety, and (2) distributions including binary code include
9 * the above copyright notice and this paragraph in its entirety in
10 * the documentation or other materials provided with the distribution.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
12 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
13 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 * FOR A PARTICULAR PURPOSE.
15 *
16 * Optimized Link State Protocl (OLSR) as per rfc3626
17 *
18 * Original code by Hannes Gredler <hannes@juniper.net>
19 * IPv6 additions by Florian Forster <octo at verplant.org>
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <netdissect-stdinc.h>
27
28 #include "netdissect.h"
29 #include "addrtoname.h"
30 #include "extract.h"
31
32 /*
33 * RFC 3626 common header
34 *
35 * 0 1 2 3
36 * 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
37 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
38 * | Packet Length | Packet Sequence Number |
39 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
40 * | Message Type | Vtime | Message Size |
41 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 * | Originator Address |
43 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 * | Time To Live | Hop Count | Message Sequence Number |
45 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
46 * | |
47 * : MESSAGE :
48 * | |
49 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
50 * | Message Type | Vtime | Message Size |
51 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
52 * | Originator Address |
53 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
54 * | Time To Live | Hop Count | Message Sequence Number |
55 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
56 * | |
57 * : MESSAGE :
58 * | |
59 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
60 * : :
61 */
62
63 struct olsr_common {
64 uint8_t packet_len[2];
65 uint8_t packet_seq[2];
66 };
67
68 #define OLSR_HELLO_MSG 1 /* rfc3626 */
69 #define OLSR_TC_MSG 2 /* rfc3626 */
70 #define OLSR_MID_MSG 3 /* rfc3626 */
71 #define OLSR_HNA_MSG 4 /* rfc3626 */
72 #define OLSR_POWERINFO_MSG 128
73 #define OLSR_NAMESERVICE_MSG 130
74 #define OLSR_HELLO_LQ_MSG 201 /* LQ extensions olsr.org */
75 #define OLSR_TC_LQ_MSG 202 /* LQ extensions olsr.org */
76
77 static const struct tok olsr_msg_values[] = {
78 { OLSR_HELLO_MSG, "Hello" },
79 { OLSR_TC_MSG, "TC" },
80 { OLSR_MID_MSG, "MID" },
81 { OLSR_HNA_MSG, "HNA" },
82 { OLSR_POWERINFO_MSG, "Powerinfo" },
83 { OLSR_NAMESERVICE_MSG, "Nameservice" },
84 { OLSR_HELLO_LQ_MSG, "Hello-LQ" },
85 { OLSR_TC_LQ_MSG, "TC-LQ" },
86 { 0, NULL}
87 };
88
89 struct olsr_msg4 {
90 uint8_t msg_type;
91 uint8_t vtime;
92 uint8_t msg_len[2];
93 uint8_t originator[4];
94 uint8_t ttl;
95 uint8_t hopcount;
96 uint8_t msg_seq[2];
97 };
98
99 struct olsr_msg6 {
100 uint8_t msg_type;
101 uint8_t vtime;
102 uint8_t msg_len[2];
103 uint8_t originator[16];
104 uint8_t ttl;
105 uint8_t hopcount;
106 uint8_t msg_seq[2];
107 };
108
109 struct olsr_hello {
110 uint8_t res[2];
111 uint8_t htime;
112 uint8_t will;
113 };
114
115 struct olsr_hello_link {
116 uint8_t link_code;
117 uint8_t res;
118 uint8_t len[2];
119 };
120
121 struct olsr_tc {
122 uint8_t ans_seq[2];
123 uint8_t res[2];
124 };
125
126 struct olsr_hna4 {
127 uint8_t network[4];
128 uint8_t mask[4];
129 };
130
131 struct olsr_hna6 {
132 uint8_t network[16];
133 uint8_t mask[16];
134 };
135
136
137 /** gateway HNA flags */
138 enum gateway_hna_flags {
139 GW_HNA_FLAG_LINKSPEED = 1 << 0,
140 GW_HNA_FLAG_IPV4 = 1 << 1,
141 GW_HNA_FLAG_IPV4_NAT = 1 << 2,
142 GW_HNA_FLAG_IPV6 = 1 << 3,
143 GW_HNA_FLAG_IPV6PREFIX = 1 << 4
144 };
145
146 /** gateway HNA field byte offsets in the netmask field of the HNA */
147 enum gateway_hna_fields {
148 GW_HNA_PAD = 0,
149 GW_HNA_FLAGS = 1,
150 GW_HNA_UPLINK = 2,
151 GW_HNA_DOWNLINK = 3,
152 GW_HNA_V6PREFIXLEN = 4,
153 GW_HNA_V6PREFIX = 5
154 };
155
156
157 #define OLSR_EXTRACT_LINK_TYPE(link_code) (link_code & 0x3)
158 #define OLSR_EXTRACT_NEIGHBOR_TYPE(link_code) (link_code >> 2)
159
160 static const struct tok olsr_link_type_values[] = {
161 { 0, "Unspecified" },
162 { 1, "Asymmetric" },
163 { 2, "Symmetric" },
164 { 3, "Lost" },
165 { 0, NULL}
166 };
167
168 static const struct tok olsr_neighbor_type_values[] = {
169 { 0, "Not-Neighbor" },
170 { 1, "Symmetric" },
171 { 2, "Symmetric-MPR" },
172 { 0, NULL}
173 };
174
175 struct olsr_lq_neighbor4 {
176 uint8_t neighbor[4];
177 uint8_t link_quality;
178 uint8_t neighbor_link_quality;
179 uint8_t res[2];
180 };
181
182 struct olsr_lq_neighbor6 {
183 uint8_t neighbor[16];
184 uint8_t link_quality;
185 uint8_t neighbor_link_quality;
186 uint8_t res[2];
187 };
188
189 #define MAX_SMARTGW_SPEED 320000000
190
191 /**
192 * Convert an encoded 1 byte transport value (5 bits mantissa, 3 bits exponent)
193 * to an uplink/downlink speed value
194 *
195 * @param value the encoded 1 byte transport value
196 * @return the uplink/downlink speed value (in kbit/s)
197 */
198 static uint32_t deserialize_gw_speed(uint8_t value) {
199 uint32_t speed;
200 uint32_t exp;
201
202 if (!value) {
203 return 0;
204 }
205
206 if (value == UINT8_MAX) {
207 /* maximum value: also return maximum value */
208 return MAX_SMARTGW_SPEED;
209 }
210
211 speed = (value >> 3) + 1;
212 exp = value & 7;
213
214 while (exp-- > 0) {
215 speed *= 10;
216 }
217 return speed;
218 }
219
220 /*
221 * macro to convert the 8-bit mantissa/exponent to a double float
222 * taken from olsr.org.
223 */
224 #define VTIME_SCALE_FACTOR 0.0625
225 #define ME_TO_DOUBLE(me) \
226 (double)(VTIME_SCALE_FACTOR*(1+(double)(me>>4)/16)*(double)(1<<(me&0x0F)))
227
228 /*
229 * print a neighbor list with LQ extensions.
230 */
231 static int
232 olsr_print_lq_neighbor4(netdissect_options *ndo,
233 const u_char *msg_data, u_int hello_len)
234 {
235 const struct olsr_lq_neighbor4 *lq_neighbor;
236
237 while (hello_len >= sizeof(struct olsr_lq_neighbor4)) {
238
239 lq_neighbor = (const struct olsr_lq_neighbor4 *)msg_data;
240 if (!ND_TTEST(*lq_neighbor))
241 return (-1);
242
243 ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2f%%"
244 ", neighbor-link-quality %.2f%%",
245 ipaddr_string(ndo, lq_neighbor->neighbor),
246 ((double)lq_neighbor->link_quality/2.55),
247 ((double)lq_neighbor->neighbor_link_quality/2.55)));
248
249 msg_data += sizeof(struct olsr_lq_neighbor4);
250 hello_len -= sizeof(struct olsr_lq_neighbor4);
251 }
252 return (0);
253 }
254
255 static int
256 olsr_print_lq_neighbor6(netdissect_options *ndo,
257 const u_char *msg_data, u_int hello_len)
258 {
259 const struct olsr_lq_neighbor6 *lq_neighbor;
260
261 while (hello_len >= sizeof(struct olsr_lq_neighbor6)) {
262
263 lq_neighbor = (const struct olsr_lq_neighbor6 *)msg_data;
264 if (!ND_TTEST(*lq_neighbor))
265 return (-1);
266
267 ND_PRINT((ndo, "\n\t neighbor %s, link-quality %.2f%%"
268 ", neighbor-link-quality %.2f%%",
269 ip6addr_string(ndo, lq_neighbor->neighbor),
270 ((double)lq_neighbor->link_quality/2.55),
271 ((double)lq_neighbor->neighbor_link_quality/2.55)));
272
273 msg_data += sizeof(struct olsr_lq_neighbor6);
274 hello_len -= sizeof(struct olsr_lq_neighbor6);
275 }
276 return (0);
277 }
278
279 /*
280 * print a neighbor list.
281 */
282 static int
283 olsr_print_neighbor(netdissect_options *ndo,
284 const u_char *msg_data, u_int hello_len)
285 {
286 int neighbor;
287
288 ND_PRINT((ndo, "\n\t neighbor\n\t\t"));
289 neighbor = 1;
290
291 while (hello_len >= sizeof(struct in_addr)) {
292
293 if (!ND_TTEST2(*msg_data, sizeof(struct in_addr)))
294 return (-1);
295 /* print 4 neighbors per line */
296
297 ND_PRINT((ndo, "%s%s", ipaddr_string(ndo, msg_data),
298 neighbor % 4 == 0 ? "\n\t\t" : " "));
299
300 msg_data += sizeof(struct in_addr);
301 hello_len -= sizeof(struct in_addr);
302 }
303 return (0);
304 }
305
306
307 void
308 olsr_print(netdissect_options *ndo,
309 const u_char *pptr, u_int length, int is_ipv6)
310 {
311 union {
312 const struct olsr_common *common;
313 const struct olsr_msg4 *msg4;
314 const struct olsr_msg6 *msg6;
315 const struct olsr_hello *hello;
316 const struct olsr_hello_link *hello_link;
317 const struct olsr_tc *tc;
318 const struct olsr_hna4 *hna;
319 } ptr;
320
321 u_int msg_type, msg_len, msg_tlen, hello_len;
322 uint16_t name_entry_type, name_entry_len;
323 u_int name_entry_padding;
324 uint8_t link_type, neighbor_type;
325 const u_char *tptr, *msg_data;
326
327 tptr = pptr;
328
329 if (length < sizeof(struct olsr_common)) {
330 goto trunc;
331 }
332
333 ND_TCHECK2(*tptr, sizeof(struct olsr_common));
334
335 ptr.common = (const struct olsr_common *)tptr;
336 length = min(length, EXTRACT_16BITS(ptr.common->packet_len));
337
338 ND_PRINT((ndo, "OLSRv%i, seq 0x%04x, length %u",
339 (is_ipv6 == 0) ? 4 : 6,
340 EXTRACT_16BITS(ptr.common->packet_seq),
341 length));
342
343 tptr += sizeof(struct olsr_common);
344
345 /*
346 * In non-verbose mode, just print version.
347 */
348 if (ndo->ndo_vflag < 1) {
349 return;
350 }
351
352 while (tptr < (pptr+length)) {
353 union
354 {
355 const struct olsr_msg4 *v4;
356 const struct olsr_msg6 *v6;
357 } msgptr;
358 int msg_len_valid = 0;
359
360 ND_TCHECK2(*tptr, sizeof(struct olsr_msg4));
361
362 if (is_ipv6)
363 {
364 msgptr.v6 = (const struct olsr_msg6 *) tptr;
365 msg_type = msgptr.v6->msg_type;
366 msg_len = EXTRACT_16BITS(msgptr.v6->msg_len);
367 if ((msg_len >= sizeof (struct olsr_msg6))
368 && (msg_len <= length))
369 msg_len_valid = 1;
370
371 /* infinite loop check */
372 if (msg_type == 0 || msg_len == 0) {
373 return;
374 }
375
376 ND_PRINT((ndo, "\n\t%s Message (%#04x), originator %s, ttl %u, hop %u"
377 "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s",
378 tok2str(olsr_msg_values, "Unknown", msg_type),
379 msg_type, ip6addr_string(ndo, msgptr.v6->originator),
380 msgptr.v6->ttl,
381 msgptr.v6->hopcount,
382 ME_TO_DOUBLE(msgptr.v6->vtime),
383 EXTRACT_16BITS(msgptr.v6->msg_seq),
384 msg_len, (msg_len_valid == 0) ? " (invalid)" : ""));
385 if (!msg_len_valid) {
386 return;
387 }
388
389 msg_tlen = msg_len - sizeof(struct olsr_msg6);
390 msg_data = tptr + sizeof(struct olsr_msg6);
391 }
392 else /* (!is_ipv6) */
393 {
394 msgptr.v4 = (const struct olsr_msg4 *) tptr;
395 msg_type = msgptr.v4->msg_type;
396 msg_len = EXTRACT_16BITS(msgptr.v4->msg_len);
397 if ((msg_len >= sizeof (struct olsr_msg4))
398 && (msg_len <= length))
399 msg_len_valid = 1;
400
401 /* infinite loop check */
402 if (msg_type == 0 || msg_len == 0) {
403 return;
404 }
405
406 ND_PRINT((ndo, "\n\t%s Message (%#04x), originator %s, ttl %u, hop %u"
407 "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s",
408 tok2str(olsr_msg_values, "Unknown", msg_type),
409 msg_type, ipaddr_string(ndo, msgptr.v4->originator),
410 msgptr.v4->ttl,
411 msgptr.v4->hopcount,
412 ME_TO_DOUBLE(msgptr.v4->vtime),
413 EXTRACT_16BITS(msgptr.v4->msg_seq),
414 msg_len, (msg_len_valid == 0) ? " (invalid)" : ""));
415 if (!msg_len_valid) {
416 return;
417 }
418
419 msg_tlen = msg_len - sizeof(struct olsr_msg4);
420 msg_data = tptr + sizeof(struct olsr_msg4);
421 }
422
423 switch (msg_type) {
424 case OLSR_HELLO_MSG:
425 case OLSR_HELLO_LQ_MSG:
426 if (msg_tlen < sizeof(struct olsr_hello))
427 goto trunc;
428 ND_TCHECK2(*msg_data, sizeof(struct olsr_hello));
429
430 ptr.hello = (const struct olsr_hello *)msg_data;
431 ND_PRINT((ndo, "\n\t hello-time %.3fs, MPR willingness %u",
432 ME_TO_DOUBLE(ptr.hello->htime), ptr.hello->will));
433 msg_data += sizeof(struct olsr_hello);
434 msg_tlen -= sizeof(struct olsr_hello);
435
436 while (msg_tlen >= sizeof(struct olsr_hello_link)) {
437 int hello_len_valid = 0;
438
439 /*
440 * link-type.
441 */
442 ND_TCHECK2(*msg_data, sizeof(struct olsr_hello_link));
443
444 ptr.hello_link = (const struct olsr_hello_link *)msg_data;
445
446 hello_len = EXTRACT_16BITS(ptr.hello_link->len);
447 link_type = OLSR_EXTRACT_LINK_TYPE(ptr.hello_link->link_code);
448 neighbor_type = OLSR_EXTRACT_NEIGHBOR_TYPE(ptr.hello_link->link_code);
449
450 if ((hello_len <= msg_tlen)
451 && (hello_len >= sizeof(struct olsr_hello_link)))
452 hello_len_valid = 1;
453
454 ND_PRINT((ndo, "\n\t link-type %s, neighbor-type %s, len %u%s",
455 tok2str(olsr_link_type_values, "Unknown", link_type),
456 tok2str(olsr_neighbor_type_values, "Unknown", neighbor_type),
457 hello_len,
458 (hello_len_valid == 0) ? " (invalid)" : ""));
459
460 if (hello_len_valid == 0)
461 break;
462
463 msg_data += sizeof(struct olsr_hello_link);
464 msg_tlen -= sizeof(struct olsr_hello_link);
465 hello_len -= sizeof(struct olsr_hello_link);
466
467 ND_TCHECK2(*msg_data, hello_len);
468 if (msg_type == OLSR_HELLO_MSG) {
469 if (olsr_print_neighbor(ndo, msg_data, hello_len) == -1)
470 goto trunc;
471 } else {
472 if (is_ipv6) {
473 if (olsr_print_lq_neighbor6(ndo, msg_data, hello_len) == -1)
474 goto trunc;
475 } else {
476 if (olsr_print_lq_neighbor4(ndo, msg_data, hello_len) == -1)
477 goto trunc;
478 }
479 }
480
481 msg_data += hello_len;
482 msg_tlen -= hello_len;
483 }
484 break;
485
486 case OLSR_TC_MSG:
487 case OLSR_TC_LQ_MSG:
488 if (msg_tlen < sizeof(struct olsr_tc))
489 goto trunc;
490 ND_TCHECK2(*msg_data, sizeof(struct olsr_tc));
491
492 ptr.tc = (const struct olsr_tc *)msg_data;
493 ND_PRINT((ndo, "\n\t advertised neighbor seq 0x%04x",
494 EXTRACT_16BITS(ptr.tc->ans_seq)));
495 msg_data += sizeof(struct olsr_tc);
496 msg_tlen -= sizeof(struct olsr_tc);
497
498 if (msg_type == OLSR_TC_MSG) {
499 if (olsr_print_neighbor(ndo, msg_data, msg_tlen) == -1)
500 goto trunc;
501 } else {
502 if (is_ipv6) {
503 if (olsr_print_lq_neighbor6(ndo, msg_data, msg_tlen) == -1)
504 goto trunc;
505 } else {
506 if (olsr_print_lq_neighbor4(ndo, msg_data, msg_tlen) == -1)
507 goto trunc;
508 }
509 }
510 break;
511
512 case OLSR_MID_MSG:
513 {
514 size_t addr_size = sizeof(struct in_addr);
515
516 if (is_ipv6)
517 addr_size = sizeof(struct in6_addr);
518
519 while (msg_tlen >= addr_size) {
520 ND_TCHECK2(*msg_data, addr_size);
521 ND_PRINT((ndo, "\n\t interface address %s",
522 is_ipv6 ? ip6addr_string(ndo, msg_data) :
523 ipaddr_string(ndo, msg_data)));
524
525 msg_data += addr_size;
526 msg_tlen -= addr_size;
527 }
528 break;
529 }
530
531 case OLSR_HNA_MSG:
532 if (is_ipv6)
533 {
534 int i = 0;
535
536 ND_PRINT((ndo, "\n\t Advertised networks (total %u)",
537 (unsigned int) (msg_tlen / sizeof(struct olsr_hna6))));
538
539 while (msg_tlen >= sizeof(struct olsr_hna6)) {
540 const struct olsr_hna6 *hna6;
541
542 ND_TCHECK2(*msg_data, sizeof(struct olsr_hna6));
543
544 hna6 = (const struct olsr_hna6 *)msg_data;
545
546 ND_PRINT((ndo, "\n\t #%i: %s/%u",
547 i, ip6addr_string(ndo, hna6->network),
548 mask62plen (hna6->mask)));
549
550 msg_data += sizeof(struct olsr_hna6);
551 msg_tlen -= sizeof(struct olsr_hna6);
552 }
553 }
554 else
555 {
556 int col = 0;
557
558 ND_PRINT((ndo, "\n\t Advertised networks (total %u)",
559 (unsigned int) (msg_tlen / sizeof(struct olsr_hna4))));
560
561 while (msg_tlen >= sizeof(struct olsr_hna4)) {
562 ND_TCHECK2(*msg_data, sizeof(struct olsr_hna4));
563
564 ptr.hna = (const struct olsr_hna4 *)msg_data;
565
566 /* print 4 prefixes per line */
567 if (!ptr.hna->network[0] && !ptr.hna->network[1] &&
568 !ptr.hna->network[2] && !ptr.hna->network[3] &&
569 !ptr.hna->mask[GW_HNA_PAD] &&
570 ptr.hna->mask[GW_HNA_FLAGS]) {
571 /* smart gateway */
572 ND_PRINT((ndo, "%sSmart-Gateway:%s%s%s%s%s %u/%u",
573 col == 0 ? "\n\t " : ", ", /* indent */
574 /* sgw */
575 /* LINKSPEED */
576 (ptr.hna->mask[GW_HNA_FLAGS] &
577 GW_HNA_FLAG_LINKSPEED) ? " LINKSPEED" : "",
578 /* IPV4 */
579 (ptr.hna->mask[GW_HNA_FLAGS] &
580 GW_HNA_FLAG_IPV4) ? " IPV4" : "",
581 /* IPV4-NAT */
582 (ptr.hna->mask[GW_HNA_FLAGS] &
583 GW_HNA_FLAG_IPV4_NAT) ? " IPV4-NAT" : "",
584 /* IPV6 */
585 (ptr.hna->mask[GW_HNA_FLAGS] &
586 GW_HNA_FLAG_IPV6) ? " IPV6" : "",
587 /* IPv6PREFIX */
588 (ptr.hna->mask[GW_HNA_FLAGS] &
589 GW_HNA_FLAG_IPV6PREFIX) ? " IPv6-PREFIX" : "",
590 /* uplink */
591 (ptr.hna->mask[GW_HNA_FLAGS] &
592 GW_HNA_FLAG_LINKSPEED) ?
593 deserialize_gw_speed(ptr.hna->mask[GW_HNA_UPLINK]) : 0,
594 /* downlink */
595 (ptr.hna->mask[GW_HNA_FLAGS] &
596 GW_HNA_FLAG_LINKSPEED) ?
597 deserialize_gw_speed(ptr.hna->mask[GW_HNA_DOWNLINK]) : 0
598 ));
599 } else {
600 /* normal route */
601 ND_PRINT((ndo, "%s%s/%u",
602 col == 0 ? "\n\t " : ", ",
603 ipaddr_string(ndo, ptr.hna->network),
604 mask2plen(EXTRACT_32BITS(ptr.hna->mask))));
605 }
606
607 msg_data += sizeof(struct olsr_hna4);
608 msg_tlen -= sizeof(struct olsr_hna4);
609
610 col = (col + 1) % 4;
611 }
612 }
613 break;
614
615 case OLSR_NAMESERVICE_MSG:
616 {
617 u_int name_entries = EXTRACT_16BITS(msg_data+2);
618 u_int addr_size = 4;
619 int name_entries_valid = 0;
620 u_int i;
621
622 if (is_ipv6)
623 addr_size = 16;
624
625 if ((name_entries > 0)
626 && ((name_entries * (4 + addr_size)) <= msg_tlen))
627 name_entries_valid = 1;
628
629 if (msg_tlen < 4)
630 goto trunc;
631 ND_TCHECK2(*msg_data, 4);
632
633 ND_PRINT((ndo, "\n\t Version %u, Entries %u%s",
634 EXTRACT_16BITS(msg_data),
635 name_entries, (name_entries_valid == 0) ? " (invalid)" : ""));
636
637 if (name_entries_valid == 0)
638 break;
639
640 msg_data += 4;
641 msg_tlen -= 4;
642
643 for (i = 0; i < name_entries; i++) {
644 int name_entry_len_valid = 0;
645
646 if (msg_tlen < 4)
647 break;
648 ND_TCHECK2(*msg_data, 4);
649
650 name_entry_type = EXTRACT_16BITS(msg_data);
651 name_entry_len = EXTRACT_16BITS(msg_data+2);
652
653 msg_data += 4;
654 msg_tlen -= 4;
655
656 if ((name_entry_len > 0) && ((addr_size + name_entry_len) <= msg_tlen))
657 name_entry_len_valid = 1;
658
659 ND_PRINT((ndo, "\n\t #%u: type %#06x, length %u%s",
660 (unsigned int) i, name_entry_type,
661 name_entry_len, (name_entry_len_valid == 0) ? " (invalid)" : ""));
662
663 if (name_entry_len_valid == 0)
664 break;
665
666 /* 32-bit alignment */
667 name_entry_padding = 0;
668 if (name_entry_len%4 != 0)
669 name_entry_padding = 4-(name_entry_len%4);
670
671 if (msg_tlen < addr_size + name_entry_len + name_entry_padding)
672 goto trunc;
673
674 ND_TCHECK2(*msg_data, addr_size + name_entry_len + name_entry_padding);
675
676 if (is_ipv6)
677 ND_PRINT((ndo, ", address %s, name \"",
678 ip6addr_string(ndo, msg_data)));
679 else
680 ND_PRINT((ndo, ", address %s, name \"",
681 ipaddr_string(ndo, msg_data)));
682 (void)fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL);
683 ND_PRINT((ndo, "\""));
684
685 msg_data += addr_size + name_entry_len + name_entry_padding;
686 msg_tlen -= addr_size + name_entry_len + name_entry_padding;
687 } /* for (i = 0; i < name_entries; i++) */
688 break;
689 } /* case OLSR_NAMESERVICE_MSG */
690
691 /*
692 * FIXME those are the defined messages that lack a decoder
693 * you are welcome to contribute code ;-)
694 */
695 case OLSR_POWERINFO_MSG:
696 default:
697 print_unknown_data(ndo, msg_data, "\n\t ", msg_tlen);
698 break;
699 } /* switch (msg_type) */
700 tptr += msg_len;
701 } /* while (tptr < (pptr+length)) */
702
703 return;
704
705 trunc:
706 ND_PRINT((ndo, "[|olsr]"));
707 }
708
709 /*
710 * Local Variables:
711 * c-style: whitesmith
712 * c-basic-offset: 4
713 * End:
714 */