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