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