The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* $OpenBSD: print-gre.c,v 1.6 2002/10/30 03:04:04 fgsch Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Copyright (c) 2002 Jason L. Wright (jason@thought.net) |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software |
| 16 | * must display the following acknowledgement: |
| 17 | * This product includes software developed by Jason L. Wright |
| 18 | * 4. The name of the author may not be used to endorse or promote products |
| 19 | * derived from this software without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 24 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 25 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 27 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 29 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 30 | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 31 | * POSSIBILITY OF SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * tcpdump filter for GRE - Generic Routing Encapsulation |
| 36 | * RFC1701 (GRE), RFC1702 (GRE IPv4), and RFC2637 (Enhanced GRE) |
| 37 | */ |
| 38 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 39 | #define NETDISSECT_REWORKED |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 40 | #ifdef HAVE_CONFIG_H |
| 41 | #include "config.h" |
| 42 | #endif |
| 43 | |
| 44 | #include <tcpdump-stdinc.h> |
| 45 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 46 | #include <string.h> |
| 47 | |
| 48 | #include "interface.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 49 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 50 | #include "ethertype.h" |
| 51 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 52 | static const char tstr[] = "[|gre]"; |
| 53 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 54 | #define GRE_CP 0x8000 /* checksum present */ |
| 55 | #define GRE_RP 0x4000 /* routing present */ |
| 56 | #define GRE_KP 0x2000 /* key present */ |
| 57 | #define GRE_SP 0x1000 /* sequence# present */ |
| 58 | #define GRE_sP 0x0800 /* source routing */ |
| 59 | #define GRE_RECRS 0x0700 /* recursion count */ |
| 60 | #define GRE_AP 0x0080 /* acknowledgment# present */ |
| 61 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 62 | static const struct tok gre_flag_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 63 | { GRE_CP, "checksum present"}, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 64 | { GRE_RP, "routing present"}, |
| 65 | { GRE_KP, "key present"}, |
| 66 | { GRE_SP, "sequence# present"}, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 67 | { GRE_sP, "source routing present"}, |
| 68 | { GRE_RECRS, "recursion count"}, |
| 69 | { GRE_AP, "ack present"}, |
| 70 | { 0, NULL } |
| 71 | }; |
| 72 | |
| 73 | #define GRE_VERS_MASK 0x0007 /* protocol version */ |
| 74 | |
| 75 | /* source route entry types */ |
| 76 | #define GRESRE_IP 0x0800 /* IP */ |
| 77 | #define GRESRE_ASN 0xfffe /* ASN */ |
| 78 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 79 | static void gre_print_0(netdissect_options *, const u_char *, u_int); |
| 80 | static void gre_print_1(netdissect_options *, const u_char *, u_int); |
| 81 | static void gre_sre_print(netdissect_options *, uint16_t, uint8_t, uint8_t, const u_char *, u_int); |
| 82 | static void gre_sre_ip_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int); |
| 83 | static void gre_sre_asn_print(netdissect_options *, uint8_t, uint8_t, const u_char *, u_int); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 84 | |
| 85 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 86 | gre_print(netdissect_options *ndo, const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 87 | { |
| 88 | u_int len = length, vers; |
| 89 | |
| 90 | if (len < 2) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 91 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 92 | return; |
| 93 | } |
| 94 | vers = EXTRACT_16BITS(bp) & GRE_VERS_MASK; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 95 | ND_PRINT((ndo, "GREv%u",vers)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 96 | |
| 97 | switch(vers) { |
| 98 | case 0: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 99 | gre_print_0(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 100 | break; |
| 101 | case 1: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 102 | gre_print_1(ndo, bp, len); |
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 | ND_PRINT((ndo, " ERROR: unknown-version")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 106 | break; |
| 107 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 108 | } |
| 109 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 110 | static void |
| 111 | gre_print_0(netdissect_options *ndo, const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 112 | { |
| 113 | u_int len = length; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 114 | uint16_t flags, prot; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 115 | |
| 116 | flags = EXTRACT_16BITS(bp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 117 | if (ndo->ndo_vflag) |
| 118 | ND_PRINT((ndo, ", Flags [%s]", |
| 119 | bittok2str(gre_flag_values,"none",flags))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 120 | |
| 121 | len -= 2; |
| 122 | bp += 2; |
| 123 | |
| 124 | if (len < 2) |
| 125 | goto trunc; |
| 126 | prot = EXTRACT_16BITS(bp); |
| 127 | len -= 2; |
| 128 | bp += 2; |
| 129 | |
| 130 | if ((flags & GRE_CP) | (flags & GRE_RP)) { |
| 131 | if (len < 2) |
| 132 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 133 | if (ndo->ndo_vflag) |
| 134 | ND_PRINT((ndo, ", sum 0x%x", EXTRACT_16BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 135 | bp += 2; |
| 136 | len -= 2; |
| 137 | |
| 138 | if (len < 2) |
| 139 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 140 | ND_PRINT((ndo, ", off 0x%x", EXTRACT_16BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 141 | bp += 2; |
| 142 | len -= 2; |
| 143 | } |
| 144 | |
| 145 | if (flags & GRE_KP) { |
| 146 | if (len < 4) |
| 147 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 148 | ND_PRINT((ndo, ", key=0x%x", EXTRACT_32BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 149 | bp += 4; |
| 150 | len -= 4; |
| 151 | } |
| 152 | |
| 153 | if (flags & GRE_SP) { |
| 154 | if (len < 4) |
| 155 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 156 | ND_PRINT((ndo, ", seq %u", EXTRACT_32BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 157 | bp += 4; |
| 158 | len -= 4; |
| 159 | } |
| 160 | |
| 161 | if (flags & GRE_RP) { |
| 162 | for (;;) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 163 | uint16_t af; |
| 164 | uint8_t sreoff; |
| 165 | uint8_t srelen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 166 | |
| 167 | if (len < 4) |
| 168 | goto trunc; |
| 169 | af = EXTRACT_16BITS(bp); |
| 170 | sreoff = *(bp + 2); |
| 171 | srelen = *(bp + 3); |
| 172 | bp += 4; |
| 173 | len -= 4; |
| 174 | |
| 175 | if (af == 0 && srelen == 0) |
| 176 | break; |
| 177 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 178 | gre_sre_print(ndo, af, sreoff, srelen, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 179 | |
| 180 | if (len < srelen) |
| 181 | goto trunc; |
| 182 | bp += srelen; |
| 183 | len -= srelen; |
| 184 | } |
| 185 | } |
| 186 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 187 | if (ndo->ndo_eflag) |
| 188 | ND_PRINT((ndo, ", proto %s (0x%04x)", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 189 | tok2str(ethertype_values,"unknown",prot), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 190 | prot)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 191 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 192 | ND_PRINT((ndo, ", length %u",length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 193 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 194 | if (ndo->ndo_vflag < 1) |
| 195 | ND_PRINT((ndo, ": ")); /* put in a colon as protocol demarc */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 196 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 197 | ND_PRINT((ndo, "\n\t")); /* if verbose go multiline */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 198 | |
| 199 | switch (prot) { |
| 200 | case ETHERTYPE_IP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 201 | ip_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 202 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 203 | case ETHERTYPE_IPV6: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 204 | ip6_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 205 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 206 | case ETHERTYPE_MPLS: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 207 | mpls_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 208 | break; |
| 209 | case ETHERTYPE_IPX: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 210 | ipx_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 211 | break; |
| 212 | case ETHERTYPE_ATALK: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 213 | atalk_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 214 | break; |
| 215 | case ETHERTYPE_GRE_ISO: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 216 | isoclns_print(ndo, bp, len, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 217 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 218 | case ETHERTYPE_TEB: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 219 | ether_print(ndo, bp, len, len, NULL, NULL); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 220 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 221 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 222 | ND_PRINT((ndo, "gre-proto-0x%x", prot)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 223 | } |
| 224 | return; |
| 225 | |
| 226 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 227 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 228 | } |
| 229 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 230 | static void |
| 231 | gre_print_1(netdissect_options *ndo, const u_char *bp, u_int length) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 232 | { |
| 233 | u_int len = length; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 234 | uint16_t flags, prot; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 235 | |
| 236 | flags = EXTRACT_16BITS(bp); |
| 237 | len -= 2; |
| 238 | bp += 2; |
| 239 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 240 | if (ndo->ndo_vflag) |
| 241 | ND_PRINT((ndo, ", Flags [%s]", |
| 242 | bittok2str(gre_flag_values,"none",flags))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 243 | |
| 244 | if (len < 2) |
| 245 | goto trunc; |
| 246 | prot = EXTRACT_16BITS(bp); |
| 247 | len -= 2; |
| 248 | bp += 2; |
| 249 | |
| 250 | |
| 251 | if (flags & GRE_KP) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 252 | uint32_t k; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 253 | |
| 254 | if (len < 4) |
| 255 | goto trunc; |
| 256 | k = EXTRACT_32BITS(bp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 257 | ND_PRINT((ndo, ", call %d", k & 0xffff)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 258 | len -= 4; |
| 259 | bp += 4; |
| 260 | } |
| 261 | |
| 262 | if (flags & GRE_SP) { |
| 263 | if (len < 4) |
| 264 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 265 | ND_PRINT((ndo, ", seq %u", EXTRACT_32BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 266 | bp += 4; |
| 267 | len -= 4; |
| 268 | } |
| 269 | |
| 270 | if (flags & GRE_AP) { |
| 271 | if (len < 4) |
| 272 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 273 | ND_PRINT((ndo, ", ack %u", EXTRACT_32BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 274 | bp += 4; |
| 275 | len -= 4; |
| 276 | } |
| 277 | |
| 278 | if ((flags & GRE_SP) == 0) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 279 | ND_PRINT((ndo, ", no-payload")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 280 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 281 | if (ndo->ndo_eflag) |
| 282 | ND_PRINT((ndo, ", proto %s (0x%04x)", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 283 | tok2str(ethertype_values,"unknown",prot), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 284 | prot)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 285 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 286 | ND_PRINT((ndo, ", length %u",length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 287 | |
| 288 | if ((flags & GRE_SP) == 0) |
| 289 | return; |
| 290 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 291 | if (ndo->ndo_vflag < 1) |
| 292 | ND_PRINT((ndo, ": ")); /* put in a colon as protocol demarc */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 293 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 294 | ND_PRINT((ndo, "\n\t")); /* if verbose go multiline */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 295 | |
| 296 | switch (prot) { |
| 297 | case ETHERTYPE_PPP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 298 | ppp_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 299 | break; |
| 300 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 301 | ND_PRINT((ndo, "gre-proto-0x%x", prot)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 302 | break; |
| 303 | } |
| 304 | return; |
| 305 | |
| 306 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 307 | ND_PRINT((ndo, "%s", tstr)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 310 | static void |
| 311 | gre_sre_print(netdissect_options *ndo, uint16_t af, uint8_t sreoff, |
| 312 | uint8_t srelen, const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 313 | { |
| 314 | switch (af) { |
| 315 | case GRESRE_IP: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 316 | ND_PRINT((ndo, ", (rtaf=ip")); |
| 317 | gre_sre_ip_print(ndo, sreoff, srelen, bp, len); |
| 318 | ND_PRINT((ndo, ") ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 319 | break; |
| 320 | case GRESRE_ASN: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 321 | ND_PRINT((ndo, ", (rtaf=asn")); |
| 322 | gre_sre_asn_print(ndo, sreoff, srelen, bp, len); |
| 323 | ND_PRINT((ndo, ") ")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 324 | break; |
| 325 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 326 | ND_PRINT((ndo, ", (rtaf=0x%x) ", af)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 327 | } |
| 328 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 329 | |
| 330 | static void |
| 331 | gre_sre_ip_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen, |
| 332 | const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 333 | { |
| 334 | struct in_addr a; |
| 335 | const u_char *up = bp; |
| 336 | |
| 337 | if (sreoff & 3) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 338 | ND_PRINT((ndo, ", badoffset=%u", sreoff)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 339 | return; |
| 340 | } |
| 341 | if (srelen & 3) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 342 | ND_PRINT((ndo, ", badlength=%u", srelen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 343 | return; |
| 344 | } |
| 345 | if (sreoff >= srelen) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 346 | ND_PRINT((ndo, ", badoff/len=%u/%u", sreoff, srelen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
| 350 | for (;;) { |
| 351 | if (len < 4 || srelen == 0) |
| 352 | return; |
| 353 | |
| 354 | memcpy(&a, bp, sizeof(a)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 355 | ND_PRINT((ndo, " %s%s", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 356 | ((bp - up) == sreoff) ? "*" : "", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 357 | inet_ntoa(a))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 358 | |
| 359 | bp += 4; |
| 360 | len -= 4; |
| 361 | srelen -= 4; |
| 362 | } |
| 363 | } |
| 364 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 365 | static void |
| 366 | gre_sre_asn_print(netdissect_options *ndo, uint8_t sreoff, uint8_t srelen, |
| 367 | const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 368 | { |
| 369 | const u_char *up = bp; |
| 370 | |
| 371 | if (sreoff & 1) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 372 | ND_PRINT((ndo, ", badoffset=%u", sreoff)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 373 | return; |
| 374 | } |
| 375 | if (srelen & 1) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 376 | ND_PRINT((ndo, ", badlength=%u", srelen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 377 | return; |
| 378 | } |
| 379 | if (sreoff >= srelen) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 380 | ND_PRINT((ndo, ", badoff/len=%u/%u", sreoff, srelen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 381 | return; |
| 382 | } |
| 383 | |
| 384 | for (;;) { |
| 385 | if (len < 2 || srelen == 0) |
| 386 | return; |
| 387 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 388 | ND_PRINT((ndo, " %s%x", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 389 | ((bp - up) == sreoff) ? "*" : "", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame^] | 390 | EXTRACT_16BITS(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 391 | |
| 392 | bp += 2; |
| 393 | len -= 2; |
| 394 | srelen -= 2; |
| 395 | } |
| 396 | } |