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