1 /* 2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that: (1) source code distributions 7 * retain the above copyright notice and this paragraph in its entirety, (2) 8 * distributions including binary code include the above copyright notice and 9 * this paragraph in its entirety in the documentation or other materials 10 * provided with the distribution, and (3) all advertising materials mentioning 11 * features or use of this software display the following acknowledgement: 12 * ``This product includes software developed by the University of California, 13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 * the University nor the names of its contributors may be used to endorse 15 * or promote products derived from this software without specific prior 16 * written permission. 17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 */ 21 22 /* \summary: DECnet printer */ 23 24 #include <config.h> 25 26 #include "netdissect-stdinc.h" 27 28 #include <stdio.h> 29 #include <stdlib.h> 30 31 #define ND_LONGJMP_FROM_TCHECK 32 #include "netdissect.h" 33 #include "extract.h" 34 #include "addrtoname.h" 35 36 37 #ifndef _WIN32 38 typedef nd_uint8_t byte; /* single byte field */ 39 #else 40 /* 41 * the keyword 'byte' generates conflicts in Windows 42 */ 43 typedef nd_uint8_t Byte; /* single byte field */ 44 #define byte Byte 45 #endif /* _WIN32 */ 46 typedef nd_uint16_t word; /* 2 byte field */ 47 typedef nd_uint32_t longword; /* 4 bytes field */ 48 49 /* 50 * Definitions for DECNET Phase IV protocol headers 51 */ 52 typedef union { 53 nd_mac_addr dne_addr; /* full Ethernet address */ 54 struct { 55 nd_byte dne_hiord[4]; /* DECnet HIORD prefix */ 56 nd_byte dne_nodeaddr[2]; /* DECnet node address */ 57 } dne_remote; 58 } etheraddr; /* Ethernet address */ 59 60 #define HIORD 0x000400aa /* high 32-bits of address (swapped) */ 61 62 #define AREAMASK 0176000 /* mask for area field */ 63 #define AREASHIFT 10 /* bit-offset for area field */ 64 #define NODEMASK 01777 /* mask for node address field */ 65 66 /* 67 * Define long and short header formats. 68 */ 69 struct shorthdr 70 { 71 byte sh_flags; /* route flags */ 72 word sh_dst; /* destination node address */ 73 word sh_src; /* source node address */ 74 byte sh_visits; /* visit count */ 75 }; 76 77 struct longhdr 78 { 79 byte lg_flags; /* route flags */ 80 byte lg_darea; /* destination area (reserved) */ 81 byte lg_dsarea; /* destination subarea (reserved) */ 82 etheraddr lg_dst; /* destination id */ 83 byte lg_sarea; /* source area (reserved) */ 84 byte lg_ssarea; /* source subarea (reserved) */ 85 etheraddr lg_src; /* source id */ 86 byte lg_nextl2; /* next level 2 router (reserved) */ 87 byte lg_visits; /* visit count */ 88 byte lg_service; /* service class (reserved) */ 89 byte lg_pt; /* protocol type (reserved) */ 90 }; 91 92 union routehdr 93 { 94 struct shorthdr rh_short; /* short route header */ 95 struct longhdr rh_long; /* long route header */ 96 }; 97 98 /* 99 * Define the values of various fields in the protocol messages. 100 * 101 * 1. Data packet formats. 102 */ 103 #define RMF_MASK 7 /* mask for message type */ 104 #define RMF_SHORT 2 /* short message format */ 105 #define RMF_LONG 6 /* long message format */ 106 #ifndef RMF_RQR 107 #define RMF_RQR 010 /* request return to sender */ 108 #define RMF_RTS 020 /* returning to sender */ 109 #define RMF_IE 040 /* intra-ethernet packet */ 110 #endif /* RMR_RQR */ 111 #define RMF_FVER 0100 /* future version flag */ 112 #define RMF_PAD 0200 /* pad field */ 113 #define RMF_PADMASK 0177 /* pad field mask */ 114 115 #define VIS_MASK 077 /* visit field mask */ 116 117 /* 118 * 2. Control packet formats. 119 */ 120 #define RMF_CTLMASK 017 /* mask for message type */ 121 #define RMF_CTLMSG 01 /* control message indicator */ 122 #define RMF_INIT 01 /* initialization message */ 123 #define RMF_VER 03 /* verification message */ 124 #define RMF_TEST 05 /* hello and test message */ 125 #define RMF_L1ROUT 07 /* level 1 routing message */ 126 #define RMF_L2ROUT 011 /* level 2 routing message */ 127 #define RMF_RHELLO 013 /* router hello message */ 128 #define RMF_EHELLO 015 /* endnode hello message */ 129 130 #define TI_L2ROUT 01 /* level 2 router */ 131 #define TI_L1ROUT 02 /* level 1 router */ 132 #define TI_ENDNODE 03 /* endnode */ 133 #define TI_VERIF 04 /* verification required */ 134 #define TI_BLOCK 010 /* blocking requested */ 135 136 #define VE_VERS 2 /* version number (2) */ 137 #define VE_ECO 0 /* ECO number */ 138 #define VE_UECO 0 /* user ECO number (0) */ 139 140 #define P3_VERS 1 /* phase III version number (1) */ 141 #define P3_ECO 3 /* ECO number (3) */ 142 #define P3_UECO 0 /* user ECO number (0) */ 143 144 #define II_L2ROUT 01 /* level 2 router */ 145 #define II_L1ROUT 02 /* level 1 router */ 146 #define II_ENDNODE 03 /* endnode */ 147 #define II_VERIF 04 /* verification required */ 148 #define II_NOMCAST 040 /* no multicast traffic accepted */ 149 #define II_BLOCK 0100 /* blocking requested */ 150 #define II_TYPEMASK 03 /* mask for node type */ 151 152 #define TESTDATA 0252 /* test data bytes */ 153 #define TESTLEN 1 /* length of transmitted test data */ 154 155 /* 156 * Define control message formats. 157 */ 158 struct initmsg /* initialization message */ 159 { 160 byte in_flags; /* route flags */ 161 word in_src; /* source node address */ 162 byte in_info; /* routing layer information */ 163 word in_blksize; /* maximum data link block size */ 164 byte in_vers; /* version number */ 165 byte in_eco; /* ECO number */ 166 byte in_ueco; /* user ECO number */ 167 word in_hello; /* hello timer */ 168 byte in_rsvd; /* reserved image field */ 169 }; 170 171 struct verifmsg /* verification message */ 172 { 173 byte ve_flags; /* route flags */ 174 word ve_src; /* source node address */ 175 byte ve_fcnval; /* function value image field */ 176 }; 177 178 struct testmsg /* hello and test message */ 179 { 180 byte te_flags; /* route flags */ 181 word te_src; /* source node address */ 182 byte te_data; /* test data image field */ 183 }; 184 185 struct l1rout /* level 1 routing message */ 186 { 187 byte r1_flags; /* route flags */ 188 word r1_src; /* source node address */ 189 byte r1_rsvd; /* reserved field */ 190 }; 191 192 struct l2rout /* level 2 routing message */ 193 { 194 byte r2_flags; /* route flags */ 195 word r2_src; /* source node address */ 196 byte r2_rsvd; /* reserved field */ 197 }; 198 199 struct rhellomsg /* router hello message */ 200 { 201 byte rh_flags; /* route flags */ 202 byte rh_vers; /* version number */ 203 byte rh_eco; /* ECO number */ 204 byte rh_ueco; /* user ECO number */ 205 etheraddr rh_src; /* source id */ 206 byte rh_info; /* routing layer information */ 207 word rh_blksize; /* maximum data link block size */ 208 byte rh_priority; /* router's priority */ 209 byte rh_area; /* reserved */ 210 word rh_hello; /* hello timer */ 211 byte rh_mpd; /* reserved */ 212 }; 213 214 struct ehellomsg /* endnode hello message */ 215 { 216 byte eh_flags; /* route flags */ 217 byte eh_vers; /* version number */ 218 byte eh_eco; /* ECO number */ 219 byte eh_ueco; /* user ECO number */ 220 etheraddr eh_src; /* source id */ 221 byte eh_info; /* routing layer information */ 222 word eh_blksize; /* maximum data link block size */ 223 byte eh_area; /* area (reserved) */ 224 byte eh_seed[8]; /* verification seed */ 225 etheraddr eh_router; /* designated router */ 226 word eh_hello; /* hello timer */ 227 byte eh_mpd; /* (reserved) */ 228 byte eh_data; /* test data image field */ 229 }; 230 231 union controlmsg 232 { 233 struct initmsg cm_init; /* initialization message */ 234 struct verifmsg cm_ver; /* verification message */ 235 struct testmsg cm_test; /* hello and test message */ 236 struct l1rout cm_l1rou; /* level 1 routing message */ 237 struct l2rout cm_l2rout; /* level 2 routing message */ 238 struct rhellomsg cm_rhello; /* router hello message */ 239 struct ehellomsg cm_ehello; /* endnode hello message */ 240 }; 241 242 /* Macros for decoding routing-info fields */ 243 #define RI_COST(x) ((x)&0777) 244 #define RI_HOPS(x) (((x)>>10)&037) 245 246 /* 247 * NSP protocol fields and values. 248 */ 249 250 #define NSP_TYPEMASK 014 /* mask to isolate type code */ 251 #define NSP_SUBMASK 0160 /* mask to isolate subtype code */ 252 #define NSP_SUBSHFT 4 /* shift to move subtype code */ 253 254 #define MFT_DATA 0 /* data message */ 255 #define MFT_ACK 04 /* acknowledgement message */ 256 #define MFT_CTL 010 /* control message */ 257 258 #define MFS_ILS 020 /* data or I/LS indicator */ 259 #define MFS_BOM 040 /* beginning of message (data) */ 260 #define MFS_MOM 0 /* middle of message (data) */ 261 #define MFS_EOM 0100 /* end of message (data) */ 262 #define MFS_INT 040 /* interrupt message */ 263 264 #define MFS_DACK 0 /* data acknowledgement */ 265 #define MFS_IACK 020 /* I/LS acknowledgement */ 266 #define MFS_CACK 040 /* connect acknowledgement */ 267 268 #define MFS_NOP 0 /* no operation */ 269 #define MFS_CI 020 /* connect initiate */ 270 #define MFS_CC 040 /* connect confirm */ 271 #define MFS_DI 060 /* disconnect initiate */ 272 #define MFS_DC 0100 /* disconnect confirm */ 273 #define MFS_RCI 0140 /* retransmitted connect initiate */ 274 275 #define SGQ_ACK 0100000 /* ack */ 276 #define SGQ_NAK 0110000 /* negative ack */ 277 #define SGQ_OACK 0120000 /* other channel ack */ 278 #define SGQ_ONAK 0130000 /* other channel negative ack */ 279 #define SGQ_MASK 07777 /* mask to isolate seq # */ 280 #define SGQ_OTHER 020000 /* other channel qualifier */ 281 #define SGQ_DELAY 010000 /* ack delay flag */ 282 283 #define SGQ_EOM 0100000 /* pseudo flag for end-of-message */ 284 285 #define LSM_MASK 03 /* mask for modifier field */ 286 #define LSM_NOCHANGE 0 /* no change */ 287 #define LSM_DONOTSEND 1 /* do not send data */ 288 #define LSM_SEND 2 /* send data */ 289 290 #define LSI_MASK 014 /* mask for interpretation field */ 291 #define LSI_DATA 0 /* data segment or message count */ 292 #define LSI_INTR 4 /* interrupt request count */ 293 #define LSI_INTM 0377 /* funny marker for int. message */ 294 295 #define COS_MASK 014 /* mask for flow control field */ 296 #define COS_NONE 0 /* no flow control */ 297 #define COS_SEGMENT 04 /* segment flow control */ 298 #define COS_MESSAGE 010 /* message flow control */ 299 #define COS_DEFAULT 1 /* default value for field */ 300 301 #define COI_MASK 3 /* mask for version field */ 302 #define COI_32 0 /* version 3.2 */ 303 #define COI_31 1 /* version 3.1 */ 304 #define COI_40 2 /* version 4.0 */ 305 #define COI_41 3 /* version 4.1 */ 306 307 #define MNU_MASK 140 /* mask for session control version */ 308 #define MNU_10 000 /* session V1.0 */ 309 #define MNU_20 040 /* session V2.0 */ 310 #define MNU_ACCESS 1 /* access control present */ 311 #define MNU_USRDATA 2 /* user data field present */ 312 #define MNU_INVKPROXY 4 /* invoke proxy field present */ 313 #define MNU_UICPROXY 8 /* use uic-based proxy */ 314 315 #define DC_NORESOURCES 1 /* no resource reason code */ 316 #define DC_NOLINK 41 /* no link terminate reason code */ 317 #define DC_COMPLETE 42 /* disconnect complete reason code */ 318 319 #define DI_NOERROR 0 /* user disconnect */ 320 #define DI_SHUT 3 /* node is shutting down */ 321 #define DI_NOUSER 4 /* destination end user does not exist */ 322 #define DI_INVDEST 5 /* invalid end user destination */ 323 #define DI_REMRESRC 6 /* insufficient remote resources */ 324 #define DI_TPA 8 /* third party abort */ 325 #define DI_PROTOCOL 7 /* protocol error discovered */ 326 #define DI_ABORT 9 /* user abort */ 327 #define DI_LOCALRESRC 32 /* insufficient local resources */ 328 #define DI_REMUSERRESRC 33 /* insufficient remote user resources */ 329 #define DI_BADACCESS 34 /* bad access control information */ 330 #define DI_BADACCNT 36 /* bad ACCOUNT information */ 331 #define DI_CONNECTABORT 38 /* connect request cancelled */ 332 #define DI_TIMEDOUT 38 /* remote node or user crashed */ 333 #define DI_UNREACHABLE 39 /* local timers expired due to ... */ 334 #define DI_BADIMAGE 43 /* bad image data in connect */ 335 #define DI_SERVMISMATCH 54 /* cryptographic service mismatch */ 336 337 #define UC_OBJREJECT 0 /* object rejected connect */ 338 #define UC_USERDISCONNECT 0 /* user disconnect */ 339 #define UC_RESOURCES 1 /* insufficient resources (local or remote) */ 340 #define UC_NOSUCHNODE 2 /* unrecognized node name */ 341 #define UC_REMOTESHUT 3 /* remote node shutting down */ 342 #define UC_NOSUCHOBJ 4 /* unrecognized object */ 343 #define UC_INVOBJFORMAT 5 /* invalid object name format */ 344 #define UC_OBJTOOBUSY 6 /* object too busy */ 345 #define UC_NETWORKABORT 8 /* network abort */ 346 #define UC_USERABORT 9 /* user abort */ 347 #define UC_INVNODEFORMAT 10 /* invalid node name format */ 348 #define UC_LOCALSHUT 11 /* local node shutting down */ 349 #define UC_ACCESSREJECT 34 /* invalid access control information */ 350 #define UC_NORESPONSE 38 /* no response from object */ 351 #define UC_UNREACHABLE 39 /* node unreachable */ 352 353 /* 354 * NSP message formats. 355 */ 356 struct nsphdr /* general nsp header */ 357 { 358 byte nh_flags; /* message flags */ 359 word nh_dst; /* destination link address */ 360 word nh_src; /* source link address */ 361 }; 362 363 struct seghdr /* data segment header */ 364 { 365 byte sh_flags; /* message flags */ 366 word sh_dst; /* destination link address */ 367 word sh_src; /* source link address */ 368 word sh_seq[3]; /* sequence numbers */ 369 }; 370 371 struct minseghdr /* minimum data segment header */ 372 { 373 byte ms_flags; /* message flags */ 374 word ms_dst; /* destination link address */ 375 word ms_src; /* source link address */ 376 word ms_seq; /* sequence number */ 377 }; 378 379 struct lsmsg /* link service message (after hdr) */ 380 { 381 byte ls_lsflags; /* link service flags */ 382 byte ls_fcval; /* flow control value */ 383 }; 384 385 struct ackmsg /* acknowledgement message */ 386 { 387 byte ak_flags; /* message flags */ 388 word ak_dst; /* destination link address */ 389 word ak_src; /* source link address */ 390 word ak_acknum[2]; /* acknowledgement numbers */ 391 }; 392 393 struct minackmsg /* minimum acknowledgement message */ 394 { 395 byte mk_flags; /* message flags */ 396 word mk_dst; /* destination link address */ 397 word mk_src; /* source link address */ 398 word mk_acknum; /* acknowledgement number */ 399 }; 400 401 struct ciackmsg /* connect acknowledgement message */ 402 { 403 byte ck_flags; /* message flags */ 404 word ck_dst; /* destination link address */ 405 }; 406 407 struct cimsg /* connect initiate message */ 408 { 409 byte ci_flags; /* message flags */ 410 word ci_dst; /* destination link address (0) */ 411 word ci_src; /* source link address */ 412 byte ci_services; /* requested services */ 413 byte ci_info; /* information */ 414 word ci_segsize; /* maximum segment size */ 415 }; 416 417 struct ccmsg /* connect confirm message */ 418 { 419 byte cc_flags; /* message flags */ 420 word cc_dst; /* destination link address */ 421 word cc_src; /* source link address */ 422 byte cc_services; /* requested services */ 423 byte cc_info; /* information */ 424 word cc_segsize; /* maximum segment size */ 425 byte cc_optlen; /* optional data length */ 426 }; 427 428 struct cnmsg /* generic connect message */ 429 { 430 byte cn_flags; /* message flags */ 431 word cn_dst; /* destination link address */ 432 word cn_src; /* source link address */ 433 byte cn_services; /* requested services */ 434 byte cn_info; /* information */ 435 word cn_segsize; /* maximum segment size */ 436 }; 437 438 struct dimsg /* disconnect initiate message */ 439 { 440 byte di_flags; /* message flags */ 441 word di_dst; /* destination link address */ 442 word di_src; /* source link address */ 443 word di_reason; /* reason code */ 444 byte di_optlen; /* optional data length */ 445 }; 446 447 struct dcmsg /* disconnect confirm message */ 448 { 449 byte dc_flags; /* message flags */ 450 word dc_dst; /* destination link address */ 451 word dc_src; /* source link address */ 452 word dc_reason; /* reason code */ 453 }; 454 455 /* Forwards */ 456 static int print_decnet_ctlmsg(netdissect_options *, const union routehdr *, u_int, u_int); 457 static void print_t_info(netdissect_options *, u_int); 458 static void print_l1_routes(netdissect_options *, const u_char *, u_int); 459 static void print_l2_routes(netdissect_options *, const u_char *, u_int); 460 static void print_i_info(netdissect_options *, u_int); 461 static void print_elist(const u_char *, u_int); 462 static int print_nsp(netdissect_options *, const u_char *, u_int); 463 static void print_reason(netdissect_options *, u_int); 464 465 void 466 decnet_print(netdissect_options *ndo, 467 const u_char *ap, u_int length, 468 u_int caplen) 469 { 470 const union routehdr *rhp; 471 u_int mflags; 472 uint16_t dst, src; 473 u_int hops; 474 u_int nsplen, pktlen; 475 const u_char *nspp; 476 477 ndo->ndo_protocol = "decnet"; 478 if (length < sizeof(struct shorthdr)) { 479 ND_PRINT(" (length %u < %zu)", length, sizeof(struct shorthdr)); 480 goto invalid; 481 } 482 483 pktlen = GET_LE_U_2(ap); 484 if (pktlen < sizeof(struct shorthdr)) { 485 ND_PRINT(" (pktlen %u < %zu)", pktlen, sizeof(struct shorthdr)); 486 goto invalid; 487 } 488 if (pktlen > length) { 489 ND_PRINT(" (pktlen %u > %u)", pktlen, length); 490 goto invalid; 491 } 492 length = pktlen; 493 494 rhp = (const union routehdr *)(ap + sizeof(short)); 495 mflags = GET_U_1(rhp->rh_short.sh_flags); 496 497 if (mflags & RMF_PAD) { 498 /* pad bytes of some sort in front of message */ 499 u_int padlen = mflags & RMF_PADMASK; 500 if (ndo->ndo_vflag) 501 ND_PRINT("[pad:%u] ", padlen); 502 if (length < padlen + 2) { 503 ND_PRINT(" (length %u < %u)", length, padlen + 2); 504 goto invalid; 505 } 506 ND_TCHECK_LEN(ap + sizeof(short), padlen); 507 ap += padlen; 508 length -= padlen; 509 caplen -= padlen; 510 rhp = (const union routehdr *)(ap + sizeof(short)); 511 mflags = GET_U_1(rhp->rh_short.sh_flags); 512 } 513 514 if (mflags & RMF_FVER) { 515 ND_PRINT("future-version-decnet"); 516 ND_DEFAULTPRINT(ap, ND_MIN(length, caplen)); 517 return; 518 } 519 520 /* is it a control message? */ 521 if (mflags & RMF_CTLMSG) { 522 if (!print_decnet_ctlmsg(ndo, rhp, length, caplen)) 523 goto invalid; 524 return; 525 } 526 527 switch (mflags & RMF_MASK) { 528 case RMF_LONG: 529 if (length < sizeof(struct longhdr)) { 530 ND_PRINT(" (length %u < %zu)", length, sizeof(struct longhdr)); 531 goto invalid; 532 } 533 ND_TCHECK_SIZE(&rhp->rh_long); 534 dst = 535 GET_LE_U_2(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr); 536 src = 537 GET_LE_U_2(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr); 538 hops = GET_U_1(rhp->rh_long.lg_visits); 539 nspp = ap + sizeof(short) + sizeof(struct longhdr); 540 nsplen = length - sizeof(struct longhdr); 541 break; 542 case RMF_SHORT: 543 dst = GET_LE_U_2(rhp->rh_short.sh_dst); 544 src = GET_LE_U_2(rhp->rh_short.sh_src); 545 hops = (GET_U_1(rhp->rh_short.sh_visits) & VIS_MASK)+1; 546 nspp = ap + sizeof(short) + sizeof(struct shorthdr); 547 nsplen = length - sizeof(struct shorthdr); 548 break; 549 default: 550 ND_PRINT("unknown message flags under mask"); 551 ND_DEFAULTPRINT((const u_char *)ap, ND_MIN(length, caplen)); 552 return; 553 } 554 555 ND_PRINT("%s > %s %u ", 556 dnaddr_string(ndo, src), dnaddr_string(ndo, dst), pktlen); 557 if (ndo->ndo_vflag) { 558 if (mflags & RMF_RQR) 559 ND_PRINT("RQR "); 560 if (mflags & RMF_RTS) 561 ND_PRINT("RTS "); 562 if (mflags & RMF_IE) 563 ND_PRINT("IE "); 564 ND_PRINT("%u hops ", hops); 565 } 566 567 if (!print_nsp(ndo, nspp, nsplen)) 568 goto invalid; 569 return; 570 571 invalid: 572 nd_print_invalid(ndo); 573 } 574 575 static int 576 print_decnet_ctlmsg(netdissect_options *ndo, 577 const union routehdr *rhp, u_int length, 578 u_int caplen) 579 { 580 /* Our caller has already checked for mflags */ 581 u_int mflags = GET_U_1(rhp->rh_short.sh_flags); 582 const union controlmsg *cmp = (const union controlmsg *)rhp; 583 uint16_t src, dst; 584 u_int info, blksize, eco, ueco, hello, other, vers; 585 u_int priority; 586 const u_char *rhpx = (const u_char *)rhp; 587 588 switch (mflags & RMF_CTLMASK) { 589 case RMF_INIT: 590 ND_PRINT("init "); 591 if (length < sizeof(struct initmsg)) 592 goto invalid; 593 ND_TCHECK_SIZE(&cmp->cm_init); 594 src = GET_LE_U_2(cmp->cm_init.in_src); 595 info = GET_U_1(cmp->cm_init.in_info); 596 blksize = GET_LE_U_2(cmp->cm_init.in_blksize); 597 vers = GET_U_1(cmp->cm_init.in_vers); 598 eco = GET_U_1(cmp->cm_init.in_eco); 599 ueco = GET_U_1(cmp->cm_init.in_ueco); 600 hello = GET_LE_U_2(cmp->cm_init.in_hello); 601 print_t_info(ndo, info); 602 ND_PRINT("src %sblksize %u vers %u eco %u ueco %u hello %u", 603 dnaddr_string(ndo, src), blksize, vers, eco, ueco, 604 hello); 605 break; 606 case RMF_VER: 607 ND_PRINT("verification "); 608 if (length < sizeof(struct verifmsg)) 609 goto invalid; 610 src = GET_LE_U_2(cmp->cm_ver.ve_src); 611 other = GET_U_1(cmp->cm_ver.ve_fcnval); 612 ND_PRINT("src %s fcnval %o", dnaddr_string(ndo, src), other); 613 break; 614 case RMF_TEST: 615 ND_PRINT("test "); 616 if (length < sizeof(struct testmsg)) 617 goto invalid; 618 src = GET_LE_U_2(cmp->cm_test.te_src); 619 other = GET_U_1(cmp->cm_test.te_data); 620 ND_PRINT("src %s data %o", dnaddr_string(ndo, src), other); 621 break; 622 case RMF_L1ROUT: 623 ND_PRINT("lev-1-routing "); 624 if (length < sizeof(struct l1rout)) 625 goto invalid; 626 ND_TCHECK_SIZE(&cmp->cm_l1rou); 627 src = GET_LE_U_2(cmp->cm_l1rou.r1_src); 628 ND_PRINT("src %s ", dnaddr_string(ndo, src)); 629 print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]), 630 length - sizeof(struct l1rout)); 631 break; 632 case RMF_L2ROUT: 633 ND_PRINT("lev-2-routing "); 634 if (length < sizeof(struct l2rout)) 635 goto invalid; 636 ND_TCHECK_SIZE(&cmp->cm_l2rout); 637 src = GET_LE_U_2(cmp->cm_l2rout.r2_src); 638 ND_PRINT("src %s ", dnaddr_string(ndo, src)); 639 print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]), 640 length - sizeof(struct l2rout)); 641 break; 642 case RMF_RHELLO: 643 ND_PRINT("router-hello "); 644 if (length < sizeof(struct rhellomsg)) 645 goto invalid; 646 ND_TCHECK_SIZE(&cmp->cm_rhello); 647 vers = GET_U_1(cmp->cm_rhello.rh_vers); 648 eco = GET_U_1(cmp->cm_rhello.rh_eco); 649 ueco = GET_U_1(cmp->cm_rhello.rh_ueco); 650 src = 651 GET_LE_U_2(cmp->cm_rhello.rh_src.dne_remote.dne_nodeaddr); 652 info = GET_U_1(cmp->cm_rhello.rh_info); 653 blksize = GET_LE_U_2(cmp->cm_rhello.rh_blksize); 654 priority = GET_U_1(cmp->cm_rhello.rh_priority); 655 hello = GET_LE_U_2(cmp->cm_rhello.rh_hello); 656 print_i_info(ndo, info); 657 ND_PRINT("vers %u eco %u ueco %u src %s blksize %u pri %u hello %u", 658 vers, eco, ueco, dnaddr_string(ndo, src), 659 blksize, priority, hello); 660 print_elist(&(rhpx[sizeof(struct rhellomsg)]), 661 length - sizeof(struct rhellomsg)); 662 break; 663 case RMF_EHELLO: 664 ND_PRINT("endnode-hello "); 665 if (length < sizeof(struct ehellomsg)) 666 goto invalid; 667 vers = GET_U_1(cmp->cm_ehello.eh_vers); 668 eco = GET_U_1(cmp->cm_ehello.eh_eco); 669 ueco = GET_U_1(cmp->cm_ehello.eh_ueco); 670 src = 671 GET_LE_U_2(cmp->cm_ehello.eh_src.dne_remote.dne_nodeaddr); 672 info = GET_U_1(cmp->cm_ehello.eh_info); 673 blksize = GET_LE_U_2(cmp->cm_ehello.eh_blksize); 674 /*seed*/ 675 dst = 676 GET_LE_U_2(cmp->cm_ehello.eh_router.dne_remote.dne_nodeaddr); 677 hello = GET_LE_U_2(cmp->cm_ehello.eh_hello); 678 other = GET_U_1(cmp->cm_ehello.eh_data); 679 print_i_info(ndo, info); 680 ND_PRINT("vers %u eco %u ueco %u src %s blksize %u rtr %s hello %u data %o", 681 vers, eco, ueco, dnaddr_string(ndo, src), 682 blksize, dnaddr_string(ndo, dst), hello, other); 683 break; 684 685 default: 686 ND_PRINT("unknown control message"); 687 ND_DEFAULTPRINT((const u_char *)rhp, ND_MIN(length, caplen)); 688 break; 689 } 690 return (1); 691 692 invalid: 693 return (0); 694 } 695 696 static void 697 print_t_info(netdissect_options *ndo, 698 u_int info) 699 { 700 u_int ntype = info & 3; 701 switch (ntype) { 702 case 0: ND_PRINT("reserved-ntype? "); break; 703 case TI_L2ROUT: ND_PRINT("l2rout "); break; 704 case TI_L1ROUT: ND_PRINT("l1rout "); break; 705 case TI_ENDNODE: ND_PRINT("endnode "); break; 706 } 707 if (info & TI_VERIF) 708 ND_PRINT("verif "); 709 if (info & TI_BLOCK) 710 ND_PRINT("blo "); 711 } 712 713 static void 714 print_l1_routes(netdissect_options *ndo, 715 const u_char *rp, u_int len) 716 { 717 u_int count; 718 u_int id; 719 u_int info; 720 721 /* The last short is a checksum */ 722 while (len > (3 * sizeof(short))) { 723 ND_TCHECK_LEN(rp, 3 * sizeof(short)); 724 count = GET_LE_U_2(rp); 725 if (count > 1024) 726 return; /* seems to be bogus from here on */ 727 rp += sizeof(short); 728 len -= sizeof(short); 729 id = GET_LE_U_2(rp); 730 rp += sizeof(short); 731 len -= sizeof(short); 732 info = GET_LE_U_2(rp); 733 rp += sizeof(short); 734 len -= sizeof(short); 735 ND_PRINT("{ids %u-%u cost %u hops %u} ", id, id + count, 736 RI_COST(info), RI_HOPS(info)); 737 } 738 } 739 740 static void 741 print_l2_routes(netdissect_options *ndo, 742 const u_char *rp, u_int len) 743 { 744 u_int count; 745 u_int area; 746 u_int info; 747 748 /* The last short is a checksum */ 749 while (len > (3 * sizeof(short))) { 750 ND_TCHECK_LEN(rp, 3 * sizeof(short)); 751 count = GET_LE_U_2(rp); 752 if (count > 1024) 753 return; /* seems to be bogus from here on */ 754 rp += sizeof(short); 755 len -= sizeof(short); 756 area = GET_LE_U_2(rp); 757 rp += sizeof(short); 758 len -= sizeof(short); 759 info = GET_LE_U_2(rp); 760 rp += sizeof(short); 761 len -= sizeof(short); 762 ND_PRINT("{areas %u-%u cost %u hops %u} ", area, area + count, 763 RI_COST(info), RI_HOPS(info)); 764 } 765 } 766 767 static void 768 print_i_info(netdissect_options *ndo, 769 u_int info) 770 { 771 u_int ntype = info & II_TYPEMASK; 772 switch (ntype) { 773 case 0: ND_PRINT("reserved-ntype? "); break; 774 case II_L2ROUT: ND_PRINT("l2rout "); break; 775 case II_L1ROUT: ND_PRINT("l1rout "); break; 776 case II_ENDNODE: ND_PRINT("endnode "); break; 777 } 778 if (info & II_VERIF) 779 ND_PRINT("verif "); 780 if (info & II_NOMCAST) 781 ND_PRINT("nomcast "); 782 if (info & II_BLOCK) 783 ND_PRINT("blo "); 784 } 785 786 static void 787 print_elist(const u_char *elp _U_, u_int len _U_) 788 { 789 /* Not enough examples available for me to debug this */ 790 } 791 792 static int 793 print_nsp(netdissect_options *ndo, 794 const u_char *nspp, u_int nsplen) 795 { 796 const struct nsphdr *nsphp = (const struct nsphdr *)nspp; 797 u_int dst, src, flags; 798 799 if (nsplen < sizeof(struct nsphdr)) { 800 ND_PRINT(" (nsplen %u < %zu)", nsplen, sizeof(struct nsphdr)); 801 goto invalid; 802 } 803 flags = GET_U_1(nsphp->nh_flags); 804 dst = GET_LE_U_2(nsphp->nh_dst); 805 src = GET_LE_U_2(nsphp->nh_src); 806 807 switch (flags & NSP_TYPEMASK) { 808 case MFT_DATA: 809 switch (flags & NSP_SUBMASK) { 810 case MFS_BOM: 811 case MFS_MOM: 812 case MFS_EOM: 813 case MFS_BOM+MFS_EOM: 814 ND_PRINT("data %u>%u ", src, dst); 815 { 816 const struct seghdr *shp = (const struct seghdr *)nspp; 817 u_int ack; 818 u_int data_off = sizeof(struct minseghdr); 819 820 if (nsplen < data_off) 821 goto invalid; 822 ack = GET_LE_U_2(shp->sh_seq[0]); 823 if (ack & SGQ_ACK) { /* acknum field */ 824 if ((ack & SGQ_NAK) == SGQ_NAK) 825 ND_PRINT("nak %u ", ack & SGQ_MASK); 826 else 827 ND_PRINT("ack %u ", ack & SGQ_MASK); 828 data_off += sizeof(short); 829 if (nsplen < data_off) 830 goto invalid; 831 ack = GET_LE_U_2(shp->sh_seq[1]); 832 if (ack & SGQ_OACK) { /* ackoth field */ 833 if ((ack & SGQ_ONAK) == SGQ_ONAK) 834 ND_PRINT("onak %u ", ack & SGQ_MASK); 835 else 836 ND_PRINT("oack %u ", ack & SGQ_MASK); 837 data_off += sizeof(short); 838 if (nsplen < data_off) 839 goto invalid; 840 ack = GET_LE_U_2(shp->sh_seq[2]); 841 } 842 } 843 ND_PRINT("seg %u ", ack & SGQ_MASK); 844 } 845 break; 846 case MFS_ILS+MFS_INT: 847 ND_PRINT("intr "); 848 { 849 const struct seghdr *shp = (const struct seghdr *)nspp; 850 u_int ack; 851 u_int data_off = sizeof(struct minseghdr); 852 853 if (nsplen < data_off) 854 goto invalid; 855 ack = GET_LE_U_2(shp->sh_seq[0]); 856 if (ack & SGQ_ACK) { /* acknum field */ 857 if ((ack & SGQ_NAK) == SGQ_NAK) 858 ND_PRINT("nak %u ", ack & SGQ_MASK); 859 else 860 ND_PRINT("ack %u ", ack & SGQ_MASK); 861 data_off += sizeof(short); 862 if (nsplen < data_off) 863 goto invalid; 864 ack = GET_LE_U_2(shp->sh_seq[1]); 865 if (ack & SGQ_OACK) { /* ackdat field */ 866 if ((ack & SGQ_ONAK) == SGQ_ONAK) 867 ND_PRINT("nakdat %u ", ack & SGQ_MASK); 868 else 869 ND_PRINT("ackdat %u ", ack & SGQ_MASK); 870 data_off += sizeof(short); 871 if (nsplen < data_off) 872 goto invalid; 873 ack = GET_LE_U_2(shp->sh_seq[2]); 874 } 875 } 876 ND_PRINT("seg %u ", ack & SGQ_MASK); 877 } 878 break; 879 case MFS_ILS: 880 ND_PRINT("link-service %u>%u ", src, dst); 881 { 882 const struct seghdr *shp = (const struct seghdr *)nspp; 883 const struct lsmsg *lsmp = 884 (const struct lsmsg *)(nspp + sizeof(struct seghdr)); 885 u_int ack; 886 u_int lsflags, fcval; 887 888 if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg)) 889 goto invalid; 890 ack = GET_LE_U_2(shp->sh_seq[0]); 891 if (ack & SGQ_ACK) { /* acknum field */ 892 if ((ack & SGQ_NAK) == SGQ_NAK) 893 ND_PRINT("nak %u ", ack & SGQ_MASK); 894 else 895 ND_PRINT("ack %u ", ack & SGQ_MASK); 896 ack = GET_LE_U_2(shp->sh_seq[1]); 897 if (ack & SGQ_OACK) { /* ackdat field */ 898 if ((ack & SGQ_ONAK) == SGQ_ONAK) 899 ND_PRINT("nakdat %u ", ack & SGQ_MASK); 900 else 901 ND_PRINT("ackdat %u ", ack & SGQ_MASK); 902 ack = GET_LE_U_2(shp->sh_seq[2]); 903 } 904 } 905 ND_PRINT("seg %u ", ack & SGQ_MASK); 906 lsflags = GET_U_1(lsmp->ls_lsflags); 907 fcval = GET_U_1(lsmp->ls_fcval); 908 switch (lsflags & LSI_MASK) { 909 case LSI_DATA: 910 ND_PRINT("dat seg count %u ", fcval); 911 switch (lsflags & LSM_MASK) { 912 case LSM_NOCHANGE: 913 break; 914 case LSM_DONOTSEND: 915 ND_PRINT("donotsend-data "); 916 break; 917 case LSM_SEND: 918 ND_PRINT("send-data "); 919 break; 920 default: 921 ND_PRINT("reserved-fcmod? %x", lsflags); 922 break; 923 } 924 break; 925 case LSI_INTR: 926 ND_PRINT("intr req count %u ", fcval); 927 break; 928 default: 929 ND_PRINT("reserved-fcval-int? %x", lsflags); 930 break; 931 } 932 } 933 break; 934 default: 935 ND_PRINT("reserved-subtype? %x %u > %u", flags, src, dst); 936 break; 937 } 938 break; 939 case MFT_ACK: 940 switch (flags & NSP_SUBMASK) { 941 case MFS_DACK: 942 ND_PRINT("data-ack %u>%u ", src, dst); 943 { 944 const struct ackmsg *amp = (const struct ackmsg *)nspp; 945 u_int ack; 946 947 if (nsplen < sizeof(struct ackmsg)) 948 goto invalid; 949 ND_TCHECK_SIZE(amp); 950 ack = GET_LE_U_2(amp->ak_acknum[0]); 951 if (ack & SGQ_ACK) { /* acknum field */ 952 if ((ack & SGQ_NAK) == SGQ_NAK) 953 ND_PRINT("nak %u ", ack & SGQ_MASK); 954 else 955 ND_PRINT("ack %u ", ack & SGQ_MASK); 956 ack = GET_LE_U_2(amp->ak_acknum[1]); 957 if (ack & SGQ_OACK) { /* ackoth field */ 958 if ((ack & SGQ_ONAK) == SGQ_ONAK) 959 ND_PRINT("onak %u ", ack & SGQ_MASK); 960 else 961 ND_PRINT("oack %u ", ack & SGQ_MASK); 962 } 963 } 964 } 965 break; 966 case MFS_IACK: 967 ND_PRINT("ils-ack %u>%u ", src, dst); 968 { 969 const struct ackmsg *amp = (const struct ackmsg *)nspp; 970 u_int ack; 971 972 if (nsplen < sizeof(struct ackmsg)) 973 goto invalid; 974 ND_TCHECK_SIZE(amp); 975 ack = GET_LE_U_2(amp->ak_acknum[0]); 976 if (ack & SGQ_ACK) { /* acknum field */ 977 if ((ack & SGQ_NAK) == SGQ_NAK) 978 ND_PRINT("nak %u ", ack & SGQ_MASK); 979 else 980 ND_PRINT("ack %u ", ack & SGQ_MASK); 981 ack = GET_LE_U_2(amp->ak_acknum[1]); 982 if (ack & SGQ_OACK) { /* ackdat field */ 983 if ((ack & SGQ_ONAK) == SGQ_ONAK) 984 ND_PRINT("nakdat %u ", ack & SGQ_MASK); 985 else 986 ND_PRINT("ackdat %u ", ack & SGQ_MASK); 987 } 988 } 989 } 990 break; 991 case MFS_CACK: 992 ND_PRINT("conn-ack %u", dst); 993 break; 994 default: 995 ND_PRINT("reserved-acktype? %x %u > %u", flags, src, dst); 996 break; 997 } 998 break; 999 case MFT_CTL: 1000 switch (flags & NSP_SUBMASK) { 1001 case MFS_CI: 1002 case MFS_RCI: 1003 if ((flags & NSP_SUBMASK) == MFS_CI) 1004 ND_PRINT("conn-initiate "); 1005 else 1006 ND_PRINT("retrans-conn-initiate "); 1007 ND_PRINT("%u>%u ", src, dst); 1008 { 1009 const struct cimsg *cimp = (const struct cimsg *)nspp; 1010 u_int services, info, segsize; 1011 1012 if (nsplen < sizeof(struct cimsg)) 1013 goto invalid; 1014 services = GET_U_1(cimp->ci_services); 1015 info = GET_U_1(cimp->ci_info); 1016 segsize = GET_LE_U_2(cimp->ci_segsize); 1017 1018 switch (services & COS_MASK) { 1019 case COS_NONE: 1020 break; 1021 case COS_SEGMENT: 1022 ND_PRINT("seg "); 1023 break; 1024 case COS_MESSAGE: 1025 ND_PRINT("msg "); 1026 break; 1027 } 1028 switch (info & COI_MASK) { 1029 case COI_32: 1030 ND_PRINT("ver 3.2 "); 1031 break; 1032 case COI_31: 1033 ND_PRINT("ver 3.1 "); 1034 break; 1035 case COI_40: 1036 ND_PRINT("ver 4.0 "); 1037 break; 1038 case COI_41: 1039 ND_PRINT("ver 4.1 "); 1040 break; 1041 } 1042 ND_PRINT("segsize %u ", segsize); 1043 } 1044 break; 1045 case MFS_CC: 1046 ND_PRINT("conn-confirm %u>%u ", src, dst); 1047 { 1048 const struct ccmsg *ccmp = (const struct ccmsg *)nspp; 1049 u_int services, info; 1050 u_int segsize, optlen; 1051 1052 if (nsplen < sizeof(struct ccmsg)) 1053 goto invalid; 1054 services = GET_U_1(ccmp->cc_services); 1055 info = GET_U_1(ccmp->cc_info); 1056 segsize = GET_LE_U_2(ccmp->cc_segsize); 1057 optlen = GET_U_1(ccmp->cc_optlen); 1058 1059 switch (services & COS_MASK) { 1060 case COS_NONE: 1061 break; 1062 case COS_SEGMENT: 1063 ND_PRINT("seg "); 1064 break; 1065 case COS_MESSAGE: 1066 ND_PRINT("msg "); 1067 break; 1068 } 1069 switch (info & COI_MASK) { 1070 case COI_32: 1071 ND_PRINT("ver 3.2 "); 1072 break; 1073 case COI_31: 1074 ND_PRINT("ver 3.1 "); 1075 break; 1076 case COI_40: 1077 ND_PRINT("ver 4.0 "); 1078 break; 1079 case COI_41: 1080 ND_PRINT("ver 4.1 "); 1081 break; 1082 } 1083 ND_PRINT("segsize %u ", segsize); 1084 if (optlen) { 1085 ND_PRINT("optlen %u ", optlen); 1086 } 1087 } 1088 break; 1089 case MFS_DI: 1090 ND_PRINT("disconn-initiate %u>%u ", src, dst); 1091 { 1092 const struct dimsg *dimp = (const struct dimsg *)nspp; 1093 u_int reason; 1094 u_int optlen; 1095 1096 if (nsplen < sizeof(struct dimsg)) 1097 goto invalid; 1098 reason = GET_LE_U_2(dimp->di_reason); 1099 optlen = GET_U_1(dimp->di_optlen); 1100 1101 print_reason(ndo, reason); 1102 if (optlen) { 1103 ND_PRINT("optlen %u ", optlen); 1104 } 1105 } 1106 break; 1107 case MFS_DC: 1108 ND_PRINT("disconn-confirm %u>%u ", src, dst); 1109 { 1110 const struct dcmsg *dcmp = (const struct dcmsg *)nspp; 1111 u_int reason; 1112 1113 reason = GET_LE_U_2(dcmp->dc_reason); 1114 1115 print_reason(ndo, reason); 1116 } 1117 break; 1118 default: 1119 ND_PRINT("reserved-ctltype? %x %u > %u", flags, src, dst); 1120 break; 1121 } 1122 break; 1123 default: 1124 ND_PRINT("reserved-type? %x %u > %u", flags, src, dst); 1125 break; 1126 } 1127 return (1); 1128 1129 invalid: 1130 return (0); 1131 } 1132 1133 static const struct tok reason2str[] = { 1134 { UC_OBJREJECT, "object rejected connect" }, 1135 { UC_RESOURCES, "insufficient resources" }, 1136 { UC_NOSUCHNODE, "unrecognized node name" }, 1137 { DI_SHUT, "node is shutting down" }, 1138 { UC_NOSUCHOBJ, "unrecognized object" }, 1139 { UC_INVOBJFORMAT, "invalid object name format" }, 1140 { UC_OBJTOOBUSY, "object too busy" }, 1141 { DI_PROTOCOL, "protocol error discovered" }, 1142 { DI_TPA, "third party abort" }, 1143 { UC_USERABORT, "user abort" }, 1144 { UC_INVNODEFORMAT, "invalid node name format" }, 1145 { UC_LOCALSHUT, "local node shutting down" }, 1146 { DI_LOCALRESRC, "insufficient local resources" }, 1147 { DI_REMUSERRESRC, "insufficient remote user resources" }, 1148 { UC_ACCESSREJECT, "invalid access control information" }, 1149 { DI_BADACCNT, "bad ACCOUNT information" }, 1150 { UC_NORESPONSE, "no response from object" }, 1151 { UC_UNREACHABLE, "node unreachable" }, 1152 { DC_NOLINK, "no link terminate" }, 1153 { DC_COMPLETE, "disconnect complete" }, 1154 { DI_BADIMAGE, "bad image data in connect" }, 1155 { DI_SERVMISMATCH, "cryptographic service mismatch" }, 1156 { 0, NULL } 1157 }; 1158 1159 static void 1160 print_reason(netdissect_options *ndo, 1161 u_int reason) 1162 { 1163 ND_PRINT("%s ", tok2str(reason2str, "reason-%u", reason)); 1164 } 1165 1166 const char * 1167 dnnum_string(netdissect_options *ndo, u_short dnaddr) 1168 { 1169 char *str; 1170 size_t siz; 1171 u_int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT; 1172 u_int node = dnaddr & NODEMASK; 1173 1174 /* malloc() return used by the 'dnaddrtable' hash table: do not free() */ 1175 str = (char *)malloc(siz = sizeof("00.0000")); 1176 if (str == NULL) 1177 (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "%s: malloc", __func__); 1178 snprintf(str, siz, "%u.%u", area, node); 1179 return(str); 1180 } 1181