The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 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 Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: Cisco HDLC printer */ |
| 23 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
| 25 | #include "config.h" |
| 26 | #endif |
| 27 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 28 | #include <netdissect-stdinc.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | #include "addrtoname.h" |
| 32 | #include "ethertype.h" |
| 33 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 34 | #include "chdlc.h" |
| 35 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 36 | static void chdlc_slarp_print(netdissect_options *, const u_char *, u_int); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 37 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 38 | static const struct tok chdlc_cast_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 39 | { CHDLC_UNICAST, "unicast" }, |
| 40 | { CHDLC_BCAST, "bcast" }, |
| 41 | { 0, NULL} |
| 42 | }; |
| 43 | |
| 44 | |
| 45 | /* Standard CHDLC printer */ |
| 46 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 47 | chdlc_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h, register const u_char *p) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 48 | { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 49 | return chdlc_print(ndo, p, h->len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | u_int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 53 | chdlc_print(netdissect_options *ndo, register const u_char *p, u_int length) |
| 54 | { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 55 | u_int proto; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 56 | const u_char *bp = p; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 57 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 58 | if (length < CHDLC_HDRLEN) |
| 59 | goto trunc; |
| 60 | ND_TCHECK2(*p, CHDLC_HDRLEN); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 61 | proto = EXTRACT_16BITS(&p[2]); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 62 | if (ndo->ndo_eflag) { |
| 63 | ND_PRINT((ndo, "%s, ethertype %s (0x%04x), length %u: ", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 64 | tok2str(chdlc_cast_values, "0x%02x", p[0]), |
| 65 | tok2str(ethertype_values, "Unknown", proto), |
| 66 | proto, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 67 | length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | length -= CHDLC_HDRLEN; |
| 71 | p += CHDLC_HDRLEN; |
| 72 | |
| 73 | switch (proto) { |
| 74 | case ETHERTYPE_IP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 75 | ip_print(ndo, p, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 76 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 77 | case ETHERTYPE_IPV6: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 78 | ip6_print(ndo, p, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 79 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 80 | case CHDLC_TYPE_SLARP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 81 | chdlc_slarp_print(ndo, p, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 82 | break; |
| 83 | #if 0 |
| 84 | case CHDLC_TYPE_CDP: |
| 85 | chdlc_cdp_print(p, length); |
| 86 | break; |
| 87 | #endif |
| 88 | case ETHERTYPE_MPLS: |
| 89 | case ETHERTYPE_MPLS_MULTI: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 90 | mpls_print(ndo, p, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 91 | break; |
| 92 | case ETHERTYPE_ISO: |
| 93 | /* is the fudge byte set ? lets verify by spotting ISO headers */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 94 | if (length < 2) |
| 95 | goto trunc; |
| 96 | ND_TCHECK_16BITS(p); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 97 | if (*(p+1) == 0x81 || |
| 98 | *(p+1) == 0x82 || |
| 99 | *(p+1) == 0x83) |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 100 | isoclns_print(ndo, p + 1, length - 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 101 | else |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 102 | isoclns_print(ndo, p, length); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 103 | break; |
| 104 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 105 | if (!ndo->ndo_eflag) |
| 106 | ND_PRINT((ndo, "unknown CHDLC protocol (0x%04x)", proto)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 107 | break; |
| 108 | } |
| 109 | |
| 110 | return (CHDLC_HDRLEN); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 111 | |
| 112 | trunc: |
| 113 | ND_PRINT((ndo, "[|chdlc]")); |
| 114 | return ndo->ndo_snapend - bp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /* |
| 118 | * The fixed-length portion of a SLARP packet. |
| 119 | */ |
| 120 | struct cisco_slarp { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 121 | uint8_t code[4]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 122 | #define SLARP_REQUEST 0 |
| 123 | #define SLARP_REPLY 1 |
| 124 | #define SLARP_KEEPALIVE 2 |
| 125 | union { |
| 126 | struct { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 127 | uint8_t addr[4]; |
| 128 | uint8_t mask[4]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 129 | } addr; |
| 130 | struct { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 131 | uint8_t myseq[4]; |
| 132 | uint8_t yourseq[4]; |
| 133 | uint8_t rel[2]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 134 | } keep; |
| 135 | } un; |
| 136 | }; |
| 137 | |
| 138 | #define SLARP_MIN_LEN 14 |
| 139 | #define SLARP_MAX_LEN 18 |
| 140 | |
| 141 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 142 | chdlc_slarp_print(netdissect_options *ndo, const u_char *cp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 143 | { |
| 144 | const struct cisco_slarp *slarp; |
| 145 | u_int sec,min,hrs,days; |
| 146 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 147 | ND_PRINT((ndo, "SLARP (length: %u), ",length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 148 | if (length < SLARP_MIN_LEN) |
| 149 | goto trunc; |
| 150 | |
| 151 | slarp = (const struct cisco_slarp *)cp; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 152 | ND_TCHECK2(*slarp, SLARP_MIN_LEN); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 153 | switch (EXTRACT_32BITS(&slarp->code)) { |
| 154 | case SLARP_REQUEST: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 155 | ND_PRINT((ndo, "request")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 156 | /* |
| 157 | * At least according to William "Chops" Westfield's |
| 158 | * message in |
| 159 | * |
| 160 | * http://www.nethelp.no/net/cisco-hdlc.txt |
| 161 | * |
| 162 | * the address and mask aren't used in requests - |
| 163 | * they're just zero. |
| 164 | */ |
| 165 | break; |
| 166 | case SLARP_REPLY: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 167 | ND_PRINT((ndo, "reply %s/%s", |
| 168 | ipaddr_string(ndo, &slarp->un.addr.addr), |
| 169 | ipaddr_string(ndo, &slarp->un.addr.mask))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 170 | break; |
| 171 | case SLARP_KEEPALIVE: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 172 | ND_PRINT((ndo, "keepalive: mineseen=0x%08x, yourseen=0x%08x, reliability=0x%04x", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 173 | EXTRACT_32BITS(&slarp->un.keep.myseq), |
| 174 | EXTRACT_32BITS(&slarp->un.keep.yourseq), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 175 | EXTRACT_16BITS(&slarp->un.keep.rel))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 176 | |
| 177 | if (length >= SLARP_MAX_LEN) { /* uptime-stamp is optional */ |
| 178 | cp += SLARP_MIN_LEN; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 179 | ND_TCHECK2(*cp, 4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 180 | sec = EXTRACT_32BITS(cp) / 1000; |
| 181 | min = sec / 60; sec -= min * 60; |
| 182 | hrs = min / 60; min -= hrs * 60; |
| 183 | days = hrs / 24; hrs -= days * 24; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 184 | ND_PRINT((ndo, ", link uptime=%ud%uh%um%us",days,hrs,min,sec)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 185 | } |
| 186 | break; |
| 187 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 188 | ND_PRINT((ndo, "0x%02x unknown", EXTRACT_32BITS(&slarp->code))); |
| 189 | if (ndo->ndo_vflag <= 1) |
| 190 | print_unknown_data(ndo,cp+4,"\n\t",length-4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 191 | break; |
| 192 | } |
| 193 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 194 | if (SLARP_MAX_LEN < length && ndo->ndo_vflag) |
| 195 | ND_PRINT((ndo, ", (trailing junk: %d bytes)", length - SLARP_MAX_LEN)); |
| 196 | if (ndo->ndo_vflag > 1) |
| 197 | print_unknown_data(ndo,cp+4,"\n\t",length-4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 198 | return; |
| 199 | |
| 200 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 201 | ND_PRINT((ndo, "[|slarp]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | /* |
| 206 | * Local Variables: |
| 207 | * c-style: whitesmith |
| 208 | * c-basic-offset: 8 |
| 209 | * End: |
| 210 | */ |