1546f56c3Schristos /*
2546f56c3Schristos  * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3546f56c3Schristos  *	The Regents of the University of California.  All rights reserved.
4546f56c3Schristos  *
5546f56c3Schristos  * Redistribution and use in source and binary forms, with or without
6546f56c3Schristos  * modification, are permitted provided that: (1) source code distributions
7546f56c3Schristos  * retain the above copyright notice and this paragraph in its entirety, (2)
8546f56c3Schristos  * distributions including binary code include the above copyright notice and
9546f56c3Schristos  * this paragraph in its entirety in the documentation or other materials
10546f56c3Schristos  * provided with the distribution, and (3) all advertising materials mentioning
11546f56c3Schristos  * features or use of this software display the following acknowledgement:
12546f56c3Schristos  * ``This product includes software developed by the University of California,
13546f56c3Schristos  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14546f56c3Schristos  * the University nor the names of its contributors may be used to endorse
15546f56c3Schristos  * or promote products derived from this software without specific prior
16546f56c3Schristos  * written permission.
17546f56c3Schristos  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18546f56c3Schristos  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19546f56c3Schristos  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20546f56c3Schristos  */
21546f56c3Schristos 
22c8632dc8Schristos #include <sys/cdefs.h>
23546f56c3Schristos #ifndef lint
24*193b2145Schristos __RCSID("$NetBSD: print-decnet.c,v 1.10 2019/10/01 16:06:16 christos Exp $");
25546f56c3Schristos #endif
26546f56c3Schristos 
27c767dfb8Sspz /* \summary: DECnet printer */
28c767dfb8Sspz 
29546f56c3Schristos #ifdef HAVE_CONFIG_H
30546f56c3Schristos #include "config.h"
31546f56c3Schristos #endif
32546f56c3Schristos 
33c746cb4fSchristos #include <netdissect-stdinc.h>
34546f56c3Schristos 
35546f56c3Schristos struct mbuf;
36546f56c3Schristos struct rtentry;
37546f56c3Schristos 
38546f56c3Schristos #include <stdio.h>
39546f56c3Schristos #include <stdlib.h>
40546f56c3Schristos #include <string.h>
41546f56c3Schristos 
42546f56c3Schristos #include "extract.h"
43c746cb4fSchristos #include "netdissect.h"
44546f56c3Schristos #include "addrtoname.h"
45546f56c3Schristos 
467e4823a9Schristos static const char tstr[] = "[|decnet]";
477e4823a9Schristos 
48c746cb4fSchristos #ifndef _WIN32
497e4823a9Schristos typedef uint8_t byte[1];		/* single byte field */
507e4823a9Schristos #else
517e4823a9Schristos /*
527e4823a9Schristos  * the keyword 'byte' generates conflicts in Windows
537e4823a9Schristos  */
547e4823a9Schristos typedef unsigned char Byte[1];		/* single byte field */
557e4823a9Schristos #define byte Byte
56c746cb4fSchristos #endif /* _WIN32 */
577e4823a9Schristos typedef uint8_t word[2];		/* 2 byte field */
587e4823a9Schristos typedef uint8_t longword[4];		/* 4 bytes field */
597e4823a9Schristos 
607e4823a9Schristos /*
617e4823a9Schristos  * Definitions for DECNET Phase IV protocol headers
627e4823a9Schristos  */
637e4823a9Schristos union etheraddress {
647e4823a9Schristos 	uint8_t   dne_addr[6];		/* full ethernet address */
657e4823a9Schristos 	struct {
667e4823a9Schristos 		uint8_t dne_hiord[4];	/* DECnet HIORD prefix */
677e4823a9Schristos 		uint8_t dne_nodeaddr[2]; /* DECnet node address */
687e4823a9Schristos 	} dne_remote;
697e4823a9Schristos };
707e4823a9Schristos 
717e4823a9Schristos typedef union etheraddress etheraddr;	/* Ethernet address */
727e4823a9Schristos 
737e4823a9Schristos #define HIORD 0x000400aa		/* high 32-bits of address (swapped) */
747e4823a9Schristos 
757e4823a9Schristos #define AREAMASK	0176000		/* mask for area field */
767e4823a9Schristos #define	AREASHIFT	10		/* bit-offset for area field */
777e4823a9Schristos #define NODEMASK	01777		/* mask for node address field */
787e4823a9Schristos 
797e4823a9Schristos /*
807e4823a9Schristos  * Define long and short header formats.
817e4823a9Schristos  */
827e4823a9Schristos struct shorthdr
837e4823a9Schristos   {
847e4823a9Schristos     byte	sh_flags;		/* route flags */
857e4823a9Schristos     word	sh_dst;			/* destination node address */
867e4823a9Schristos     word	sh_src;			/* source node address */
877e4823a9Schristos     byte	sh_visits;		/* visit count */
887e4823a9Schristos   };
897e4823a9Schristos 
907e4823a9Schristos struct longhdr
917e4823a9Schristos   {
927e4823a9Schristos     byte	lg_flags;		/* route flags */
937e4823a9Schristos     byte	lg_darea;		/* destination area (reserved) */
947e4823a9Schristos     byte	lg_dsarea;		/* destination subarea (reserved) */
957e4823a9Schristos     etheraddr	lg_dst;			/* destination id */
967e4823a9Schristos     byte	lg_sarea;		/* source area (reserved) */
977e4823a9Schristos     byte	lg_ssarea;		/* source subarea (reserved) */
987e4823a9Schristos     etheraddr	lg_src;			/* source id */
997e4823a9Schristos     byte	lg_nextl2;		/* next level 2 router (reserved) */
1007e4823a9Schristos     byte	lg_visits;		/* visit count */
1017e4823a9Schristos     byte	lg_service;		/* service class (reserved) */
1027e4823a9Schristos     byte	lg_pt;			/* protocol type (reserved) */
1037e4823a9Schristos   };
1047e4823a9Schristos 
1057e4823a9Schristos union routehdr
1067e4823a9Schristos   {
1077e4823a9Schristos     struct shorthdr rh_short;		/* short route header */
1087e4823a9Schristos     struct longhdr rh_long;		/* long route header */
1097e4823a9Schristos   };
1107e4823a9Schristos 
1117e4823a9Schristos /*
1127e4823a9Schristos  * Define the values of various fields in the protocol messages.
1137e4823a9Schristos  *
1147e4823a9Schristos  * 1. Data packet formats.
1157e4823a9Schristos  */
1167e4823a9Schristos #define RMF_MASK	7		/* mask for message type */
1177e4823a9Schristos #define RMF_SHORT	2		/* short message format */
1187e4823a9Schristos #define RMF_LONG	6		/* long message format */
1197e4823a9Schristos #ifndef RMF_RQR
1207e4823a9Schristos #define RMF_RQR		010		/* request return to sender */
1217e4823a9Schristos #define RMF_RTS		020		/* returning to sender */
1227e4823a9Schristos #define RMF_IE		040		/* intra-ethernet packet */
1237e4823a9Schristos #endif /* RMR_RQR */
1247e4823a9Schristos #define RMF_FVER	0100		/* future version flag */
1257e4823a9Schristos #define RMF_PAD		0200		/* pad field */
1267e4823a9Schristos #define RMF_PADMASK	0177		/* pad field mask */
1277e4823a9Schristos 
1287e4823a9Schristos #define VIS_MASK	077		/* visit field mask */
1297e4823a9Schristos 
1307e4823a9Schristos /*
1317e4823a9Schristos  * 2. Control packet formats.
1327e4823a9Schristos  */
1337e4823a9Schristos #define RMF_CTLMASK	017		/* mask for message type */
1347e4823a9Schristos #define RMF_CTLMSG	01		/* control message indicator */
1357e4823a9Schristos #define RMF_INIT	01		/* initialization message */
1367e4823a9Schristos #define RMF_VER		03		/* verification message */
1377e4823a9Schristos #define RMF_TEST	05		/* hello and test message */
1387e4823a9Schristos #define RMF_L1ROUT	07		/* level 1 routing message */
1397e4823a9Schristos #define RMF_L2ROUT	011		/* level 2 routing message */
1407e4823a9Schristos #define RMF_RHELLO	013		/* router hello message */
1417e4823a9Schristos #define RMF_EHELLO	015		/* endnode hello message */
1427e4823a9Schristos 
1437e4823a9Schristos #define TI_L2ROUT	01		/* level 2 router */
1447e4823a9Schristos #define TI_L1ROUT	02		/* level 1 router */
1457e4823a9Schristos #define TI_ENDNODE	03		/* endnode */
1467e4823a9Schristos #define TI_VERIF	04		/* verification required */
1477e4823a9Schristos #define TI_BLOCK	010		/* blocking requested */
1487e4823a9Schristos 
1497e4823a9Schristos #define VE_VERS		2		/* version number (2) */
1507e4823a9Schristos #define VE_ECO		0		/* ECO number */
1517e4823a9Schristos #define VE_UECO		0		/* user ECO number (0) */
1527e4823a9Schristos 
1537e4823a9Schristos #define P3_VERS		1		/* phase III version number (1) */
1547e4823a9Schristos #define P3_ECO		3		/* ECO number (3) */
1557e4823a9Schristos #define P3_UECO		0		/* user ECO number (0) */
1567e4823a9Schristos 
1577e4823a9Schristos #define II_L2ROUT	01		/* level 2 router */
1587e4823a9Schristos #define II_L1ROUT	02		/* level 1 router */
1597e4823a9Schristos #define II_ENDNODE	03		/* endnode */
1607e4823a9Schristos #define II_VERIF	04		/* verification required */
1617e4823a9Schristos #define II_NOMCAST	040		/* no multicast traffic accepted */
1627e4823a9Schristos #define II_BLOCK	0100		/* blocking requested */
1637e4823a9Schristos #define II_TYPEMASK	03		/* mask for node type */
1647e4823a9Schristos 
1657e4823a9Schristos #define TESTDATA	0252		/* test data bytes */
1667e4823a9Schristos #define TESTLEN		1		/* length of transmitted test data */
1677e4823a9Schristos 
1687e4823a9Schristos /*
1697e4823a9Schristos  * Define control message formats.
1707e4823a9Schristos  */
1717e4823a9Schristos struct initmsgIII			/* phase III initialization message */
1727e4823a9Schristos   {
1737e4823a9Schristos     byte	inIII_flags;		/* route flags */
1747e4823a9Schristos     word	inIII_src;		/* source node address */
1757e4823a9Schristos     byte	inIII_info;		/* routing layer information */
1767e4823a9Schristos     word	inIII_blksize;		/* maximum data link block size */
1777e4823a9Schristos     byte	inIII_vers;		/* version number */
1787e4823a9Schristos     byte	inIII_eco;		/* ECO number */
1797e4823a9Schristos     byte	inIII_ueco;		/* user ECO number */
1807e4823a9Schristos     byte	inIII_rsvd;		/* reserved image field */
1817e4823a9Schristos   };
1827e4823a9Schristos 
1837e4823a9Schristos struct initmsg				/* initialization message */
1847e4823a9Schristos   {
1857e4823a9Schristos     byte	in_flags;		/* route flags */
1867e4823a9Schristos     word	in_src;			/* source node address */
1877e4823a9Schristos     byte	in_info;		/* routing layer information */
1887e4823a9Schristos     word	in_blksize;		/* maximum data link block size */
1897e4823a9Schristos     byte	in_vers;		/* version number */
1907e4823a9Schristos     byte	in_eco;			/* ECO number */
1917e4823a9Schristos     byte	in_ueco;		/* user ECO number */
1927e4823a9Schristos     word	in_hello;		/* hello timer */
1937e4823a9Schristos     byte	in_rsvd;		/* reserved image field */
1947e4823a9Schristos   };
1957e4823a9Schristos 
1967e4823a9Schristos struct verifmsg				/* verification message */
1977e4823a9Schristos   {
1987e4823a9Schristos     byte	ve_flags;		/* route flags */
1997e4823a9Schristos     word	ve_src;			/* source node address */
2007e4823a9Schristos     byte	ve_fcnval;		/* function value image field */
2017e4823a9Schristos   };
2027e4823a9Schristos 
2037e4823a9Schristos struct testmsg				/* hello and test message */
2047e4823a9Schristos   {
2057e4823a9Schristos     byte	te_flags;		/* route flags */
2067e4823a9Schristos     word	te_src;			/* source node address */
2077e4823a9Schristos     byte	te_data;		/* test data image field */
2087e4823a9Schristos   };
2097e4823a9Schristos 
2107e4823a9Schristos struct l1rout				/* level 1 routing message */
2117e4823a9Schristos   {
2127e4823a9Schristos     byte	r1_flags;		/* route flags */
2137e4823a9Schristos     word	r1_src;			/* source node address */
2147e4823a9Schristos     byte	r1_rsvd;		/* reserved field */
2157e4823a9Schristos   };
2167e4823a9Schristos 
2177e4823a9Schristos struct l2rout				/* level 2 routing message */
2187e4823a9Schristos   {
2197e4823a9Schristos     byte	r2_flags;		/* route flags */
2207e4823a9Schristos     word	r2_src;			/* source node address */
2217e4823a9Schristos     byte	r2_rsvd;		/* reserved field */
2227e4823a9Schristos   };
2237e4823a9Schristos 
2247e4823a9Schristos struct rhellomsg			/* router hello message */
2257e4823a9Schristos   {
2267e4823a9Schristos     byte	rh_flags;		/* route flags */
2277e4823a9Schristos     byte	rh_vers;		/* version number */
2287e4823a9Schristos     byte	rh_eco;			/* ECO number */
2297e4823a9Schristos     byte	rh_ueco;		/* user ECO number */
2307e4823a9Schristos     etheraddr	rh_src;			/* source id */
2317e4823a9Schristos     byte	rh_info;		/* routing layer information */
2327e4823a9Schristos     word	rh_blksize;		/* maximum data link block size */
2337e4823a9Schristos     byte	rh_priority;		/* router's priority */
2347e4823a9Schristos     byte	rh_area;		/* reserved */
2357e4823a9Schristos     word	rh_hello;		/* hello timer */
2367e4823a9Schristos     byte	rh_mpd;			/* reserved */
2377e4823a9Schristos   };
2387e4823a9Schristos 
2397e4823a9Schristos struct ehellomsg			/* endnode hello message */
2407e4823a9Schristos   {
2417e4823a9Schristos     byte	eh_flags;		/* route flags */
2427e4823a9Schristos     byte	eh_vers;		/* version number */
2437e4823a9Schristos     byte	eh_eco;			/* ECO number */
2447e4823a9Schristos     byte	eh_ueco;		/* user ECO number */
2457e4823a9Schristos     etheraddr	eh_src;			/* source id */
2467e4823a9Schristos     byte	eh_info;		/* routing layer information */
2477e4823a9Schristos     word	eh_blksize;		/* maximum data link block size */
2487e4823a9Schristos     byte	eh_area;		/* area (reserved) */
2497e4823a9Schristos     byte	eh_seed[8];		/* verification seed */
2507e4823a9Schristos     etheraddr	eh_router;		/* designated router */
2517e4823a9Schristos     word	eh_hello;		/* hello timer */
2527e4823a9Schristos     byte	eh_mpd;			/* (reserved) */
2537e4823a9Schristos     byte	eh_data;		/* test data image field */
2547e4823a9Schristos   };
2557e4823a9Schristos 
2567e4823a9Schristos union controlmsg
2577e4823a9Schristos   {
2587e4823a9Schristos     struct initmsg	cm_init;	/* initialization message */
2597e4823a9Schristos     struct verifmsg	cm_ver;		/* verification message */
2607e4823a9Schristos     struct testmsg	cm_test;	/* hello and test message */
2617e4823a9Schristos     struct l1rout	cm_l1rou;	/* level 1 routing message */
2627e4823a9Schristos     struct l2rout	cm_l2rout;	/* level 2 routing message */
2637e4823a9Schristos     struct rhellomsg	cm_rhello;	/* router hello message */
2647e4823a9Schristos     struct ehellomsg	cm_ehello;	/* endnode hello message */
2657e4823a9Schristos   };
2667e4823a9Schristos 
2677e4823a9Schristos /* Macros for decoding routing-info fields */
2687e4823a9Schristos #define	RI_COST(x)	((x)&0777)
2697e4823a9Schristos #define	RI_HOPS(x)	(((x)>>10)&037)
27066c3c5b8Schristos 
2717e4823a9Schristos /*
2727e4823a9Schristos  * NSP protocol fields and values.
2737e4823a9Schristos  */
2747e4823a9Schristos 
2757e4823a9Schristos #define NSP_TYPEMASK 014		/* mask to isolate type code */
2767e4823a9Schristos #define NSP_SUBMASK 0160		/* mask to isolate subtype code */
2777e4823a9Schristos #define NSP_SUBSHFT 4			/* shift to move subtype code */
2787e4823a9Schristos 
2797e4823a9Schristos #define MFT_DATA 0			/* data message */
2807e4823a9Schristos #define MFT_ACK  04			/* acknowledgement message */
2817e4823a9Schristos #define MFT_CTL  010			/* control message */
2827e4823a9Schristos 
2837e4823a9Schristos #define MFS_ILS  020			/* data or I/LS indicator */
2847e4823a9Schristos #define MFS_BOM  040			/* beginning of message (data) */
2857e4823a9Schristos #define MFS_MOM  0			/* middle of message (data) */
2867e4823a9Schristos #define MFS_EOM  0100			/* end of message (data) */
2877e4823a9Schristos #define MFS_INT  040			/* interrupt message */
2887e4823a9Schristos 
2897e4823a9Schristos #define MFS_DACK 0			/* data acknowledgement */
2907e4823a9Schristos #define MFS_IACK 020			/* I/LS acknowledgement */
2917e4823a9Schristos #define MFS_CACK 040			/* connect acknowledgement */
2927e4823a9Schristos 
2937e4823a9Schristos #define MFS_NOP  0			/* no operation */
2947e4823a9Schristos #define MFS_CI   020			/* connect initiate */
2957e4823a9Schristos #define MFS_CC   040			/* connect confirm */
2967e4823a9Schristos #define MFS_DI   060			/* disconnect initiate */
2977e4823a9Schristos #define MFS_DC   0100			/* disconnect confirm */
2987e4823a9Schristos #define MFS_RCI  0140			/* retransmitted connect initiate */
2997e4823a9Schristos 
3007e4823a9Schristos #define SGQ_ACK  0100000		/* ack */
3017e4823a9Schristos #define SGQ_NAK  0110000		/* negative ack */
3027e4823a9Schristos #define SGQ_OACK 0120000		/* other channel ack */
3037e4823a9Schristos #define SGQ_ONAK 0130000		/* other channel negative ack */
3047e4823a9Schristos #define SGQ_MASK 07777			/* mask to isolate seq # */
3057e4823a9Schristos #define SGQ_OTHER 020000		/* other channel qualifier */
3067e4823a9Schristos #define SGQ_DELAY 010000		/* ack delay flag */
3077e4823a9Schristos 
3087e4823a9Schristos #define SGQ_EOM  0100000		/* pseudo flag for end-of-message */
3097e4823a9Schristos 
3107e4823a9Schristos #define LSM_MASK 03			/* mask for modifier field */
3117e4823a9Schristos #define LSM_NOCHANGE 0			/* no change */
3127e4823a9Schristos #define LSM_DONOTSEND 1			/* do not send data */
3137e4823a9Schristos #define LSM_SEND 2			/* send data */
3147e4823a9Schristos 
3157e4823a9Schristos #define LSI_MASK 014			/* mask for interpretation field */
3167e4823a9Schristos #define LSI_DATA 0			/* data segment or message count */
3177e4823a9Schristos #define LSI_INTR 4			/* interrupt request count */
3187e4823a9Schristos #define LSI_INTM 0377			/* funny marker for int. message */
3197e4823a9Schristos 
3207e4823a9Schristos #define COS_MASK 014			/* mask for flow control field */
3217e4823a9Schristos #define COS_NONE 0			/* no flow control */
3227e4823a9Schristos #define COS_SEGMENT 04			/* segment flow control */
3237e4823a9Schristos #define COS_MESSAGE 010			/* message flow control */
3247e4823a9Schristos #define COS_DEFAULT 1			/* default value for field */
3257e4823a9Schristos 
3267e4823a9Schristos #define COI_MASK 3			/* mask for version field */
3277e4823a9Schristos #define COI_32 0			/* version 3.2 */
3287e4823a9Schristos #define COI_31 1			/* version 3.1 */
3297e4823a9Schristos #define COI_40 2			/* version 4.0 */
3307e4823a9Schristos #define COI_41 3			/* version 4.1 */
3317e4823a9Schristos 
3327e4823a9Schristos #define MNU_MASK 140			/* mask for session control version */
3337e4823a9Schristos #define MNU_10 000				/* session V1.0 */
3347e4823a9Schristos #define MNU_20 040				/* session V2.0 */
3357e4823a9Schristos #define MNU_ACCESS 1			/* access control present */
3367e4823a9Schristos #define MNU_USRDATA 2			/* user data field present */
3377e4823a9Schristos #define MNU_INVKPROXY 4			/* invoke proxy field present */
3387e4823a9Schristos #define MNU_UICPROXY 8			/* use uic-based proxy */
3397e4823a9Schristos 
3407e4823a9Schristos #define DC_NORESOURCES 1		/* no resource reason code */
3417e4823a9Schristos #define DC_NOLINK 41			/* no link terminate reason code */
3427e4823a9Schristos #define DC_COMPLETE 42			/* disconnect complete reason code */
3437e4823a9Schristos 
3447e4823a9Schristos #define DI_NOERROR 0			/* user disconnect */
3457e4823a9Schristos #define DI_SHUT 3			/* node is shutting down */
3467e4823a9Schristos #define DI_NOUSER 4			/* destination end user does not exist */
3477e4823a9Schristos #define DI_INVDEST 5			/* invalid end user destination */
3487e4823a9Schristos #define DI_REMRESRC 6			/* insufficient remote resources */
3497e4823a9Schristos #define DI_TPA 8			/* third party abort */
3507e4823a9Schristos #define DI_PROTOCOL 7			/* protocol error discovered */
3517e4823a9Schristos #define DI_ABORT 9			/* user abort */
3527e4823a9Schristos #define DI_LOCALRESRC 32		/* insufficient local resources */
3537e4823a9Schristos #define DI_REMUSERRESRC 33		/* insufficient remote user resources */
3547e4823a9Schristos #define DI_BADACCESS 34			/* bad access control information */
3557e4823a9Schristos #define DI_BADACCNT 36			/* bad ACCOUNT information */
3567e4823a9Schristos #define DI_CONNECTABORT 38		/* connect request cancelled */
3577e4823a9Schristos #define DI_TIMEDOUT 38			/* remote node or user crashed */
3587e4823a9Schristos #define DI_UNREACHABLE 39		/* local timers expired due to ... */
3597e4823a9Schristos #define DI_BADIMAGE 43			/* bad image data in connect */
3607e4823a9Schristos #define DI_SERVMISMATCH 54		/* cryptographic service mismatch */
3617e4823a9Schristos 
3627e4823a9Schristos #define UC_OBJREJECT 0			/* object rejected connect */
3637e4823a9Schristos #define UC_USERDISCONNECT 0		/* user disconnect */
3647e4823a9Schristos #define UC_RESOURCES 1			/* insufficient resources (local or remote) */
3657e4823a9Schristos #define UC_NOSUCHNODE 2			/* unrecognized node name */
3667e4823a9Schristos #define UC_REMOTESHUT 3			/* remote node shutting down */
3677e4823a9Schristos #define UC_NOSUCHOBJ 4			/* unrecognized object */
3687e4823a9Schristos #define UC_INVOBJFORMAT 5		/* invalid object name format */
3697e4823a9Schristos #define UC_OBJTOOBUSY 6			/* object too busy */
3707e4823a9Schristos #define UC_NETWORKABORT 8		/* network abort */
3717e4823a9Schristos #define UC_USERABORT 9			/* user abort */
3727e4823a9Schristos #define UC_INVNODEFORMAT 10		/* invalid node name format */
3737e4823a9Schristos #define UC_LOCALSHUT 11			/* local node shutting down */
3747e4823a9Schristos #define UC_ACCESSREJECT 34		/* invalid access control information */
3757e4823a9Schristos #define UC_NORESPONSE 38		/* no response from object */
3767e4823a9Schristos #define UC_UNREACHABLE 39		/* node unreachable */
3777e4823a9Schristos 
3787e4823a9Schristos /*
3797e4823a9Schristos  * NSP message formats.
3807e4823a9Schristos  */
3817e4823a9Schristos struct nsphdr				/* general nsp header */
3827e4823a9Schristos   {
3837e4823a9Schristos     byte	nh_flags;		/* message flags */
3847e4823a9Schristos     word	nh_dst;			/* destination link address */
3857e4823a9Schristos     word	nh_src;			/* source link address */
3867e4823a9Schristos   };
3877e4823a9Schristos 
3887e4823a9Schristos struct seghdr				/* data segment header */
3897e4823a9Schristos   {
3907e4823a9Schristos     byte	sh_flags;		/* message flags */
3917e4823a9Schristos     word	sh_dst;			/* destination link address */
3927e4823a9Schristos     word	sh_src;			/* source link address */
3937e4823a9Schristos     word	sh_seq[3];		/* sequence numbers */
3947e4823a9Schristos   };
3957e4823a9Schristos 
3967e4823a9Schristos struct minseghdr			/* minimum data segment header */
3977e4823a9Schristos   {
3987e4823a9Schristos     byte	ms_flags;		/* message flags */
3997e4823a9Schristos     word	ms_dst;			/* destination link address */
4007e4823a9Schristos     word	ms_src;			/* source link address */
4017e4823a9Schristos     word	ms_seq;			/* sequence number */
4027e4823a9Schristos   };
4037e4823a9Schristos 
4047e4823a9Schristos struct lsmsg				/* link service message (after hdr) */
4057e4823a9Schristos   {
4067e4823a9Schristos     byte	ls_lsflags;		/* link service flags */
4077e4823a9Schristos     byte	ls_fcval;		/* flow control value */
4087e4823a9Schristos   };
4097e4823a9Schristos 
4107e4823a9Schristos struct ackmsg				/* acknowledgement message */
4117e4823a9Schristos   {
4127e4823a9Schristos     byte	ak_flags;		/* message flags */
4137e4823a9Schristos     word	ak_dst;			/* destination link address */
4147e4823a9Schristos     word	ak_src;			/* source link address */
4157e4823a9Schristos     word	ak_acknum[2];		/* acknowledgement numbers */
4167e4823a9Schristos   };
4177e4823a9Schristos 
4187e4823a9Schristos struct minackmsg			/* minimum acknowledgement message */
4197e4823a9Schristos   {
4207e4823a9Schristos     byte	mk_flags;		/* message flags */
4217e4823a9Schristos     word	mk_dst;			/* destination link address */
4227e4823a9Schristos     word	mk_src;			/* source link address */
4237e4823a9Schristos     word	mk_acknum;		/* acknowledgement number */
4247e4823a9Schristos   };
4257e4823a9Schristos 
4267e4823a9Schristos struct ciackmsg				/* connect acknowledgement message */
4277e4823a9Schristos   {
4287e4823a9Schristos     byte	ck_flags;		/* message flags */
4297e4823a9Schristos     word	ck_dst;			/* destination link address */
4307e4823a9Schristos   };
4317e4823a9Schristos 
4327e4823a9Schristos struct cimsg				/* connect initiate message */
4337e4823a9Schristos   {
4347e4823a9Schristos     byte	ci_flags;		/* message flags */
4357e4823a9Schristos     word	ci_dst;			/* destination link address (0) */
4367e4823a9Schristos     word	ci_src;			/* source link address */
4377e4823a9Schristos     byte	ci_services;		/* requested services */
4387e4823a9Schristos     byte	ci_info;		/* information */
4397e4823a9Schristos     word	ci_segsize;		/* maximum segment size */
4407e4823a9Schristos   };
4417e4823a9Schristos 
4427e4823a9Schristos struct ccmsg				/* connect confirm message */
4437e4823a9Schristos   {
4447e4823a9Schristos     byte	cc_flags;		/* message flags */
4457e4823a9Schristos     word	cc_dst;			/* destination link address */
4467e4823a9Schristos     word	cc_src;			/* source link address */
4477e4823a9Schristos     byte	cc_services;		/* requested services */
4487e4823a9Schristos     byte	cc_info;		/* information */
4497e4823a9Schristos     word	cc_segsize;		/* maximum segment size */
4507e4823a9Schristos     byte	cc_optlen;		/* optional data length */
4517e4823a9Schristos   };
4527e4823a9Schristos 
4537e4823a9Schristos struct cnmsg				/* generic connect message */
4547e4823a9Schristos   {
4557e4823a9Schristos     byte	cn_flags;		/* message flags */
4567e4823a9Schristos     word	cn_dst;			/* destination link address */
4577e4823a9Schristos     word	cn_src;			/* source link address */
4587e4823a9Schristos     byte	cn_services;		/* requested services */
4597e4823a9Schristos     byte	cn_info;		/* information */
4607e4823a9Schristos     word	cn_segsize;		/* maximum segment size */
4617e4823a9Schristos   };
4627e4823a9Schristos 
4637e4823a9Schristos struct dimsg				/* disconnect initiate message */
4647e4823a9Schristos   {
4657e4823a9Schristos     byte	di_flags;		/* message flags */
4667e4823a9Schristos     word	di_dst;			/* destination link address */
4677e4823a9Schristos     word	di_src;			/* source link address */
4687e4823a9Schristos     word	di_reason;		/* reason code */
4697e4823a9Schristos     byte	di_optlen;		/* optional data length */
4707e4823a9Schristos   };
4717e4823a9Schristos 
4727e4823a9Schristos struct dcmsg				/* disconnect confirm message */
4737e4823a9Schristos   {
4747e4823a9Schristos     byte	dc_flags;		/* message flags */
4757e4823a9Schristos     word	dc_dst;			/* destination link address */
4767e4823a9Schristos     word	dc_src;			/* source link address */
4777e4823a9Schristos     word	dc_reason;		/* reason code */
4787e4823a9Schristos   };
4797e4823a9Schristos 
480546f56c3Schristos /* Forwards */
4817e4823a9Schristos static int print_decnet_ctlmsg(netdissect_options *, const union routehdr *, u_int, u_int);
4827e4823a9Schristos static void print_t_info(netdissect_options *, int);
4837e4823a9Schristos static int print_l1_routes(netdissect_options *, const char *, u_int);
4847e4823a9Schristos static int print_l2_routes(netdissect_options *, const char *, u_int);
4857e4823a9Schristos static void print_i_info(netdissect_options *, int);
486546f56c3Schristos static int print_elist(const char *, u_int);
4877e4823a9Schristos static int print_nsp(netdissect_options *, const u_char *, u_int);
4887e4823a9Schristos static void print_reason(netdissect_options *, int);
489546f56c3Schristos 
490546f56c3Schristos void
decnet_print(netdissect_options * ndo,register const u_char * ap,register u_int length,register u_int caplen)4917e4823a9Schristos decnet_print(netdissect_options *ndo,
4927e4823a9Schristos              register const u_char *ap, register u_int length,
493546f56c3Schristos              register u_int caplen)
494546f56c3Schristos {
495546f56c3Schristos 	register const union routehdr *rhp;
496546f56c3Schristos 	register int mflags;
497546f56c3Schristos 	int dst, src, hops;
498546f56c3Schristos 	u_int nsplen, pktlen;
499546f56c3Schristos 	const u_char *nspp;
500546f56c3Schristos 
501546f56c3Schristos 	if (length < sizeof(struct shorthdr)) {
5027e4823a9Schristos 		ND_PRINT((ndo, "%s", tstr));
503546f56c3Schristos 		return;
504546f56c3Schristos 	}
505546f56c3Schristos 
5067e4823a9Schristos 	ND_TCHECK2(*ap, sizeof(short));
507546f56c3Schristos 	pktlen = EXTRACT_LE_16BITS(ap);
508546f56c3Schristos 	if (pktlen < sizeof(struct shorthdr)) {
5097e4823a9Schristos 		ND_PRINT((ndo, "%s", tstr));
510546f56c3Schristos 		return;
511546f56c3Schristos 	}
512546f56c3Schristos 	if (pktlen > length) {
5137e4823a9Schristos 		ND_PRINT((ndo, "%s", tstr));
514546f56c3Schristos 		return;
515546f56c3Schristos 	}
516546f56c3Schristos 	length = pktlen;
517546f56c3Schristos 
518546f56c3Schristos 	rhp = (const union routehdr *)&(ap[sizeof(short)]);
5197e4823a9Schristos 	ND_TCHECK(rhp->rh_short.sh_flags);
520546f56c3Schristos 	mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
521546f56c3Schristos 
522546f56c3Schristos 	if (mflags & RMF_PAD) {
523546f56c3Schristos 	    /* pad bytes of some sort in front of message */
524546f56c3Schristos 	    u_int padlen = mflags & RMF_PADMASK;
5257e4823a9Schristos 	    if (ndo->ndo_vflag)
5267e4823a9Schristos 		ND_PRINT((ndo, "[pad:%d] ", padlen));
527546f56c3Schristos 	    if (length < padlen + 2) {
5287e4823a9Schristos 		ND_PRINT((ndo, "%s", tstr));
529546f56c3Schristos 		return;
530546f56c3Schristos 	    }
5317e4823a9Schristos 	    ND_TCHECK2(ap[sizeof(short)], padlen);
532546f56c3Schristos 	    ap += padlen;
533546f56c3Schristos 	    length -= padlen;
534546f56c3Schristos 	    caplen -= padlen;
535546f56c3Schristos 	    rhp = (const union routehdr *)&(ap[sizeof(short)]);
5361c9cc6b1Schristos 	    ND_TCHECK(rhp->rh_short.sh_flags);
537546f56c3Schristos 	    mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
538546f56c3Schristos 	}
539546f56c3Schristos 
540546f56c3Schristos 	if (mflags & RMF_FVER) {
5417e4823a9Schristos 		ND_PRINT((ndo, "future-version-decnet"));
5427e4823a9Schristos 		ND_DEFAULTPRINT(ap, min(length, caplen));
543546f56c3Schristos 		return;
544546f56c3Schristos 	}
545546f56c3Schristos 
546546f56c3Schristos 	/* is it a control message? */
547546f56c3Schristos 	if (mflags & RMF_CTLMSG) {
5487e4823a9Schristos 		if (!print_decnet_ctlmsg(ndo, rhp, length, caplen))
549546f56c3Schristos 			goto trunc;
550546f56c3Schristos 		return;
551546f56c3Schristos 	}
552546f56c3Schristos 
553546f56c3Schristos 	switch (mflags & RMF_MASK) {
554546f56c3Schristos 	case RMF_LONG:
555546f56c3Schristos 	    if (length < sizeof(struct longhdr)) {
5567e4823a9Schristos 		ND_PRINT((ndo, "%s", tstr));
557546f56c3Schristos 		return;
558546f56c3Schristos 	    }
5597e4823a9Schristos 	    ND_TCHECK(rhp->rh_long);
560546f56c3Schristos 	    dst =
561546f56c3Schristos 		EXTRACT_LE_16BITS(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
562546f56c3Schristos 	    src =
563546f56c3Schristos 		EXTRACT_LE_16BITS(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
564546f56c3Schristos 	    hops = EXTRACT_LE_8BITS(rhp->rh_long.lg_visits);
565546f56c3Schristos 	    nspp = &(ap[sizeof(short) + sizeof(struct longhdr)]);
566546f56c3Schristos 	    nsplen = length - sizeof(struct longhdr);
567546f56c3Schristos 	    break;
568546f56c3Schristos 	case RMF_SHORT:
5697e4823a9Schristos 	    ND_TCHECK(rhp->rh_short);
570546f56c3Schristos 	    dst = EXTRACT_LE_16BITS(rhp->rh_short.sh_dst);
571546f56c3Schristos 	    src = EXTRACT_LE_16BITS(rhp->rh_short.sh_src);
572546f56c3Schristos 	    hops = (EXTRACT_LE_8BITS(rhp->rh_short.sh_visits) & VIS_MASK)+1;
573546f56c3Schristos 	    nspp = &(ap[sizeof(short) + sizeof(struct shorthdr)]);
574546f56c3Schristos 	    nsplen = length - sizeof(struct shorthdr);
575546f56c3Schristos 	    break;
576546f56c3Schristos 	default:
5777e4823a9Schristos 	    ND_PRINT((ndo, "unknown message flags under mask"));
578c746cb4fSchristos 	    ND_DEFAULTPRINT((const u_char *)ap, min(length, caplen));
579546f56c3Schristos 	    return;
580546f56c3Schristos 	}
581546f56c3Schristos 
5827e4823a9Schristos 	ND_PRINT((ndo, "%s > %s %d ",
5837e4823a9Schristos 			dnaddr_string(ndo, src), dnaddr_string(ndo, dst), pktlen));
5847e4823a9Schristos 	if (ndo->ndo_vflag) {
585546f56c3Schristos 	    if (mflags & RMF_RQR)
5867e4823a9Schristos 		ND_PRINT((ndo, "RQR "));
587546f56c3Schristos 	    if (mflags & RMF_RTS)
5887e4823a9Schristos 		ND_PRINT((ndo, "RTS "));
589546f56c3Schristos 	    if (mflags & RMF_IE)
5907e4823a9Schristos 		ND_PRINT((ndo, "IE "));
5917e4823a9Schristos 	    ND_PRINT((ndo, "%d hops ", hops));
592546f56c3Schristos 	}
593546f56c3Schristos 
5947e4823a9Schristos 	if (!print_nsp(ndo, nspp, nsplen))
595546f56c3Schristos 		goto trunc;
596546f56c3Schristos 	return;
597546f56c3Schristos 
598546f56c3Schristos trunc:
5997e4823a9Schristos 	ND_PRINT((ndo, "%s", tstr));
600546f56c3Schristos 	return;
601546f56c3Schristos }
602546f56c3Schristos 
603546f56c3Schristos static int
print_decnet_ctlmsg(netdissect_options * ndo,register const union routehdr * rhp,u_int length,u_int caplen)6047e4823a9Schristos print_decnet_ctlmsg(netdissect_options *ndo,
6057e4823a9Schristos                     register const union routehdr *rhp, u_int length,
606546f56c3Schristos                     u_int caplen)
607546f56c3Schristos {
6081c9cc6b1Schristos 	/* Our caller has already checked for mflags */
609546f56c3Schristos 	int mflags = EXTRACT_LE_8BITS(rhp->rh_short.sh_flags);
610c746cb4fSchristos 	register const union controlmsg *cmp = (const union controlmsg *)rhp;
611546f56c3Schristos 	int src, dst, info, blksize, eco, ueco, hello, other, vers;
612546f56c3Schristos 	etheraddr srcea, rtea;
613546f56c3Schristos 	int priority;
614c746cb4fSchristos 	const char *rhpx = (const char *)rhp;
615546f56c3Schristos 	int ret;
616546f56c3Schristos 
617546f56c3Schristos 	switch (mflags & RMF_CTLMASK) {
618546f56c3Schristos 	case RMF_INIT:
6197e4823a9Schristos 	    ND_PRINT((ndo, "init "));
620546f56c3Schristos 	    if (length < sizeof(struct initmsg))
621546f56c3Schristos 		goto trunc;
6227e4823a9Schristos 	    ND_TCHECK(cmp->cm_init);
623546f56c3Schristos 	    src = EXTRACT_LE_16BITS(cmp->cm_init.in_src);
624546f56c3Schristos 	    info = EXTRACT_LE_8BITS(cmp->cm_init.in_info);
625546f56c3Schristos 	    blksize = EXTRACT_LE_16BITS(cmp->cm_init.in_blksize);
626546f56c3Schristos 	    vers = EXTRACT_LE_8BITS(cmp->cm_init.in_vers);
627546f56c3Schristos 	    eco = EXTRACT_LE_8BITS(cmp->cm_init.in_eco);
628546f56c3Schristos 	    ueco = EXTRACT_LE_8BITS(cmp->cm_init.in_ueco);
629546f56c3Schristos 	    hello = EXTRACT_LE_16BITS(cmp->cm_init.in_hello);
6307e4823a9Schristos 	    print_t_info(ndo, info);
6317e4823a9Schristos 	    ND_PRINT((ndo,
632546f56c3Schristos 		"src %sblksize %d vers %d eco %d ueco %d hello %d",
6337e4823a9Schristos 			dnaddr_string(ndo, src), blksize, vers, eco, ueco,
6347e4823a9Schristos 			hello));
635546f56c3Schristos 	    ret = 1;
636546f56c3Schristos 	    break;
637546f56c3Schristos 	case RMF_VER:
6387e4823a9Schristos 	    ND_PRINT((ndo, "verification "));
639546f56c3Schristos 	    if (length < sizeof(struct verifmsg))
640546f56c3Schristos 		goto trunc;
6417e4823a9Schristos 	    ND_TCHECK(cmp->cm_ver);
642546f56c3Schristos 	    src = EXTRACT_LE_16BITS(cmp->cm_ver.ve_src);
643546f56c3Schristos 	    other = EXTRACT_LE_8BITS(cmp->cm_ver.ve_fcnval);
6447e4823a9Schristos 	    ND_PRINT((ndo, "src %s fcnval %o", dnaddr_string(ndo, src), other));
645546f56c3Schristos 	    ret = 1;
646546f56c3Schristos 	    break;
647546f56c3Schristos 	case RMF_TEST:
6487e4823a9Schristos 	    ND_PRINT((ndo, "test "));
649546f56c3Schristos 	    if (length < sizeof(struct testmsg))
650546f56c3Schristos 		goto trunc;
6517e4823a9Schristos 	    ND_TCHECK(cmp->cm_test);
652546f56c3Schristos 	    src = EXTRACT_LE_16BITS(cmp->cm_test.te_src);
653546f56c3Schristos 	    other = EXTRACT_LE_8BITS(cmp->cm_test.te_data);
6547e4823a9Schristos 	    ND_PRINT((ndo, "src %s data %o", dnaddr_string(ndo, src), other));
655546f56c3Schristos 	    ret = 1;
656546f56c3Schristos 	    break;
657546f56c3Schristos 	case RMF_L1ROUT:
6587e4823a9Schristos 	    ND_PRINT((ndo, "lev-1-routing "));
659546f56c3Schristos 	    if (length < sizeof(struct l1rout))
660546f56c3Schristos 		goto trunc;
6617e4823a9Schristos 	    ND_TCHECK(cmp->cm_l1rou);
662546f56c3Schristos 	    src = EXTRACT_LE_16BITS(cmp->cm_l1rou.r1_src);
6637e4823a9Schristos 	    ND_PRINT((ndo, "src %s ", dnaddr_string(ndo, src)));
6647e4823a9Schristos 	    ret = print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]),
665546f56c3Schristos 				length - sizeof(struct l1rout));
666546f56c3Schristos 	    break;
667546f56c3Schristos 	case RMF_L2ROUT:
6687e4823a9Schristos 	    ND_PRINT((ndo, "lev-2-routing "));
669546f56c3Schristos 	    if (length < sizeof(struct l2rout))
670546f56c3Schristos 		goto trunc;
6717e4823a9Schristos 	    ND_TCHECK(cmp->cm_l2rout);
672546f56c3Schristos 	    src = EXTRACT_LE_16BITS(cmp->cm_l2rout.r2_src);
6737e4823a9Schristos 	    ND_PRINT((ndo, "src %s ", dnaddr_string(ndo, src)));
6747e4823a9Schristos 	    ret = print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]),
675546f56c3Schristos 				length - sizeof(struct l2rout));
676546f56c3Schristos 	    break;
677546f56c3Schristos 	case RMF_RHELLO:
6787e4823a9Schristos 	    ND_PRINT((ndo, "router-hello "));
679546f56c3Schristos 	    if (length < sizeof(struct rhellomsg))
680546f56c3Schristos 		goto trunc;
6817e4823a9Schristos 	    ND_TCHECK(cmp->cm_rhello);
682546f56c3Schristos 	    vers = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_vers);
683546f56c3Schristos 	    eco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_eco);
684546f56c3Schristos 	    ueco = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_ueco);
685c746cb4fSchristos 	    memcpy((char *)&srcea, (const char *)&(cmp->cm_rhello.rh_src),
686546f56c3Schristos 		sizeof(srcea));
687546f56c3Schristos 	    src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
688546f56c3Schristos 	    info = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_info);
689546f56c3Schristos 	    blksize = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_blksize);
690546f56c3Schristos 	    priority = EXTRACT_LE_8BITS(cmp->cm_rhello.rh_priority);
691546f56c3Schristos 	    hello = EXTRACT_LE_16BITS(cmp->cm_rhello.rh_hello);
6927e4823a9Schristos 	    print_i_info(ndo, info);
6937e4823a9Schristos 	    ND_PRINT((ndo,
694546f56c3Schristos 	    "vers %d eco %d ueco %d src %s blksize %d pri %d hello %d",
6957e4823a9Schristos 			vers, eco, ueco, dnaddr_string(ndo, src),
6967e4823a9Schristos 			blksize, priority, hello));
697546f56c3Schristos 	    ret = print_elist(&(rhpx[sizeof(struct rhellomsg)]),
698546f56c3Schristos 				length - sizeof(struct rhellomsg));
699546f56c3Schristos 	    break;
700546f56c3Schristos 	case RMF_EHELLO:
7017e4823a9Schristos 	    ND_PRINT((ndo, "endnode-hello "));
702546f56c3Schristos 	    if (length < sizeof(struct ehellomsg))
703546f56c3Schristos 		goto trunc;
7047e4823a9Schristos 	    ND_TCHECK(cmp->cm_ehello);
705546f56c3Schristos 	    vers = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_vers);
706546f56c3Schristos 	    eco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_eco);
707546f56c3Schristos 	    ueco = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_ueco);
708c746cb4fSchristos 	    memcpy((char *)&srcea, (const char *)&(cmp->cm_ehello.eh_src),
709546f56c3Schristos 		sizeof(srcea));
710546f56c3Schristos 	    src = EXTRACT_LE_16BITS(srcea.dne_remote.dne_nodeaddr);
711546f56c3Schristos 	    info = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_info);
712546f56c3Schristos 	    blksize = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_blksize);
713546f56c3Schristos 	    /*seed*/
714c746cb4fSchristos 	    memcpy((char *)&rtea, (const char *)&(cmp->cm_ehello.eh_router),
715546f56c3Schristos 		sizeof(rtea));
716546f56c3Schristos 	    dst = EXTRACT_LE_16BITS(rtea.dne_remote.dne_nodeaddr);
717546f56c3Schristos 	    hello = EXTRACT_LE_16BITS(cmp->cm_ehello.eh_hello);
718546f56c3Schristos 	    other = EXTRACT_LE_8BITS(cmp->cm_ehello.eh_data);
7197e4823a9Schristos 	    print_i_info(ndo, info);
7207e4823a9Schristos 	    ND_PRINT((ndo,
721546f56c3Schristos 	"vers %d eco %d ueco %d src %s blksize %d rtr %s hello %d data %o",
7227e4823a9Schristos 			vers, eco, ueco, dnaddr_string(ndo, src),
7237e4823a9Schristos 			blksize, dnaddr_string(ndo, dst), hello, other));
724546f56c3Schristos 	    ret = 1;
725546f56c3Schristos 	    break;
726546f56c3Schristos 
727546f56c3Schristos 	default:
7287e4823a9Schristos 	    ND_PRINT((ndo, "unknown control message"));
729c746cb4fSchristos 	    ND_DEFAULTPRINT((const u_char *)rhp, min(length, caplen));
730546f56c3Schristos 	    ret = 1;
731546f56c3Schristos 	    break;
732546f56c3Schristos 	}
733546f56c3Schristos 	return (ret);
734546f56c3Schristos 
735546f56c3Schristos trunc:
736546f56c3Schristos 	return (0);
737546f56c3Schristos }
738546f56c3Schristos 
739546f56c3Schristos static void
print_t_info(netdissect_options * ndo,int info)7407e4823a9Schristos print_t_info(netdissect_options *ndo,
7417e4823a9Schristos              int info)
742546f56c3Schristos {
743546f56c3Schristos 	int ntype = info & 3;
744546f56c3Schristos 	switch (ntype) {
7457e4823a9Schristos 	case 0: ND_PRINT((ndo, "reserved-ntype? ")); break;
7467e4823a9Schristos 	case TI_L2ROUT: ND_PRINT((ndo, "l2rout ")); break;
7477e4823a9Schristos 	case TI_L1ROUT: ND_PRINT((ndo, "l1rout ")); break;
7487e4823a9Schristos 	case TI_ENDNODE: ND_PRINT((ndo, "endnode ")); break;
749546f56c3Schristos 	}
750546f56c3Schristos 	if (info & TI_VERIF)
7517e4823a9Schristos 	    ND_PRINT((ndo, "verif "));
752546f56c3Schristos 	if (info & TI_BLOCK)
7537e4823a9Schristos 	    ND_PRINT((ndo, "blo "));
754546f56c3Schristos }
755546f56c3Schristos 
756546f56c3Schristos static int
print_l1_routes(netdissect_options * ndo,const char * rp,u_int len)7577e4823a9Schristos print_l1_routes(netdissect_options *ndo,
7587e4823a9Schristos                 const char *rp, u_int len)
759546f56c3Schristos {
760546f56c3Schristos 	int count;
761546f56c3Schristos 	int id;
762546f56c3Schristos 	int info;
763546f56c3Schristos 
764546f56c3Schristos 	/* The last short is a checksum */
765546f56c3Schristos 	while (len > (3 * sizeof(short))) {
7667e4823a9Schristos 	    ND_TCHECK2(*rp, 3 * sizeof(short));
767546f56c3Schristos 	    count = EXTRACT_LE_16BITS(rp);
768546f56c3Schristos 	    if (count > 1024)
769546f56c3Schristos 		return (1);	/* seems to be bogus from here on */
770546f56c3Schristos 	    rp += sizeof(short);
771546f56c3Schristos 	    len -= sizeof(short);
772546f56c3Schristos 	    id = EXTRACT_LE_16BITS(rp);
773546f56c3Schristos 	    rp += sizeof(short);
774546f56c3Schristos 	    len -= sizeof(short);
775546f56c3Schristos 	    info = EXTRACT_LE_16BITS(rp);
776546f56c3Schristos 	    rp += sizeof(short);
777546f56c3Schristos 	    len -= sizeof(short);
7787e4823a9Schristos 	    ND_PRINT((ndo, "{ids %d-%d cost %d hops %d} ", id, id + count,
7797e4823a9Schristos 			    RI_COST(info), RI_HOPS(info)));
780546f56c3Schristos 	}
781546f56c3Schristos 	return (1);
782546f56c3Schristos 
783546f56c3Schristos trunc:
784546f56c3Schristos 	return (0);
785546f56c3Schristos }
786546f56c3Schristos 
787546f56c3Schristos static int
print_l2_routes(netdissect_options * ndo,const char * rp,u_int len)7887e4823a9Schristos print_l2_routes(netdissect_options *ndo,
7897e4823a9Schristos                 const char *rp, u_int len)
790546f56c3Schristos {
791546f56c3Schristos 	int count;
792546f56c3Schristos 	int area;
793546f56c3Schristos 	int info;
794546f56c3Schristos 
795546f56c3Schristos 	/* The last short is a checksum */
796546f56c3Schristos 	while (len > (3 * sizeof(short))) {
7977e4823a9Schristos 	    ND_TCHECK2(*rp, 3 * sizeof(short));
798546f56c3Schristos 	    count = EXTRACT_LE_16BITS(rp);
799546f56c3Schristos 	    if (count > 1024)
800546f56c3Schristos 		return (1);	/* seems to be bogus from here on */
801546f56c3Schristos 	    rp += sizeof(short);
802546f56c3Schristos 	    len -= sizeof(short);
803546f56c3Schristos 	    area = EXTRACT_LE_16BITS(rp);
804546f56c3Schristos 	    rp += sizeof(short);
805546f56c3Schristos 	    len -= sizeof(short);
806546f56c3Schristos 	    info = EXTRACT_LE_16BITS(rp);
807546f56c3Schristos 	    rp += sizeof(short);
808546f56c3Schristos 	    len -= sizeof(short);
8097e4823a9Schristos 	    ND_PRINT((ndo, "{areas %d-%d cost %d hops %d} ", area, area + count,
8107e4823a9Schristos 			    RI_COST(info), RI_HOPS(info)));
811546f56c3Schristos 	}
812546f56c3Schristos 	return (1);
813546f56c3Schristos 
814546f56c3Schristos trunc:
815546f56c3Schristos 	return (0);
816546f56c3Schristos }
817546f56c3Schristos 
818546f56c3Schristos static void
print_i_info(netdissect_options * ndo,int info)8197e4823a9Schristos print_i_info(netdissect_options *ndo,
8207e4823a9Schristos              int info)
821546f56c3Schristos {
822546f56c3Schristos 	int ntype = info & II_TYPEMASK;
823546f56c3Schristos 	switch (ntype) {
8247e4823a9Schristos 	case 0: ND_PRINT((ndo, "reserved-ntype? ")); break;
8257e4823a9Schristos 	case II_L2ROUT: ND_PRINT((ndo, "l2rout ")); break;
8267e4823a9Schristos 	case II_L1ROUT: ND_PRINT((ndo, "l1rout ")); break;
8277e4823a9Schristos 	case II_ENDNODE: ND_PRINT((ndo, "endnode ")); break;
828546f56c3Schristos 	}
829546f56c3Schristos 	if (info & II_VERIF)
8307e4823a9Schristos 	    ND_PRINT((ndo, "verif "));
831546f56c3Schristos 	if (info & II_NOMCAST)
8327e4823a9Schristos 	    ND_PRINT((ndo, "nomcast "));
833546f56c3Schristos 	if (info & II_BLOCK)
8347e4823a9Schristos 	    ND_PRINT((ndo, "blo "));
835546f56c3Schristos }
836546f56c3Schristos 
837546f56c3Schristos static int
print_elist(const char * elp _U_,u_int len _U_)838546f56c3Schristos print_elist(const char *elp _U_, u_int len _U_)
839546f56c3Schristos {
840546f56c3Schristos 	/* Not enough examples available for me to debug this */
841546f56c3Schristos 	return (1);
842546f56c3Schristos }
843546f56c3Schristos 
844546f56c3Schristos static int
print_nsp(netdissect_options * ndo,const u_char * nspp,u_int nsplen)8457e4823a9Schristos print_nsp(netdissect_options *ndo,
8467e4823a9Schristos           const u_char *nspp, u_int nsplen)
847546f56c3Schristos {
848c746cb4fSchristos 	const struct nsphdr *nsphp = (const struct nsphdr *)nspp;
849546f56c3Schristos 	int dst, src, flags;
850546f56c3Schristos 
851546f56c3Schristos 	if (nsplen < sizeof(struct nsphdr))
852546f56c3Schristos 		goto trunc;
8537e4823a9Schristos 	ND_TCHECK(*nsphp);
854546f56c3Schristos 	flags = EXTRACT_LE_8BITS(nsphp->nh_flags);
855546f56c3Schristos 	dst = EXTRACT_LE_16BITS(nsphp->nh_dst);
856546f56c3Schristos 	src = EXTRACT_LE_16BITS(nsphp->nh_src);
857546f56c3Schristos 
858546f56c3Schristos 	switch (flags & NSP_TYPEMASK) {
859546f56c3Schristos 	case MFT_DATA:
860546f56c3Schristos 	    switch (flags & NSP_SUBMASK) {
861546f56c3Schristos 	    case MFS_BOM:
862546f56c3Schristos 	    case MFS_MOM:
863546f56c3Schristos 	    case MFS_EOM:
864546f56c3Schristos 	    case MFS_BOM+MFS_EOM:
8657e4823a9Schristos 		ND_PRINT((ndo, "data %d>%d ", src, dst));
866546f56c3Schristos 		{
867c746cb4fSchristos 		    const struct seghdr *shp = (const struct seghdr *)nspp;
868546f56c3Schristos 		    int ack;
869546f56c3Schristos 		    u_int data_off = sizeof(struct minseghdr);
870546f56c3Schristos 
871546f56c3Schristos 		    if (nsplen < data_off)
872546f56c3Schristos 			goto trunc;
8737e4823a9Schristos 		    ND_TCHECK(shp->sh_seq[0]);
874546f56c3Schristos 		    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
875546f56c3Schristos 		    if (ack & SGQ_ACK) {	/* acknum field */
876546f56c3Schristos 			if ((ack & SGQ_NAK) == SGQ_NAK)
8777e4823a9Schristos 			    ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
878546f56c3Schristos 			else
8797e4823a9Schristos 			    ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
880546f56c3Schristos 			data_off += sizeof(short);
881546f56c3Schristos 			if (nsplen < data_off)
882546f56c3Schristos 			    goto trunc;
8837e4823a9Schristos 			ND_TCHECK(shp->sh_seq[1]);
884546f56c3Schristos 		        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
885546f56c3Schristos 			if (ack & SGQ_OACK) {	/* ackoth field */
886546f56c3Schristos 			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
8877e4823a9Schristos 				ND_PRINT((ndo, "onak %d ", ack & SGQ_MASK));
888546f56c3Schristos 			    else
8897e4823a9Schristos 				ND_PRINT((ndo, "oack %d ", ack & SGQ_MASK));
890546f56c3Schristos 			    data_off += sizeof(short);
891546f56c3Schristos 			    if (nsplen < data_off)
892546f56c3Schristos 				goto trunc;
8937e4823a9Schristos 			    ND_TCHECK(shp->sh_seq[2]);
894546f56c3Schristos 			    ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
895546f56c3Schristos 			}
896546f56c3Schristos 		    }
8977e4823a9Schristos 		    ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
898546f56c3Schristos 		}
899546f56c3Schristos 		break;
900546f56c3Schristos 	    case MFS_ILS+MFS_INT:
9017e4823a9Schristos 		ND_PRINT((ndo, "intr "));
902546f56c3Schristos 		{
903c746cb4fSchristos 		    const struct seghdr *shp = (const struct seghdr *)nspp;
904546f56c3Schristos 		    int ack;
905546f56c3Schristos 		    u_int data_off = sizeof(struct minseghdr);
906546f56c3Schristos 
907546f56c3Schristos 		    if (nsplen < data_off)
908546f56c3Schristos 			goto trunc;
9097e4823a9Schristos 		    ND_TCHECK(shp->sh_seq[0]);
910546f56c3Schristos 		    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
911546f56c3Schristos 		    if (ack & SGQ_ACK) {	/* acknum field */
912546f56c3Schristos 			if ((ack & SGQ_NAK) == SGQ_NAK)
9137e4823a9Schristos 			    ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
914546f56c3Schristos 			else
9157e4823a9Schristos 			    ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
916546f56c3Schristos 			data_off += sizeof(short);
917546f56c3Schristos 			if (nsplen < data_off)
918546f56c3Schristos 			    goto trunc;
9197e4823a9Schristos 			ND_TCHECK(shp->sh_seq[1]);
920546f56c3Schristos 		        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
921546f56c3Schristos 			if (ack & SGQ_OACK) {	/* ackdat field */
922546f56c3Schristos 			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
9237e4823a9Schristos 				ND_PRINT((ndo, "nakdat %d ", ack & SGQ_MASK));
924546f56c3Schristos 			    else
9257e4823a9Schristos 				ND_PRINT((ndo, "ackdat %d ", ack & SGQ_MASK));
926546f56c3Schristos 			    data_off += sizeof(short);
927546f56c3Schristos 			    if (nsplen < data_off)
928546f56c3Schristos 				goto trunc;
9297e4823a9Schristos 			    ND_TCHECK(shp->sh_seq[2]);
930546f56c3Schristos 			    ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
931546f56c3Schristos 			}
932546f56c3Schristos 		    }
9337e4823a9Schristos 		    ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
934546f56c3Schristos 		}
935546f56c3Schristos 		break;
936546f56c3Schristos 	    case MFS_ILS:
9377e4823a9Schristos 		ND_PRINT((ndo, "link-service %d>%d ", src, dst));
938546f56c3Schristos 		{
939c746cb4fSchristos 		    const struct seghdr *shp = (const struct seghdr *)nspp;
940c746cb4fSchristos 		    const struct lsmsg *lsmp =
941c746cb4fSchristos 			(const struct lsmsg *)&(nspp[sizeof(struct seghdr)]);
942546f56c3Schristos 		    int ack;
943546f56c3Schristos 		    int lsflags, fcval;
944546f56c3Schristos 
945546f56c3Schristos 		    if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
946546f56c3Schristos 			goto trunc;
9477e4823a9Schristos 		    ND_TCHECK(shp->sh_seq[0]);
948546f56c3Schristos 		    ack = EXTRACT_LE_16BITS(shp->sh_seq[0]);
949546f56c3Schristos 		    if (ack & SGQ_ACK) {	/* acknum field */
950546f56c3Schristos 			if ((ack & SGQ_NAK) == SGQ_NAK)
9517e4823a9Schristos 			    ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
952546f56c3Schristos 			else
9537e4823a9Schristos 			    ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
9547e4823a9Schristos 			ND_TCHECK(shp->sh_seq[1]);
955546f56c3Schristos 		        ack = EXTRACT_LE_16BITS(shp->sh_seq[1]);
956546f56c3Schristos 			if (ack & SGQ_OACK) {	/* ackdat field */
957546f56c3Schristos 			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
9587e4823a9Schristos 				ND_PRINT((ndo, "nakdat %d ", ack & SGQ_MASK));
959546f56c3Schristos 			    else
9607e4823a9Schristos 				ND_PRINT((ndo, "ackdat %d ", ack & SGQ_MASK));
9617e4823a9Schristos 			    ND_TCHECK(shp->sh_seq[2]);
962546f56c3Schristos 			    ack = EXTRACT_LE_16BITS(shp->sh_seq[2]);
963546f56c3Schristos 			}
964546f56c3Schristos 		    }
9657e4823a9Schristos 		    ND_PRINT((ndo, "seg %d ", ack & SGQ_MASK));
9667e4823a9Schristos 		    ND_TCHECK(*lsmp);
967546f56c3Schristos 		    lsflags = EXTRACT_LE_8BITS(lsmp->ls_lsflags);
968546f56c3Schristos 		    fcval = EXTRACT_LE_8BITS(lsmp->ls_fcval);
969546f56c3Schristos 		    switch (lsflags & LSI_MASK) {
970546f56c3Schristos 		    case LSI_DATA:
9717e4823a9Schristos 			ND_PRINT((ndo, "dat seg count %d ", fcval));
972546f56c3Schristos 			switch (lsflags & LSM_MASK) {
973546f56c3Schristos 			case LSM_NOCHANGE:
974546f56c3Schristos 			    break;
975546f56c3Schristos 			case LSM_DONOTSEND:
9767e4823a9Schristos 			    ND_PRINT((ndo, "donotsend-data "));
977546f56c3Schristos 			    break;
978546f56c3Schristos 			case LSM_SEND:
9797e4823a9Schristos 			    ND_PRINT((ndo, "send-data "));
980546f56c3Schristos 			    break;
981546f56c3Schristos 			default:
9827e4823a9Schristos 			    ND_PRINT((ndo, "reserved-fcmod? %x", lsflags));
983546f56c3Schristos 			    break;
984546f56c3Schristos 			}
985546f56c3Schristos 			break;
986546f56c3Schristos 		    case LSI_INTR:
9877e4823a9Schristos 			ND_PRINT((ndo, "intr req count %d ", fcval));
988546f56c3Schristos 			break;
989546f56c3Schristos 		    default:
9907e4823a9Schristos 			ND_PRINT((ndo, "reserved-fcval-int? %x", lsflags));
991546f56c3Schristos 			break;
992546f56c3Schristos 		    }
993546f56c3Schristos 		}
994546f56c3Schristos 		break;
995546f56c3Schristos 	    default:
9967e4823a9Schristos 		ND_PRINT((ndo, "reserved-subtype? %x %d > %d", flags, src, dst));
997546f56c3Schristos 		break;
998546f56c3Schristos 	    }
999546f56c3Schristos 	    break;
1000546f56c3Schristos 	case MFT_ACK:
1001546f56c3Schristos 	    switch (flags & NSP_SUBMASK) {
1002546f56c3Schristos 	    case MFS_DACK:
10037e4823a9Schristos 		ND_PRINT((ndo, "data-ack %d>%d ", src, dst));
1004546f56c3Schristos 		{
1005c746cb4fSchristos 		    const struct ackmsg *amp = (const struct ackmsg *)nspp;
1006546f56c3Schristos 		    int ack;
1007546f56c3Schristos 
1008546f56c3Schristos 		    if (nsplen < sizeof(struct ackmsg))
1009546f56c3Schristos 			goto trunc;
10107e4823a9Schristos 		    ND_TCHECK(*amp);
1011546f56c3Schristos 		    ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
1012546f56c3Schristos 		    if (ack & SGQ_ACK) {	/* acknum field */
1013546f56c3Schristos 			if ((ack & SGQ_NAK) == SGQ_NAK)
10147e4823a9Schristos 			    ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
1015546f56c3Schristos 			else
10167e4823a9Schristos 			    ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
1017546f56c3Schristos 		        ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
1018546f56c3Schristos 			if (ack & SGQ_OACK) {	/* ackoth field */
1019546f56c3Schristos 			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
10207e4823a9Schristos 				ND_PRINT((ndo, "onak %d ", ack & SGQ_MASK));
1021546f56c3Schristos 			    else
10227e4823a9Schristos 				ND_PRINT((ndo, "oack %d ", ack & SGQ_MASK));
1023546f56c3Schristos 			}
1024546f56c3Schristos 		    }
1025546f56c3Schristos 		}
1026546f56c3Schristos 		break;
1027546f56c3Schristos 	    case MFS_IACK:
10287e4823a9Schristos 		ND_PRINT((ndo, "ils-ack %d>%d ", src, dst));
1029546f56c3Schristos 		{
1030c746cb4fSchristos 		    const struct ackmsg *amp = (const struct ackmsg *)nspp;
1031546f56c3Schristos 		    int ack;
1032546f56c3Schristos 
1033546f56c3Schristos 		    if (nsplen < sizeof(struct ackmsg))
1034546f56c3Schristos 			goto trunc;
10357e4823a9Schristos 		    ND_TCHECK(*amp);
1036546f56c3Schristos 		    ack = EXTRACT_LE_16BITS(amp->ak_acknum[0]);
1037546f56c3Schristos 		    if (ack & SGQ_ACK) {	/* acknum field */
1038546f56c3Schristos 			if ((ack & SGQ_NAK) == SGQ_NAK)
10397e4823a9Schristos 			    ND_PRINT((ndo, "nak %d ", ack & SGQ_MASK));
1040546f56c3Schristos 			else
10417e4823a9Schristos 			    ND_PRINT((ndo, "ack %d ", ack & SGQ_MASK));
10427e4823a9Schristos 			ND_TCHECK(amp->ak_acknum[1]);
1043546f56c3Schristos 		        ack = EXTRACT_LE_16BITS(amp->ak_acknum[1]);
1044546f56c3Schristos 			if (ack & SGQ_OACK) {	/* ackdat field */
1045546f56c3Schristos 			    if ((ack & SGQ_ONAK) == SGQ_ONAK)
10467e4823a9Schristos 				ND_PRINT((ndo, "nakdat %d ", ack & SGQ_MASK));
1047546f56c3Schristos 			    else
10487e4823a9Schristos 				ND_PRINT((ndo, "ackdat %d ", ack & SGQ_MASK));
1049546f56c3Schristos 			}
1050546f56c3Schristos 		    }
1051546f56c3Schristos 		}
1052546f56c3Schristos 		break;
1053546f56c3Schristos 	    case MFS_CACK:
10547e4823a9Schristos 		ND_PRINT((ndo, "conn-ack %d", dst));
1055546f56c3Schristos 		break;
1056546f56c3Schristos 	    default:
10577e4823a9Schristos 		ND_PRINT((ndo, "reserved-acktype? %x %d > %d", flags, src, dst));
1058546f56c3Schristos 		break;
1059546f56c3Schristos 	    }
1060546f56c3Schristos 	    break;
1061546f56c3Schristos 	case MFT_CTL:
1062546f56c3Schristos 	    switch (flags & NSP_SUBMASK) {
1063546f56c3Schristos 	    case MFS_CI:
1064546f56c3Schristos 	    case MFS_RCI:
1065546f56c3Schristos 		if ((flags & NSP_SUBMASK) == MFS_CI)
10667e4823a9Schristos 		    ND_PRINT((ndo, "conn-initiate "));
1067546f56c3Schristos 		else
10687e4823a9Schristos 		    ND_PRINT((ndo, "retrans-conn-initiate "));
10697e4823a9Schristos 		ND_PRINT((ndo, "%d>%d ", src, dst));
1070546f56c3Schristos 		{
1071c746cb4fSchristos 		    const struct cimsg *cimp = (const struct cimsg *)nspp;
1072546f56c3Schristos 		    int services, info, segsize;
1073546f56c3Schristos 
1074546f56c3Schristos 		    if (nsplen < sizeof(struct cimsg))
1075546f56c3Schristos 			goto trunc;
10767e4823a9Schristos 		    ND_TCHECK(*cimp);
1077546f56c3Schristos 		    services = EXTRACT_LE_8BITS(cimp->ci_services);
1078546f56c3Schristos 		    info = EXTRACT_LE_8BITS(cimp->ci_info);
1079546f56c3Schristos 		    segsize = EXTRACT_LE_16BITS(cimp->ci_segsize);
1080546f56c3Schristos 
1081546f56c3Schristos 		    switch (services & COS_MASK) {
1082546f56c3Schristos 		    case COS_NONE:
1083546f56c3Schristos 			break;
1084546f56c3Schristos 		    case COS_SEGMENT:
10857e4823a9Schristos 			ND_PRINT((ndo, "seg "));
1086546f56c3Schristos 			break;
1087546f56c3Schristos 		    case COS_MESSAGE:
10887e4823a9Schristos 			ND_PRINT((ndo, "msg "));
1089546f56c3Schristos 			break;
1090546f56c3Schristos 		    }
1091546f56c3Schristos 		    switch (info & COI_MASK) {
1092546f56c3Schristos 		    case COI_32:
10937e4823a9Schristos 			ND_PRINT((ndo, "ver 3.2 "));
1094546f56c3Schristos 			break;
1095546f56c3Schristos 		    case COI_31:
10967e4823a9Schristos 			ND_PRINT((ndo, "ver 3.1 "));
1097546f56c3Schristos 			break;
1098546f56c3Schristos 		    case COI_40:
10997e4823a9Schristos 			ND_PRINT((ndo, "ver 4.0 "));
1100546f56c3Schristos 			break;
1101546f56c3Schristos 		    case COI_41:
11027e4823a9Schristos 			ND_PRINT((ndo, "ver 4.1 "));
1103546f56c3Schristos 			break;
1104546f56c3Schristos 		    }
11057e4823a9Schristos 		    ND_PRINT((ndo, "segsize %d ", segsize));
1106546f56c3Schristos 		}
1107546f56c3Schristos 		break;
1108546f56c3Schristos 	    case MFS_CC:
11097e4823a9Schristos 		ND_PRINT((ndo, "conn-confirm %d>%d ", src, dst));
1110546f56c3Schristos 		{
1111c746cb4fSchristos 		    const struct ccmsg *ccmp = (const struct ccmsg *)nspp;
1112546f56c3Schristos 		    int services, info;
1113546f56c3Schristos 		    u_int segsize, optlen;
1114546f56c3Schristos 
1115546f56c3Schristos 		    if (nsplen < sizeof(struct ccmsg))
1116546f56c3Schristos 			goto trunc;
11177e4823a9Schristos 		    ND_TCHECK(*ccmp);
1118546f56c3Schristos 		    services = EXTRACT_LE_8BITS(ccmp->cc_services);
1119546f56c3Schristos 		    info = EXTRACT_LE_8BITS(ccmp->cc_info);
1120546f56c3Schristos 		    segsize = EXTRACT_LE_16BITS(ccmp->cc_segsize);
1121546f56c3Schristos 		    optlen = EXTRACT_LE_8BITS(ccmp->cc_optlen);
1122546f56c3Schristos 
1123546f56c3Schristos 		    switch (services & COS_MASK) {
1124546f56c3Schristos 		    case COS_NONE:
1125546f56c3Schristos 			break;
1126546f56c3Schristos 		    case COS_SEGMENT:
11277e4823a9Schristos 			ND_PRINT((ndo, "seg "));
1128546f56c3Schristos 			break;
1129546f56c3Schristos 		    case COS_MESSAGE:
11307e4823a9Schristos 			ND_PRINT((ndo, "msg "));
1131546f56c3Schristos 			break;
1132546f56c3Schristos 		    }
1133546f56c3Schristos 		    switch (info & COI_MASK) {
1134546f56c3Schristos 		    case COI_32:
11357e4823a9Schristos 			ND_PRINT((ndo, "ver 3.2 "));
1136546f56c3Schristos 			break;
1137546f56c3Schristos 		    case COI_31:
11387e4823a9Schristos 			ND_PRINT((ndo, "ver 3.1 "));
1139546f56c3Schristos 			break;
1140546f56c3Schristos 		    case COI_40:
11417e4823a9Schristos 			ND_PRINT((ndo, "ver 4.0 "));
1142546f56c3Schristos 			break;
1143546f56c3Schristos 		    case COI_41:
11447e4823a9Schristos 			ND_PRINT((ndo, "ver 4.1 "));
1145546f56c3Schristos 			break;
1146546f56c3Schristos 		    }
11477e4823a9Schristos 		    ND_PRINT((ndo, "segsize %d ", segsize));
1148546f56c3Schristos 		    if (optlen) {
11497e4823a9Schristos 			ND_PRINT((ndo, "optlen %d ", optlen));
1150546f56c3Schristos 		    }
1151546f56c3Schristos 		}
1152546f56c3Schristos 		break;
1153546f56c3Schristos 	    case MFS_DI:
11547e4823a9Schristos 		ND_PRINT((ndo, "disconn-initiate %d>%d ", src, dst));
1155546f56c3Schristos 		{
1156c746cb4fSchristos 		    const struct dimsg *dimp = (const struct dimsg *)nspp;
1157546f56c3Schristos 		    int reason;
1158546f56c3Schristos 		    u_int optlen;
1159546f56c3Schristos 
1160546f56c3Schristos 		    if (nsplen < sizeof(struct dimsg))
1161546f56c3Schristos 			goto trunc;
11627e4823a9Schristos 		    ND_TCHECK(*dimp);
1163546f56c3Schristos 		    reason = EXTRACT_LE_16BITS(dimp->di_reason);
1164546f56c3Schristos 		    optlen = EXTRACT_LE_8BITS(dimp->di_optlen);
1165546f56c3Schristos 
11667e4823a9Schristos 		    print_reason(ndo, reason);
1167546f56c3Schristos 		    if (optlen) {
11687e4823a9Schristos 			ND_PRINT((ndo, "optlen %d ", optlen));
1169546f56c3Schristos 		    }
1170546f56c3Schristos 		}
1171546f56c3Schristos 		break;
1172546f56c3Schristos 	    case MFS_DC:
11737e4823a9Schristos 		ND_PRINT((ndo, "disconn-confirm %d>%d ", src, dst));
1174546f56c3Schristos 		{
1175c746cb4fSchristos 		    const struct dcmsg *dcmp = (const struct dcmsg *)nspp;
1176546f56c3Schristos 		    int reason;
1177546f56c3Schristos 
11787e4823a9Schristos 		    ND_TCHECK(*dcmp);
1179546f56c3Schristos 		    reason = EXTRACT_LE_16BITS(dcmp->dc_reason);
1180546f56c3Schristos 
11817e4823a9Schristos 		    print_reason(ndo, reason);
1182546f56c3Schristos 		}
1183546f56c3Schristos 		break;
1184546f56c3Schristos 	    default:
11857e4823a9Schristos 		ND_PRINT((ndo, "reserved-ctltype? %x %d > %d", flags, src, dst));
1186546f56c3Schristos 		break;
1187546f56c3Schristos 	    }
1188546f56c3Schristos 	    break;
1189546f56c3Schristos 	default:
11907e4823a9Schristos 	    ND_PRINT((ndo, "reserved-type? %x %d > %d", flags, src, dst));
1191546f56c3Schristos 	    break;
1192546f56c3Schristos 	}
1193546f56c3Schristos 	return (1);
1194546f56c3Schristos 
1195546f56c3Schristos trunc:
1196546f56c3Schristos 	return (0);
1197546f56c3Schristos }
1198546f56c3Schristos 
1199aecd9f07Schristos static const struct tok reason2str[] = {
1200546f56c3Schristos 	{ UC_OBJREJECT,		"object rejected connect" },
1201546f56c3Schristos 	{ UC_RESOURCES,		"insufficient resources" },
1202546f56c3Schristos 	{ UC_NOSUCHNODE,	"unrecognized node name" },
1203546f56c3Schristos 	{ DI_SHUT,		"node is shutting down" },
1204546f56c3Schristos 	{ UC_NOSUCHOBJ,		"unrecognized object" },
1205546f56c3Schristos 	{ UC_INVOBJFORMAT,	"invalid object name format" },
1206546f56c3Schristos 	{ UC_OBJTOOBUSY,	"object too busy" },
1207546f56c3Schristos 	{ DI_PROTOCOL,		"protocol error discovered" },
1208546f56c3Schristos 	{ DI_TPA,		"third party abort" },
1209546f56c3Schristos 	{ UC_USERABORT,		"user abort" },
1210546f56c3Schristos 	{ UC_INVNODEFORMAT,	"invalid node name format" },
1211546f56c3Schristos 	{ UC_LOCALSHUT,		"local node shutting down" },
1212546f56c3Schristos 	{ DI_LOCALRESRC,	"insufficient local resources" },
1213546f56c3Schristos 	{ DI_REMUSERRESRC,	"insufficient remote user resources" },
1214546f56c3Schristos 	{ UC_ACCESSREJECT,	"invalid access control information" },
1215546f56c3Schristos 	{ DI_BADACCNT,		"bad ACCOUNT information" },
1216546f56c3Schristos 	{ UC_NORESPONSE,	"no response from object" },
1217546f56c3Schristos 	{ UC_UNREACHABLE,	"node unreachable" },
1218546f56c3Schristos 	{ DC_NOLINK,		"no link terminate" },
1219546f56c3Schristos 	{ DC_COMPLETE,		"disconnect complete" },
1220546f56c3Schristos 	{ DI_BADIMAGE,		"bad image data in connect" },
1221546f56c3Schristos 	{ DI_SERVMISMATCH,	"cryptographic service mismatch" },
1222546f56c3Schristos 	{ 0,			NULL }
1223546f56c3Schristos };
1224546f56c3Schristos 
1225546f56c3Schristos static void
print_reason(netdissect_options * ndo,register int reason)12267e4823a9Schristos print_reason(netdissect_options *ndo,
12277e4823a9Schristos              register int reason)
1228546f56c3Schristos {
12297e4823a9Schristos 	ND_PRINT((ndo, "%s ", tok2str(reason2str, "reason-%d", reason)));
1230546f56c3Schristos }
1231546f56c3Schristos 
1232546f56c3Schristos const char *
dnnum_string(netdissect_options * ndo,u_short dnaddr)1233c746cb4fSchristos dnnum_string(netdissect_options *ndo, u_short dnaddr)
1234546f56c3Schristos {
1235546f56c3Schristos 	char *str;
1236546f56c3Schristos 	size_t siz;
1237546f56c3Schristos 	int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
1238546f56c3Schristos 	int node = dnaddr & NODEMASK;
1239546f56c3Schristos 
1240546f56c3Schristos 	str = (char *)malloc(siz = sizeof("00.0000"));
1241546f56c3Schristos 	if (str == NULL)
1242c746cb4fSchristos 		(*ndo->ndo_error)(ndo, "dnnum_string: malloc");
1243546f56c3Schristos 	snprintf(str, siz, "%d.%d", area, node);
1244546f56c3Schristos 	return(str);
1245546f56c3Schristos }
1246