blob: 6a6dd25982f9376d2b1bcdf3f1c34b1a9aa2156f [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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
Elliott Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: DECnet printer */
23
The Android Open Source Project2949f582009-03-03 19:30:46 -080024#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070025#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#endif
27
Elliott Hughes820eced2021-08-20 18:00:50 -070028#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080029
30#include <stdio.h>
31#include <stdlib.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080032
Elliott Hughes820eced2021-08-20 18:00:50 -070033#define ND_LONGJMP_FROM_TCHECK
Elliott Hughese2e3bd12017-05-15 10:59:29 -070034#include "netdissect.h"
Elliott Hughes820eced2021-08-20 18:00:50 -070035#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080036#include "addrtoname.h"
37
Elliott Hughes892a68b2015-10-19 14:43:53 -070038
Elliott Hughese2e3bd12017-05-15 10:59:29 -070039#ifndef _WIN32
Elliott Hughes820eced2021-08-20 18:00:50 -070040typedef nd_uint8_t byte; /* single byte field */
Elliott Hughes892a68b2015-10-19 14:43:53 -070041#else
42/*
43 * the keyword 'byte' generates conflicts in Windows
44 */
Elliott Hughes820eced2021-08-20 18:00:50 -070045typedef nd_uint8_t Byte; /* single byte field */
Elliott Hughes892a68b2015-10-19 14:43:53 -070046#define byte Byte
Elliott Hughese2e3bd12017-05-15 10:59:29 -070047#endif /* _WIN32 */
Elliott Hughes820eced2021-08-20 18:00:50 -070048typedef nd_uint16_t word; /* 2 byte field */
49typedef nd_uint32_t longword; /* 4 bytes field */
Elliott Hughes892a68b2015-10-19 14:43:53 -070050
51/*
52 * Definitions for DECNET Phase IV protocol headers
53 */
Elliott Hughes820eced2021-08-20 18:00:50 -070054typedef union {
55 nd_mac_addr dne_addr; /* full Ethernet address */
Elliott Hughes892a68b2015-10-19 14:43:53 -070056 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -070057 nd_byte dne_hiord[4]; /* DECnet HIORD prefix */
58 nd_byte dne_nodeaddr[2]; /* DECnet node address */
Elliott Hughes892a68b2015-10-19 14:43:53 -070059 } dne_remote;
Elliott Hughes820eced2021-08-20 18:00:50 -070060} etheraddr; /* Ethernet address */
Elliott Hughes892a68b2015-10-19 14:43:53 -070061
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
Elliott Hughes892a68b2015-10-19 14:43:53 -070068/*
69 * Define long and short header formats.
70 */
71struct 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
79struct 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
94union 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 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700160struct initmsg /* initialization message */
161 {
162 byte in_flags; /* route flags */
163 word in_src; /* source node address */
164 byte in_info; /* routing layer information */
165 word in_blksize; /* maximum data link block size */
166 byte in_vers; /* version number */
167 byte in_eco; /* ECO number */
168 byte in_ueco; /* user ECO number */
169 word in_hello; /* hello timer */
170 byte in_rsvd; /* reserved image field */
171 };
172
173struct verifmsg /* verification message */
174 {
175 byte ve_flags; /* route flags */
176 word ve_src; /* source node address */
177 byte ve_fcnval; /* function value image field */
178 };
179
180struct testmsg /* hello and test message */
181 {
182 byte te_flags; /* route flags */
183 word te_src; /* source node address */
184 byte te_data; /* test data image field */
185 };
186
187struct l1rout /* level 1 routing message */
188 {
189 byte r1_flags; /* route flags */
190 word r1_src; /* source node address */
191 byte r1_rsvd; /* reserved field */
192 };
193
194struct l2rout /* level 2 routing message */
195 {
196 byte r2_flags; /* route flags */
197 word r2_src; /* source node address */
198 byte r2_rsvd; /* reserved field */
199 };
200
201struct rhellomsg /* router hello message */
202 {
203 byte rh_flags; /* route flags */
204 byte rh_vers; /* version number */
205 byte rh_eco; /* ECO number */
206 byte rh_ueco; /* user ECO number */
207 etheraddr rh_src; /* source id */
208 byte rh_info; /* routing layer information */
209 word rh_blksize; /* maximum data link block size */
210 byte rh_priority; /* router's priority */
211 byte rh_area; /* reserved */
212 word rh_hello; /* hello timer */
213 byte rh_mpd; /* reserved */
214 };
215
216struct ehellomsg /* endnode hello message */
217 {
218 byte eh_flags; /* route flags */
219 byte eh_vers; /* version number */
220 byte eh_eco; /* ECO number */
221 byte eh_ueco; /* user ECO number */
222 etheraddr eh_src; /* source id */
223 byte eh_info; /* routing layer information */
224 word eh_blksize; /* maximum data link block size */
225 byte eh_area; /* area (reserved) */
226 byte eh_seed[8]; /* verification seed */
227 etheraddr eh_router; /* designated router */
228 word eh_hello; /* hello timer */
229 byte eh_mpd; /* (reserved) */
230 byte eh_data; /* test data image field */
231 };
232
233union controlmsg
234 {
235 struct initmsg cm_init; /* initialization message */
236 struct verifmsg cm_ver; /* verification message */
237 struct testmsg cm_test; /* hello and test message */
238 struct l1rout cm_l1rou; /* level 1 routing message */
239 struct l2rout cm_l2rout; /* level 2 routing message */
240 struct rhellomsg cm_rhello; /* router hello message */
241 struct ehellomsg cm_ehello; /* endnode hello message */
242 };
243
244/* Macros for decoding routing-info fields */
245#define RI_COST(x) ((x)&0777)
246#define RI_HOPS(x) (((x)>>10)&037)
247
248/*
249 * NSP protocol fields and values.
250 */
251
252#define NSP_TYPEMASK 014 /* mask to isolate type code */
253#define NSP_SUBMASK 0160 /* mask to isolate subtype code */
254#define NSP_SUBSHFT 4 /* shift to move subtype code */
255
256#define MFT_DATA 0 /* data message */
257#define MFT_ACK 04 /* acknowledgement message */
258#define MFT_CTL 010 /* control message */
259
260#define MFS_ILS 020 /* data or I/LS indicator */
261#define MFS_BOM 040 /* beginning of message (data) */
262#define MFS_MOM 0 /* middle of message (data) */
263#define MFS_EOM 0100 /* end of message (data) */
264#define MFS_INT 040 /* interrupt message */
265
266#define MFS_DACK 0 /* data acknowledgement */
267#define MFS_IACK 020 /* I/LS acknowledgement */
268#define MFS_CACK 040 /* connect acknowledgement */
269
270#define MFS_NOP 0 /* no operation */
271#define MFS_CI 020 /* connect initiate */
272#define MFS_CC 040 /* connect confirm */
273#define MFS_DI 060 /* disconnect initiate */
274#define MFS_DC 0100 /* disconnect confirm */
275#define MFS_RCI 0140 /* retransmitted connect initiate */
276
277#define SGQ_ACK 0100000 /* ack */
278#define SGQ_NAK 0110000 /* negative ack */
279#define SGQ_OACK 0120000 /* other channel ack */
280#define SGQ_ONAK 0130000 /* other channel negative ack */
281#define SGQ_MASK 07777 /* mask to isolate seq # */
282#define SGQ_OTHER 020000 /* other channel qualifier */
283#define SGQ_DELAY 010000 /* ack delay flag */
284
285#define SGQ_EOM 0100000 /* pseudo flag for end-of-message */
286
287#define LSM_MASK 03 /* mask for modifier field */
288#define LSM_NOCHANGE 0 /* no change */
289#define LSM_DONOTSEND 1 /* do not send data */
290#define LSM_SEND 2 /* send data */
291
292#define LSI_MASK 014 /* mask for interpretation field */
293#define LSI_DATA 0 /* data segment or message count */
294#define LSI_INTR 4 /* interrupt request count */
295#define LSI_INTM 0377 /* funny marker for int. message */
296
297#define COS_MASK 014 /* mask for flow control field */
298#define COS_NONE 0 /* no flow control */
299#define COS_SEGMENT 04 /* segment flow control */
300#define COS_MESSAGE 010 /* message flow control */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700301#define COS_DEFAULT 1 /* default value for field */
302
303#define COI_MASK 3 /* mask for version field */
304#define COI_32 0 /* version 3.2 */
305#define COI_31 1 /* version 3.1 */
306#define COI_40 2 /* version 4.0 */
307#define COI_41 3 /* version 4.1 */
308
309#define MNU_MASK 140 /* mask for session control version */
310#define MNU_10 000 /* session V1.0 */
311#define MNU_20 040 /* session V2.0 */
312#define MNU_ACCESS 1 /* access control present */
313#define MNU_USRDATA 2 /* user data field present */
314#define MNU_INVKPROXY 4 /* invoke proxy field present */
315#define MNU_UICPROXY 8 /* use uic-based proxy */
316
317#define DC_NORESOURCES 1 /* no resource reason code */
318#define DC_NOLINK 41 /* no link terminate reason code */
319#define DC_COMPLETE 42 /* disconnect complete reason code */
320
321#define DI_NOERROR 0 /* user disconnect */
322#define DI_SHUT 3 /* node is shutting down */
323#define DI_NOUSER 4 /* destination end user does not exist */
324#define DI_INVDEST 5 /* invalid end user destination */
325#define DI_REMRESRC 6 /* insufficient remote resources */
326#define DI_TPA 8 /* third party abort */
327#define DI_PROTOCOL 7 /* protocol error discovered */
328#define DI_ABORT 9 /* user abort */
329#define DI_LOCALRESRC 32 /* insufficient local resources */
330#define DI_REMUSERRESRC 33 /* insufficient remote user resources */
331#define DI_BADACCESS 34 /* bad access control information */
332#define DI_BADACCNT 36 /* bad ACCOUNT information */
333#define DI_CONNECTABORT 38 /* connect request cancelled */
334#define DI_TIMEDOUT 38 /* remote node or user crashed */
335#define DI_UNREACHABLE 39 /* local timers expired due to ... */
336#define DI_BADIMAGE 43 /* bad image data in connect */
337#define DI_SERVMISMATCH 54 /* cryptographic service mismatch */
338
339#define UC_OBJREJECT 0 /* object rejected connect */
340#define UC_USERDISCONNECT 0 /* user disconnect */
341#define UC_RESOURCES 1 /* insufficient resources (local or remote) */
342#define UC_NOSUCHNODE 2 /* unrecognized node name */
343#define UC_REMOTESHUT 3 /* remote node shutting down */
344#define UC_NOSUCHOBJ 4 /* unrecognized object */
345#define UC_INVOBJFORMAT 5 /* invalid object name format */
346#define UC_OBJTOOBUSY 6 /* object too busy */
347#define UC_NETWORKABORT 8 /* network abort */
348#define UC_USERABORT 9 /* user abort */
349#define UC_INVNODEFORMAT 10 /* invalid node name format */
350#define UC_LOCALSHUT 11 /* local node shutting down */
351#define UC_ACCESSREJECT 34 /* invalid access control information */
352#define UC_NORESPONSE 38 /* no response from object */
353#define UC_UNREACHABLE 39 /* node unreachable */
354
355/*
356 * NSP message formats.
357 */
358struct nsphdr /* general nsp header */
359 {
360 byte nh_flags; /* message flags */
361 word nh_dst; /* destination link address */
362 word nh_src; /* source link address */
363 };
364
365struct seghdr /* data segment header */
366 {
367 byte sh_flags; /* message flags */
368 word sh_dst; /* destination link address */
369 word sh_src; /* source link address */
370 word sh_seq[3]; /* sequence numbers */
371 };
372
373struct minseghdr /* minimum data segment header */
374 {
375 byte ms_flags; /* message flags */
376 word ms_dst; /* destination link address */
377 word ms_src; /* source link address */
378 word ms_seq; /* sequence number */
379 };
380
381struct lsmsg /* link service message (after hdr) */
382 {
383 byte ls_lsflags; /* link service flags */
384 byte ls_fcval; /* flow control value */
385 };
386
387struct ackmsg /* acknowledgement message */
388 {
389 byte ak_flags; /* message flags */
390 word ak_dst; /* destination link address */
391 word ak_src; /* source link address */
392 word ak_acknum[2]; /* acknowledgement numbers */
393 };
394
395struct minackmsg /* minimum acknowledgement message */
396 {
397 byte mk_flags; /* message flags */
398 word mk_dst; /* destination link address */
399 word mk_src; /* source link address */
400 word mk_acknum; /* acknowledgement number */
401 };
402
403struct ciackmsg /* connect acknowledgement message */
404 {
405 byte ck_flags; /* message flags */
406 word ck_dst; /* destination link address */
407 };
408
409struct cimsg /* connect initiate message */
410 {
411 byte ci_flags; /* message flags */
412 word ci_dst; /* destination link address (0) */
413 word ci_src; /* source link address */
414 byte ci_services; /* requested services */
415 byte ci_info; /* information */
416 word ci_segsize; /* maximum segment size */
417 };
418
419struct ccmsg /* connect confirm message */
420 {
421 byte cc_flags; /* message flags */
422 word cc_dst; /* destination link address */
423 word cc_src; /* source link address */
424 byte cc_services; /* requested services */
425 byte cc_info; /* information */
426 word cc_segsize; /* maximum segment size */
427 byte cc_optlen; /* optional data length */
428 };
429
430struct cnmsg /* generic connect message */
431 {
432 byte cn_flags; /* message flags */
433 word cn_dst; /* destination link address */
434 word cn_src; /* source link address */
435 byte cn_services; /* requested services */
436 byte cn_info; /* information */
437 word cn_segsize; /* maximum segment size */
438 };
439
440struct dimsg /* disconnect initiate message */
441 {
442 byte di_flags; /* message flags */
443 word di_dst; /* destination link address */
444 word di_src; /* source link address */
445 word di_reason; /* reason code */
446 byte di_optlen; /* optional data length */
447 };
448
449struct dcmsg /* disconnect confirm message */
450 {
451 byte dc_flags; /* message flags */
452 word dc_dst; /* destination link address */
453 word dc_src; /* source link address */
454 word dc_reason; /* reason code */
455 };
456
The Android Open Source Project2949f582009-03-03 19:30:46 -0800457/* Forwards */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700458static int print_decnet_ctlmsg(netdissect_options *, const union routehdr *, u_int, u_int);
Elliott Hughes820eced2021-08-20 18:00:50 -0700459static void print_t_info(netdissect_options *, u_int);
460static void print_l1_routes(netdissect_options *, const u_char *, u_int);
461static void print_l2_routes(netdissect_options *, const u_char *, u_int);
462static void print_i_info(netdissect_options *, u_int);
463static void print_elist(const u_char *, u_int);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700464static int print_nsp(netdissect_options *, const u_char *, u_int);
Elliott Hughes820eced2021-08-20 18:00:50 -0700465static void print_reason(netdissect_options *, u_int);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800466
467void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700468decnet_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700469 const u_char *ap, u_int length,
470 u_int caplen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800471{
Elliott Hughes820eced2021-08-20 18:00:50 -0700472 const union routehdr *rhp;
473 u_int mflags;
474 uint16_t dst, src;
475 u_int hops;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800476 u_int nsplen, pktlen;
477 const u_char *nspp;
478
Elliott Hughes820eced2021-08-20 18:00:50 -0700479 ndo->ndo_protocol = "decnet";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800480 if (length < sizeof(struct shorthdr)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700481 ND_PRINT(" (length %u < %zu)", length, sizeof(struct shorthdr));
482 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800483 }
484
Elliott Hughes820eced2021-08-20 18:00:50 -0700485 pktlen = GET_LE_U_2(ap);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800486 if (pktlen < sizeof(struct shorthdr)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700487 ND_PRINT(" (pktlen %u < %zu)", pktlen, sizeof(struct shorthdr));
488 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800489 }
490 if (pktlen > length) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700491 ND_PRINT(" (pktlen %u > %u)", pktlen, length);
492 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800493 }
494 length = pktlen;
495
Elliott Hughes820eced2021-08-20 18:00:50 -0700496 rhp = (const union routehdr *)(ap + sizeof(short));
497 mflags = GET_U_1(rhp->rh_short.sh_flags);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800498
499 if (mflags & RMF_PAD) {
500 /* pad bytes of some sort in front of message */
501 u_int padlen = mflags & RMF_PADMASK;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700502 if (ndo->ndo_vflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700503 ND_PRINT("[pad:%u] ", padlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800504 if (length < padlen + 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700505 ND_PRINT(" (length %u < %u)", length, padlen + 2);
506 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800507 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700508 ND_TCHECK_LEN(ap + sizeof(short), padlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800509 ap += padlen;
510 length -= padlen;
511 caplen -= padlen;
Elliott Hughes820eced2021-08-20 18:00:50 -0700512 rhp = (const union routehdr *)(ap + sizeof(short));
513 mflags = GET_U_1(rhp->rh_short.sh_flags);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800514 }
515
516 if (mflags & RMF_FVER) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700517 ND_PRINT("future-version-decnet");
518 ND_DEFAULTPRINT(ap, ND_MIN(length, caplen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800519 return;
520 }
521
522 /* is it a control message? */
523 if (mflags & RMF_CTLMSG) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700524 if (!print_decnet_ctlmsg(ndo, rhp, length, caplen))
Elliott Hughes820eced2021-08-20 18:00:50 -0700525 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800526 return;
527 }
528
529 switch (mflags & RMF_MASK) {
530 case RMF_LONG:
531 if (length < sizeof(struct longhdr)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700532 ND_PRINT(" (length %u < %zu)", length, sizeof(struct longhdr));
533 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800534 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700535 ND_TCHECK_SIZE(&rhp->rh_long);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800536 dst =
Elliott Hughes820eced2021-08-20 18:00:50 -0700537 GET_LE_U_2(rhp->rh_long.lg_dst.dne_remote.dne_nodeaddr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800538 src =
Elliott Hughes820eced2021-08-20 18:00:50 -0700539 GET_LE_U_2(rhp->rh_long.lg_src.dne_remote.dne_nodeaddr);
540 hops = GET_U_1(rhp->rh_long.lg_visits);
541 nspp = ap + sizeof(short) + sizeof(struct longhdr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800542 nsplen = length - sizeof(struct longhdr);
543 break;
544 case RMF_SHORT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700545 dst = GET_LE_U_2(rhp->rh_short.sh_dst);
546 src = GET_LE_U_2(rhp->rh_short.sh_src);
547 hops = (GET_U_1(rhp->rh_short.sh_visits) & VIS_MASK)+1;
548 nspp = ap + sizeof(short) + sizeof(struct shorthdr);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800549 nsplen = length - sizeof(struct shorthdr);
550 break;
551 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700552 ND_PRINT("unknown message flags under mask");
553 ND_DEFAULTPRINT((const u_char *)ap, ND_MIN(length, caplen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800554 return;
555 }
556
Elliott Hughes820eced2021-08-20 18:00:50 -0700557 ND_PRINT("%s > %s %u ",
558 dnaddr_string(ndo, src), dnaddr_string(ndo, dst), pktlen);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700559 if (ndo->ndo_vflag) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800560 if (mflags & RMF_RQR)
Elliott Hughes820eced2021-08-20 18:00:50 -0700561 ND_PRINT("RQR ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800562 if (mflags & RMF_RTS)
Elliott Hughes820eced2021-08-20 18:00:50 -0700563 ND_PRINT("RTS ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800564 if (mflags & RMF_IE)
Elliott Hughes820eced2021-08-20 18:00:50 -0700565 ND_PRINT("IE ");
566 ND_PRINT("%u hops ", hops);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800567 }
568
Elliott Hughes892a68b2015-10-19 14:43:53 -0700569 if (!print_nsp(ndo, nspp, nsplen))
Elliott Hughes820eced2021-08-20 18:00:50 -0700570 goto invalid;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800571 return;
572
Elliott Hughes820eced2021-08-20 18:00:50 -0700573invalid:
574 nd_print_invalid(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800575}
576
577static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700578print_decnet_ctlmsg(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700579 const union routehdr *rhp, u_int length,
Elliott Hughes892a68b2015-10-19 14:43:53 -0700580 u_int caplen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800581{
Elliott Hughescec480a2017-12-19 16:54:57 -0800582 /* Our caller has already checked for mflags */
Elliott Hughes820eced2021-08-20 18:00:50 -0700583 u_int mflags = GET_U_1(rhp->rh_short.sh_flags);
584 const union controlmsg *cmp = (const union controlmsg *)rhp;
585 uint16_t src, dst;
586 u_int info, blksize, eco, ueco, hello, other, vers;
587 u_int priority;
588 const u_char *rhpx = (const u_char *)rhp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800589
590 switch (mflags & RMF_CTLMASK) {
591 case RMF_INIT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700592 ND_PRINT("init ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800593 if (length < sizeof(struct initmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700594 goto invalid;
595 ND_TCHECK_SIZE(&cmp->cm_init);
596 src = GET_LE_U_2(cmp->cm_init.in_src);
597 info = GET_U_1(cmp->cm_init.in_info);
598 blksize = GET_LE_U_2(cmp->cm_init.in_blksize);
599 vers = GET_U_1(cmp->cm_init.in_vers);
600 eco = GET_U_1(cmp->cm_init.in_eco);
601 ueco = GET_U_1(cmp->cm_init.in_ueco);
602 hello = GET_LE_U_2(cmp->cm_init.in_hello);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700603 print_t_info(ndo, info);
Elliott Hughes820eced2021-08-20 18:00:50 -0700604 ND_PRINT("src %sblksize %u vers %u eco %u ueco %u hello %u",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700605 dnaddr_string(ndo, src), blksize, vers, eco, ueco,
Elliott Hughes820eced2021-08-20 18:00:50 -0700606 hello);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800607 break;
608 case RMF_VER:
Elliott Hughes820eced2021-08-20 18:00:50 -0700609 ND_PRINT("verification ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800610 if (length < sizeof(struct verifmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700611 goto invalid;
612 src = GET_LE_U_2(cmp->cm_ver.ve_src);
613 other = GET_U_1(cmp->cm_ver.ve_fcnval);
614 ND_PRINT("src %s fcnval %o", dnaddr_string(ndo, src), other);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800615 break;
616 case RMF_TEST:
Elliott Hughes820eced2021-08-20 18:00:50 -0700617 ND_PRINT("test ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800618 if (length < sizeof(struct testmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700619 goto invalid;
620 src = GET_LE_U_2(cmp->cm_test.te_src);
621 other = GET_U_1(cmp->cm_test.te_data);
622 ND_PRINT("src %s data %o", dnaddr_string(ndo, src), other);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800623 break;
624 case RMF_L1ROUT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700625 ND_PRINT("lev-1-routing ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800626 if (length < sizeof(struct l1rout))
Elliott Hughes820eced2021-08-20 18:00:50 -0700627 goto invalid;
628 ND_TCHECK_SIZE(&cmp->cm_l1rou);
629 src = GET_LE_U_2(cmp->cm_l1rou.r1_src);
630 ND_PRINT("src %s ", dnaddr_string(ndo, src));
631 print_l1_routes(ndo, &(rhpx[sizeof(struct l1rout)]),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800632 length - sizeof(struct l1rout));
633 break;
634 case RMF_L2ROUT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700635 ND_PRINT("lev-2-routing ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800636 if (length < sizeof(struct l2rout))
Elliott Hughes820eced2021-08-20 18:00:50 -0700637 goto invalid;
638 ND_TCHECK_SIZE(&cmp->cm_l2rout);
639 src = GET_LE_U_2(cmp->cm_l2rout.r2_src);
640 ND_PRINT("src %s ", dnaddr_string(ndo, src));
641 print_l2_routes(ndo, &(rhpx[sizeof(struct l2rout)]),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800642 length - sizeof(struct l2rout));
643 break;
644 case RMF_RHELLO:
Elliott Hughes820eced2021-08-20 18:00:50 -0700645 ND_PRINT("router-hello ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800646 if (length < sizeof(struct rhellomsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700647 goto invalid;
648 ND_TCHECK_SIZE(&cmp->cm_rhello);
649 vers = GET_U_1(cmp->cm_rhello.rh_vers);
650 eco = GET_U_1(cmp->cm_rhello.rh_eco);
651 ueco = GET_U_1(cmp->cm_rhello.rh_ueco);
652 src =
653 GET_LE_U_2(cmp->cm_rhello.rh_src.dne_remote.dne_nodeaddr);
654 info = GET_U_1(cmp->cm_rhello.rh_info);
655 blksize = GET_LE_U_2(cmp->cm_rhello.rh_blksize);
656 priority = GET_U_1(cmp->cm_rhello.rh_priority);
657 hello = GET_LE_U_2(cmp->cm_rhello.rh_hello);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700658 print_i_info(ndo, info);
Elliott Hughes820eced2021-08-20 18:00:50 -0700659 ND_PRINT("vers %u eco %u ueco %u src %s blksize %u pri %u hello %u",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700660 vers, eco, ueco, dnaddr_string(ndo, src),
Elliott Hughes820eced2021-08-20 18:00:50 -0700661 blksize, priority, hello);
662 print_elist(&(rhpx[sizeof(struct rhellomsg)]),
The Android Open Source Project2949f582009-03-03 19:30:46 -0800663 length - sizeof(struct rhellomsg));
664 break;
665 case RMF_EHELLO:
Elliott Hughes820eced2021-08-20 18:00:50 -0700666 ND_PRINT("endnode-hello ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800667 if (length < sizeof(struct ehellomsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700668 goto invalid;
669 vers = GET_U_1(cmp->cm_ehello.eh_vers);
670 eco = GET_U_1(cmp->cm_ehello.eh_eco);
671 ueco = GET_U_1(cmp->cm_ehello.eh_ueco);
672 src =
673 GET_LE_U_2(cmp->cm_ehello.eh_src.dne_remote.dne_nodeaddr);
674 info = GET_U_1(cmp->cm_ehello.eh_info);
675 blksize = GET_LE_U_2(cmp->cm_ehello.eh_blksize);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800676 /*seed*/
Elliott Hughes820eced2021-08-20 18:00:50 -0700677 dst =
678 GET_LE_U_2(cmp->cm_ehello.eh_router.dne_remote.dne_nodeaddr);
679 hello = GET_LE_U_2(cmp->cm_ehello.eh_hello);
680 other = GET_U_1(cmp->cm_ehello.eh_data);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700681 print_i_info(ndo, info);
Elliott Hughes820eced2021-08-20 18:00:50 -0700682 ND_PRINT("vers %u eco %u ueco %u src %s blksize %u rtr %s hello %u data %o",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700683 vers, eco, ueco, dnaddr_string(ndo, src),
Elliott Hughes820eced2021-08-20 18:00:50 -0700684 blksize, dnaddr_string(ndo, dst), hello, other);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800685 break;
686
687 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700688 ND_PRINT("unknown control message");
689 ND_DEFAULTPRINT((const u_char *)rhp, ND_MIN(length, caplen));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800690 break;
691 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700692 return (1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800693
Elliott Hughes820eced2021-08-20 18:00:50 -0700694invalid:
The Android Open Source Project2949f582009-03-03 19:30:46 -0800695 return (0);
696}
697
698static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700699print_t_info(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700700 u_int info)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800701{
Elliott Hughes820eced2021-08-20 18:00:50 -0700702 u_int ntype = info & 3;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800703 switch (ntype) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700704 case 0: ND_PRINT("reserved-ntype? "); break;
705 case TI_L2ROUT: ND_PRINT("l2rout "); break;
706 case TI_L1ROUT: ND_PRINT("l1rout "); break;
707 case TI_ENDNODE: ND_PRINT("endnode "); break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800708 }
709 if (info & TI_VERIF)
Elliott Hughes820eced2021-08-20 18:00:50 -0700710 ND_PRINT("verif ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800711 if (info & TI_BLOCK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700712 ND_PRINT("blo ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800713}
714
Elliott Hughes820eced2021-08-20 18:00:50 -0700715static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700716print_l1_routes(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700717 const u_char *rp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800718{
Elliott Hughes820eced2021-08-20 18:00:50 -0700719 u_int count;
720 u_int id;
721 u_int info;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800722
723 /* The last short is a checksum */
724 while (len > (3 * sizeof(short))) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700725 ND_TCHECK_LEN(rp, 3 * sizeof(short));
726 count = GET_LE_U_2(rp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800727 if (count > 1024)
Elliott Hughes820eced2021-08-20 18:00:50 -0700728 return; /* seems to be bogus from here on */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800729 rp += sizeof(short);
730 len -= sizeof(short);
Elliott Hughes820eced2021-08-20 18:00:50 -0700731 id = GET_LE_U_2(rp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800732 rp += sizeof(short);
733 len -= sizeof(short);
Elliott Hughes820eced2021-08-20 18:00:50 -0700734 info = GET_LE_U_2(rp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800735 rp += sizeof(short);
736 len -= sizeof(short);
Elliott Hughes820eced2021-08-20 18:00:50 -0700737 ND_PRINT("{ids %u-%u cost %u hops %u} ", id, id + count,
738 RI_COST(info), RI_HOPS(info));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800739 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800740}
741
Elliott Hughes820eced2021-08-20 18:00:50 -0700742static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700743print_l2_routes(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700744 const u_char *rp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800745{
Elliott Hughes820eced2021-08-20 18:00:50 -0700746 u_int count;
747 u_int area;
748 u_int info;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800749
750 /* The last short is a checksum */
751 while (len > (3 * sizeof(short))) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700752 ND_TCHECK_LEN(rp, 3 * sizeof(short));
753 count = GET_LE_U_2(rp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800754 if (count > 1024)
Elliott Hughes820eced2021-08-20 18:00:50 -0700755 return; /* seems to be bogus from here on */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800756 rp += sizeof(short);
757 len -= sizeof(short);
Elliott Hughes820eced2021-08-20 18:00:50 -0700758 area = GET_LE_U_2(rp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800759 rp += sizeof(short);
760 len -= sizeof(short);
Elliott Hughes820eced2021-08-20 18:00:50 -0700761 info = GET_LE_U_2(rp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800762 rp += sizeof(short);
763 len -= sizeof(short);
Elliott Hughes820eced2021-08-20 18:00:50 -0700764 ND_PRINT("{areas %u-%u cost %u hops %u} ", area, area + count,
765 RI_COST(info), RI_HOPS(info));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800766 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800767}
768
769static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700770print_i_info(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700771 u_int info)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800772{
Elliott Hughes820eced2021-08-20 18:00:50 -0700773 u_int ntype = info & II_TYPEMASK;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800774 switch (ntype) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700775 case 0: ND_PRINT("reserved-ntype? "); break;
776 case II_L2ROUT: ND_PRINT("l2rout "); break;
777 case II_L1ROUT: ND_PRINT("l1rout "); break;
778 case II_ENDNODE: ND_PRINT("endnode "); break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800779 }
780 if (info & II_VERIF)
Elliott Hughes820eced2021-08-20 18:00:50 -0700781 ND_PRINT("verif ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800782 if (info & II_NOMCAST)
Elliott Hughes820eced2021-08-20 18:00:50 -0700783 ND_PRINT("nomcast ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800784 if (info & II_BLOCK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700785 ND_PRINT("blo ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800786}
787
Elliott Hughes820eced2021-08-20 18:00:50 -0700788static void
789print_elist(const u_char *elp _U_, u_int len _U_)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800790{
791 /* Not enough examples available for me to debug this */
The Android Open Source Project2949f582009-03-03 19:30:46 -0800792}
793
794static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700795print_nsp(netdissect_options *ndo,
796 const u_char *nspp, u_int nsplen)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800797{
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700798 const struct nsphdr *nsphp = (const struct nsphdr *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700799 u_int dst, src, flags;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800800
Elliott Hughes820eced2021-08-20 18:00:50 -0700801 if (nsplen < sizeof(struct nsphdr)) {
802 ND_PRINT(" (nsplen %u < %zu)", nsplen, sizeof(struct nsphdr));
803 goto invalid;
804 }
805 flags = GET_U_1(nsphp->nh_flags);
806 dst = GET_LE_U_2(nsphp->nh_dst);
807 src = GET_LE_U_2(nsphp->nh_src);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800808
809 switch (flags & NSP_TYPEMASK) {
810 case MFT_DATA:
811 switch (flags & NSP_SUBMASK) {
812 case MFS_BOM:
813 case MFS_MOM:
814 case MFS_EOM:
815 case MFS_BOM+MFS_EOM:
Elliott Hughes820eced2021-08-20 18:00:50 -0700816 ND_PRINT("data %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800817 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700818 const struct seghdr *shp = (const struct seghdr *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700819 u_int ack;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800820 u_int data_off = sizeof(struct minseghdr);
821
822 if (nsplen < data_off)
Elliott Hughes820eced2021-08-20 18:00:50 -0700823 goto invalid;
824 ack = GET_LE_U_2(shp->sh_seq[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800825 if (ack & SGQ_ACK) { /* acknum field */
826 if ((ack & SGQ_NAK) == SGQ_NAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700827 ND_PRINT("nak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800828 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700829 ND_PRINT("ack %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800830 data_off += sizeof(short);
831 if (nsplen < data_off)
Elliott Hughes820eced2021-08-20 18:00:50 -0700832 goto invalid;
833 ack = GET_LE_U_2(shp->sh_seq[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800834 if (ack & SGQ_OACK) { /* ackoth field */
835 if ((ack & SGQ_ONAK) == SGQ_ONAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700836 ND_PRINT("onak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800837 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700838 ND_PRINT("oack %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800839 data_off += sizeof(short);
840 if (nsplen < data_off)
Elliott Hughes820eced2021-08-20 18:00:50 -0700841 goto invalid;
842 ack = GET_LE_U_2(shp->sh_seq[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800843 }
844 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700845 ND_PRINT("seg %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800846 }
847 break;
848 case MFS_ILS+MFS_INT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700849 ND_PRINT("intr ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800850 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700851 const struct seghdr *shp = (const struct seghdr *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700852 u_int ack;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800853 u_int data_off = sizeof(struct minseghdr);
854
855 if (nsplen < data_off)
Elliott Hughes820eced2021-08-20 18:00:50 -0700856 goto invalid;
857 ack = GET_LE_U_2(shp->sh_seq[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800858 if (ack & SGQ_ACK) { /* acknum field */
859 if ((ack & SGQ_NAK) == SGQ_NAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700860 ND_PRINT("nak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800861 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700862 ND_PRINT("ack %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800863 data_off += sizeof(short);
864 if (nsplen < data_off)
Elliott Hughes820eced2021-08-20 18:00:50 -0700865 goto invalid;
866 ack = GET_LE_U_2(shp->sh_seq[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800867 if (ack & SGQ_OACK) { /* ackdat field */
868 if ((ack & SGQ_ONAK) == SGQ_ONAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700869 ND_PRINT("nakdat %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800870 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700871 ND_PRINT("ackdat %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800872 data_off += sizeof(short);
873 if (nsplen < data_off)
Elliott Hughes820eced2021-08-20 18:00:50 -0700874 goto invalid;
875 ack = GET_LE_U_2(shp->sh_seq[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800876 }
877 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700878 ND_PRINT("seg %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800879 }
880 break;
881 case MFS_ILS:
Elliott Hughes820eced2021-08-20 18:00:50 -0700882 ND_PRINT("link-service %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800883 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700884 const struct seghdr *shp = (const struct seghdr *)nspp;
885 const struct lsmsg *lsmp =
Elliott Hughes820eced2021-08-20 18:00:50 -0700886 (const struct lsmsg *)(nspp + sizeof(struct seghdr));
887 u_int ack;
888 u_int lsflags, fcval;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800889
890 if (nsplen < sizeof(struct seghdr) + sizeof(struct lsmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700891 goto invalid;
892 ack = GET_LE_U_2(shp->sh_seq[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800893 if (ack & SGQ_ACK) { /* acknum field */
894 if ((ack & SGQ_NAK) == SGQ_NAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700895 ND_PRINT("nak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800896 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700897 ND_PRINT("ack %u ", ack & SGQ_MASK);
898 ack = GET_LE_U_2(shp->sh_seq[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800899 if (ack & SGQ_OACK) { /* ackdat field */
900 if ((ack & SGQ_ONAK) == SGQ_ONAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700901 ND_PRINT("nakdat %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800902 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700903 ND_PRINT("ackdat %u ", ack & SGQ_MASK);
904 ack = GET_LE_U_2(shp->sh_seq[2]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800905 }
906 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700907 ND_PRINT("seg %u ", ack & SGQ_MASK);
908 lsflags = GET_U_1(lsmp->ls_lsflags);
909 fcval = GET_U_1(lsmp->ls_fcval);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800910 switch (lsflags & LSI_MASK) {
911 case LSI_DATA:
Elliott Hughes820eced2021-08-20 18:00:50 -0700912 ND_PRINT("dat seg count %u ", fcval);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800913 switch (lsflags & LSM_MASK) {
914 case LSM_NOCHANGE:
915 break;
916 case LSM_DONOTSEND:
Elliott Hughes820eced2021-08-20 18:00:50 -0700917 ND_PRINT("donotsend-data ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800918 break;
919 case LSM_SEND:
Elliott Hughes820eced2021-08-20 18:00:50 -0700920 ND_PRINT("send-data ");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800921 break;
922 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700923 ND_PRINT("reserved-fcmod? %x", lsflags);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800924 break;
925 }
926 break;
927 case LSI_INTR:
Elliott Hughes820eced2021-08-20 18:00:50 -0700928 ND_PRINT("intr req count %u ", fcval);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800929 break;
930 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700931 ND_PRINT("reserved-fcval-int? %x", lsflags);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800932 break;
933 }
934 }
935 break;
936 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700937 ND_PRINT("reserved-subtype? %x %u > %u", flags, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800938 break;
939 }
940 break;
941 case MFT_ACK:
942 switch (flags & NSP_SUBMASK) {
943 case MFS_DACK:
Elliott Hughes820eced2021-08-20 18:00:50 -0700944 ND_PRINT("data-ack %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800945 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700946 const struct ackmsg *amp = (const struct ackmsg *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700947 u_int ack;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800948
949 if (nsplen < sizeof(struct ackmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700950 goto invalid;
951 ND_TCHECK_SIZE(amp);
952 ack = GET_LE_U_2(amp->ak_acknum[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800953 if (ack & SGQ_ACK) { /* acknum field */
954 if ((ack & SGQ_NAK) == SGQ_NAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700955 ND_PRINT("nak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800956 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700957 ND_PRINT("ack %u ", ack & SGQ_MASK);
958 ack = GET_LE_U_2(amp->ak_acknum[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800959 if (ack & SGQ_OACK) { /* ackoth field */
960 if ((ack & SGQ_ONAK) == SGQ_ONAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700961 ND_PRINT("onak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800962 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700963 ND_PRINT("oack %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800964 }
965 }
966 }
967 break;
968 case MFS_IACK:
Elliott Hughes820eced2021-08-20 18:00:50 -0700969 ND_PRINT("ils-ack %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800970 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700971 const struct ackmsg *amp = (const struct ackmsg *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700972 u_int ack;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800973
974 if (nsplen < sizeof(struct ackmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -0700975 goto invalid;
976 ND_TCHECK_SIZE(amp);
977 ack = GET_LE_U_2(amp->ak_acknum[0]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800978 if (ack & SGQ_ACK) { /* acknum field */
979 if ((ack & SGQ_NAK) == SGQ_NAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700980 ND_PRINT("nak %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800981 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700982 ND_PRINT("ack %u ", ack & SGQ_MASK);
983 ack = GET_LE_U_2(amp->ak_acknum[1]);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800984 if (ack & SGQ_OACK) { /* ackdat field */
985 if ((ack & SGQ_ONAK) == SGQ_ONAK)
Elliott Hughes820eced2021-08-20 18:00:50 -0700986 ND_PRINT("nakdat %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800987 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700988 ND_PRINT("ackdat %u ", ack & SGQ_MASK);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800989 }
990 }
991 }
992 break;
993 case MFS_CACK:
Elliott Hughes820eced2021-08-20 18:00:50 -0700994 ND_PRINT("conn-ack %u", dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800995 break;
996 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700997 ND_PRINT("reserved-acktype? %x %u > %u", flags, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800998 break;
999 }
1000 break;
1001 case MFT_CTL:
1002 switch (flags & NSP_SUBMASK) {
1003 case MFS_CI:
1004 case MFS_RCI:
1005 if ((flags & NSP_SUBMASK) == MFS_CI)
Elliott Hughes820eced2021-08-20 18:00:50 -07001006 ND_PRINT("conn-initiate ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001007 else
Elliott Hughes820eced2021-08-20 18:00:50 -07001008 ND_PRINT("retrans-conn-initiate ");
1009 ND_PRINT("%u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001010 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001011 const struct cimsg *cimp = (const struct cimsg *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -07001012 u_int services, info, segsize;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001013
1014 if (nsplen < sizeof(struct cimsg))
Elliott Hughes820eced2021-08-20 18:00:50 -07001015 goto invalid;
1016 services = GET_U_1(cimp->ci_services);
1017 info = GET_U_1(cimp->ci_info);
1018 segsize = GET_LE_U_2(cimp->ci_segsize);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001019
1020 switch (services & COS_MASK) {
1021 case COS_NONE:
1022 break;
1023 case COS_SEGMENT:
Elliott Hughes820eced2021-08-20 18:00:50 -07001024 ND_PRINT("seg ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001025 break;
1026 case COS_MESSAGE:
Elliott Hughes820eced2021-08-20 18:00:50 -07001027 ND_PRINT("msg ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001028 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001029 }
1030 switch (info & COI_MASK) {
1031 case COI_32:
Elliott Hughes820eced2021-08-20 18:00:50 -07001032 ND_PRINT("ver 3.2 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001033 break;
1034 case COI_31:
Elliott Hughes820eced2021-08-20 18:00:50 -07001035 ND_PRINT("ver 3.1 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001036 break;
1037 case COI_40:
Elliott Hughes820eced2021-08-20 18:00:50 -07001038 ND_PRINT("ver 4.0 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001039 break;
1040 case COI_41:
Elliott Hughes820eced2021-08-20 18:00:50 -07001041 ND_PRINT("ver 4.1 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001042 break;
1043 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001044 ND_PRINT("segsize %u ", segsize);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001045 }
1046 break;
1047 case MFS_CC:
Elliott Hughes820eced2021-08-20 18:00:50 -07001048 ND_PRINT("conn-confirm %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001049 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001050 const struct ccmsg *ccmp = (const struct ccmsg *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -07001051 u_int services, info;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001052 u_int segsize, optlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001053
1054 if (nsplen < sizeof(struct ccmsg))
Elliott Hughes820eced2021-08-20 18:00:50 -07001055 goto invalid;
1056 services = GET_U_1(ccmp->cc_services);
1057 info = GET_U_1(ccmp->cc_info);
1058 segsize = GET_LE_U_2(ccmp->cc_segsize);
1059 optlen = GET_U_1(ccmp->cc_optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001060
1061 switch (services & COS_MASK) {
1062 case COS_NONE:
1063 break;
1064 case COS_SEGMENT:
Elliott Hughes820eced2021-08-20 18:00:50 -07001065 ND_PRINT("seg ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001066 break;
1067 case COS_MESSAGE:
Elliott Hughes820eced2021-08-20 18:00:50 -07001068 ND_PRINT("msg ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001069 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001070 }
1071 switch (info & COI_MASK) {
1072 case COI_32:
Elliott Hughes820eced2021-08-20 18:00:50 -07001073 ND_PRINT("ver 3.2 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001074 break;
1075 case COI_31:
Elliott Hughes820eced2021-08-20 18:00:50 -07001076 ND_PRINT("ver 3.1 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001077 break;
1078 case COI_40:
Elliott Hughes820eced2021-08-20 18:00:50 -07001079 ND_PRINT("ver 4.0 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001080 break;
1081 case COI_41:
Elliott Hughes820eced2021-08-20 18:00:50 -07001082 ND_PRINT("ver 4.1 ");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001083 break;
1084 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001085 ND_PRINT("segsize %u ", segsize);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001086 if (optlen) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001087 ND_PRINT("optlen %u ", optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001088 }
1089 }
1090 break;
1091 case MFS_DI:
Elliott Hughes820eced2021-08-20 18:00:50 -07001092 ND_PRINT("disconn-initiate %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001093 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001094 const struct dimsg *dimp = (const struct dimsg *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -07001095 u_int reason;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001096 u_int optlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001097
1098 if (nsplen < sizeof(struct dimsg))
Elliott Hughes820eced2021-08-20 18:00:50 -07001099 goto invalid;
1100 reason = GET_LE_U_2(dimp->di_reason);
1101 optlen = GET_U_1(dimp->di_optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001102
Elliott Hughes892a68b2015-10-19 14:43:53 -07001103 print_reason(ndo, reason);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001104 if (optlen) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001105 ND_PRINT("optlen %u ", optlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001106 }
1107 }
1108 break;
1109 case MFS_DC:
Elliott Hughes820eced2021-08-20 18:00:50 -07001110 ND_PRINT("disconn-confirm %u>%u ", src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001111 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001112 const struct dcmsg *dcmp = (const struct dcmsg *)nspp;
Elliott Hughes820eced2021-08-20 18:00:50 -07001113 u_int reason;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001114
Elliott Hughes820eced2021-08-20 18:00:50 -07001115 reason = GET_LE_U_2(dcmp->dc_reason);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001116
Elliott Hughes892a68b2015-10-19 14:43:53 -07001117 print_reason(ndo, reason);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001118 }
1119 break;
1120 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001121 ND_PRINT("reserved-ctltype? %x %u > %u", flags, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001122 break;
1123 }
1124 break;
1125 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001126 ND_PRINT("reserved-type? %x %u > %u", flags, src, dst);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001127 break;
1128 }
1129 return (1);
1130
Elliott Hughes820eced2021-08-20 18:00:50 -07001131invalid:
The Android Open Source Project2949f582009-03-03 19:30:46 -08001132 return (0);
1133}
1134
JP Abgrall53f17a92014-02-12 14:02:41 -08001135static const struct tok reason2str[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001136 { UC_OBJREJECT, "object rejected connect" },
1137 { UC_RESOURCES, "insufficient resources" },
1138 { UC_NOSUCHNODE, "unrecognized node name" },
1139 { DI_SHUT, "node is shutting down" },
1140 { UC_NOSUCHOBJ, "unrecognized object" },
1141 { UC_INVOBJFORMAT, "invalid object name format" },
1142 { UC_OBJTOOBUSY, "object too busy" },
1143 { DI_PROTOCOL, "protocol error discovered" },
1144 { DI_TPA, "third party abort" },
1145 { UC_USERABORT, "user abort" },
1146 { UC_INVNODEFORMAT, "invalid node name format" },
1147 { UC_LOCALSHUT, "local node shutting down" },
1148 { DI_LOCALRESRC, "insufficient local resources" },
1149 { DI_REMUSERRESRC, "insufficient remote user resources" },
1150 { UC_ACCESSREJECT, "invalid access control information" },
1151 { DI_BADACCNT, "bad ACCOUNT information" },
1152 { UC_NORESPONSE, "no response from object" },
1153 { UC_UNREACHABLE, "node unreachable" },
1154 { DC_NOLINK, "no link terminate" },
1155 { DC_COMPLETE, "disconnect complete" },
1156 { DI_BADIMAGE, "bad image data in connect" },
1157 { DI_SERVMISMATCH, "cryptographic service mismatch" },
1158 { 0, NULL }
1159};
1160
1161static void
Elliott Hughes892a68b2015-10-19 14:43:53 -07001162print_reason(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -07001163 u_int reason)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001164{
Elliott Hughes820eced2021-08-20 18:00:50 -07001165 ND_PRINT("%s ", tok2str(reason2str, "reason-%u", reason));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001166}
1167
1168const char *
Elliott Hughese2e3bd12017-05-15 10:59:29 -07001169dnnum_string(netdissect_options *ndo, u_short dnaddr)
The Android Open Source Project2949f582009-03-03 19:30:46 -08001170{
1171 char *str;
1172 size_t siz;
Elliott Hughes820eced2021-08-20 18:00:50 -07001173 u_int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
1174 u_int node = dnaddr & NODEMASK;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001175
Elliott Hughes820eced2021-08-20 18:00:50 -07001176 /* malloc() return used by the 'dnaddrtable' hash table: do not free() */
The Android Open Source Project2949f582009-03-03 19:30:46 -08001177 str = (char *)malloc(siz = sizeof("00.0000"));
1178 if (str == NULL)
Elliott Hughes820eced2021-08-20 18:00:50 -07001179 (*ndo->ndo_error)(ndo, S_ERR_ND_MEM_ALLOC, "%s: malloc", __func__);
1180 snprintf(str, siz, "%u.%u", area, node);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001181 return(str);
1182}