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