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