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