The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1988, 1989, 1990, 1991, 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 Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: Domain Name System (DNS) 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 | |
| 30 | #include "nameser.h" |
| 31 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 32 | #include <string.h> |
| 33 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 34 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | #include "addrtoname.h" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 36 | #include "addrtostr.h" |
| 37 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 38 | |
| 39 | static const char *ns_ops[] = { |
| 40 | "", " inv_q", " stat", " op3", " notify", " update", " op6", " op7", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 41 | " op8", " updateA", " updateD", " updateDA", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 42 | " updateM", " updateMA", " zoneInit", " zoneRef", |
| 43 | }; |
| 44 | |
| 45 | static const char *ns_resp[] = { |
| 46 | "", " FormErr", " ServFail", " NXDomain", |
| 47 | " NotImp", " Refused", " YXDomain", " YXRRSet", |
| 48 | " NXRRSet", " NotAuth", " NotZone", " Resp11", |
| 49 | " Resp12", " Resp13", " Resp14", " NoChange", |
| 50 | }; |
| 51 | |
| 52 | /* skip over a domain name */ |
| 53 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 54 | ns_nskip(netdissect_options *ndo, |
| 55 | register const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 56 | { |
| 57 | register u_char i; |
| 58 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 59 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 60 | return (NULL); |
| 61 | i = *cp++; |
| 62 | while (i) { |
| 63 | if ((i & INDIR_MASK) == INDIR_MASK) |
| 64 | return (cp + 1); |
| 65 | if ((i & INDIR_MASK) == EDNS0_MASK) { |
| 66 | int bitlen, bytelen; |
| 67 | |
| 68 | if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL) |
| 69 | return(NULL); /* unknown ELT */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 70 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 71 | return (NULL); |
| 72 | if ((bitlen = *cp++) == 0) |
| 73 | bitlen = 256; |
| 74 | bytelen = (bitlen + 7) / 8; |
| 75 | cp += bytelen; |
| 76 | } else |
| 77 | cp += i; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 78 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 79 | return (NULL); |
| 80 | i = *cp++; |
| 81 | } |
| 82 | return (cp); |
| 83 | } |
| 84 | |
| 85 | /* print a <domain-name> */ |
| 86 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 87 | blabel_print(netdissect_options *ndo, |
| 88 | const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 89 | { |
| 90 | int bitlen, slen, b; |
| 91 | const u_char *bitp, *lim; |
| 92 | char tc; |
| 93 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 94 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 95 | return(NULL); |
| 96 | if ((bitlen = *cp) == 0) |
| 97 | bitlen = 256; |
| 98 | slen = (bitlen + 3) / 4; |
| 99 | lim = cp + 1 + slen; |
| 100 | |
| 101 | /* print the bit string as a hex string */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 102 | ND_PRINT((ndo, "\\[x")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 103 | for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 104 | ND_TCHECK(*bitp); |
| 105 | ND_PRINT((ndo, "%02x", *bitp)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 106 | } |
| 107 | if (b > 4) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 108 | ND_TCHECK(*bitp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 109 | tc = *bitp++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 110 | ND_PRINT((ndo, "%02x", tc & (0xff << (8 - b)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 111 | } else if (b > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 112 | ND_TCHECK(*bitp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 113 | tc = *bitp++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 114 | ND_PRINT((ndo, "%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 115 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 116 | ND_PRINT((ndo, "/%d]", bitlen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 117 | return lim; |
| 118 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 119 | ND_PRINT((ndo, ".../%d]", bitlen)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 120 | return NULL; |
| 121 | } |
| 122 | |
| 123 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 124 | labellen(netdissect_options *ndo, |
| 125 | const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 126 | { |
| 127 | register u_int i; |
| 128 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 129 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 130 | return(-1); |
| 131 | i = *cp; |
| 132 | if ((i & INDIR_MASK) == EDNS0_MASK) { |
| 133 | int bitlen, elt; |
| 134 | if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 135 | ND_PRINT((ndo, "<ELT %d>", elt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 136 | return(-1); |
| 137 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 138 | if (!ND_TTEST2(*(cp + 1), 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 139 | return(-1); |
| 140 | if ((bitlen = *(cp + 1)) == 0) |
| 141 | bitlen = 256; |
| 142 | return(((bitlen + 7) / 8) + 1); |
| 143 | } else |
| 144 | return(i); |
| 145 | } |
| 146 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 147 | const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 148 | ns_nprint(netdissect_options *ndo, |
| 149 | register const u_char *cp, register const u_char *bp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 150 | { |
| 151 | register u_int i, l; |
| 152 | register const u_char *rp = NULL; |
| 153 | register int compress = 0; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 154 | int elt; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 155 | u_int offset, max_offset; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 156 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 157 | if ((l = labellen(ndo, cp)) == (u_int)-1) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 158 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 159 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 160 | return(NULL); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 161 | max_offset = (u_int)(cp - bp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 162 | if (((i = *cp++) & INDIR_MASK) != INDIR_MASK) { |
| 163 | compress = 0; |
| 164 | rp = cp + l; |
| 165 | } |
| 166 | |
| 167 | if (i != 0) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 168 | while (i && cp < ndo->ndo_snapend) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 169 | if ((i & INDIR_MASK) == INDIR_MASK) { |
| 170 | if (!compress) { |
| 171 | rp = cp + 1; |
| 172 | compress = 1; |
| 173 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 174 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 175 | return(NULL); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 176 | offset = (((i << 8) | *cp) & 0x3fff); |
| 177 | /* |
| 178 | * This must move backwards in the packet. |
| 179 | * No RFC explicitly says that, but BIND's |
| 180 | * name decompression code requires it, |
| 181 | * as a way of preventing infinite loops |
| 182 | * and other bad behavior, and it's probably |
| 183 | * what was intended (compress by pointing |
| 184 | * to domain name suffixes already seen in |
| 185 | * the packet). |
| 186 | */ |
| 187 | if (offset >= max_offset) { |
| 188 | ND_PRINT((ndo, "<BAD PTR>")); |
| 189 | return(NULL); |
| 190 | } |
| 191 | max_offset = offset; |
| 192 | cp = bp + offset; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 193 | if ((l = labellen(ndo, cp)) == (u_int)-1) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 194 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 195 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 196 | return(NULL); |
| 197 | i = *cp++; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 198 | continue; |
| 199 | } |
| 200 | if ((i & INDIR_MASK) == EDNS0_MASK) { |
| 201 | elt = (i & ~INDIR_MASK); |
| 202 | switch(elt) { |
| 203 | case EDNS0_ELT_BITLABEL: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 204 | if (blabel_print(ndo, cp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 205 | return (NULL); |
| 206 | break; |
| 207 | default: |
| 208 | /* unknown ELT */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 209 | ND_PRINT((ndo, "<ELT %d>", elt)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 210 | return(NULL); |
| 211 | } |
| 212 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 213 | if (fn_printn(ndo, cp, l, ndo->ndo_snapend)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 214 | return(NULL); |
| 215 | } |
| 216 | |
| 217 | cp += l; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 218 | ND_PRINT((ndo, ".")); |
| 219 | if ((l = labellen(ndo, cp)) == (u_int)-1) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 220 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 221 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 222 | return(NULL); |
| 223 | i = *cp++; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 224 | if (!compress) |
| 225 | rp += l + 1; |
| 226 | } |
| 227 | else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 228 | ND_PRINT((ndo, ".")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 229 | return (rp); |
| 230 | } |
| 231 | |
| 232 | /* print a <character-string> */ |
| 233 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 234 | ns_cprint(netdissect_options *ndo, |
| 235 | register const u_char *cp) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 236 | { |
| 237 | register u_int i; |
| 238 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 239 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 240 | return (NULL); |
| 241 | i = *cp++; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 242 | if (fn_printn(ndo, cp, i, ndo->ndo_snapend)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 243 | return (NULL); |
| 244 | return (cp + i); |
| 245 | } |
| 246 | |
| 247 | /* http://www.iana.org/assignments/dns-parameters */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 248 | const struct tok ns_type2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 249 | { T_A, "A" }, /* RFC 1035 */ |
| 250 | { T_NS, "NS" }, /* RFC 1035 */ |
| 251 | { T_MD, "MD" }, /* RFC 1035 */ |
| 252 | { T_MF, "MF" }, /* RFC 1035 */ |
| 253 | { T_CNAME, "CNAME" }, /* RFC 1035 */ |
| 254 | { T_SOA, "SOA" }, /* RFC 1035 */ |
| 255 | { T_MB, "MB" }, /* RFC 1035 */ |
| 256 | { T_MG, "MG" }, /* RFC 1035 */ |
| 257 | { T_MR, "MR" }, /* RFC 1035 */ |
| 258 | { T_NULL, "NULL" }, /* RFC 1035 */ |
| 259 | { T_WKS, "WKS" }, /* RFC 1035 */ |
| 260 | { T_PTR, "PTR" }, /* RFC 1035 */ |
| 261 | { T_HINFO, "HINFO" }, /* RFC 1035 */ |
| 262 | { T_MINFO, "MINFO" }, /* RFC 1035 */ |
| 263 | { T_MX, "MX" }, /* RFC 1035 */ |
| 264 | { T_TXT, "TXT" }, /* RFC 1035 */ |
| 265 | { T_RP, "RP" }, /* RFC 1183 */ |
| 266 | { T_AFSDB, "AFSDB" }, /* RFC 1183 */ |
| 267 | { T_X25, "X25" }, /* RFC 1183 */ |
| 268 | { T_ISDN, "ISDN" }, /* RFC 1183 */ |
| 269 | { T_RT, "RT" }, /* RFC 1183 */ |
| 270 | { T_NSAP, "NSAP" }, /* RFC 1706 */ |
| 271 | { T_NSAP_PTR, "NSAP_PTR" }, |
| 272 | { T_SIG, "SIG" }, /* RFC 2535 */ |
| 273 | { T_KEY, "KEY" }, /* RFC 2535 */ |
| 274 | { T_PX, "PX" }, /* RFC 2163 */ |
| 275 | { T_GPOS, "GPOS" }, /* RFC 1712 */ |
| 276 | { T_AAAA, "AAAA" }, /* RFC 1886 */ |
| 277 | { T_LOC, "LOC" }, /* RFC 1876 */ |
| 278 | { T_NXT, "NXT" }, /* RFC 2535 */ |
| 279 | { T_EID, "EID" }, /* Nimrod */ |
| 280 | { T_NIMLOC, "NIMLOC" }, /* Nimrod */ |
| 281 | { T_SRV, "SRV" }, /* RFC 2782 */ |
| 282 | { T_ATMA, "ATMA" }, /* ATM Forum */ |
| 283 | { T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */ |
| 284 | { T_KX, "KX" }, /* RFC 2230 */ |
| 285 | { T_CERT, "CERT" }, /* RFC 2538 */ |
| 286 | { T_A6, "A6" }, /* RFC 2874 */ |
| 287 | { T_DNAME, "DNAME" }, /* RFC 2672 */ |
| 288 | { T_SINK, "SINK" }, |
| 289 | { T_OPT, "OPT" }, /* RFC 2671 */ |
| 290 | { T_APL, "APL" }, /* RFC 3123 */ |
| 291 | { T_DS, "DS" }, /* RFC 4034 */ |
| 292 | { T_SSHFP, "SSHFP" }, /* RFC 4255 */ |
| 293 | { T_IPSECKEY, "IPSECKEY" }, /* RFC 4025 */ |
| 294 | { T_RRSIG, "RRSIG" }, /* RFC 4034 */ |
| 295 | { T_NSEC, "NSEC" }, /* RFC 4034 */ |
| 296 | { T_DNSKEY, "DNSKEY" }, /* RFC 4034 */ |
| 297 | { T_SPF, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */ |
| 298 | { T_UINFO, "UINFO" }, |
| 299 | { T_UID, "UID" }, |
| 300 | { T_GID, "GID" }, |
| 301 | { T_UNSPEC, "UNSPEC" }, |
| 302 | { T_UNSPECA, "UNSPECA" }, |
| 303 | { T_TKEY, "TKEY" }, /* RFC 2930 */ |
| 304 | { T_TSIG, "TSIG" }, /* RFC 2845 */ |
| 305 | { T_IXFR, "IXFR" }, /* RFC 1995 */ |
| 306 | { T_AXFR, "AXFR" }, /* RFC 1035 */ |
| 307 | { T_MAILB, "MAILB" }, /* RFC 1035 */ |
| 308 | { T_MAILA, "MAILA" }, /* RFC 1035 */ |
| 309 | { T_ANY, "ANY" }, |
| 310 | { 0, NULL } |
| 311 | }; |
| 312 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 313 | const struct tok ns_class2str[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 314 | { C_IN, "IN" }, /* Not used */ |
| 315 | { C_CHAOS, "CHAOS" }, |
| 316 | { C_HS, "HS" }, |
| 317 | { C_ANY, "ANY" }, |
| 318 | { 0, NULL } |
| 319 | }; |
| 320 | |
| 321 | /* print a query */ |
| 322 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 323 | ns_qprint(netdissect_options *ndo, |
| 324 | register const u_char *cp, register const u_char *bp, int is_mdns) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 325 | { |
| 326 | register const u_char *np = cp; |
| 327 | register u_int i, class; |
| 328 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 329 | cp = ns_nskip(ndo, cp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 330 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 331 | if (cp == NULL || !ND_TTEST2(*cp, 4)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 332 | return(NULL); |
| 333 | |
| 334 | /* print the qtype */ |
| 335 | i = EXTRACT_16BITS(cp); |
| 336 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 337 | ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d", i))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 338 | /* print the qclass (if it's not IN) */ |
| 339 | i = EXTRACT_16BITS(cp); |
| 340 | cp += 2; |
| 341 | if (is_mdns) |
| 342 | class = (i & ~C_QU); |
| 343 | else |
| 344 | class = i; |
| 345 | if (class != C_IN) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 346 | ND_PRINT((ndo, " %s", tok2str(ns_class2str, "(Class %d)", class))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 347 | if (is_mdns) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 348 | ND_PRINT((ndo, i & C_QU ? " (QU)" : " (QM)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 349 | } |
| 350 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 351 | ND_PRINT((ndo, "? ")); |
| 352 | cp = ns_nprint(ndo, np, bp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 353 | return(cp ? cp + 4 : NULL); |
| 354 | } |
| 355 | |
| 356 | /* print a reply */ |
| 357 | static const u_char * |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 358 | ns_rprint(netdissect_options *ndo, |
| 359 | register const u_char *cp, register const u_char *bp, int is_mdns) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 360 | { |
| 361 | register u_int i, class, opt_flags = 0; |
| 362 | register u_short typ, len; |
| 363 | register const u_char *rp; |
| 364 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 365 | if (ndo->ndo_vflag) { |
| 366 | ND_PRINT((ndo, " ")); |
| 367 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 368 | return NULL; |
| 369 | } else |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 370 | cp = ns_nskip(ndo, cp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 371 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 372 | if (cp == NULL || !ND_TTEST2(*cp, 10)) |
| 373 | return (ndo->ndo_snapend); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 374 | |
| 375 | /* print the type/qtype */ |
| 376 | typ = EXTRACT_16BITS(cp); |
| 377 | cp += 2; |
| 378 | /* print the class (if it's not IN and the type isn't OPT) */ |
| 379 | i = EXTRACT_16BITS(cp); |
| 380 | cp += 2; |
| 381 | if (is_mdns) |
| 382 | class = (i & ~C_CACHE_FLUSH); |
| 383 | else |
| 384 | class = i; |
| 385 | if (class != C_IN && typ != T_OPT) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 386 | ND_PRINT((ndo, " %s", tok2str(ns_class2str, "(Class %d)", class))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 387 | if (is_mdns) { |
| 388 | if (i & C_CACHE_FLUSH) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 389 | ND_PRINT((ndo, " (Cache flush)")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 390 | } |
| 391 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 392 | if (typ == T_OPT) { |
| 393 | /* get opt flags */ |
| 394 | cp += 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 395 | opt_flags = EXTRACT_16BITS(cp); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 396 | /* ignore rest of ttl field */ |
| 397 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 398 | } else if (ndo->ndo_vflag > 2) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 399 | /* print ttl */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 400 | ND_PRINT((ndo, " [")); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 401 | unsigned_relts_print(ndo, EXTRACT_32BITS(cp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 402 | ND_PRINT((ndo, "]")); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 403 | cp += 4; |
| 404 | } else { |
| 405 | /* ignore ttl */ |
| 406 | cp += 4; |
| 407 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 408 | |
| 409 | len = EXTRACT_16BITS(cp); |
| 410 | cp += 2; |
| 411 | |
| 412 | rp = cp + len; |
| 413 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 414 | ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d", typ))); |
| 415 | if (rp > ndo->ndo_snapend) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 416 | return(NULL); |
| 417 | |
| 418 | switch (typ) { |
| 419 | case T_A: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 420 | if (!ND_TTEST2(*cp, sizeof(struct in_addr))) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 421 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 422 | ND_PRINT((ndo, " %s", intoa(htonl(EXTRACT_32BITS(cp))))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 423 | break; |
| 424 | |
| 425 | case T_NS: |
| 426 | case T_CNAME: |
| 427 | case T_PTR: |
| 428 | #ifdef T_DNAME |
| 429 | case T_DNAME: |
| 430 | #endif |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 431 | ND_PRINT((ndo, " ")); |
| 432 | if (ns_nprint(ndo, cp, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 433 | return(NULL); |
| 434 | break; |
| 435 | |
| 436 | case T_SOA: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 437 | if (!ndo->ndo_vflag) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 438 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 439 | ND_PRINT((ndo, " ")); |
| 440 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 441 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 442 | ND_PRINT((ndo, " ")); |
| 443 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 444 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 445 | if (!ND_TTEST2(*cp, 5 * 4)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 446 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 447 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 448 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 449 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 450 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 451 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 452 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 453 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 454 | cp += 4; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 455 | ND_PRINT((ndo, " %u", EXTRACT_32BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 456 | cp += 4; |
| 457 | break; |
| 458 | case T_MX: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 459 | ND_PRINT((ndo, " ")); |
| 460 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 461 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 462 | if (ns_nprint(ndo, cp + 2, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 463 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 464 | ND_PRINT((ndo, " %d", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 465 | break; |
| 466 | |
| 467 | case T_TXT: |
| 468 | while (cp < rp) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 469 | ND_PRINT((ndo, " \"")); |
| 470 | cp = ns_cprint(ndo, cp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 471 | if (cp == NULL) |
| 472 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 473 | ND_PRINT((ndo, "\"")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 474 | } |
| 475 | break; |
| 476 | |
| 477 | case T_SRV: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 478 | ND_PRINT((ndo, " ")); |
| 479 | if (!ND_TTEST2(*cp, 6)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 480 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 481 | if (ns_nprint(ndo, cp + 6, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 482 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 483 | ND_PRINT((ndo, ":%d %d %d", EXTRACT_16BITS(cp + 4), |
| 484 | EXTRACT_16BITS(cp), EXTRACT_16BITS(cp + 2))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 485 | break; |
| 486 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 487 | case T_AAAA: |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 488 | { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 489 | char ntop_buf[INET6_ADDRSTRLEN]; |
| 490 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 491 | if (!ND_TTEST2(*cp, sizeof(struct in6_addr))) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 492 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 493 | ND_PRINT((ndo, " %s", |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 494 | addrtostr6(cp, ntop_buf, sizeof(ntop_buf)))); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 495 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 496 | break; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 497 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 498 | |
| 499 | case T_A6: |
| 500 | { |
| 501 | struct in6_addr a; |
| 502 | int pbit, pbyte; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 503 | char ntop_buf[INET6_ADDRSTRLEN]; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 504 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 505 | if (!ND_TTEST2(*cp, 1)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 506 | return(NULL); |
| 507 | pbit = *cp; |
| 508 | pbyte = (pbit & ~7) / 8; |
| 509 | if (pbit > 128) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 510 | ND_PRINT((ndo, " %u(bad plen)", pbit)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 511 | break; |
| 512 | } else if (pbit < 128) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 513 | if (!ND_TTEST2(*(cp + 1), sizeof(a) - pbyte)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 514 | return(NULL); |
| 515 | memset(&a, 0, sizeof(a)); |
| 516 | memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 517 | ND_PRINT((ndo, " %u %s", pbit, |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 518 | addrtostr6(&a, ntop_buf, sizeof(ntop_buf)))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 519 | } |
| 520 | if (pbit > 0) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 521 | ND_PRINT((ndo, " ")); |
| 522 | if (ns_nprint(ndo, cp + 1 + sizeof(a) - pbyte, bp) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 523 | return(NULL); |
| 524 | } |
| 525 | break; |
| 526 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 527 | |
| 528 | case T_OPT: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 529 | ND_PRINT((ndo, " UDPsize=%u", class)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 530 | if (opt_flags & 0x8000) |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 531 | ND_PRINT((ndo, " DO")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 532 | break; |
| 533 | |
| 534 | case T_UNSPECA: /* One long string */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 535 | if (!ND_TTEST2(*cp, len)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 536 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 537 | if (fn_printn(ndo, cp, len, ndo->ndo_snapend)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 538 | return(NULL); |
| 539 | break; |
| 540 | |
| 541 | case T_TSIG: |
| 542 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 543 | if (cp + len > ndo->ndo_snapend) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 544 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 545 | if (!ndo->ndo_vflag) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 546 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 547 | ND_PRINT((ndo, " ")); |
| 548 | if ((cp = ns_nprint(ndo, cp, bp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 549 | return(NULL); |
| 550 | cp += 6; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 551 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 552 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 553 | ND_PRINT((ndo, " fudge=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 554 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 555 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 556 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 557 | ND_PRINT((ndo, " maclen=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 558 | cp += 2 + EXTRACT_16BITS(cp); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 559 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 560 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 561 | ND_PRINT((ndo, " origid=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 562 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 563 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 564 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 565 | ND_PRINT((ndo, " error=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 566 | cp += 2; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 567 | if (!ND_TTEST2(*cp, 2)) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 568 | return(NULL); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 569 | ND_PRINT((ndo, " otherlen=%u", EXTRACT_16BITS(cp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 570 | cp += 2; |
| 571 | } |
| 572 | } |
| 573 | return (rp); /* XXX This isn't always right */ |
| 574 | } |
| 575 | |
| 576 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 577 | ns_print(netdissect_options *ndo, |
| 578 | register const u_char *bp, u_int length, int is_mdns) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 579 | { |
| 580 | register const HEADER *np; |
| 581 | register int qdcount, ancount, nscount, arcount; |
| 582 | register const u_char *cp; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 583 | uint16_t b2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 584 | |
| 585 | np = (const HEADER *)bp; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 586 | ND_TCHECK(*np); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 587 | /* get the byte-order right */ |
| 588 | qdcount = EXTRACT_16BITS(&np->qdcount); |
| 589 | ancount = EXTRACT_16BITS(&np->ancount); |
| 590 | nscount = EXTRACT_16BITS(&np->nscount); |
| 591 | arcount = EXTRACT_16BITS(&np->arcount); |
| 592 | |
| 593 | if (DNS_QR(np)) { |
| 594 | /* this is a response */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 595 | ND_PRINT((ndo, "%d%s%s%s%s%s%s", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 596 | EXTRACT_16BITS(&np->id), |
| 597 | ns_ops[DNS_OPCODE(np)], |
| 598 | ns_resp[DNS_RCODE(np)], |
| 599 | DNS_AA(np)? "*" : "", |
| 600 | DNS_RA(np)? "" : "-", |
| 601 | DNS_TC(np)? "|" : "", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 602 | DNS_AD(np)? "$" : "")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 603 | |
| 604 | if (qdcount != 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 605 | ND_PRINT((ndo, " [%dq]", qdcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 606 | /* Print QUESTION section on -vv */ |
| 607 | cp = (const u_char *)(np + 1); |
| 608 | while (qdcount--) { |
| 609 | if (qdcount < EXTRACT_16BITS(&np->qdcount) - 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 610 | ND_PRINT((ndo, ",")); |
| 611 | if (ndo->ndo_vflag > 1) { |
| 612 | ND_PRINT((ndo, " q:")); |
| 613 | if ((cp = ns_qprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 614 | goto trunc; |
| 615 | } else { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 616 | if ((cp = ns_nskip(ndo, cp)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 617 | goto trunc; |
| 618 | cp += 4; /* skip QTYPE and QCLASS */ |
| 619 | } |
| 620 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 621 | ND_PRINT((ndo, " %d/%d/%d", ancount, nscount, arcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 622 | if (ancount--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 623 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 624 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 625 | while (cp < ndo->ndo_snapend && ancount--) { |
| 626 | ND_PRINT((ndo, ",")); |
| 627 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 628 | goto trunc; |
| 629 | } |
| 630 | } |
| 631 | if (ancount > 0) |
| 632 | goto trunc; |
| 633 | /* Print NS and AR sections on -vv */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 634 | if (ndo->ndo_vflag > 1) { |
| 635 | if (cp < ndo->ndo_snapend && nscount--) { |
| 636 | ND_PRINT((ndo, " ns:")); |
| 637 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 638 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 639 | while (cp < ndo->ndo_snapend && nscount--) { |
| 640 | ND_PRINT((ndo, ",")); |
| 641 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 642 | goto trunc; |
| 643 | } |
| 644 | } |
| 645 | if (nscount > 0) |
| 646 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 647 | if (cp < ndo->ndo_snapend && arcount--) { |
| 648 | ND_PRINT((ndo, " ar:")); |
| 649 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 650 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 651 | while (cp < ndo->ndo_snapend && arcount--) { |
| 652 | ND_PRINT((ndo, ",")); |
| 653 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 654 | goto trunc; |
| 655 | } |
| 656 | } |
| 657 | if (arcount > 0) |
| 658 | goto trunc; |
| 659 | } |
| 660 | } |
| 661 | else { |
| 662 | /* this is a request */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 663 | ND_PRINT((ndo, "%d%s%s%s", EXTRACT_16BITS(&np->id), ns_ops[DNS_OPCODE(np)], |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 664 | DNS_RD(np) ? "+" : "", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 665 | DNS_CD(np) ? "%" : "")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 666 | |
| 667 | /* any weirdness? */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 668 | b2 = EXTRACT_16BITS(((const u_short *)np)+1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 669 | if (b2 & 0x6cf) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 670 | ND_PRINT((ndo, " [b2&3=0x%x]", b2)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 671 | |
| 672 | if (DNS_OPCODE(np) == IQUERY) { |
| 673 | if (qdcount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 674 | ND_PRINT((ndo, " [%dq]", qdcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 675 | if (ancount != 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 676 | ND_PRINT((ndo, " [%da]", ancount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 677 | } |
| 678 | else { |
| 679 | if (ancount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 680 | ND_PRINT((ndo, " [%da]", ancount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 681 | if (qdcount != 1) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 682 | ND_PRINT((ndo, " [%dq]", qdcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 683 | } |
| 684 | if (nscount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 685 | ND_PRINT((ndo, " [%dn]", nscount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 686 | if (arcount) |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 687 | ND_PRINT((ndo, " [%dau]", arcount)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 688 | |
| 689 | cp = (const u_char *)(np + 1); |
| 690 | if (qdcount--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 691 | cp = ns_qprint(ndo, cp, (const u_char *)np, is_mdns); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 692 | if (!cp) |
| 693 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 694 | while (cp < ndo->ndo_snapend && qdcount--) { |
| 695 | cp = ns_qprint(ndo, (const u_char *)cp, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 696 | (const u_char *)np, |
| 697 | is_mdns); |
| 698 | if (!cp) |
| 699 | goto trunc; |
| 700 | } |
| 701 | } |
| 702 | if (qdcount > 0) |
| 703 | goto trunc; |
| 704 | |
| 705 | /* Print remaining sections on -vv */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 706 | if (ndo->ndo_vflag > 1) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 707 | if (ancount--) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 708 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 709 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 710 | while (cp < ndo->ndo_snapend && ancount--) { |
| 711 | ND_PRINT((ndo, ",")); |
| 712 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 713 | goto trunc; |
| 714 | } |
| 715 | } |
| 716 | if (ancount > 0) |
| 717 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 718 | if (cp < ndo->ndo_snapend && nscount--) { |
| 719 | ND_PRINT((ndo, " ns:")); |
| 720 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 721 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 722 | while (nscount-- && cp < ndo->ndo_snapend) { |
| 723 | ND_PRINT((ndo, ",")); |
| 724 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 725 | goto trunc; |
| 726 | } |
| 727 | } |
| 728 | if (nscount > 0) |
| 729 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 730 | if (cp < ndo->ndo_snapend && arcount--) { |
| 731 | ND_PRINT((ndo, " ar:")); |
| 732 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 733 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 734 | while (cp < ndo->ndo_snapend && arcount--) { |
| 735 | ND_PRINT((ndo, ",")); |
| 736 | if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 737 | goto trunc; |
| 738 | } |
| 739 | } |
| 740 | if (arcount > 0) |
| 741 | goto trunc; |
| 742 | } |
| 743 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 744 | ND_PRINT((ndo, " (%d)", length)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 745 | return; |
| 746 | |
| 747 | trunc: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 748 | ND_PRINT((ndo, "[|domain]")); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 749 | } |