1 /* 2 * Copyright (c) 2007-2011 Grégoire Henry, Juliusz Chroboczek 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 3. Neither the name of the project nor the names of its contributors 13 * may be used to endorse or promote products derived from this software 14 * without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 #ifndef lint 31 __RCSID("$NetBSD: print-babel.c,v 1.6 2024/09/02 16:15:30 christos Exp $"); 32 #endif 33 34 /* \summary: Babel Routing Protocol printer */ 35 /* Specifications: 36 * 37 * RFC 6126 38 * RFC 7298 39 * RFC 7557 40 * draft-ietf-babel-rfc6126bis-17 41 * draft-ietf-babel-hmac-10 42 * draft-ietf-babel-source-specific-0 43 */ 44 45 #include <config.h> 46 47 #include "netdissect-stdinc.h" 48 49 #include <stdio.h> 50 #include <string.h> 51 52 #include "netdissect.h" 53 #include "addrtoname.h" 54 #include "extract.h" 55 56 static void babel_print_v2(netdissect_options *, const u_char *cp, u_int length); 57 58 void 59 babel_print(netdissect_options *ndo, 60 const u_char *cp, u_int length) 61 { 62 ndo->ndo_protocol = "babel"; 63 ND_PRINT("babel"); 64 65 ND_TCHECK_4(cp); 66 67 if(GET_U_1(cp) != 42) { 68 ND_PRINT(" invalid header"); 69 return; 70 } else { 71 ND_PRINT(" %u", GET_U_1(cp + 1)); 72 } 73 74 switch(GET_U_1(cp + 1)) { 75 case 2: 76 babel_print_v2(ndo, cp, length); 77 break; 78 default: 79 ND_PRINT(" unknown version"); 80 break; 81 } 82 83 return; 84 85 trunc: 86 nd_print_trunc(ndo); 87 } 88 89 /* TLVs */ 90 #define MESSAGE_PAD1 0 91 #define MESSAGE_PADN 1 92 #define MESSAGE_ACK_REQ 2 93 #define MESSAGE_ACK 3 94 #define MESSAGE_HELLO 4 95 #define MESSAGE_IHU 5 96 #define MESSAGE_ROUTER_ID 6 97 #define MESSAGE_NH 7 98 #define MESSAGE_UPDATE 8 99 #define MESSAGE_ROUTE_REQUEST 9 100 #define MESSAGE_SEQNO_REQUEST 10 101 #define MESSAGE_TSPC 11 102 #define MESSAGE_HMAC 12 103 #define MESSAGE_UPDATE_SRC_SPECIFIC 13 /* last appearance in draft-boutier-babel-source-specific-01 */ 104 #define MESSAGE_REQUEST_SRC_SPECIFIC 14 /* idem */ 105 #define MESSAGE_MH_REQUEST_SRC_SPECIFIC 15 /* idem */ 106 #define MESSAGE_MAC 16 107 #define MESSAGE_PC 17 108 #define MESSAGE_CHALLENGE_REQUEST 18 109 #define MESSAGE_CHALLENGE_REPLY 19 110 111 /* sub-TLVs */ 112 #define MESSAGE_SUB_PAD1 0 113 #define MESSAGE_SUB_PADN 1 114 #define MESSAGE_SUB_DIVERSITY 2 115 #define MESSAGE_SUB_TIMESTAMP 3 116 117 /* "Mandatory" bit in sub-TLV types */ 118 #define MANDATORY_MASK 0x80 119 120 /* Flags for the Hello TLV */ 121 #define UNICAST_MASK 0x8000 122 123 /* Diversity sub-TLV channel codes */ 124 static const struct tok diversity_str[] = { 125 { 0, "reserved" }, 126 { 255, "all" }, 127 { 0, NULL } 128 }; 129 130 static const char * 131 format_id(netdissect_options *ndo, const u_char *id) 132 { 133 static char buf[25]; 134 snprintf(buf, 25, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", 135 GET_U_1(id), GET_U_1(id + 1), GET_U_1(id + 2), 136 GET_U_1(id + 3), GET_U_1(id + 4), GET_U_1(id + 5), 137 GET_U_1(id + 6), GET_U_1(id + 7)); 138 buf[24] = '\0'; 139 return buf; 140 } 141 142 static const unsigned char v4prefix[16] = 143 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }; 144 145 static const char * 146 format_prefix(netdissect_options *ndo, const u_char *prefix, unsigned char plen) 147 { 148 static char buf[50]; 149 150 /* 151 * prefix points to a buffer on the stack into which the prefix has 152 * been placed, so we can't use GET_IPADDR_STRING() or 153 * GET_IP6ADDR_STRING() on it. 154 */ 155 if(plen >= 96 && memcmp(prefix, v4prefix, 12) == 0) 156 snprintf(buf, 50, "%s/%u", ipaddr_string(ndo, prefix + 12), plen - 96); 157 else 158 snprintf(buf, 50, "%s/%u", ip6addr_string(ndo, prefix), plen); 159 buf[49] = '\0'; 160 return buf; 161 } 162 163 static const char * 164 format_address(netdissect_options *ndo, const u_char *prefix) 165 { 166 /* 167 * prefix points to a buffer on the stack into which the prefix has 168 * been placed, so we can't use GET_IPADDR_STRING() or 169 * GET_IP6ADDR_STRING() on it. 170 */ 171 if(memcmp(prefix, v4prefix, 12) == 0) 172 return ipaddr_string(ndo, prefix + 12); 173 else 174 return ip6addr_string(ndo, prefix); 175 } 176 177 static const char * 178 format_interval(const uint16_t i) 179 { 180 static char buf[sizeof("000.00s")]; 181 182 if (i == 0) 183 return "0.0s (bogus)"; 184 snprintf(buf, sizeof(buf), "%u.%02us", i / 100, i % 100); 185 return buf; 186 } 187 188 static const char * 189 format_interval_update(const uint16_t i) 190 { 191 return i == 0xFFFF ? "infinity" : format_interval(i); 192 } 193 194 static const char * 195 format_timestamp(const uint32_t i) 196 { 197 static char buf[sizeof("0000.000000s")]; 198 snprintf(buf, sizeof(buf), "%u.%06us", i / 1000000, i % 1000000); 199 return buf; 200 } 201 202 /* Return number of octets consumed from the input buffer (not the prefix length 203 * in bytes), or -1 for encoding error. */ 204 static int 205 network_prefix(int ae, int plen, unsigned int omitted, 206 const unsigned char *p, const unsigned char *dp, 207 unsigned int len, unsigned char *p_r) 208 { 209 unsigned pb; 210 unsigned char prefix[16]; 211 int consumed = 0; 212 213 if(plen >= 0) 214 pb = (plen + 7) / 8; 215 else if(ae == 1) 216 pb = 4; 217 else 218 pb = 16; 219 220 if(pb > 16) 221 return -1; 222 223 memset(prefix, 0, 16); 224 225 switch(ae) { 226 case 0: break; 227 case 1: 228 if(omitted > 4 || pb > 4 || (pb > omitted && len < pb - omitted)) 229 return -1; 230 memcpy(prefix, v4prefix, 12); 231 if(omitted) { 232 if (dp == NULL) return -1; 233 memcpy(prefix, dp, 12 + omitted); 234 } 235 if(pb > omitted) { 236 memcpy(prefix + 12 + omitted, p, pb - omitted); 237 consumed = pb - omitted; 238 } 239 break; 240 case 2: 241 if(omitted > 16 || (pb > omitted && len < pb - omitted)) 242 return -1; 243 if(omitted) { 244 if (dp == NULL) return -1; 245 memcpy(prefix, dp, omitted); 246 } 247 if(pb > omitted) { 248 memcpy(prefix + omitted, p, pb - omitted); 249 consumed = pb - omitted; 250 } 251 break; 252 case 3: 253 if(pb > 8 && len < pb - 8) return -1; 254 prefix[0] = 0xfe; 255 prefix[1] = 0x80; 256 if(pb > 8) { 257 memcpy(prefix + 8, p, pb - 8); 258 consumed = pb - 8; 259 } 260 break; 261 default: 262 return -1; 263 } 264 265 memcpy(p_r, prefix, 16); 266 return consumed; 267 } 268 269 static int 270 network_address(int ae, const unsigned char *a, unsigned int len, 271 unsigned char *a_r) 272 { 273 return network_prefix(ae, -1, 0, a, NULL, len, a_r); 274 } 275 276 /* 277 * Sub-TLVs consume the "extra data" of Babel TLVs (see Section 4.3 of RFC6126), 278 * their encoding is similar to the encoding of TLVs, but the type namespace is 279 * different: 280 * 281 * o Type 0 stands for Pad1 sub-TLV with the same encoding as the Pad1 TLV. 282 * o Type 1 stands for PadN sub-TLV with the same encoding as the PadN TLV. 283 * o Type 2 stands for Diversity sub-TLV, which propagates diversity routing 284 * data. Its body is a variable-length sequence of 8-bit unsigned integers, 285 * each representing per-hop number of interfering radio channel for the 286 * prefix. Channel 0 is invalid and must not be used in the sub-TLV, channel 287 * 255 interferes with any other channel. 288 * o Type 3 stands for Timestamp sub-TLV, used to compute RTT between 289 * neighbours. In the case of a Hello TLV, the body stores a 32-bits 290 * timestamp, while in the case of a IHU TLV, two 32-bits timestamps are 291 * stored. 292 * 293 * Sub-TLV types 0 and 1 are valid for any TLV type, whether sub-TLV type 2 is 294 * only valid for TLV type 8 (Update). Note that within an Update TLV a missing 295 * Diversity sub-TLV is not the same as a Diversity sub-TLV with an empty body. 296 * The former would mean a lack of any claims about the interference, and the 297 * latter would state that interference is definitely absent. 298 * A type 3 sub-TLV is valid both for Hello and IHU TLVs, though the exact 299 * semantic of the sub-TLV is different in each case. 300 */ 301 static void 302 subtlvs_print(netdissect_options *ndo, 303 const u_char *cp, const u_char *ep, const uint8_t tlv_type) 304 { 305 uint8_t subtype, sublen; 306 const char *sep; 307 uint32_t t1, t2; 308 309 while (cp < ep) { 310 subtype = GET_U_1(cp); 311 cp++; 312 if(subtype == MESSAGE_SUB_PAD1) { 313 ND_PRINT(" sub-pad1"); 314 continue; 315 } 316 if ((MANDATORY_MASK & subtype) != 0) 317 ND_PRINT(" (M)"); 318 if(cp == ep) 319 goto invalid; 320 sublen = GET_U_1(cp); 321 cp++; 322 if(cp + sublen > ep) 323 goto invalid; 324 325 switch(subtype) { 326 case MESSAGE_SUB_PADN: 327 ND_PRINT(" sub-padn"); 328 cp += sublen; 329 break; 330 case MESSAGE_SUB_DIVERSITY: 331 ND_PRINT(" sub-diversity"); 332 if (sublen == 0) { 333 ND_PRINT(" empty"); 334 break; 335 } 336 sep = " "; 337 while (sublen) { 338 ND_PRINT("%s%s", sep, 339 tok2str(diversity_str, "%u", GET_U_1(cp))); 340 cp++; 341 sep = "-"; 342 sublen--; 343 } 344 if(tlv_type != MESSAGE_UPDATE && 345 tlv_type != MESSAGE_UPDATE_SRC_SPECIFIC) 346 ND_PRINT(" (bogus)"); 347 break; 348 case MESSAGE_SUB_TIMESTAMP: 349 ND_PRINT(" sub-timestamp"); 350 if(tlv_type == MESSAGE_HELLO) { 351 if(sublen < 4) 352 goto invalid; 353 t1 = GET_BE_U_4(cp); 354 ND_PRINT(" %s", format_timestamp(t1)); 355 } else if(tlv_type == MESSAGE_IHU) { 356 if(sublen < 8) 357 goto invalid; 358 t1 = GET_BE_U_4(cp); 359 ND_PRINT(" %s", format_timestamp(t1)); 360 t2 = GET_BE_U_4(cp + 4); 361 ND_PRINT("|%s", format_timestamp(t2)); 362 } else 363 ND_PRINT(" (bogus)"); 364 cp += sublen; 365 break; 366 default: 367 ND_PRINT(" sub-unknown-0x%02x", subtype); 368 cp += sublen; 369 } /* switch */ 370 } /* while */ 371 return; 372 373 invalid: 374 nd_print_invalid(ndo); 375 } 376 377 #define ICHECK(i, l) \ 378 if ((i) + (l) > tlvs_length || (i) + (l) > packet_length_remaining) \ 379 goto invalid; 380 381 static int 382 babel_print_v2_tlvs(netdissect_options *ndo, 383 const u_char *cp, u_int tlvs_length, 384 u_int packet_length_remaining) 385 { 386 u_int i; 387 u_char v4_prefix[16] = 388 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0 }; 389 u_char v6_prefix[16] = {0}; 390 391 i = 0; 392 while(i < tlvs_length) { 393 const u_char *message; 394 uint8_t type; 395 u_int len; 396 397 message = cp + i; 398 399 ICHECK(i, 1); 400 if((type = GET_U_1(message)) == MESSAGE_PAD1) { 401 ND_PRINT(ndo->ndo_vflag ? "\n\tPad 1" : " pad1"); 402 i += 1; 403 continue; 404 } 405 406 ICHECK(i, 2); 407 ND_TCHECK_2(message); 408 len = GET_U_1(message + 1); 409 410 ICHECK(i, 2 + len); 411 ND_TCHECK_LEN(message, 2 + len); 412 413 switch(type) { 414 case MESSAGE_PADN: { 415 if (!ndo->ndo_vflag) 416 ND_PRINT(" padN"); 417 else 418 ND_PRINT("\n\tPad %u", len + 2); 419 } 420 break; 421 422 case MESSAGE_ACK_REQ: { 423 u_short nonce, interval; 424 if (!ndo->ndo_vflag) 425 ND_PRINT(" ack-req"); 426 else { 427 ND_PRINT("\n\tAcknowledgment Request "); 428 if(len < 6) goto invalid; 429 nonce = GET_BE_U_2(message + 4); 430 interval = GET_BE_U_2(message + 6); 431 ND_PRINT("%04x %s", nonce, format_interval(interval)); 432 } 433 } 434 break; 435 436 case MESSAGE_ACK: { 437 u_short nonce; 438 if (!ndo->ndo_vflag) 439 ND_PRINT(" ack"); 440 else { 441 ND_PRINT("\n\tAcknowledgment "); 442 if(len < 2) goto invalid; 443 nonce = GET_BE_U_2(message + 2); 444 ND_PRINT("%04x", nonce); 445 } 446 } 447 break; 448 449 case MESSAGE_HELLO: { 450 u_short seqno, interval, unicast; 451 if (!ndo->ndo_vflag) 452 ND_PRINT(" hello"); 453 else { 454 ND_PRINT("\n\tHello "); 455 if(len < 6) goto invalid; 456 unicast = (GET_BE_U_2(message + 2) & UNICAST_MASK); 457 seqno = GET_BE_U_2(message + 4); 458 interval = GET_BE_U_2(message + 6); 459 if(unicast) 460 ND_PRINT("(Unicast) "); 461 ND_PRINT("seqno %u ", seqno); 462 if(interval!=0) 463 ND_PRINT("interval %s", format_interval(interval)); 464 else 465 ND_PRINT("unscheduled"); 466 /* Extra data. */ 467 if(len > 6) 468 subtlvs_print(ndo, message + 8, message + 2 + len, type); 469 } 470 } 471 break; 472 473 case MESSAGE_IHU: { 474 unsigned short rxcost, interval; 475 if (!ndo->ndo_vflag) 476 ND_PRINT(" ihu"); 477 else { 478 u_char address[16]; 479 u_char ae; 480 int rc; 481 ND_PRINT("\n\tIHU "); 482 if(len < 6) goto invalid; 483 rxcost = GET_BE_U_2(message + 4); 484 interval = GET_BE_U_2(message + 6); 485 ae = GET_U_1(message + 2); 486 rc = network_address(ae, message + 8, 487 len - 6, address); 488 if(rc < 0) { nd_print_trunc(ndo); break; } 489 ND_PRINT("%s rxcost %u interval %s", 490 ae == 0 ? "any" : format_address(ndo, address), 491 rxcost, format_interval(interval)); 492 /* Extra data. */ 493 if((u_int)rc < len - 6) 494 subtlvs_print(ndo, message + 8 + rc, message + 2 + len, 495 type); 496 } 497 } 498 break; 499 500 case MESSAGE_ROUTER_ID: { 501 if (!ndo->ndo_vflag) 502 ND_PRINT(" router-id"); 503 else { 504 ND_PRINT("\n\tRouter Id"); 505 if(len < 10) goto invalid; 506 ND_PRINT(" %s", format_id(ndo, message + 4)); 507 } 508 } 509 break; 510 511 case MESSAGE_NH: { 512 if (!ndo->ndo_vflag) 513 ND_PRINT(" nh"); 514 else { 515 int rc; 516 u_char ae; 517 u_char nh[16]; 518 ND_PRINT("\n\tNext Hop"); 519 if(len < 2) goto invalid; 520 ae = GET_U_1(message + 2); 521 rc = network_address(ae, message + 4, 522 len - 2, nh); 523 if(rc < 0) goto invalid; 524 ND_PRINT(" %s", ae == 0 ? "invalid AE 0" : format_address(ndo, nh)); 525 } 526 } 527 break; 528 529 case MESSAGE_UPDATE: { 530 if (!ndo->ndo_vflag) { 531 ND_PRINT(" update"); 532 if(len < 10) 533 goto invalid; 534 else 535 ND_PRINT("%s%s%s", 536 (GET_U_1(message + 3) & 0x80) ? "/prefix": "", 537 (GET_U_1(message + 3) & 0x40) ? "/id" : "", 538 (GET_U_1(message + 3) & 0x3f) ? "/unknown" : ""); 539 } else { 540 u_short interval, seqno, metric; 541 u_char ae, plen; 542 int rc; 543 u_char prefix[16]; 544 ND_PRINT("\n\tUpdate"); 545 if(len < 10) goto invalid; 546 ae = GET_U_1(message + 2); 547 plen = GET_U_1(message + 4) + (GET_U_1(message + 2) == 1 ? 96 : 0); 548 rc = network_prefix(ae, 549 GET_U_1(message + 4), 550 GET_U_1(message + 5), 551 message + 12, 552 GET_U_1(message + 2) == 1 ? v4_prefix : v6_prefix, 553 len - 10, prefix); 554 if(rc < 0) goto invalid; 555 interval = GET_BE_U_2(message + 6); 556 seqno = GET_BE_U_2(message + 8); 557 metric = GET_BE_U_2(message + 10); 558 ND_PRINT("%s%s%s %s metric %u seqno %u interval %s", 559 (GET_U_1(message + 3) & 0x80) ? "/prefix": "", 560 (GET_U_1(message + 3) & 0x40) ? "/id" : "", 561 (GET_U_1(message + 3) & 0x3f) ? "/unknown" : "", 562 ae == 0 ? "any" : format_prefix(ndo, prefix, plen), 563 metric, seqno, format_interval_update(interval)); 564 if(GET_U_1(message + 3) & 0x80) { 565 if(GET_U_1(message + 2) == 1) 566 memcpy(v4_prefix, prefix, 16); 567 else 568 memcpy(v6_prefix, prefix, 16); 569 } 570 /* extra data? */ 571 if((u_int)rc < len - 10) 572 subtlvs_print(ndo, message + 12 + rc, message + 2 + len, type); 573 } 574 } 575 break; 576 577 case MESSAGE_ROUTE_REQUEST: { 578 if (!ndo->ndo_vflag) 579 ND_PRINT(" route-request"); 580 else { 581 int rc; 582 u_char prefix[16], ae, plen; 583 ND_PRINT("\n\tRoute Request "); 584 if(len < 2) goto invalid; 585 ae = GET_U_1(message + 2); 586 plen = GET_U_1(message + 3) + (GET_U_1(message + 2) == 1 ? 96 : 0); 587 rc = network_prefix(ae, 588 GET_U_1(message + 3), 0, 589 message + 4, NULL, len - 2, prefix); 590 if(rc < 0) goto invalid; 591 ND_PRINT("for %s", 592 ae == 0 ? "any" : format_prefix(ndo, prefix, plen)); 593 } 594 } 595 break; 596 597 case MESSAGE_SEQNO_REQUEST : { 598 if (!ndo->ndo_vflag) 599 ND_PRINT(" seqno-request"); 600 else { 601 int rc; 602 u_short seqno; 603 u_char prefix[16], ae, plen; 604 ND_PRINT("\n\tSeqno Request "); 605 if(len < 14) goto invalid; 606 ae = GET_U_1(message + 2); 607 seqno = GET_BE_U_2(message + 4); 608 rc = network_prefix(ae, 609 GET_U_1(message + 3), 0, 610 message + 16, NULL, len - 14, prefix); 611 if(rc < 0) goto invalid; 612 plen = GET_U_1(message + 3) + (GET_U_1(message + 2) == 1 ? 96 : 0); 613 ND_PRINT("(%u hops) for %s seqno %u id %s", 614 GET_U_1(message + 6), 615 ae == 0 ? "invalid AE 0" : format_prefix(ndo, prefix, plen), 616 seqno, format_id(ndo, message + 8)); 617 } 618 } 619 break; 620 case MESSAGE_TSPC : 621 if (!ndo->ndo_vflag) 622 ND_PRINT(" tspc"); 623 else { 624 ND_PRINT("\n\tTS/PC "); 625 if(len < 6) goto invalid; 626 ND_PRINT("timestamp %u packetcounter %u", 627 GET_BE_U_4(message + 4), 628 GET_BE_U_2(message + 2)); 629 } 630 break; 631 case MESSAGE_HMAC : { 632 if (!ndo->ndo_vflag) 633 ND_PRINT(" hmac"); 634 else { 635 unsigned j; 636 ND_PRINT("\n\tHMAC "); 637 if(len < 18) goto invalid; 638 ND_PRINT("key-id %u digest-%u ", GET_BE_U_2(message + 2), 639 len - 2); 640 for (j = 0; j < len - 2; j++) 641 ND_PRINT("%02X", GET_U_1(message + j + 4)); 642 } 643 } 644 break; 645 646 case MESSAGE_UPDATE_SRC_SPECIFIC : { 647 if(!ndo->ndo_vflag) { 648 ND_PRINT(" ss-update"); 649 } else { 650 u_char prefix[16], src_prefix[16]; 651 u_short interval, seqno, metric; 652 u_char ae, plen, src_plen, omitted; 653 int rc; 654 int parsed_len = 10; 655 ND_PRINT("\n\tSS-Update"); 656 if(len < 10) goto invalid; 657 ae = GET_U_1(message + 2); 658 src_plen = GET_U_1(message + 3); 659 plen = GET_U_1(message + 4); 660 omitted = GET_U_1(message + 5); 661 interval = GET_BE_U_2(message + 6); 662 seqno = GET_BE_U_2(message + 8); 663 metric = GET_BE_U_2(message + 10); 664 rc = network_prefix(ae, plen, omitted, message + 2 + parsed_len, 665 ae == 1 ? v4_prefix : v6_prefix, 666 len - parsed_len, prefix); 667 if(rc < 0) goto invalid; 668 if(ae == 1) 669 plen += 96; 670 parsed_len += rc; 671 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len, 672 NULL, len - parsed_len, src_prefix); 673 if(rc < 0) goto invalid; 674 if(ae == 1) 675 src_plen += 96; 676 parsed_len += rc; 677 678 ND_PRINT(" %s from", format_prefix(ndo, prefix, plen)); 679 ND_PRINT(" %s metric %u seqno %u interval %s", 680 format_prefix(ndo, src_prefix, src_plen), 681 metric, seqno, format_interval_update(interval)); 682 /* extra data? */ 683 if((u_int)parsed_len < len) 684 subtlvs_print(ndo, message + 2 + parsed_len, 685 message + 2 + len, type); 686 } 687 } 688 break; 689 690 case MESSAGE_REQUEST_SRC_SPECIFIC : { 691 if(!ndo->ndo_vflag) 692 ND_PRINT(" ss-request"); 693 else { 694 int rc, parsed_len = 3; 695 u_char ae, plen, src_plen, prefix[16], src_prefix[16]; 696 ND_PRINT("\n\tSS-Request "); 697 if(len < 3) goto invalid; 698 ae = GET_U_1(message + 2); 699 plen = GET_U_1(message + 3); 700 src_plen = GET_U_1(message + 4); 701 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len, 702 NULL, len - parsed_len, prefix); 703 if(rc < 0) goto invalid; 704 if(ae == 1) 705 plen += 96; 706 parsed_len += rc; 707 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len, 708 NULL, len - parsed_len, src_prefix); 709 if(rc < 0) goto invalid; 710 if(ae == 1) 711 src_plen += 96; 712 parsed_len += rc; 713 if(ae == 0) { 714 ND_PRINT("for any"); 715 } else { 716 ND_PRINT("for (%s, ", format_prefix(ndo, prefix, plen)); 717 ND_PRINT("%s)", format_prefix(ndo, src_prefix, src_plen)); 718 } 719 } 720 } 721 break; 722 723 case MESSAGE_MH_REQUEST_SRC_SPECIFIC : { 724 if(!ndo->ndo_vflag) 725 ND_PRINT(" ss-mh-request"); 726 else { 727 int rc, parsed_len = 14; 728 u_short seqno; 729 u_char ae, plen, src_plen, prefix[16], src_prefix[16], hopc; 730 const u_char *router_id = NULL; 731 ND_PRINT("\n\tSS-MH-Request "); 732 if(len < 14) goto invalid; 733 ae = GET_U_1(message + 2); 734 plen = GET_U_1(message + 3); 735 seqno = GET_BE_U_2(message + 4); 736 hopc = GET_U_1(message + 6); 737 src_plen = GET_U_1(message + 7); 738 router_id = message + 8; 739 rc = network_prefix(ae, plen, 0, message + 2 + parsed_len, 740 NULL, len - parsed_len, prefix); 741 if(rc < 0) goto invalid; 742 if(ae == 1) 743 plen += 96; 744 parsed_len += rc; 745 rc = network_prefix(ae, src_plen, 0, message + 2 + parsed_len, 746 NULL, len - parsed_len, src_prefix); 747 if(rc < 0) goto invalid; 748 if(ae == 1) 749 src_plen += 96; 750 ND_PRINT("(%u hops) for (%s, ", 751 hopc, format_prefix(ndo, prefix, plen)); 752 ND_PRINT("%s) seqno %u id %s", 753 format_prefix(ndo, src_prefix, src_plen), 754 seqno, format_id(ndo, router_id)); 755 } 756 } 757 break; 758 759 case MESSAGE_MAC: { 760 if (!ndo->ndo_vflag) 761 ND_PRINT(" mac"); 762 else { 763 ND_PRINT("\n\tMAC "); 764 ND_PRINT("len %u", len); 765 } 766 } 767 break; 768 769 case MESSAGE_PC: { 770 if (!ndo->ndo_vflag) 771 ND_PRINT(" pc"); 772 else { 773 ND_PRINT("\n\tPC"); 774 if(len < 4) goto invalid; 775 ND_PRINT(" value %u", 776 GET_BE_U_4(message + 2)); 777 ND_PRINT(" index len %u", len-4); 778 } 779 } 780 break; 781 782 case MESSAGE_CHALLENGE_REQUEST: { 783 if (!ndo->ndo_vflag) 784 ND_PRINT(" challenge_request"); 785 else { 786 ND_PRINT("\n\tChallenge Request"); 787 if(len > 192) goto invalid; 788 ND_PRINT(" len %u", len); 789 } 790 } 791 break; 792 793 case MESSAGE_CHALLENGE_REPLY: { 794 if (!ndo->ndo_vflag) 795 ND_PRINT(" challenge_reply"); 796 else { 797 ND_PRINT("\n\tChallenge Reply"); 798 if (len > 192) goto invalid; 799 ND_PRINT(" len %u", len); 800 } 801 } 802 break; 803 804 default: 805 if (!ndo->ndo_vflag) 806 ND_PRINT(" unknown"); 807 else 808 ND_PRINT("\n\tUnknown message type %u", type); 809 } 810 i += len + 2; 811 } 812 813 return 0; /* OK */ 814 815 trunc: 816 return -1; /* packet truncated by capture process */ 817 818 invalid: 819 return -2; /* packet is invalid */ 820 } 821 822 static void 823 babel_print_v2(netdissect_options *ndo, 824 const u_char *cp, u_int length) 825 { 826 u_short bodylen; 827 int ret; 828 829 ND_TCHECK_4(cp); 830 if (length < 4) 831 goto invalid; 832 bodylen = GET_BE_U_2(cp + 2); 833 ND_PRINT(" (%u)", bodylen); 834 length -= 4; 835 cp += 4; 836 837 /* Process the TLVs in the body */ 838 if (length < bodylen) 839 goto invalid; 840 ret = babel_print_v2_tlvs(ndo, cp, bodylen, length); 841 if (ret == -1) 842 goto trunc; 843 if (ret == -2) 844 goto invalid; 845 length -= bodylen; 846 cp += bodylen; 847 848 /* If there's a trailer, process the TLVs in the trailer */ 849 if (length != 0) { 850 if(ndo->ndo_vflag) ND_PRINT("\n\t----"); 851 else ND_PRINT(" |"); 852 ret = babel_print_v2_tlvs(ndo, cp, length, length); 853 if (ret == -1) 854 goto trunc; 855 if (ret == -2) 856 goto invalid; 857 } 858 return; 859 860 trunc: 861 nd_print_trunc(ndo); 862 return; 863 864 invalid: 865 nd_print_invalid(ndo); 866 } 867