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