X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/568866ab384cea6a370bcbf1c811acb66dd72e97..6c8ef0eb86a39c277d1a43802dd8ea01b51cfb2a:/print-olsr.c diff --git a/print-olsr.c b/print-olsr.c index dfa09da4..e67988df 100644 --- a/print-olsr.c +++ b/print-olsr.c @@ -13,19 +13,21 @@ * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE. * - * Optimized Link State Protocl (OLSR) as per rfc3626 - * - * Original code by Hannes Gredler + * Original code by Hannes Gredler * IPv6 additions by Florian Forster */ +/* \summary: Optimized Link State Routing Protocol (OLSR) printer */ + +/* specification: RFC 3626 */ + #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include +#include -#include "interface.h" +#include "netdissect.h" #include "addrtoname.h" #include "extract.h" @@ -252,7 +254,6 @@ olsr_print_lq_neighbor4(netdissect_options *ndo, return (0); } -#if INET6 static int olsr_print_lq_neighbor6(netdissect_options *ndo, const u_char *msg_data, u_int hello_len) @@ -276,7 +277,6 @@ olsr_print_lq_neighbor6(netdissect_options *ndo, } return (0); } -#endif /* INET6 */ /* * print a neighbor list. @@ -359,11 +359,9 @@ olsr_print(netdissect_options *ndo, } msgptr; int msg_len_valid = 0; - ND_TCHECK2(*tptr, sizeof(struct olsr_msg4)); - -#if INET6 if (is_ipv6) { + ND_TCHECK2(*tptr, sizeof(struct olsr_msg6)); msgptr.v6 = (const struct olsr_msg6 *) tptr; msg_type = msgptr.v6->msg_type; msg_len = EXTRACT_16BITS(msgptr.v6->msg_len); @@ -393,8 +391,8 @@ olsr_print(netdissect_options *ndo, msg_data = tptr + sizeof(struct olsr_msg6); } else /* (!is_ipv6) */ -#endif /* INET6 */ { + ND_TCHECK2(*tptr, sizeof(struct olsr_msg4)); msgptr.v4 = (const struct olsr_msg4 *) tptr; msg_type = msgptr.v4->msg_type; msg_len = EXTRACT_16BITS(msgptr.v4->msg_len); @@ -473,13 +471,10 @@ olsr_print(netdissect_options *ndo, if (olsr_print_neighbor(ndo, msg_data, hello_len) == -1) goto trunc; } else { -#if INET6 if (is_ipv6) { if (olsr_print_lq_neighbor6(ndo, msg_data, hello_len) == -1) goto trunc; - } else -#endif - { + } else { if (olsr_print_lq_neighbor4(ndo, msg_data, hello_len) == -1) goto trunc; } @@ -506,13 +501,10 @@ olsr_print(netdissect_options *ndo, if (olsr_print_neighbor(ndo, msg_data, msg_tlen) == -1) goto trunc; } else { -#if INET6 if (is_ipv6) { if (olsr_print_lq_neighbor6(ndo, msg_data, msg_tlen) == -1) goto trunc; - } else -#endif - { + } else { if (olsr_print_lq_neighbor4(ndo, msg_data, msg_tlen) == -1) goto trunc; } @@ -523,21 +515,14 @@ olsr_print(netdissect_options *ndo, { size_t addr_size = sizeof(struct in_addr); -#if INET6 if (is_ipv6) addr_size = sizeof(struct in6_addr); -#endif while (msg_tlen >= addr_size) { ND_TCHECK2(*msg_data, addr_size); -#if INET6 ND_PRINT((ndo, "\n\t interface address %s", is_ipv6 ? ip6addr_string(ndo, msg_data) : ipaddr_string(ndo, msg_data))); -#else - ND_PRINT((ndo, "\n\t interface address %s", - ipaddr_string(ndo, msg_data))); -#endif msg_data += addr_size; msg_tlen -= addr_size; @@ -546,7 +531,6 @@ olsr_print(netdissect_options *ndo, } case OLSR_HNA_MSG: -#if INET6 if (is_ipv6) { int i = 0; @@ -570,7 +554,6 @@ olsr_print(netdissect_options *ndo, } } else -#endif { int col = 0; @@ -633,22 +616,25 @@ olsr_print(netdissect_options *ndo, case OLSR_NAMESERVICE_MSG: { - u_int name_entries = EXTRACT_16BITS(msg_data+2); - u_int addr_size = 4; - int name_entries_valid = 0; + u_int name_entries; + u_int addr_size; + int name_entries_valid; u_int i; + if (msg_tlen < 4) + goto trunc; + ND_TCHECK2(*msg_data, 4); + + name_entries = EXTRACT_16BITS(msg_data+2); + addr_size = 4; if (is_ipv6) addr_size = 16; + name_entries_valid = 0; if ((name_entries > 0) && ((name_entries * (4 + addr_size)) <= msg_tlen)) name_entries_valid = 1; - if (msg_tlen < 4) - goto trunc; - ND_TCHECK2(*msg_data, 4); - ND_PRINT((ndo, "\n\t Version %u, Entries %u%s", EXTRACT_16BITS(msg_data), name_entries, (name_entries_valid == 0) ? " (invalid)" : "")); @@ -692,12 +678,10 @@ olsr_print(netdissect_options *ndo, ND_TCHECK2(*msg_data, addr_size + name_entry_len + name_entry_padding); -#if INET6 if (is_ipv6) ND_PRINT((ndo, ", address %s, name \"", ip6addr_string(ndo, msg_data))); else -#endif ND_PRINT((ndo, ", address %s, name \"", ipaddr_string(ndo, msg_data))); (void)fn_printn(ndo, msg_data + addr_size, name_entry_len, NULL);