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