blob: 235675da42b17ebc35653799e447735ea146774b [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
2 * Copyright (c) 1990, 1991, 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: Cisco HDLC 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
Elliott Hughese2e3bd12017-05-15 10:59:29 -070030#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080031#include "addrtoname.h"
32#include "ethertype.h"
33#include "extract.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080034#include "chdlc.h"
Elliott Hughes820eced2021-08-20 18:00:50 -070035#include "nlpid.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080036
Elliott Hughes892a68b2015-10-19 14:43:53 -070037static void chdlc_slarp_print(netdissect_options *, const u_char *, u_int);
The Android Open Source Project2949f582009-03-03 19:30:46 -080038
Elliott Hughes892a68b2015-10-19 14:43:53 -070039static const struct tok chdlc_cast_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080040 { CHDLC_UNICAST, "unicast" },
41 { CHDLC_BCAST, "bcast" },
42 { 0, NULL}
43};
44
45
46/* Standard CHDLC printer */
Elliott Hughes820eced2021-08-20 18:00:50 -070047void
48chdlc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, const u_char *p)
The Android Open Source Project2949f582009-03-03 19:30:46 -080049{
Elliott Hughes820eced2021-08-20 18:00:50 -070050 ndo->ndo_protocol = "chdlc";
51 ndo->ndo_ll_hdr_len += chdlc_print(ndo, p, h->len);
The Android Open Source Project2949f582009-03-03 19:30:46 -080052}
53
54u_int
Elliott Hughes820eced2021-08-20 18:00:50 -070055chdlc_print(netdissect_options *ndo, const u_char *p, u_int length)
Elliott Hughes892a68b2015-10-19 14:43:53 -070056{
The Android Open Source Project2949f582009-03-03 19:30:46 -080057 u_int proto;
Elliott Hughescec480a2017-12-19 16:54:57 -080058 const u_char *bp = p;
The Android Open Source Project2949f582009-03-03 19:30:46 -080059
Elliott Hughes820eced2021-08-20 18:00:50 -070060 ndo->ndo_protocol = "chdlc";
Elliott Hughescec480a2017-12-19 16:54:57 -080061 if (length < CHDLC_HDRLEN)
62 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -070063 proto = GET_BE_U_2(p + 2);
Elliott Hughes892a68b2015-10-19 14:43:53 -070064 if (ndo->ndo_eflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -070065 ND_PRINT("%s, ethertype %s (0x%04x), length %u: ",
66 tok2str(chdlc_cast_values, "0x%02x", GET_U_1(p)),
The Android Open Source Project2949f582009-03-03 19:30:46 -080067 tok2str(ethertype_values, "Unknown", proto),
68 proto,
Elliott Hughes820eced2021-08-20 18:00:50 -070069 length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080070 }
71
72 length -= CHDLC_HDRLEN;
73 p += CHDLC_HDRLEN;
74
75 switch (proto) {
76 case ETHERTYPE_IP:
Elliott Hughes892a68b2015-10-19 14:43:53 -070077 ip_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080078 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -080079 case ETHERTYPE_IPV6:
Elliott Hughes892a68b2015-10-19 14:43:53 -070080 ip6_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080081 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -080082 case CHDLC_TYPE_SLARP:
Elliott Hughes892a68b2015-10-19 14:43:53 -070083 chdlc_slarp_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080084 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -080085 case ETHERTYPE_MPLS:
86 case ETHERTYPE_MPLS_MULTI:
Elliott Hughes892a68b2015-10-19 14:43:53 -070087 mpls_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080088 break;
89 case ETHERTYPE_ISO:
90 /* is the fudge byte set ? lets verify by spotting ISO headers */
Elliott Hughescec480a2017-12-19 16:54:57 -080091 if (length < 2)
92 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -070093 if (GET_U_1(p + 1) == NLPID_CLNP ||
94 GET_U_1(p + 1) == NLPID_ESIS ||
95 GET_U_1(p + 1) == NLPID_ISIS)
Elliott Hughescec480a2017-12-19 16:54:57 -080096 isoclns_print(ndo, p + 1, length - 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -080097 else
Elliott Hughescec480a2017-12-19 16:54:57 -080098 isoclns_print(ndo, p, length);
The Android Open Source Project2949f582009-03-03 19:30:46 -080099 break;
100 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700101 if (!ndo->ndo_eflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700102 ND_PRINT("unknown CHDLC protocol (0x%04x)", proto);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800103 break;
104 }
105
106 return (CHDLC_HDRLEN);
Elliott Hughescec480a2017-12-19 16:54:57 -0800107
108trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700109 nd_print_trunc(ndo);
110 return (ND_BYTES_AVAILABLE_AFTER(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800111}
112
113/*
114 * The fixed-length portion of a SLARP packet.
115 */
116struct cisco_slarp {
Elliott Hughes820eced2021-08-20 18:00:50 -0700117 nd_uint32_t code;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800118#define SLARP_REQUEST 0
119#define SLARP_REPLY 1
120#define SLARP_KEEPALIVE 2
121 union {
122 struct {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700123 uint8_t addr[4];
124 uint8_t mask[4];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800125 } addr;
126 struct {
Elliott Hughes820eced2021-08-20 18:00:50 -0700127 nd_uint32_t myseq;
128 nd_uint32_t yourseq;
129 nd_uint16_t rel;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800130 } keep;
131 } un;
132};
133
134#define SLARP_MIN_LEN 14
135#define SLARP_MAX_LEN 18
136
137static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700138chdlc_slarp_print(netdissect_options *ndo, const u_char *cp, u_int length)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800139{
140 const struct cisco_slarp *slarp;
141 u_int sec,min,hrs,days;
142
Elliott Hughes820eced2021-08-20 18:00:50 -0700143 ndo->ndo_protocol = "chdlc_slarp";
144 ND_PRINT("SLARP (length: %u), ",length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800145 if (length < SLARP_MIN_LEN)
146 goto trunc;
147
148 slarp = (const struct cisco_slarp *)cp;
Elliott Hughes820eced2021-08-20 18:00:50 -0700149 ND_TCHECK_LEN(slarp, SLARP_MIN_LEN);
150 switch (GET_BE_U_4(slarp->code)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800151 case SLARP_REQUEST:
Elliott Hughes820eced2021-08-20 18:00:50 -0700152 ND_PRINT("request");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800153 /*
154 * At least according to William "Chops" Westfield's
155 * message in
156 *
Elliott Hughes820eced2021-08-20 18:00:50 -0700157 * https://web.archive.org/web/20190725151313/www.nethelp.no/net/cisco-hdlc.txt
The Android Open Source Project2949f582009-03-03 19:30:46 -0800158 *
159 * the address and mask aren't used in requests -
160 * they're just zero.
161 */
162 break;
163 case SLARP_REPLY:
Elliott Hughes820eced2021-08-20 18:00:50 -0700164 ND_PRINT("reply %s/%s",
165 GET_IPADDR_STRING(slarp->un.addr.addr),
166 GET_IPADDR_STRING(slarp->un.addr.mask));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800167 break;
168 case SLARP_KEEPALIVE:
Elliott Hughes820eced2021-08-20 18:00:50 -0700169 ND_PRINT("keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x",
170 GET_BE_U_4(slarp->un.keep.myseq),
171 GET_BE_U_4(slarp->un.keep.yourseq),
172 GET_BE_U_2(slarp->un.keep.rel));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800173
174 if (length >= SLARP_MAX_LEN) { /* uptime-stamp is optional */
175 cp += SLARP_MIN_LEN;
Elliott Hughes820eced2021-08-20 18:00:50 -0700176 sec = GET_BE_U_4(cp) / 1000;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800177 min = sec / 60; sec -= min * 60;
178 hrs = min / 60; min -= hrs * 60;
179 days = hrs / 24; hrs -= days * 24;
Elliott Hughes820eced2021-08-20 18:00:50 -0700180 ND_PRINT(", link uptime=%ud%uh%um%us",days,hrs,min,sec);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800181 }
182 break;
183 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700184 ND_PRINT("0x%02x unknown", GET_BE_U_4(slarp->code));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700185 if (ndo->ndo_vflag <= 1)
186 print_unknown_data(ndo,cp+4,"\n\t",length-4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800187 break;
188 }
189
Elliott Hughes892a68b2015-10-19 14:43:53 -0700190 if (SLARP_MAX_LEN < length && ndo->ndo_vflag)
Elliott Hughes820eced2021-08-20 18:00:50 -0700191 ND_PRINT(", (trailing junk: %u bytes)", length - SLARP_MAX_LEN);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700192 if (ndo->ndo_vflag > 1)
193 print_unknown_data(ndo,cp+4,"\n\t",length-4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800194 return;
195
196trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700197 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800198}