]> The Tcpdump Group git mirrors - tcpdump/blob - print-decnet.c
Remove useless 'return' at end of void functions (style)
[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 }
590
591 static int
592 print_decnet_ctlmsg(netdissect_options *ndo,
593 const union routehdr *rhp, u_int length,
594 u_int caplen)
595 {
596 /* Our caller has already checked for mflags */
597 u_int mflags = GET_U_1(rhp->rh_short.sh_flags);
598 const union controlmsg *cmp = (const union controlmsg *)rhp;
599 uint16_t src, dst;
600 u_int info, blksize, eco, ueco, hello, other, vers;
601 u_int priority;
602 const u_char *rhpx = (const u_char *)rhp;
603 int ret;
604
605 switch (mflags & RMF_CTLMASK) {
606 case RMF_INIT:
607 ND_PRINT("init ");
608 if (length < sizeof(struct initmsg))
609 goto trunc;
610 ND_TCHECK_SIZE(&cmp->cm_init);
611 src = GET_LE_U_2(cmp->cm_init.in_src);
612 info = GET_U_1(cmp->cm_init.in_info);
613 blksize = GET_LE_U_2(cmp->cm_init.in_blksize);
614 vers = GET_U_1(cmp->cm_init.in_vers);
615 eco = GET_U_1(cmp->cm_init.in_eco);
616 ueco = GET_U_1(cmp->cm_init.in_ueco);
617 hello = GET_LE_U_2(cmp->cm_init.in_hello);
618 print_t_info(ndo, info);
619 ND_PRINT("src %sblksize %u vers %u eco %u ueco %u hello %u",
620 dnaddr_string(ndo, src), blksize, vers, eco, ueco,
621 hello);
622 ret = 1;
623 break;
624 case RMF_VER:
625 ND_PRINT("verification ");
626 if (length < sizeof(struct verifmsg))
627 goto trunc;
628 ND_TCHECK_SIZE(&cmp->cm_ver);
629 src = GET_LE_U_2(cmp->cm_ver.ve_src);
630 other = GET_U_1(cmp->cm_ver.ve_fcnval);
631 ND_PRINT("src %s fcnval %o", dnaddr_string(ndo, src), other);
632 ret = 1;
633 break;
634 case RMF_TEST:
635 ND_PRINT("test ");
636 if (length < sizeof(struct testmsg))
637 goto trunc;
638 ND_TCHECK_SIZE(&cmp->cm_test);
639 src = GET_LE_U_2(cmp->cm_test.te_src);
640 other = GET_U_1(cmp->cm_test.te_data);
641 ND_PRINT("src %s data %o", dnaddr_string(ndo, src), other);
642 ret = 1;
643 break;
644 case RMF_L1ROUT:
645 ND_PRINT("lev-1-routing ");
646 if (length < sizeof(struct l1rout))
647 goto trunc;
648 ND_TCHECK_SIZE(&cmp->cm_l1rou);
649 src = GET_LE_U_2(cmp->cm_l1rou.r1_src);
650 ND_PRINT("src %s ", dnaddr_string(ndo, src));
651 ret = print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]),
652 length - sizeof(struct l1rout));
653 break;
654 case RMF_L2ROUT:
655 ND_PRINT("lev-2-routing ");
656 if (length < sizeof(struct l2rout))
657 goto trunc;
658 ND_TCHECK_SIZE(&cmp->cm_l2rout);
659 src = GET_LE_U_2(cmp->cm_l2rout.r2_src);
660 ND_PRINT("src %s ", dnaddr_string(ndo, src));
661 ret = print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]),
662 length - sizeof(struct l2rout));
663 break;
664 case RMF_RHELLO:
665 ND_PRINT("router-hello ");
666 if (length < sizeof(struct rhellomsg))
667 goto trunc;
668 ND_TCHECK_SIZE(&cmp->cm_rhello);
669 vers = GET_U_1(cmp->cm_rhello.rh_vers);
670 eco = GET_U_1(cmp->cm_rhello.rh_eco);
671 ueco = GET_U_1(cmp->cm_rhello.rh_ueco);
672 src =
673 GET_LE_U_2(cmp->cm_rhello.rh_src.dne_remote.dne_nodeaddr);
674 info = GET_U_1(cmp->cm_rhello.rh_info);
675 blksize = GET_LE_U_2(cmp->cm_rhello.rh_blksize);
676 priority = GET_U_1(cmp->cm_rhello.rh_priority);
677 hello = GET_LE_U_2(cmp->cm_rhello.rh_hello);
678 print_i_info(ndo, info);
679 ND_PRINT("vers %u eco %u ueco %u src %s blksize %u pri %u hello %u",
680 vers, eco, ueco, dnaddr_string(ndo, src),
681 blksize, priority, hello);
682 ret = print_elist(&(rhpx[sizeof(struct rhellomsg)]),
683 length - sizeof(struct rhellomsg));
684 break;
685 case RMF_EHELLO:
686 ND_PRINT("endnode-hello ");
687 if (length < sizeof(struct ehellomsg))
688 goto trunc;
689 ND_TCHECK_SIZE(&cmp->cm_ehello);
690 vers = GET_U_1(cmp->cm_ehello.eh_vers);
691 eco = GET_U_1(cmp->cm_ehello.eh_eco);
692 ueco = GET_U_1(cmp->cm_ehello.eh_ueco);
693 src =
694 GET_LE_U_2(cmp->cm_ehello.eh_src.dne_remote.dne_nodeaddr);
695 info = GET_U_1(cmp->cm_ehello.eh_info);
696 blksize = GET_LE_U_2(cmp->cm_ehello.eh_blksize);
697 /*seed*/
698 dst =
699 GET_LE_U_2(cmp->cm_ehello.eh_router.dne_remote.dne_nodeaddr);
700 hello = GET_LE_U_2(cmp->cm_ehello.eh_hello);
701 other = GET_U_1(cmp->cm_ehello.eh_data);
702 print_i_info(ndo, info);
703 ND_PRINT("vers %u eco %u ueco %u src %s blksize %u rtr %s hello %u data %o",
704 vers, eco, ueco, dnaddr_string(ndo, src),
705 blksize, dnaddr_string(ndo, dst), hello, other);
706 ret = 1;
707 break;
708
709 default:
710 ND_PRINT("unknown control message");
711 ND_DEFAULTPRINT((const u_char *)rhp, ND_MIN(length, caplen));
712 ret = 1;
713 break;
714 }
715 return (ret);
716
717 trunc:
718 return (0);
719 }
720
721 static void
722 print_t_info(netdissect_options *ndo,
723 u_int info)
724 {
725 u_int ntype = info & 3;
726 switch (ntype) {
727 case 0: ND_PRINT("reserved-ntype? "); break;
728 case TI_L2ROUT: ND_PRINT("l2rout "); break;
729 case TI_L1ROUT: ND_PRINT("l1rout "); break;
730 case TI_ENDNODE: ND_PRINT("endnode "); break;
731 }
732 if (info & TI_VERIF)
733 ND_PRINT("verif ");
734 if (info & TI_BLOCK)
735 ND_PRINT("blo ");
736 }
737
738 static int
739 print_l1_routes(netdissect_options *ndo,
740 const u_char *rp, u_int len)
741 {
742 u_int count;
743 u_int id;
744 u_int info;
745
746 /* The last short is a checksum */
747 while (len > (3 * sizeof(short))) {
748 ND_TCHECK_LEN(rp, 3 * sizeof(short));
749 count = GET_LE_U_2(rp);
750 if (count > 1024)
751 return (1); /* seems to be bogus from here on */
752 rp += sizeof(short);
753 len -= sizeof(short);
754 id = GET_LE_U_2(rp);
755 rp += sizeof(short);
756 len -= sizeof(short);
757 info = GET_LE_U_2(rp);
758 rp += sizeof(short);
759 len -= sizeof(short);
760 ND_PRINT("{ids %u-%u cost %u hops %u} ", id, id + count,
761 RI_COST(info), RI_HOPS(info));
762 }
763 return (1);
764
765 trunc:
766 return (0);
767 }
768
769 static int
770 print_l2_routes(netdissect_options *ndo,
771 const u_char *rp, u_int len)
772 {
773 u_int count;
774 u_int area;
775 u_int info;
776
777 /* The last short is a checksum */
778 while (len > (3 * sizeof(short))) {
779 ND_TCHECK_LEN(rp, 3 * sizeof(short));
780 count = GET_LE_U_2(rp);
781 if (count > 1024)
782 return (1); /* seems to be bogus from here on */
783 rp += sizeof(short);
784 len -= sizeof(short);
785 area = GET_LE_U_2(rp);
786 rp += sizeof(short);
787 len -= sizeof(short);
788 info = GET_LE_U_2(rp);
789 rp += sizeof(short);
790 len -= sizeof(short);
791 ND_PRINT("{areas %u-%u cost %u hops %u} ", area, area + count,
792 RI_COST(info), RI_HOPS(info));
793 }
794 return (1);
795
796 trunc:
797 return (0);
798 }
799
800 static void
801 print_i_info(netdissect_options *ndo,
802 u_int info)
803 {
804 u_int ntype = info & II_TYPEMASK;
805 switch (ntype) {
806 case 0: ND_PRINT("reserved-ntype? "); break;
807 case II_L2ROUT: ND_PRINT("l2rout "); break;
808 case II_L1ROUT: ND_PRINT("l1rout "); break;
809 case II_ENDNODE: ND_PRINT("endnode "); break;
810 }
811 if (info & II_VERIF)
812 ND_PRINT("verif ");
813 if (info & II_NOMCAST)
814 ND_PRINT("nomcast ");
815 if (info & II_BLOCK)
816 ND_PRINT("blo ");
817 }
818
819 static int
820 print_elist(const u_char *elp _U_, u_int len _U_)
821 {
822 /* Not enough examples available for me to debug this */
823 return (1);
824 }
825
826 static int
827 print_nsp(netdissect_options *ndo,
828 const u_char *nspp, u_int nsplen)
829 {
830 const struct nsphdr *nsphp = (const struct nsphdr *)nspp;
831 u_int dst, src, flags;
832
833 if (nsplen < sizeof(struct nsphdr))
834 goto trunc;
835 ND_TCHECK_SIZE(nsphp);
836 flags = GET_U_1(nsphp->nh_flags);
837 dst = GET_LE_U_2(nsphp->nh_dst);
838 src = GET_LE_U_2(nsphp->nh_src);
839
840 switch (flags & NSP_TYPEMASK) {
841 case MFT_DATA:
842 switch (flags & NSP_SUBMASK) {
843 case MFS_BOM:
844 case MFS_MOM:
845 case MFS_EOM:
846 case MFS_BOM+MFS_EOM:
847 ND_PRINT("data %u>%u ", src, dst);
848 {
849 const struct seghdr *shp = (const struct seghdr *)nspp;
850 u_int ack;
851 u_int data_off = sizeof(struct minseghdr);
852
853 if (nsplen < data_off)
854 goto trunc;
855 ack = GET_LE_U_2(shp->sh_seq[0]);
856 if (ack & SGQ_ACK) { /* acknum field */
857 if ((ack & SGQ_NAK) == SGQ_NAK)
858 ND_PRINT("nak %u ", ack & SGQ_MASK);
859 else
860 ND_PRINT("ack %u ", ack & SGQ_MASK);
861 data_off += sizeof(short);
862 if (nsplen < data_off)
863 goto trunc;
864 ack = GET_LE_U_2(shp->sh_seq[1]);
865 if (ack & SGQ_OACK) { /* ackoth field */
866 if ((ack & SGQ_ONAK) == SGQ_ONAK)
867 ND_PRINT("onak %u ", ack & SGQ_MASK);
868 else
869 ND_PRINT("oack %u ", ack & SGQ_MASK);
870 data_off += sizeof(short);
871 if (nsplen < data_off)
872 goto trunc;
873 ack = GET_LE_U_2(shp->sh_seq[2]);
874 }
875 }
876 ND_PRINT("seg %u ", ack & SGQ_MASK);
877 }
878 break;
879 case MFS_ILS+MFS_INT:
880 ND_PRINT("intr ");
881 {
882 const struct seghdr *shp = (const struct seghdr *)nspp;
883 u_int ack;
884 u_int data_off = sizeof(struct minseghdr);
885
886 if (nsplen < data_off)
887 goto trunc;
888 ack = GET_LE_U_2(shp->sh_seq[0]);
889 if (ack & SGQ_ACK) { /* acknum field */
890 if ((ack & SGQ_NAK) == SGQ_NAK)
891 ND_PRINT("nak %u ", ack & SGQ_MASK);
892 else
893 ND_PRINT("ack %u ", ack & SGQ_MASK);
894 data_off += sizeof(short);
895 if (nsplen < data_off)
896 goto trunc;
897 ack = GET_LE_U_2(shp->sh_seq[1]);
898 if (ack & SGQ_OACK) { /* ackdat field */
899 if ((ack & SGQ_ONAK) == SGQ_ONAK)
900 ND_PRINT("nakdat %u ", ack & SGQ_MASK);
901 else
902 ND_PRINT("ackdat %u ", ack & SGQ_MASK);
903 data_off += sizeof(short);
904 if (nsplen < data_off)
905 goto trunc;
906 ack = GET_LE_U_2(shp->sh_seq[2]);
907 }
908 }
909 ND_PRINT("seg %u ", ack & SGQ_MASK);
910 }
911 break;
912 case MFS_ILS:
913 ND_PRINT("link-service %u>%u ", src, dst);
914 {
915 const struct seghdr *shp = (const struct seghdr *)nspp;
916 const struct lsmsg *lsmp =
917 (const struct lsmsg *)(nspp + sizeof(struct seghdr));
918 u_int ack;
919 u_int lsflags, fcval;
920
921 if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
922 goto trunc;
923 ack = GET_LE_U_2(shp->sh_seq[0]);
924 if (ack & SGQ_ACK) { /* acknum field */
925 if ((ack & SGQ_NAK) == SGQ_NAK)
926 ND_PRINT("nak %u ", ack & SGQ_MASK);
927 else
928 ND_PRINT("ack %u ", ack & SGQ_MASK);
929 ack = GET_LE_U_2(shp->sh_seq[1]);
930 if (ack & SGQ_OACK) { /* ackdat field */
931 if ((ack & SGQ_ONAK) == SGQ_ONAK)
932 ND_PRINT("nakdat %u ", ack & SGQ_MASK);
933 else
934 ND_PRINT("ackdat %u ", ack & SGQ_MASK);
935 ack = GET_LE_U_2(shp->sh_seq[2]);
936 }
937 }
938 ND_PRINT("seg %u ", ack & SGQ_MASK);
939 ND_TCHECK_SIZE(lsmp);
940 lsflags = GET_U_1(lsmp->ls_lsflags);
941 fcval = GET_U_1(lsmp->ls_fcval);
942 switch (lsflags & LSI_MASK) {
943 case LSI_DATA:
944 ND_PRINT("dat seg count %u ", fcval);
945 switch (lsflags & LSM_MASK) {
946 case LSM_NOCHANGE:
947 break;
948 case LSM_DONOTSEND:
949 ND_PRINT("donotsend-data ");
950 break;
951 case LSM_SEND:
952 ND_PRINT("send-data ");
953 break;
954 default:
955 ND_PRINT("reserved-fcmod? %x", lsflags);
956 break;
957 }
958 break;
959 case LSI_INTR:
960 ND_PRINT("intr req count %u ", fcval);
961 break;
962 default:
963 ND_PRINT("reserved-fcval-int? %x", lsflags);
964 break;
965 }
966 }
967 break;
968 default:
969 ND_PRINT("reserved-subtype? %x %u > %u", flags, src, dst);
970 break;
971 }
972 break;
973 case MFT_ACK:
974 switch (flags & NSP_SUBMASK) {
975 case MFS_DACK:
976 ND_PRINT("data-ack %u>%u ", src, dst);
977 {
978 const struct ackmsg *amp = (const struct ackmsg *)nspp;
979 u_int ack;
980
981 if (nsplen < sizeof(struct ackmsg))
982 goto trunc;
983 ND_TCHECK_SIZE(amp);
984 ack = GET_LE_U_2(amp->ak_acknum[0]);
985 if (ack & SGQ_ACK) { /* acknum field */
986 if ((ack & SGQ_NAK) == SGQ_NAK)
987 ND_PRINT("nak %u ", ack & SGQ_MASK);
988 else
989 ND_PRINT("ack %u ", ack & SGQ_MASK);
990 ack = GET_LE_U_2(amp->ak_acknum[1]);
991 if (ack & SGQ_OACK) { /* ackoth field */
992 if ((ack & SGQ_ONAK) == SGQ_ONAK)
993 ND_PRINT("onak %u ", ack & SGQ_MASK);
994 else
995 ND_PRINT("oack %u ", ack & SGQ_MASK);
996 }
997 }
998 }
999 break;
1000 case MFS_IACK:
1001 ND_PRINT("ils-ack %u>%u ", src, dst);
1002 {
1003 const struct ackmsg *amp = (const struct ackmsg *)nspp;
1004 u_int ack;
1005
1006 if (nsplen < sizeof(struct ackmsg))
1007 goto trunc;
1008 ND_TCHECK_SIZE(amp);
1009 ack = GET_LE_U_2(amp->ak_acknum[0]);
1010 if (ack & SGQ_ACK) { /* acknum field */
1011 if ((ack & SGQ_NAK) == SGQ_NAK)
1012 ND_PRINT("nak %u ", ack & SGQ_MASK);
1013 else
1014 ND_PRINT("ack %u ", ack & SGQ_MASK);
1015 ack = GET_LE_U_2(amp->ak_acknum[1]);
1016 if (ack & SGQ_OACK) { /* ackdat field */
1017 if ((ack & SGQ_ONAK) == SGQ_ONAK)
1018 ND_PRINT("nakdat %u ", ack & SGQ_MASK);
1019 else
1020 ND_PRINT("ackdat %u ", ack & SGQ_MASK);
1021 }
1022 }
1023 }
1024 break;
1025 case MFS_CACK:
1026 ND_PRINT("conn-ack %u", dst);
1027 break;
1028 default:
1029 ND_PRINT("reserved-acktype? %x %u > %u", flags, src, dst);
1030 break;
1031 }
1032 break;
1033 case MFT_CTL:
1034 switch (flags & NSP_SUBMASK) {
1035 case MFS_CI:
1036 case MFS_RCI:
1037 if ((flags & NSP_SUBMASK) == MFS_CI)
1038 ND_PRINT("conn-initiate ");
1039 else
1040 ND_PRINT("retrans-conn-initiate ");
1041 ND_PRINT("%u>%u ", src, dst);
1042 {
1043 const struct cimsg *cimp = (const struct cimsg *)nspp;
1044 u_int services, info, segsize;
1045
1046 if (nsplen < sizeof(struct cimsg))
1047 goto trunc;
1048 ND_TCHECK_SIZE(cimp);
1049 services = GET_U_1(cimp->ci_services);
1050 info = GET_U_1(cimp->ci_info);
1051 segsize = GET_LE_U_2(cimp->ci_segsize);
1052
1053 switch (services & COS_MASK) {
1054 case COS_NONE:
1055 break;
1056 case COS_SEGMENT:
1057 ND_PRINT("seg ");
1058 break;
1059 case COS_MESSAGE:
1060 ND_PRINT("msg ");
1061 break;
1062 }
1063 switch (info & COI_MASK) {
1064 case COI_32:
1065 ND_PRINT("ver 3.2 ");
1066 break;
1067 case COI_31:
1068 ND_PRINT("ver 3.1 ");
1069 break;
1070 case COI_40:
1071 ND_PRINT("ver 4.0 ");
1072 break;
1073 case COI_41:
1074 ND_PRINT("ver 4.1 ");
1075 break;
1076 }
1077 ND_PRINT("segsize %u ", segsize);
1078 }
1079 break;
1080 case MFS_CC:
1081 ND_PRINT("conn-confirm %u>%u ", src, dst);
1082 {
1083 const struct ccmsg *ccmp = (const struct ccmsg *)nspp;
1084 u_int services, info;
1085 u_int segsize, optlen;
1086
1087 if (nsplen < sizeof(struct ccmsg))
1088 goto trunc;
1089 ND_TCHECK_SIZE(ccmp);
1090 services = GET_U_1(ccmp->cc_services);
1091 info = GET_U_1(ccmp->cc_info);
1092 segsize = GET_LE_U_2(ccmp->cc_segsize);
1093 optlen = GET_U_1(ccmp->cc_optlen);
1094
1095 switch (services & COS_MASK) {
1096 case COS_NONE:
1097 break;
1098 case COS_SEGMENT:
1099 ND_PRINT("seg ");
1100 break;
1101 case COS_MESSAGE:
1102 ND_PRINT("msg ");
1103 break;
1104 }
1105 switch (info & COI_MASK) {
1106 case COI_32:
1107 ND_PRINT("ver 3.2 ");
1108 break;
1109 case COI_31:
1110 ND_PRINT("ver 3.1 ");
1111 break;
1112 case COI_40:
1113 ND_PRINT("ver 4.0 ");
1114 break;
1115 case COI_41:
1116 ND_PRINT("ver 4.1 ");
1117 break;
1118 }
1119 ND_PRINT("segsize %u ", segsize);
1120 if (optlen) {
1121 ND_PRINT("optlen %u ", optlen);
1122 }
1123 }
1124 break;
1125 case MFS_DI:
1126 ND_PRINT("disconn-initiate %u>%u ", src, dst);
1127 {
1128 const struct dimsg *dimp = (const struct dimsg *)nspp;
1129 u_int reason;
1130 u_int optlen;
1131
1132 if (nsplen < sizeof(struct dimsg))
1133 goto trunc;
1134 ND_TCHECK_SIZE(dimp);
1135 reason = GET_LE_U_2(dimp->di_reason);
1136 optlen = GET_U_1(dimp->di_optlen);
1137
1138 print_reason(ndo, reason);
1139 if (optlen) {
1140 ND_PRINT("optlen %u ", optlen);
1141 }
1142 }
1143 break;
1144 case MFS_DC:
1145 ND_PRINT("disconn-confirm %u>%u ", src, dst);
1146 {
1147 const struct dcmsg *dcmp = (const struct dcmsg *)nspp;
1148 u_int reason;
1149
1150 ND_TCHECK_SIZE(dcmp);
1151 reason = GET_LE_U_2(dcmp->dc_reason);
1152
1153 print_reason(ndo, reason);
1154 }
1155 break;
1156 default:
1157 ND_PRINT("reserved-ctltype? %x %u > %u", flags, src, dst);
1158 break;
1159 }
1160 break;
1161 default:
1162 ND_PRINT("reserved-type? %x %u > %u", flags, src, dst);
1163 break;
1164 }
1165 return (1);
1166
1167 trunc:
1168 return (0);
1169 }
1170
1171 static const struct tok reason2str[] = {
1172 { UC_OBJREJECT, "object rejected connect" },
1173 { UC_RESOURCES, "insufficient resources" },
1174 { UC_NOSUCHNODE, "unrecognized node name" },
1175 { DI_SHUT, "node is shutting down" },
1176 { UC_NOSUCHOBJ, "unrecognized object" },
1177 { UC_INVOBJFORMAT, "invalid object name format" },
1178 { UC_OBJTOOBUSY, "object too busy" },
1179 { DI_PROTOCOL, "protocol error discovered" },
1180 { DI_TPA, "third party abort" },
1181 { UC_USERABORT, "user abort" },
1182 { UC_INVNODEFORMAT, "invalid node name format" },
1183 { UC_LOCALSHUT, "local node shutting down" },
1184 { DI_LOCALRESRC, "insufficient local resources" },
1185 { DI_REMUSERRESRC, "insufficient remote user resources" },
1186 { UC_ACCESSREJECT, "invalid access control information" },
1187 { DI_BADACCNT, "bad ACCOUNT information" },
1188 { UC_NORESPONSE, "no response from object" },
1189 { UC_UNREACHABLE, "node unreachable" },
1190 { DC_NOLINK, "no link terminate" },
1191 { DC_COMPLETE, "disconnect complete" },
1192 { DI_BADIMAGE, "bad image data in connect" },
1193 { DI_SERVMISMATCH, "cryptographic service mismatch" },
1194 { 0, NULL }
1195 };
1196
1197 static void
1198 print_reason(netdissect_options *ndo,
1199 u_int reason)
1200 {
1201 ND_PRINT("%s ", tok2str(reason2str, "reason-%u", reason));
1202 }
1203
1204 const char *
1205 dnnum_string(netdissect_options *ndo, u_short dnaddr)
1206 {
1207 char *str;
1208 size_t siz;
1209 u_int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
1210 u_int node = dnaddr & NODEMASK;
1211
1212 /* malloc() return used by the 'dnaddrtable' hash table: do not free() */
1213 str = (char *)malloc(siz = sizeof("00.0000"));
1214 if (str == NULL)
1215 (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "dnnum_string: malloc");
1216 snprintf(str, siz, "%u.%u", area, node);
1217 return(str);
1218 }