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