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 |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 25 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #endif |
| 27 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 66 | nd_uint16_t packet_len; |
| 67 | nd_uint16_t packet_seq; |
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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 92 | nd_uint8_t msg_type; |
| 93 | nd_uint8_t vtime; |
| 94 | nd_uint16_t msg_len; |
| 95 | nd_ipv4 originator; |
| 96 | nd_uint8_t ttl; |
| 97 | nd_uint8_t hopcount; |
| 98 | nd_uint16_t msg_seq; |
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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 102 | nd_uint8_t msg_type; |
| 103 | nd_uint8_t vtime; |
| 104 | nd_uint16_t msg_len; |
| 105 | nd_ipv6 originator; |
| 106 | nd_uint8_t ttl; |
| 107 | nd_uint8_t hopcount; |
| 108 | nd_uint16_t msg_seq; |
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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 112 | nd_byte res[2]; |
| 113 | nd_uint8_t htime; |
| 114 | nd_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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 118 | nd_uint8_t link_code; |
| 119 | nd_byte res; |
| 120 | nd_uint16_t len; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | struct olsr_tc { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 124 | nd_uint16_t ans_seq; |
| 125 | nd_byte 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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 129 | nd_ipv4 network; |
| 130 | nd_ipv4 mask; |
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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 134 | nd_ipv6 network; |
| 135 | nd_ipv6 mask; |
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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 178 | nd_ipv4 neighbor; |
| 179 | nd_uint8_t link_quality; |
| 180 | nd_uint8_t neighbor_link_quality; |
| 181 | nd_byte 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 | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 185 | nd_ipv6 neighbor; |
| 186 | nd_uint8_t link_quality; |
| 187 | nd_uint8_t neighbor_link_quality; |
| 188 | nd_byte 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 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 216 | while (exp != 0) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 217 | speed *= 10; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 218 | exp--; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 219 | } |
| 220 | return speed; |
| 221 | } |
| 222 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 223 | /* |
| 224 | * macro to convert the 8-bit mantissa/exponent to a double float |
| 225 | * taken from olsr.org. |
| 226 | */ |
| 227 | #define VTIME_SCALE_FACTOR 0.0625 |
| 228 | #define ME_TO_DOUBLE(me) \ |
| 229 | (double)(VTIME_SCALE_FACTOR*(1+(double)(me>>4)/16)*(double)(1<<(me&0x0F))) |
| 230 | |
| 231 | /* |
| 232 | * print a neighbor list with LQ extensions. |
| 233 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 234 | static int |
| 235 | olsr_print_lq_neighbor4(netdissect_options *ndo, |
| 236 | const u_char *msg_data, u_int hello_len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 237 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 238 | const struct olsr_lq_neighbor4 *lq_neighbor; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 239 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 240 | while (hello_len >= sizeof(struct olsr_lq_neighbor4)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 241 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 242 | lq_neighbor = (const struct olsr_lq_neighbor4 *)msg_data; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 243 | ND_TCHECK_SIZE(lq_neighbor); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 244 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 245 | ND_PRINT("\n\t neighbor %s, link-quality %.2f%%" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 246 | ", neighbor-link-quality %.2f%%", |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 247 | GET_IPADDR_STRING(lq_neighbor->neighbor), |
| 248 | ((double) GET_U_1(lq_neighbor->link_quality)/2.55), |
| 249 | ((double) GET_U_1(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); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 255 | trunc: |
| 256 | return -1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 259 | static int |
| 260 | olsr_print_lq_neighbor6(netdissect_options *ndo, |
| 261 | const u_char *msg_data, u_int hello_len) |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 262 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 263 | const struct olsr_lq_neighbor6 *lq_neighbor; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 264 | |
| 265 | while (hello_len >= sizeof(struct olsr_lq_neighbor6)) { |
| 266 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 267 | lq_neighbor = (const struct olsr_lq_neighbor6 *)msg_data; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 268 | ND_TCHECK_SIZE(lq_neighbor); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 269 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 270 | ND_PRINT("\n\t neighbor %s, link-quality %.2f%%" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 271 | ", neighbor-link-quality %.2f%%", |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 272 | GET_IP6ADDR_STRING(lq_neighbor->neighbor), |
| 273 | ((double) GET_U_1(lq_neighbor->link_quality)/2.55), |
| 274 | ((double) GET_U_1(lq_neighbor->neighbor_link_quality)/2.55)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 275 | |
| 276 | msg_data += sizeof(struct olsr_lq_neighbor6); |
| 277 | hello_len -= sizeof(struct olsr_lq_neighbor6); |
| 278 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 279 | return (0); |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 280 | trunc: |
| 281 | return -1; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 282 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 283 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 284 | /* |
| 285 | * print a neighbor list. |
| 286 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 287 | static int |
| 288 | olsr_print_neighbor(netdissect_options *ndo, |
| 289 | const u_char *msg_data, u_int hello_len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 290 | { |
| 291 | int neighbor; |
| 292 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 293 | ND_PRINT("\n\t neighbor\n\t\t"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 294 | neighbor = 1; |
| 295 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 296 | while (hello_len >= sizeof(nd_ipv4)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 297 | /* print 4 neighbors per line */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 298 | ND_PRINT("%s%s", GET_IPADDR_STRING(msg_data), |
| 299 | neighbor % 4 == 0 ? "\n\t\t" : " "); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 300 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 301 | msg_data += sizeof(nd_ipv4); |
| 302 | hello_len -= sizeof(nd_ipv4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 303 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 304 | return (0); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | |
| 308 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 309 | olsr_print(netdissect_options *ndo, |
| 310 | 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] | 311 | { |
| 312 | union { |
| 313 | const struct olsr_common *common; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 314 | const struct olsr_msg4 *msg4; |
| 315 | const struct olsr_msg6 *msg6; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 316 | const struct olsr_hello *hello; |
| 317 | const struct olsr_hello_link *hello_link; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 318 | const struct olsr_tc *tc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 319 | const struct olsr_hna4 *hna; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 320 | } ptr; |
| 321 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 322 | u_int msg_type, msg_len, msg_tlen, hello_len; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 323 | uint16_t name_entry_type, name_entry_len; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 324 | u_int name_entry_padding; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 325 | uint8_t link_type, neighbor_type; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 326 | const u_char *tptr, *msg_data; |
| 327 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 328 | ndo->ndo_protocol = "olsr"; |
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 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 331 | nd_print_protocol_caps(ndo); |
| 332 | ND_PRINT("v%u", (is_ipv6) ? 6 : 4); |
| 333 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 334 | if (length < sizeof(struct olsr_common)) { |
| 335 | goto trunc; |
| 336 | } |
| 337 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 338 | ND_TCHECK_LEN(tptr, sizeof(struct olsr_common)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 339 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 340 | ptr.common = (const struct olsr_common *)tptr; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 341 | length = ND_MIN(length, GET_BE_U_2(ptr.common->packet_len)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 342 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 343 | ND_PRINT(", seq 0x%04x, length %u", |
| 344 | GET_BE_U_2(ptr.common->packet_seq), |
| 345 | length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 346 | |
| 347 | tptr += sizeof(struct olsr_common); |
| 348 | |
| 349 | /* |
| 350 | * In non-verbose mode, just print version. |
| 351 | */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 352 | if (ndo->ndo_vflag < 1) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 353 | return; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | while (tptr < (pptr+length)) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 357 | union |
| 358 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 359 | const struct olsr_msg4 *v4; |
| 360 | const struct olsr_msg6 *v6; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 361 | } msgptr; |
| 362 | int msg_len_valid = 0; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 363 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 364 | if (is_ipv6) |
| 365 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 366 | ND_TCHECK_LEN(tptr, sizeof(struct olsr_msg6)); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 367 | msgptr.v6 = (const struct olsr_msg6 *) tptr; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 368 | msg_type = GET_U_1(msgptr.v6->msg_type); |
| 369 | msg_len = GET_BE_U_2(msgptr.v6->msg_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 370 | if ((msg_len >= sizeof (struct olsr_msg6)) |
| 371 | && (msg_len <= length)) |
| 372 | msg_len_valid = 1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 373 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 374 | /* infinite loop check */ |
| 375 | if (msg_type == 0 || msg_len == 0) { |
| 376 | return; |
| 377 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 378 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 379 | ND_PRINT("\n\t%s Message (%#04x), originator %s, ttl %u, hop %u" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 380 | "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 381 | tok2str(olsr_msg_values, "Unknown", msg_type), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 382 | msg_type, GET_IP6ADDR_STRING(msgptr.v6->originator), |
| 383 | GET_U_1(msgptr.v6->ttl), |
| 384 | GET_U_1(msgptr.v6->hopcount), |
| 385 | ME_TO_DOUBLE(GET_U_1(msgptr.v6->vtime)), |
| 386 | GET_BE_U_2(msgptr.v6->msg_seq), |
| 387 | msg_len, (msg_len_valid == 0) ? " (invalid)" : ""); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 388 | if (!msg_len_valid) { |
| 389 | return; |
| 390 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 391 | |
| 392 | msg_tlen = msg_len - sizeof(struct olsr_msg6); |
| 393 | msg_data = tptr + sizeof(struct olsr_msg6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 394 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 395 | else /* (!is_ipv6) */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 396 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 397 | ND_TCHECK_LEN(tptr, sizeof(struct olsr_msg4)); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 398 | msgptr.v4 = (const struct olsr_msg4 *) tptr; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 399 | msg_type = GET_U_1(msgptr.v4->msg_type); |
| 400 | msg_len = GET_BE_U_2(msgptr.v4->msg_len); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 401 | if ((msg_len >= sizeof (struct olsr_msg4)) |
| 402 | && (msg_len <= length)) |
| 403 | msg_len_valid = 1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 404 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 405 | /* infinite loop check */ |
| 406 | if (msg_type == 0 || msg_len == 0) { |
| 407 | return; |
| 408 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 409 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 410 | ND_PRINT("\n\t%s Message (%#04x), originator %s, ttl %u, hop %u" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 411 | "\n\t vtime %.3fs, msg-seq 0x%04x, length %u%s", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 412 | tok2str(olsr_msg_values, "Unknown", msg_type), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 413 | msg_type, GET_IPADDR_STRING(msgptr.v4->originator), |
| 414 | GET_U_1(msgptr.v4->ttl), |
| 415 | GET_U_1(msgptr.v4->hopcount), |
| 416 | ME_TO_DOUBLE(GET_U_1(msgptr.v4->vtime)), |
| 417 | GET_BE_U_2(msgptr.v4->msg_seq), |
| 418 | msg_len, (msg_len_valid == 0) ? " (invalid)" : ""); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 419 | if (!msg_len_valid) { |
| 420 | return; |
| 421 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 422 | |
| 423 | msg_tlen = msg_len - sizeof(struct olsr_msg4); |
| 424 | msg_data = tptr + sizeof(struct olsr_msg4); |
| 425 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 426 | |
| 427 | switch (msg_type) { |
| 428 | case OLSR_HELLO_MSG: |
| 429 | case OLSR_HELLO_LQ_MSG: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 430 | if (msg_tlen < sizeof(struct olsr_hello)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 431 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 432 | ND_TCHECK_LEN(msg_data, sizeof(struct olsr_hello)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 433 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 434 | ptr.hello = (const struct olsr_hello *)msg_data; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 435 | ND_PRINT("\n\t hello-time %.3fs, MPR willingness %u", |
| 436 | ME_TO_DOUBLE(GET_U_1(ptr.hello->htime)), |
| 437 | GET_U_1(ptr.hello->will)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 438 | msg_data += sizeof(struct olsr_hello); |
| 439 | msg_tlen -= sizeof(struct olsr_hello); |
| 440 | |
| 441 | while (msg_tlen >= sizeof(struct olsr_hello_link)) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 442 | int hello_len_valid = 0; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 443 | |
| 444 | /* |
| 445 | * link-type. |
| 446 | */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 447 | ND_TCHECK_LEN(msg_data, sizeof(struct olsr_hello_link)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 448 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 449 | 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] | 450 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 451 | hello_len = GET_BE_U_2(ptr.hello_link->len); |
| 452 | link_type = OLSR_EXTRACT_LINK_TYPE(GET_U_1(ptr.hello_link->link_code)); |
| 453 | neighbor_type = OLSR_EXTRACT_NEIGHBOR_TYPE(GET_U_1(ptr.hello_link->link_code)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 454 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 455 | if ((hello_len <= msg_tlen) |
| 456 | && (hello_len >= sizeof(struct olsr_hello_link))) |
| 457 | hello_len_valid = 1; |
| 458 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 459 | ND_PRINT("\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] | 460 | tok2str(olsr_link_type_values, "Unknown", link_type), |
| 461 | tok2str(olsr_neighbor_type_values, "Unknown", neighbor_type), |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 462 | hello_len, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 463 | (hello_len_valid == 0) ? " (invalid)" : ""); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 464 | |
| 465 | if (hello_len_valid == 0) |
| 466 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 467 | |
| 468 | msg_data += sizeof(struct olsr_hello_link); |
| 469 | msg_tlen -= sizeof(struct olsr_hello_link); |
| 470 | hello_len -= sizeof(struct olsr_hello_link); |
| 471 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 472 | ND_TCHECK_LEN(msg_data, hello_len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 473 | if (msg_type == OLSR_HELLO_MSG) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 474 | if (olsr_print_neighbor(ndo, msg_data, hello_len) == -1) |
| 475 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 476 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 477 | if (is_ipv6) { |
| 478 | if (olsr_print_lq_neighbor6(ndo, msg_data, hello_len) == -1) |
| 479 | goto trunc; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 480 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 481 | if (olsr_print_lq_neighbor4(ndo, msg_data, hello_len) == -1) |
| 482 | goto trunc; |
| 483 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | msg_data += hello_len; |
| 487 | msg_tlen -= hello_len; |
| 488 | } |
| 489 | break; |
| 490 | |
| 491 | case OLSR_TC_MSG: |
| 492 | case OLSR_TC_LQ_MSG: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 493 | if (msg_tlen < sizeof(struct olsr_tc)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 494 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 495 | ND_TCHECK_LEN(msg_data, sizeof(struct olsr_tc)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 496 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 497 | ptr.tc = (const struct olsr_tc *)msg_data; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 498 | ND_PRINT("\n\t advertised neighbor seq 0x%04x", |
| 499 | GET_BE_U_2(ptr.tc->ans_seq)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 500 | msg_data += sizeof(struct olsr_tc); |
| 501 | msg_tlen -= sizeof(struct olsr_tc); |
| 502 | |
| 503 | if (msg_type == OLSR_TC_MSG) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 504 | if (olsr_print_neighbor(ndo, msg_data, msg_tlen) == -1) |
| 505 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 506 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 507 | if (is_ipv6) { |
| 508 | if (olsr_print_lq_neighbor6(ndo, msg_data, msg_tlen) == -1) |
| 509 | goto trunc; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 510 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 511 | if (olsr_print_lq_neighbor4(ndo, msg_data, msg_tlen) == -1) |
| 512 | goto trunc; |
| 513 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 514 | } |
| 515 | break; |
| 516 | |
| 517 | case OLSR_MID_MSG: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 518 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 519 | u_int addr_size = (u_int)sizeof(nd_ipv4); |
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 | if (is_ipv6) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 522 | addr_size = (u_int)sizeof(nd_ipv6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 523 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 524 | while (msg_tlen >= addr_size) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 525 | ND_TCHECK_LEN(msg_data, addr_size); |
| 526 | ND_PRINT("\n\t interface address %s", |
| 527 | is_ipv6 ? GET_IP6ADDR_STRING(msg_data) : |
| 528 | GET_IPADDR_STRING(msg_data)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 529 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 530 | msg_data += addr_size; |
| 531 | msg_tlen -= addr_size; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 532 | } |
| 533 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | case OLSR_HNA_MSG: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 537 | if (is_ipv6) |
| 538 | { |
| 539 | int i = 0; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 540 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 541 | ND_PRINT("\n\t Advertised networks (total %u)", |
| 542 | (unsigned int) (msg_tlen / sizeof(struct olsr_hna6))); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 543 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 544 | while (msg_tlen >= sizeof(struct olsr_hna6)) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 545 | const struct olsr_hna6 *hna6; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 546 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 547 | ND_TCHECK_LEN(msg_data, sizeof(struct olsr_hna6)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 548 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 549 | hna6 = (const struct olsr_hna6 *)msg_data; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 550 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 551 | ND_PRINT("\n\t #%i: %s/%u", |
| 552 | i, GET_IP6ADDR_STRING(hna6->network), |
| 553 | mask62plen (hna6->mask)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 554 | |
| 555 | msg_data += sizeof(struct olsr_hna6); |
| 556 | msg_tlen -= sizeof(struct olsr_hna6); |
| 557 | } |
| 558 | } |
| 559 | else |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 560 | { |
| 561 | int col = 0; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 562 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 563 | ND_PRINT("\n\t Advertised networks (total %u)", |
| 564 | (unsigned int) (msg_tlen / sizeof(struct olsr_hna4))); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 565 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 566 | while (msg_tlen >= sizeof(struct olsr_hna4)) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 567 | ND_TCHECK_LEN(msg_data, sizeof(struct olsr_hna4)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 568 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 569 | ptr.hna = (const struct olsr_hna4 *)msg_data; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 570 | |
| 571 | /* print 4 prefixes per line */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 572 | if (!ptr.hna->network[0] && !ptr.hna->network[1] && |
| 573 | !ptr.hna->network[2] && !ptr.hna->network[3] && |
| 574 | !ptr.hna->mask[GW_HNA_PAD] && |
| 575 | ptr.hna->mask[GW_HNA_FLAGS]) { |
| 576 | /* smart gateway */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 577 | ND_PRINT("%sSmart-Gateway:%s%s%s%s%s %u/%u", |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 578 | col == 0 ? "\n\t " : ", ", /* indent */ |
| 579 | /* sgw */ |
| 580 | /* LINKSPEED */ |
| 581 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 582 | GW_HNA_FLAG_LINKSPEED) ? " LINKSPEED" : "", |
| 583 | /* IPV4 */ |
| 584 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 585 | GW_HNA_FLAG_IPV4) ? " IPV4" : "", |
| 586 | /* IPV4-NAT */ |
| 587 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 588 | GW_HNA_FLAG_IPV4_NAT) ? " IPV4-NAT" : "", |
| 589 | /* IPV6 */ |
| 590 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 591 | GW_HNA_FLAG_IPV6) ? " IPV6" : "", |
| 592 | /* IPv6PREFIX */ |
| 593 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 594 | GW_HNA_FLAG_IPV6PREFIX) ? " IPv6-PREFIX" : "", |
| 595 | /* uplink */ |
| 596 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 597 | GW_HNA_FLAG_LINKSPEED) ? |
| 598 | deserialize_gw_speed(ptr.hna->mask[GW_HNA_UPLINK]) : 0, |
| 599 | /* downlink */ |
| 600 | (ptr.hna->mask[GW_HNA_FLAGS] & |
| 601 | GW_HNA_FLAG_LINKSPEED) ? |
| 602 | deserialize_gw_speed(ptr.hna->mask[GW_HNA_DOWNLINK]) : 0 |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 603 | ); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 604 | } else { |
| 605 | /* normal route */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 606 | ND_PRINT("%s%s/%u", |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 607 | col == 0 ? "\n\t " : ", ", |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 608 | GET_IPADDR_STRING(ptr.hna->network), |
| 609 | mask2plen(GET_BE_U_4(ptr.hna->mask))); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 610 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 611 | |
| 612 | msg_data += sizeof(struct olsr_hna4); |
| 613 | msg_tlen -= sizeof(struct olsr_hna4); |
| 614 | |
| 615 | col = (col + 1) % 4; |
| 616 | } |
| 617 | } |
| 618 | break; |
| 619 | |
| 620 | case OLSR_NAMESERVICE_MSG: |
| 621 | { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 622 | u_int name_entries; |
| 623 | u_int addr_size; |
| 624 | int name_entries_valid; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 625 | u_int i; |
| 626 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 627 | if (msg_tlen < 4) |
| 628 | goto trunc; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 629 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 630 | name_entries = GET_BE_U_2(msg_data + 2); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 631 | addr_size = 4; |
| 632 | if (is_ipv6) |
| 633 | addr_size = 16; |
| 634 | |
| 635 | name_entries_valid = 0; |
| 636 | if ((name_entries > 0) |
| 637 | && ((name_entries * (4 + addr_size)) <= msg_tlen)) |
| 638 | name_entries_valid = 1; |
| 639 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 640 | ND_PRINT("\n\t Version %u, Entries %u%s", |
| 641 | GET_BE_U_2(msg_data), |
| 642 | name_entries, (name_entries_valid == 0) ? " (invalid)" : ""); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 643 | |
| 644 | if (name_entries_valid == 0) |
| 645 | break; |
| 646 | |
| 647 | msg_data += 4; |
| 648 | msg_tlen -= 4; |
| 649 | |
| 650 | for (i = 0; i < name_entries; i++) { |
| 651 | int name_entry_len_valid = 0; |
| 652 | |
| 653 | if (msg_tlen < 4) |
| 654 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 655 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 656 | name_entry_type = GET_BE_U_2(msg_data); |
| 657 | name_entry_len = GET_BE_U_2(msg_data + 2); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 658 | |
| 659 | msg_data += 4; |
| 660 | msg_tlen -= 4; |
| 661 | |
| 662 | if ((name_entry_len > 0) && ((addr_size + name_entry_len) <= msg_tlen)) |
| 663 | name_entry_len_valid = 1; |
| 664 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 665 | ND_PRINT("\n\t #%u: type %#06x, length %u%s", |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 666 | (unsigned int) i, name_entry_type, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 667 | name_entry_len, (name_entry_len_valid == 0) ? " (invalid)" : ""); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 668 | |
| 669 | if (name_entry_len_valid == 0) |
| 670 | break; |
| 671 | |
| 672 | /* 32-bit alignment */ |
| 673 | name_entry_padding = 0; |
| 674 | if (name_entry_len%4 != 0) |
| 675 | name_entry_padding = 4-(name_entry_len%4); |
| 676 | |
| 677 | if (msg_tlen < addr_size + name_entry_len + name_entry_padding) |
| 678 | goto trunc; |
| 679 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 680 | ND_TCHECK_LEN(msg_data, |
| 681 | addr_size + name_entry_len + name_entry_padding); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 682 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 683 | if (is_ipv6) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 684 | ND_PRINT(", address %s, name \"", |
| 685 | GET_IP6ADDR_STRING(msg_data)); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 686 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 687 | ND_PRINT(", address %s, name \"", |
| 688 | GET_IPADDR_STRING(msg_data)); |
| 689 | (void)nd_printn(ndo, msg_data + addr_size, name_entry_len, NULL); |
| 690 | ND_PRINT("\""); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 691 | |
| 692 | msg_data += addr_size + name_entry_len + name_entry_padding; |
| 693 | msg_tlen -= addr_size + name_entry_len + name_entry_padding; |
| 694 | } /* for (i = 0; i < name_entries; i++) */ |
| 695 | break; |
| 696 | } /* case OLSR_NAMESERVICE_MSG */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 697 | |
| 698 | /* |
| 699 | * FIXME those are the defined messages that lack a decoder |
| 700 | * you are welcome to contribute code ;-) |
| 701 | */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 702 | case OLSR_POWERINFO_MSG: |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 703 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 704 | 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] | 705 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 706 | } /* switch (msg_type) */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 707 | tptr += msg_len; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 708 | } /* while (tptr < (pptr+length)) */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 709 | |
| 710 | return; |
| 711 | |
| 712 | trunc: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 713 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 714 | } |