1999-10-08 07:47:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that: (1) source code distributions
|
|
|
|
* retain the above copyright notice and this paragraph in its entirety, (2)
|
|
|
|
* distributions including binary code include the above copyright notice and
|
|
|
|
* this paragraph in its entirety in the documentation or other materials
|
|
|
|
* provided with the distribution, and (3) all advertising materials mentioning
|
|
|
|
* features or use of this software display the following acknowledgement:
|
|
|
|
* ``This product includes software developed by the University of California,
|
|
|
|
* Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
|
|
* the University nor the names of its contributors may be used to endorse
|
|
|
|
* or promote products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: Domain Name System (DNS) printer */
|
|
|
|
|
1999-11-21 17:36:43 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
1999-10-08 07:47:09 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
1999-10-08 07:47:09 +08:00
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
#include <string.h>
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
1999-10-08 07:47:09 +08:00
|
|
|
#include "addrtoname.h"
|
2015-09-18 05:56:44 +08:00
|
|
|
#include "addrtostr.h"
|
2015-09-07 21:01:46 +08:00
|
|
|
#include "extract.h"
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2017-12-14 01:32:44 +08:00
|
|
|
#include "nameser.h"
|
|
|
|
|
2001-09-18 05:57:50 +08:00
|
|
|
static const char *ns_ops[] = {
|
2001-02-20 14:22:57 +08:00
|
|
|
"", " inv_q", " stat", " op3", " notify", " update", " op6", " op7",
|
2014-03-25 15:56:49 +08:00
|
|
|
" op8", " updateA", " updateD", " updateDA",
|
1999-10-08 07:47:09 +08:00
|
|
|
" updateM", " updateMA", " zoneInit", " zoneRef",
|
|
|
|
};
|
|
|
|
|
2001-09-18 05:57:50 +08:00
|
|
|
static const char *ns_resp[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
"", " FormErr", " ServFail", " NXDomain",
|
2001-02-20 14:22:57 +08:00
|
|
|
" NotImp", " Refused", " YXDomain", " YXRRSet",
|
|
|
|
" NXRRSet", " NotAuth", " NotZone", " Resp11",
|
1999-10-08 07:47:09 +08:00
|
|
|
" Resp12", " Resp13", " Resp14", " NoChange",
|
2019-02-13 06:50:17 +08:00
|
|
|
" BadVers", "Resp17", " Resp18", " Resp19",
|
|
|
|
" Resp20", "Resp21", " Resp22", " BadCookie",
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
|
2019-02-13 06:50:17 +08:00
|
|
|
static const char *
|
2019-03-27 08:54:39 +08:00
|
|
|
ns_rcode(u_int rcode) {
|
2019-02-13 06:50:17 +08:00
|
|
|
static char buf[sizeof(" Resp4095")];
|
|
|
|
|
|
|
|
if (rcode < sizeof(ns_resp)/sizeof(ns_resp[0])) {
|
|
|
|
return (ns_resp[rcode]);
|
|
|
|
}
|
|
|
|
snprintf(buf, sizeof(buf), " Resp%u", rcode & 0xfff);
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
/* skip over a domain name */
|
|
|
|
static const u_char *
|
2014-03-25 19:05:59 +08:00
|
|
|
ns_nskip(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
u_char i;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return (NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
2001-02-23 16:55:21 +08:00
|
|
|
while (i) {
|
2003-04-04 08:18:54 +08:00
|
|
|
if ((i & INDIR_MASK) == INDIR_MASK)
|
|
|
|
return (cp + 1);
|
2000-12-29 04:30:41 +08:00
|
|
|
if ((i & INDIR_MASK) == EDNS0_MASK) {
|
|
|
|
int bitlen, bytelen;
|
|
|
|
|
|
|
|
if ((i & ~INDIR_MASK) != EDNS0_ELT_BITLABEL)
|
|
|
|
return(NULL); /* unknown ELT */
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return (NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
if ((bitlen = GET_U_1(cp)) == 0)
|
2000-12-29 04:30:41 +08:00
|
|
|
bitlen = 256;
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
2000-12-29 04:30:41 +08:00
|
|
|
bytelen = (bitlen + 7) / 8;
|
|
|
|
cp += bytelen;
|
|
|
|
} else
|
|
|
|
cp += i;
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return (NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
return (cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const u_char *
|
2014-03-25 19:05:59 +08:00
|
|
|
blabel_print(netdissect_options *ndo,
|
|
|
|
const u_char *cp)
|
2000-12-29 04:30:41 +08:00
|
|
|
{
|
2018-01-12 03:52:30 +08:00
|
|
|
u_int bitlen, slen, b;
|
2000-12-29 04:30:41 +08:00
|
|
|
const u_char *bitp, *lim;
|
2018-01-12 03:52:30 +08:00
|
|
|
uint8_t tc;
|
2000-12-29 04:30:41 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
if ((bitlen = GET_U_1(cp)) == 0)
|
2000-12-29 04:30:41 +08:00
|
|
|
bitlen = 256;
|
2000-12-30 23:47:58 +08:00
|
|
|
slen = (bitlen + 3) / 4;
|
2004-03-24 03:03:03 +08:00
|
|
|
lim = cp + 1 + slen;
|
2000-12-29 04:30:41 +08:00
|
|
|
|
|
|
|
/* print the bit string as a hex string */
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\\[x");
|
2004-03-24 03:03:03 +08:00
|
|
|
for (bitp = cp + 1, b = bitlen; bitp < lim && b > 7; b -= 8, bitp++) {
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(bitp);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT("%02x", GET_U_1(bitp));
|
2004-03-24 03:03:03 +08:00
|
|
|
}
|
|
|
|
if (b > 4) {
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(bitp);
|
2018-06-16 23:23:21 +08:00
|
|
|
tc = GET_U_1(bitp);
|
2017-11-20 09:59:51 +08:00
|
|
|
bitp++;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%02x", tc & (0xff << (8 - b)));
|
2000-12-30 23:47:58 +08:00
|
|
|
} else if (b > 0) {
|
2017-12-05 03:21:48 +08:00
|
|
|
ND_TCHECK_1(bitp);
|
2018-06-16 23:23:21 +08:00
|
|
|
tc = GET_U_1(bitp);
|
2017-11-20 09:59:51 +08:00
|
|
|
bitp++;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b)));
|
2000-12-30 23:47:58 +08:00
|
|
|
}
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT("/%u]", bitlen);
|
2004-03-24 03:03:03 +08:00
|
|
|
return lim;
|
|
|
|
trunc:
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(".../%u]", bitlen);
|
2004-03-24 03:03:03 +08:00
|
|
|
return NULL;
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-03-25 19:05:59 +08:00
|
|
|
labellen(netdissect_options *ndo,
|
|
|
|
const u_char *cp)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i;
|
2000-12-29 04:30:41 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(-1);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2000-12-29 04:30:41 +08:00
|
|
|
if ((i & INDIR_MASK) == EDNS0_MASK) {
|
2018-01-12 03:52:30 +08:00
|
|
|
u_int bitlen, elt;
|
2005-04-21 04:59:30 +08:00
|
|
|
if ((elt = (i & ~INDIR_MASK)) != EDNS0_ELT_BITLABEL) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("<ELT %d>", elt);
|
2000-12-29 04:30:41 +08:00
|
|
|
return(-1);
|
2005-04-21 04:59:30 +08:00
|
|
|
}
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp + 1))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(-1);
|
2018-06-16 23:23:21 +08:00
|
|
|
if ((bitlen = GET_U_1(cp + 1)) == 0)
|
2000-12-29 04:30:41 +08:00
|
|
|
bitlen = 256;
|
|
|
|
return(((bitlen + 7) / 8) + 1);
|
|
|
|
} else
|
|
|
|
return(i);
|
|
|
|
}
|
|
|
|
|
2019-04-03 20:38:03 +08:00
|
|
|
/* print a <domain-name> */
|
2012-04-13 20:32:40 +08:00
|
|
|
const u_char *
|
2019-04-03 20:38:03 +08:00
|
|
|
fqdn_print(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp, const u_char *bp)
|
2000-12-29 04:30:41 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i, l;
|
|
|
|
const u_char *rp = NULL;
|
|
|
|
int compress = 0;
|
2018-01-12 03:52:30 +08:00
|
|
|
u_int elt;
|
2017-02-11 10:52:17 +08:00
|
|
|
u_int offset, max_offset;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((l = labellen(ndo, cp)) == (u_int)-1)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2017-02-11 10:52:17 +08:00
|
|
|
max_offset = (u_int)(cp - bp);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
|
|
|
if ((i & INDIR_MASK) != INDIR_MASK) {
|
1999-10-08 07:47:09 +08:00
|
|
|
compress = 0;
|
2000-12-29 04:30:41 +08:00
|
|
|
rp = cp + l;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
if (i != 0)
|
2014-03-25 19:05:59 +08:00
|
|
|
while (i && cp < ndo->ndo_snapend) {
|
1999-10-08 07:47:09 +08:00
|
|
|
if ((i & INDIR_MASK) == INDIR_MASK) {
|
2000-12-29 04:30:41 +08:00
|
|
|
if (!compress) {
|
|
|
|
rp = cp + 1;
|
|
|
|
compress = 1;
|
|
|
|
}
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
offset = (((i << 8) | GET_U_1(cp)) & 0x3fff);
|
2017-02-11 10:52:17 +08:00
|
|
|
/*
|
|
|
|
* This must move backwards in the packet.
|
|
|
|
* No RFC explicitly says that, but BIND's
|
|
|
|
* name decompression code requires it,
|
|
|
|
* as a way of preventing infinite loops
|
|
|
|
* and other bad behavior, and it's probably
|
|
|
|
* what was intended (compress by pointing
|
|
|
|
* to domain name suffixes already seen in
|
|
|
|
* the packet).
|
|
|
|
*/
|
|
|
|
if (offset >= max_offset) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("<BAD PTR>");
|
2017-02-11 10:52:17 +08:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
max_offset = offset;
|
|
|
|
cp = bp + offset;
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((l = labellen(ndo, cp)) == (u_int)-1)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
1999-10-08 07:47:09 +08:00
|
|
|
continue;
|
|
|
|
}
|
2000-12-29 04:30:41 +08:00
|
|
|
if ((i & INDIR_MASK) == EDNS0_MASK) {
|
|
|
|
elt = (i & ~INDIR_MASK);
|
|
|
|
switch(elt) {
|
|
|
|
case EDNS0_ELT_BITLABEL:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (blabel_print(ndo, cp) == NULL)
|
2001-02-23 16:55:21 +08:00
|
|
|
return (NULL);
|
2000-12-29 04:30:41 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* unknown ELT */
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT("<ELT %u>", elt);
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
|
|
|
}
|
|
|
|
} else {
|
2018-04-30 18:52:10 +08:00
|
|
|
if (nd_printn(ndo, cp, l, ndo->ndo_snapend))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
cp += l;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(".");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((l = labellen(ndo, cp)) == (u_int)-1)
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
1999-10-08 07:47:09 +08:00
|
|
|
if (!compress)
|
2000-12-29 04:30:41 +08:00
|
|
|
rp += l + 1;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
else
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(".");
|
1999-10-08 07:47:09 +08:00
|
|
|
return (rp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* print a <character-string> */
|
|
|
|
static const u_char *
|
2014-03-25 19:05:59 +08:00
|
|
|
ns_cprint(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return (NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_U_1(cp);
|
2017-11-20 09:59:51 +08:00
|
|
|
cp++;
|
2018-04-30 18:52:10 +08:00
|
|
|
if (nd_printn(ndo, cp, i, ndo->ndo_snapend))
|
2001-02-23 16:55:21 +08:00
|
|
|
return (NULL);
|
1999-10-08 07:47:09 +08:00
|
|
|
return (cp + i);
|
|
|
|
}
|
|
|
|
|
2017-12-31 03:12:07 +08:00
|
|
|
extern const struct tok ns_type2str[];
|
|
|
|
|
2003-04-04 11:49:25 +08:00
|
|
|
/* http://www.iana.org/assignments/dns-parameters */
|
2013-09-25 00:46:24 +08:00
|
|
|
const struct tok ns_type2str[] = {
|
2003-04-04 11:49:25 +08:00
|
|
|
{ T_A, "A" }, /* RFC 1035 */
|
|
|
|
{ T_NS, "NS" }, /* RFC 1035 */
|
|
|
|
{ T_MD, "MD" }, /* RFC 1035 */
|
|
|
|
{ T_MF, "MF" }, /* RFC 1035 */
|
|
|
|
{ T_CNAME, "CNAME" }, /* RFC 1035 */
|
|
|
|
{ T_SOA, "SOA" }, /* RFC 1035 */
|
|
|
|
{ T_MB, "MB" }, /* RFC 1035 */
|
|
|
|
{ T_MG, "MG" }, /* RFC 1035 */
|
|
|
|
{ T_MR, "MR" }, /* RFC 1035 */
|
|
|
|
{ T_NULL, "NULL" }, /* RFC 1035 */
|
|
|
|
{ T_WKS, "WKS" }, /* RFC 1035 */
|
|
|
|
{ T_PTR, "PTR" }, /* RFC 1035 */
|
|
|
|
{ T_HINFO, "HINFO" }, /* RFC 1035 */
|
|
|
|
{ T_MINFO, "MINFO" }, /* RFC 1035 */
|
|
|
|
{ T_MX, "MX" }, /* RFC 1035 */
|
|
|
|
{ T_TXT, "TXT" }, /* RFC 1035 */
|
|
|
|
{ T_RP, "RP" }, /* RFC 1183 */
|
|
|
|
{ T_AFSDB, "AFSDB" }, /* RFC 1183 */
|
|
|
|
{ T_X25, "X25" }, /* RFC 1183 */
|
|
|
|
{ T_ISDN, "ISDN" }, /* RFC 1183 */
|
|
|
|
{ T_RT, "RT" }, /* RFC 1183 */
|
|
|
|
{ T_NSAP, "NSAP" }, /* RFC 1706 */
|
1999-10-08 07:47:09 +08:00
|
|
|
{ T_NSAP_PTR, "NSAP_PTR" },
|
2003-04-04 11:49:25 +08:00
|
|
|
{ T_SIG, "SIG" }, /* RFC 2535 */
|
|
|
|
{ T_KEY, "KEY" }, /* RFC 2535 */
|
|
|
|
{ T_PX, "PX" }, /* RFC 2163 */
|
|
|
|
{ T_GPOS, "GPOS" }, /* RFC 1712 */
|
|
|
|
{ T_AAAA, "AAAA" }, /* RFC 1886 */
|
|
|
|
{ T_LOC, "LOC" }, /* RFC 1876 */
|
|
|
|
{ T_NXT, "NXT" }, /* RFC 2535 */
|
|
|
|
{ T_EID, "EID" }, /* Nimrod */
|
|
|
|
{ T_NIMLOC, "NIMLOC" }, /* Nimrod */
|
|
|
|
{ T_SRV, "SRV" }, /* RFC 2782 */
|
|
|
|
{ T_ATMA, "ATMA" }, /* ATM Forum */
|
|
|
|
{ T_NAPTR, "NAPTR" }, /* RFC 2168, RFC 2915 */
|
2006-04-07 16:47:34 +08:00
|
|
|
{ T_KX, "KX" }, /* RFC 2230 */
|
|
|
|
{ T_CERT, "CERT" }, /* RFC 2538 */
|
2003-04-04 11:49:25 +08:00
|
|
|
{ T_A6, "A6" }, /* RFC 2874 */
|
|
|
|
{ T_DNAME, "DNAME" }, /* RFC 2672 */
|
2006-04-07 16:47:34 +08:00
|
|
|
{ T_SINK, "SINK" },
|
2003-04-04 11:49:25 +08:00
|
|
|
{ T_OPT, "OPT" }, /* RFC 2671 */
|
2006-04-07 16:47:34 +08:00
|
|
|
{ T_APL, "APL" }, /* RFC 3123 */
|
|
|
|
{ T_DS, "DS" }, /* RFC 4034 */
|
|
|
|
{ T_SSHFP, "SSHFP" }, /* RFC 4255 */
|
|
|
|
{ T_IPSECKEY, "IPSECKEY" }, /* RFC 4025 */
|
|
|
|
{ T_RRSIG, "RRSIG" }, /* RFC 4034 */
|
|
|
|
{ T_NSEC, "NSEC" }, /* RFC 4034 */
|
|
|
|
{ T_DNSKEY, "DNSKEY" }, /* RFC 4034 */
|
|
|
|
{ T_SPF, "SPF" }, /* RFC-schlitt-spf-classic-02.txt */
|
1999-10-08 07:47:09 +08:00
|
|
|
{ T_UINFO, "UINFO" },
|
|
|
|
{ T_UID, "UID" },
|
|
|
|
{ T_GID, "GID" },
|
|
|
|
{ T_UNSPEC, "UNSPEC" },
|
|
|
|
{ T_UNSPECA, "UNSPECA" },
|
2003-04-04 11:49:25 +08:00
|
|
|
{ T_TKEY, "TKEY" }, /* RFC 2930 */
|
|
|
|
{ T_TSIG, "TSIG" }, /* RFC 2845 */
|
|
|
|
{ T_IXFR, "IXFR" }, /* RFC 1995 */
|
|
|
|
{ T_AXFR, "AXFR" }, /* RFC 1035 */
|
|
|
|
{ T_MAILB, "MAILB" }, /* RFC 1035 */
|
|
|
|
{ T_MAILA, "MAILA" }, /* RFC 1035 */
|
1999-10-08 07:47:09 +08:00
|
|
|
{ T_ANY, "ANY" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
2017-12-31 03:12:07 +08:00
|
|
|
extern const struct tok ns_class2str[];
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
const struct tok ns_class2str[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
{ C_IN, "IN" }, /* Not used */
|
2001-01-28 15:56:21 +08:00
|
|
|
{ C_CHAOS, "CHAOS" },
|
1999-10-08 07:47:09 +08:00
|
|
|
{ C_HS, "HS" },
|
|
|
|
{ C_ANY, "ANY" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* print a query */
|
2000-12-29 04:30:41 +08:00
|
|
|
static const u_char *
|
2014-03-25 19:05:59 +08:00
|
|
|
ns_qprint(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp, const u_char *bp, int is_mdns)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *np = cp;
|
|
|
|
u_int i, class;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
cp = ns_nskip(ndo, cp);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2017-11-25 05:48:55 +08:00
|
|
|
if (cp == NULL || !ND_TTEST_4(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2006-11-10 11:18:21 +08:00
|
|
|
/* print the qtype */
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_BE_U_2(cp);
|
2003-04-04 11:49:25 +08:00
|
|
|
cp += 2;
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_type2str, "Type%u", i));
|
2006-11-10 11:18:21 +08:00
|
|
|
/* print the qclass (if it's not IN) */
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_BE_U_2(cp);
|
2003-04-04 11:49:25 +08:00
|
|
|
cp += 2;
|
2007-02-14 03:19:00 +08:00
|
|
|
if (is_mdns)
|
2006-11-10 11:18:21 +08:00
|
|
|
class = (i & ~C_QU);
|
2007-02-14 03:19:00 +08:00
|
|
|
else
|
2006-11-10 11:18:21 +08:00
|
|
|
class = i;
|
|
|
|
if (class != C_IN)
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_class2str, "(Class %u)", class));
|
2007-02-14 03:19:00 +08:00
|
|
|
if (is_mdns) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(i & C_QU ? " (QU)" : " (QM)");
|
2007-02-14 03:19:00 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("? ");
|
2019-04-03 20:38:03 +08:00
|
|
|
cp = fqdn_print(ndo, np, bp);
|
2000-12-29 04:30:41 +08:00
|
|
|
return(cp ? cp + 4 : NULL);
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* print a reply */
|
|
|
|
static const u_char *
|
2014-03-25 19:05:59 +08:00
|
|
|
ns_rprint(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp, const u_char *bp, int is_mdns)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2017-12-14 02:17:47 +08:00
|
|
|
u_int i, class, opt_flags = 0;
|
|
|
|
u_short typ, len;
|
|
|
|
const u_char *rp;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2019-04-03 20:38:03 +08:00
|
|
|
if ((cp = fqdn_print(ndo, cp, bp)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
return NULL;
|
1999-10-08 07:47:09 +08:00
|
|
|
} else
|
2014-03-25 19:05:59 +08:00
|
|
|
cp = ns_nskip(ndo, cp);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2017-12-11 19:46:51 +08:00
|
|
|
if (cp == NULL || !ND_TTEST_LEN(cp, 10))
|
2014-03-25 19:05:59 +08:00
|
|
|
return (ndo->ndo_snapend);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2006-11-10 11:18:21 +08:00
|
|
|
/* print the type/qtype */
|
2018-06-16 23:23:21 +08:00
|
|
|
typ = GET_BE_U_2(cp);
|
2003-04-04 11:49:25 +08:00
|
|
|
cp += 2;
|
2006-11-10 11:18:21 +08:00
|
|
|
/* print the class (if it's not IN and the type isn't OPT) */
|
2018-06-16 23:23:21 +08:00
|
|
|
i = GET_BE_U_2(cp);
|
2003-04-04 11:49:25 +08:00
|
|
|
cp += 2;
|
2007-02-14 03:19:00 +08:00
|
|
|
if (is_mdns)
|
2006-11-10 11:18:21 +08:00
|
|
|
class = (i & ~C_CACHE_FLUSH);
|
2007-02-14 03:19:00 +08:00
|
|
|
else
|
2006-11-10 11:18:21 +08:00
|
|
|
class = i;
|
|
|
|
if (class != C_IN && typ != T_OPT)
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_class2str, "(Class %u)", class));
|
2007-02-14 03:19:00 +08:00
|
|
|
if (is_mdns) {
|
|
|
|
if (i & C_CACHE_FLUSH)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" (Cache flush)");
|
2007-02-14 03:19:00 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2007-12-09 09:40:32 +08:00
|
|
|
if (typ == T_OPT) {
|
|
|
|
/* get opt flags */
|
|
|
|
cp += 2;
|
2018-06-16 23:23:21 +08:00
|
|
|
opt_flags = GET_BE_U_2(cp);
|
2007-12-09 09:40:32 +08:00
|
|
|
/* ignore rest of ttl field */
|
|
|
|
cp += 2;
|
2014-03-25 19:05:59 +08:00
|
|
|
} else if (ndo->ndo_vflag > 2) {
|
2007-12-09 09:40:32 +08:00
|
|
|
/* print ttl */
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [");
|
2018-06-16 23:23:21 +08:00
|
|
|
unsigned_relts_print(ndo, GET_BE_U_4(cp));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("]");
|
2007-12-09 09:40:32 +08:00
|
|
|
cp += 4;
|
|
|
|
} else {
|
|
|
|
/* ignore ttl */
|
|
|
|
cp += 4;
|
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2018-06-16 23:23:21 +08:00
|
|
|
len = GET_BE_U_2(cp);
|
2003-04-04 11:49:25 +08:00
|
|
|
cp += 2;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
rp = cp + len;
|
|
|
|
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_type2str, "Type%u", typ));
|
2014-03-25 19:05:59 +08:00
|
|
|
if (rp > ndo->ndo_snapend)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2000-12-29 04:30:41 +08:00
|
|
|
switch (typ) {
|
1999-10-08 07:47:09 +08:00
|
|
|
case T_A:
|
2018-01-31 09:29:33 +08:00
|
|
|
if (!ND_TTEST_LEN(cp, sizeof(nd_ipv4)))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %s", intoa(GET_IPV4_TO_NETWORK_ORDER(cp)));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_NS:
|
|
|
|
case T_CNAME:
|
|
|
|
case T_PTR:
|
1999-10-30 13:11:06 +08:00
|
|
|
#ifdef T_DNAME
|
2000-12-29 04:30:41 +08:00
|
|
|
case T_DNAME:
|
1999-10-30 13:11:06 +08:00
|
|
|
#endif
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2019-04-03 20:38:03 +08:00
|
|
|
if (fqdn_print(ndo, cp, bp) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
2000-12-29 04:30:41 +08:00
|
|
|
case T_SOA:
|
2014-03-25 19:05:59 +08:00
|
|
|
if (!ndo->ndo_vflag)
|
2000-12-29 04:30:41 +08:00
|
|
|
break;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2019-04-03 20:38:03 +08:00
|
|
|
if ((cp = fqdn_print(ndo, cp, bp)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2019-04-03 20:38:03 +08:00
|
|
|
if ((cp = fqdn_print(ndo, cp, bp)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2017-12-11 19:46:51 +08:00
|
|
|
if (!ND_TTEST_LEN(cp, 5 * 4))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %u", GET_BE_U_4(cp));
|
2000-12-29 04:30:41 +08:00
|
|
|
cp += 4;
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %u", GET_BE_U_4(cp));
|
2000-12-29 04:30:41 +08:00
|
|
|
cp += 4;
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %u", GET_BE_U_4(cp));
|
2000-12-29 04:30:41 +08:00
|
|
|
cp += 4;
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %u", GET_BE_U_4(cp));
|
2000-12-29 04:30:41 +08:00
|
|
|
cp += 4;
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %u", GET_BE_U_4(cp));
|
2000-12-29 04:30:41 +08:00
|
|
|
cp += 4;
|
|
|
|
break;
|
1999-10-08 07:47:09 +08:00
|
|
|
case T_MX:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2017-11-25 05:48:55 +08:00
|
|
|
if (!ND_TTEST_2(cp))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2019-04-03 20:38:03 +08:00
|
|
|
if (fqdn_print(ndo, cp + 2, bp) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" %u", GET_BE_U_2(cp));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_TXT:
|
2003-04-04 11:49:25 +08:00
|
|
|
while (cp < rp) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" \"");
|
2014-03-25 19:05:59 +08:00
|
|
|
cp = ns_cprint(ndo, cp);
|
2003-04-04 11:49:25 +08:00
|
|
|
if (cp == NULL)
|
|
|
|
return(NULL);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("\"");
|
2003-04-04 11:49:25 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
2003-04-04 08:18:54 +08:00
|
|
|
case T_SRV:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2017-11-25 05:48:55 +08:00
|
|
|
if (!ND_TTEST_6(cp))
|
2003-04-04 08:18:54 +08:00
|
|
|
return(NULL);
|
2019-04-03 20:38:03 +08:00
|
|
|
if (fqdn_print(ndo, cp + 6, bp) == NULL)
|
2003-04-04 08:18:54 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(":%u %u %u", GET_BE_U_2(cp + 4),
|
|
|
|
GET_BE_U_2(cp), GET_BE_U_2(cp + 2));
|
2003-04-04 08:18:54 +08:00
|
|
|
break;
|
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
case T_AAAA:
|
2007-12-09 09:40:32 +08:00
|
|
|
{
|
|
|
|
char ntop_buf[INET6_ADDRSTRLEN];
|
|
|
|
|
2018-01-31 09:29:33 +08:00
|
|
|
if (!ND_TTEST_LEN(cp, sizeof(nd_ipv6)))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s",
|
|
|
|
addrtostr6(cp, ntop_buf, sizeof(ntop_buf)));
|
2007-12-09 09:40:32 +08:00
|
|
|
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
2007-12-09 09:40:32 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
|
2000-12-29 04:30:41 +08:00
|
|
|
case T_A6:
|
1999-10-30 13:11:06 +08:00
|
|
|
{
|
|
|
|
struct in6_addr a;
|
2000-12-29 04:30:41 +08:00
|
|
|
int pbit, pbyte;
|
2007-12-09 09:40:32 +08:00
|
|
|
char ntop_buf[INET6_ADDRSTRLEN];
|
2000-12-29 04:30:41 +08:00
|
|
|
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_1(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
pbit = GET_U_1(cp);
|
2000-12-29 04:30:41 +08:00
|
|
|
pbyte = (pbit & ~7) / 8;
|
|
|
|
if (pbit > 128) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u(bad plen)", pbit);
|
2000-12-29 04:30:41 +08:00
|
|
|
break;
|
|
|
|
} else if (pbit < 128) {
|
2017-12-11 19:46:51 +08:00
|
|
|
if (!ND_TTEST_LEN(cp + 1, sizeof(a) - pbyte))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2000-12-29 04:30:41 +08:00
|
|
|
memset(&a, 0, sizeof(a));
|
|
|
|
memcpy(&a.s6_addr[pbyte], cp + 1, sizeof(a) - pbyte);
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u %s", pbit,
|
|
|
|
addrtostr6(&a, ntop_buf, sizeof(ntop_buf)));
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
2000-12-30 17:07:40 +08:00
|
|
|
if (pbit > 0) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2019-04-03 20:38:03 +08:00
|
|
|
if (fqdn_print(ndo, cp + 1 + sizeof(a) - pbyte, bp) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
2000-12-30 17:07:40 +08:00
|
|
|
}
|
1999-10-30 13:11:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-12-30 17:06:21 +08:00
|
|
|
case T_OPT:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" UDPsize=%u", class);
|
2006-04-07 16:58:29 +08:00
|
|
|
if (opt_flags & 0x8000)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" DO");
|
2000-12-30 17:06:21 +08:00
|
|
|
break;
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
case T_UNSPECA: /* One long string */
|
2017-12-11 19:46:51 +08:00
|
|
|
if (!ND_TTEST_LEN(cp, len))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-04-30 18:52:10 +08:00
|
|
|
if (nd_printn(ndo, cp, len, ndo->ndo_snapend))
|
2000-12-29 04:30:41 +08:00
|
|
|
return(NULL);
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
2001-02-20 15:22:17 +08:00
|
|
|
|
|
|
|
case T_TSIG:
|
|
|
|
{
|
2014-03-25 19:05:59 +08:00
|
|
|
if (cp + len > ndo->ndo_snapend)
|
2001-02-20 15:22:17 +08:00
|
|
|
return(NULL);
|
2014-03-25 19:05:59 +08:00
|
|
|
if (!ndo->ndo_vflag)
|
2001-02-20 15:22:17 +08:00
|
|
|
break;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2019-04-03 20:38:03 +08:00
|
|
|
if ((cp = fqdn_print(ndo, cp, bp)) == NULL)
|
2001-02-20 15:22:17 +08:00
|
|
|
return(NULL);
|
|
|
|
cp += 6;
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_2(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" fudge=%u", GET_BE_U_2(cp));
|
2001-02-20 15:22:17 +08:00
|
|
|
cp += 2;
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_2(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" maclen=%u", GET_BE_U_2(cp));
|
|
|
|
cp += 2 + GET_BE_U_2(cp);
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_2(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" origid=%u", GET_BE_U_2(cp));
|
2001-02-20 15:22:17 +08:00
|
|
|
cp += 2;
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_2(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" error=%u", GET_BE_U_2(cp));
|
2001-02-20 15:22:17 +08:00
|
|
|
cp += 2;
|
2017-11-23 04:58:44 +08:00
|
|
|
if (!ND_TTEST_2(cp))
|
2001-02-23 16:55:21 +08:00
|
|
|
return(NULL);
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT(" otherlen=%u", GET_BE_U_2(cp));
|
2001-02-20 15:22:17 +08:00
|
|
|
cp += 2;
|
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
return (rp); /* XXX This isn't always right */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-11-16 16:40:19 +08:00
|
|
|
domain_print(netdissect_options *ndo,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int length, int is_mdns)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
2018-01-02 23:57:13 +08:00
|
|
|
const dns_header_t *np;
|
2019-02-13 06:50:17 +08:00
|
|
|
uint16_t flags, rcode, rdlen, type;
|
2017-12-14 01:32:44 +08:00
|
|
|
u_int qdcount, ancount, nscount, arcount;
|
|
|
|
u_int i;
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *cp;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t b2;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "domain";
|
2018-01-02 23:57:13 +08:00
|
|
|
np = (const dns_header_t *)bp;
|
2018-01-04 04:32:07 +08:00
|
|
|
ND_TCHECK_SIZE(np);
|
2018-06-16 23:23:21 +08:00
|
|
|
flags = GET_BE_U_2(np->flags);
|
1999-10-08 07:47:09 +08:00
|
|
|
/* get the byte-order right */
|
2018-06-16 23:23:21 +08:00
|
|
|
qdcount = GET_BE_U_2(np->qdcount);
|
|
|
|
ancount = GET_BE_U_2(np->ancount);
|
|
|
|
nscount = GET_BE_U_2(np->nscount);
|
|
|
|
arcount = GET_BE_U_2(np->arcount);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2019-02-13 06:50:17 +08:00
|
|
|
/* find the opt record to extract extended rcode */
|
|
|
|
cp = (const u_char *)(np + 1);
|
|
|
|
rcode = DNS_RCODE(flags);
|
|
|
|
for (i = 0; i < qdcount; i++) {
|
|
|
|
if ((cp = ns_nskip(ndo, cp)) == NULL)
|
|
|
|
goto print;
|
|
|
|
cp += 4; /* skip QTYPE and QCLASS */
|
|
|
|
if (cp >= ndo->ndo_snapend)
|
|
|
|
goto print;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ancount + nscount; i++) {
|
|
|
|
if ((cp = ns_nskip(ndo, cp)) == NULL)
|
|
|
|
goto print;
|
|
|
|
cp += 8; /* skip TYPE, CLASS and TTL */
|
|
|
|
if (cp + 2 > ndo->ndo_snapend)
|
|
|
|
goto print;
|
2018-06-16 23:23:21 +08:00
|
|
|
rdlen = GET_BE_U_2(cp);
|
2019-02-13 06:50:17 +08:00
|
|
|
cp += 2 + rdlen;
|
|
|
|
if (cp >= ndo->ndo_snapend)
|
|
|
|
goto print;
|
|
|
|
}
|
|
|
|
for (i = 0; i < arcount; i++) {
|
|
|
|
if ((cp = ns_nskip(ndo, cp)) == NULL)
|
|
|
|
goto print;
|
|
|
|
if (cp + 2 > ndo->ndo_snapend)
|
|
|
|
goto print;
|
2018-06-16 23:23:21 +08:00
|
|
|
type = GET_BE_U_2(cp);
|
2019-02-13 06:50:17 +08:00
|
|
|
cp += 4; /* skip TYPE and CLASS */
|
|
|
|
if (cp + 1 > ndo->ndo_snapend)
|
|
|
|
goto print;
|
|
|
|
if (type == T_OPT) {
|
|
|
|
rcode |= (*cp << 4);
|
|
|
|
goto print;
|
|
|
|
}
|
|
|
|
cp += 4;
|
|
|
|
if (cp + 2 > ndo->ndo_snapend)
|
|
|
|
goto print;
|
2018-06-16 23:23:21 +08:00
|
|
|
rdlen = GET_BE_U_2(cp);
|
2019-02-13 06:50:17 +08:00
|
|
|
cp += 2 + rdlen;
|
|
|
|
if (cp >= ndo->ndo_snapend)
|
|
|
|
goto print;
|
|
|
|
}
|
|
|
|
|
|
|
|
print:
|
2017-12-14 01:32:44 +08:00
|
|
|
if (DNS_QR(flags)) {
|
1999-10-08 07:47:09 +08:00
|
|
|
/* this is a response */
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT("%u%s%s%s%s%s%s",
|
2018-06-16 23:23:21 +08:00
|
|
|
GET_BE_U_2(np->id),
|
2017-12-14 01:32:44 +08:00
|
|
|
ns_ops[DNS_OPCODE(flags)],
|
2019-02-13 06:50:17 +08:00
|
|
|
ns_rcode(rcode),
|
2017-12-14 01:32:44 +08:00
|
|
|
DNS_AA(flags)? "*" : "",
|
|
|
|
DNS_RA(flags)? "" : "-",
|
|
|
|
DNS_TC(flags)? "|" : "",
|
2018-01-07 18:47:30 +08:00
|
|
|
DNS_AD(flags)? "$" : "");
|
2000-04-27 11:44:05 +08:00
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
if (qdcount != 1)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%uq]", qdcount);
|
1999-10-08 07:47:09 +08:00
|
|
|
/* Print QUESTION section on -vv */
|
2001-02-20 14:03:42 +08:00
|
|
|
cp = (const u_char *)(np + 1);
|
2017-12-14 01:32:44 +08:00
|
|
|
for (i = 0; i < qdcount; i++) {
|
|
|
|
if (i != 0)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag > 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" q:");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_qprint(ndo, cp, bp, is_mdns)) == NULL)
|
2001-02-03 13:04:33 +08:00
|
|
|
goto trunc;
|
|
|
|
} else {
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_nskip(ndo, cp)) == NULL)
|
2001-02-03 13:04:33 +08:00
|
|
|
goto trunc;
|
|
|
|
cp += 4; /* skip QTYPE and QCLASS */
|
|
|
|
}
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u/%u/%u", ancount, nscount, arcount);
|
2017-12-14 01:32:44 +08:00
|
|
|
if (ancount) {
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
ancount--;
|
|
|
|
while (cp < ndo->ndo_snapend && ancount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
ancount--;
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 01:32:44 +08:00
|
|
|
if (ancount)
|
2001-01-12 23:06:06 +08:00
|
|
|
goto trunc;
|
2000-12-29 04:30:41 +08:00
|
|
|
/* Print NS and AR sections on -vv */
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag > 1) {
|
2017-12-14 01:32:44 +08:00
|
|
|
if (cp < ndo->ndo_snapend && nscount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ns:");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
nscount--;
|
|
|
|
while (cp < ndo->ndo_snapend && nscount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
nscount--;
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 01:32:44 +08:00
|
|
|
if (nscount)
|
2001-01-12 23:06:06 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
if (cp < ndo->ndo_snapend && arcount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ar:");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
arcount--;
|
|
|
|
while (cp < ndo->ndo_snapend && arcount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-29 04:30:41 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
arcount--;
|
2000-12-29 04:30:41 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
2017-12-14 01:32:44 +08:00
|
|
|
if (arcount)
|
2001-01-12 23:06:06 +08:00
|
|
|
goto trunc;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* this is a request */
|
2018-06-16 23:23:21 +08:00
|
|
|
ND_PRINT("%u%s%s%s", GET_BE_U_2(np->id),
|
|
|
|
ns_ops[DNS_OPCODE(flags)],
|
2017-12-14 01:32:44 +08:00
|
|
|
DNS_RD(flags) ? "+" : "",
|
2018-01-07 18:47:30 +08:00
|
|
|
DNS_CD(flags) ? "%" : "");
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* any weirdness? */
|
2018-06-16 23:23:21 +08:00
|
|
|
b2 = GET_BE_U_2(((const u_short *)np) + 1);
|
2002-12-11 15:13:49 +08:00
|
|
|
if (b2 & 0x6cf)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [b2&3=0x%x]", b2);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2017-12-14 01:32:44 +08:00
|
|
|
if (DNS_OPCODE(flags) == IQUERY) {
|
1999-10-08 07:47:09 +08:00
|
|
|
if (qdcount)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%uq]", qdcount);
|
1999-10-08 07:47:09 +08:00
|
|
|
if (ancount != 1)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%ua]", ancount);
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (ancount)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%ua]", ancount);
|
1999-10-08 07:47:09 +08:00
|
|
|
if (qdcount != 1)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%uq]", qdcount);
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
if (nscount)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%un]", nscount);
|
1999-10-08 07:47:09 +08:00
|
|
|
if (arcount)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [%uau]", arcount);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2001-10-19 17:00:48 +08:00
|
|
|
cp = (const u_char *)(np + 1);
|
2017-12-14 01:32:44 +08:00
|
|
|
if (qdcount) {
|
2014-03-25 19:05:59 +08:00
|
|
|
cp = ns_qprint(ndo, cp, (const u_char *)np, is_mdns);
|
2001-01-01 12:22:56 +08:00
|
|
|
if (!cp)
|
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
qdcount--;
|
|
|
|
while (cp < ndo->ndo_snapend && qdcount) {
|
2014-03-25 19:05:59 +08:00
|
|
|
cp = ns_qprint(ndo, (const u_char *)cp,
|
2003-11-05 14:02:58 +08:00
|
|
|
(const u_char *)np,
|
|
|
|
is_mdns);
|
2001-01-01 12:22:56 +08:00
|
|
|
if (!cp)
|
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
qdcount--;
|
2000-12-30 17:06:21 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 01:32:44 +08:00
|
|
|
if (qdcount)
|
2001-01-12 23:06:06 +08:00
|
|
|
goto trunc;
|
2000-12-30 17:06:21 +08:00
|
|
|
|
|
|
|
/* Print remaining sections on -vv */
|
2014-03-25 19:05:59 +08:00
|
|
|
if (ndo->ndo_vflag > 1) {
|
2017-12-14 01:32:44 +08:00
|
|
|
if (ancount) {
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-30 17:06:21 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
ancount--;
|
|
|
|
while (cp < ndo->ndo_snapend && ancount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-30 17:06:21 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
ancount--;
|
2000-12-30 17:06:21 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 01:32:44 +08:00
|
|
|
if (ancount)
|
2001-01-12 23:06:06 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
if (cp < ndo->ndo_snapend && nscount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ns:");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-30 17:06:21 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
nscount--;
|
|
|
|
while (cp < ndo->ndo_snapend && nscount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-30 17:06:21 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
nscount--;
|
2000-12-30 17:06:21 +08:00
|
|
|
}
|
|
|
|
}
|
2001-01-12 23:06:06 +08:00
|
|
|
if (nscount > 0)
|
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
if (cp < ndo->ndo_snapend && arcount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ar:");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-30 17:06:21 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
arcount--;
|
|
|
|
while (cp < ndo->ndo_snapend && arcount) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(",");
|
2014-03-25 19:05:59 +08:00
|
|
|
if ((cp = ns_rprint(ndo, cp, bp, is_mdns)) == NULL)
|
2000-12-30 17:06:21 +08:00
|
|
|
goto trunc;
|
2017-12-14 01:32:44 +08:00
|
|
|
arcount--;
|
2000-12-30 17:06:21 +08:00
|
|
|
}
|
|
|
|
}
|
2017-12-14 01:32:44 +08:00
|
|
|
if (arcount)
|
2001-01-12 23:06:06 +08:00
|
|
|
goto trunc;
|
2000-12-30 17:06:21 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
2018-01-12 03:52:30 +08:00
|
|
|
ND_PRINT(" (%u)", length);
|
2000-12-29 04:30:41 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2018-05-11 00:05:56 +08:00
|
|
|
nd_print_trunc(ndo);
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|