2001-01-29 17:18:46 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2001 WIDE Project.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of the project 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 BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2002-08-01 16:52:55 +08:00
|
|
|
#include <tcpdump-stdinc.h>
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
#include "nameser.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2015-09-06 05:35:58 +08:00
|
|
|
#include "netdissect.h"
|
2001-01-29 17:18:46 +08:00
|
|
|
#include "addrtoname.h"
|
2015-09-07 21:01:46 +08:00
|
|
|
#include "extract.h"
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
/* BIND9 lib/lwres/include/lwres */
|
2014-04-23 15:20:40 +08:00
|
|
|
typedef uint32_t lwres_uint32_t;
|
|
|
|
typedef uint16_t lwres_uint16_t;
|
|
|
|
typedef uint8_t lwres_uint8_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
struct lwres_lwpacket {
|
|
|
|
lwres_uint32_t length;
|
|
|
|
lwres_uint16_t version;
|
|
|
|
lwres_uint16_t pktflags;
|
|
|
|
lwres_uint32_t serial;
|
|
|
|
lwres_uint32_t opcode;
|
|
|
|
lwres_uint32_t result;
|
|
|
|
lwres_uint32_t recvlength;
|
|
|
|
lwres_uint16_t authtype;
|
|
|
|
lwres_uint16_t authlength;
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
#define LWRES_LWPACKETFLAG_RESPONSE 0x0001U /* if set, pkt is a response */
|
|
|
|
|
|
|
|
#define LWRES_LWPACKETVERSION_0 0
|
|
|
|
|
2001-01-29 17:18:46 +08:00
|
|
|
#define LWRES_FLAG_TRUSTNOTREQUIRED 0x00000001U
|
|
|
|
#define LWRES_FLAG_SECUREDATA 0x00000002U
|
|
|
|
|
|
|
|
/*
|
|
|
|
* no-op
|
|
|
|
*/
|
|
|
|
#define LWRES_OPCODE_NOOP 0x00000000U
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint16_t datalength;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* data follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_nooprequest_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint16_t datalength;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* data follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_noopresponse_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get addresses by name
|
|
|
|
*/
|
|
|
|
#define LWRES_OPCODE_GETADDRSBYNAME 0x00010001U
|
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
typedef struct lwres_addr lwres_addr_t;
|
|
|
|
|
|
|
|
struct lwres_addr {
|
|
|
|
lwres_uint32_t family;
|
|
|
|
lwres_uint16_t length;
|
|
|
|
/* address folows */
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2001-01-29 17:18:46 +08:00
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint32_t flags;
|
|
|
|
lwres_uint32_t addrtypes;
|
|
|
|
lwres_uint16_t namelen;
|
|
|
|
/* name follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_gabnrequest_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint32_t flags;
|
|
|
|
lwres_uint16_t naliases;
|
|
|
|
lwres_uint16_t naddrs;
|
|
|
|
lwres_uint16_t realnamelen;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* aliases follows */
|
|
|
|
/* addrs follows */
|
|
|
|
/* realname follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_gabnresponse_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get name by address
|
|
|
|
*/
|
|
|
|
#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint32_t flags;
|
|
|
|
lwres_addr_t addr;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* addr body follows */
|
2001-01-29 17:18:46 +08:00
|
|
|
} lwres_gnbarequest_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint32_t flags;
|
|
|
|
lwres_uint16_t naliases;
|
|
|
|
lwres_uint16_t realnamelen;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* aliases follows */
|
|
|
|
/* realname follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_gnbaresponse_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get rdata by name
|
|
|
|
*/
|
|
|
|
#define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint32_t flags;
|
|
|
|
lwres_uint16_t rdclass;
|
|
|
|
lwres_uint16_t rdtype;
|
|
|
|
lwres_uint16_t namelen;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* name follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_grbnrequest_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
|
|
|
lwres_uint32_t flags;
|
|
|
|
lwres_uint16_t rdclass;
|
|
|
|
lwres_uint16_t rdtype;
|
|
|
|
lwres_uint32_t ttl;
|
|
|
|
lwres_uint16_t nrdatas;
|
|
|
|
lwres_uint16_t nsigs;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* realname here (len + name) */
|
|
|
|
/* rdata here (len + name) */
|
|
|
|
/* signatures here (len + name) */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_grbnresponse_t;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
#define LWRDATA_VALIDATED 0x00000001
|
|
|
|
|
|
|
|
#define LWRES_ADDRTYPE_V4 0x00000001U /* ipv4 */
|
|
|
|
#define LWRES_ADDRTYPE_V6 0x00000002U /* ipv6 */
|
|
|
|
|
|
|
|
#define LWRES_MAX_ALIASES 16 /* max # of aliases */
|
|
|
|
#define LWRES_MAX_ADDRS 64 /* max # of addrs */
|
|
|
|
|
2013-09-25 00:46:24 +08:00
|
|
|
static const struct tok opcode[] = {
|
2001-01-29 17:18:46 +08:00
|
|
|
{ LWRES_OPCODE_NOOP, "noop", },
|
|
|
|
{ LWRES_OPCODE_GETADDRSBYNAME, "getaddrsbyname", },
|
|
|
|
{ LWRES_OPCODE_GETNAMEBYADDR, "getnamebyaddr", },
|
|
|
|
{ LWRES_OPCODE_GETRDATABYNAME, "getrdatabyname", },
|
|
|
|
{ 0, NULL, },
|
|
|
|
};
|
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
/* print-domain.c */
|
2013-09-25 00:46:24 +08:00
|
|
|
extern const struct tok ns_type2str[];
|
|
|
|
extern const struct tok ns_class2str[];
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
static int
|
2014-04-01 23:42:33 +08:00
|
|
|
lwres_printname(netdissect_options *ndo,
|
|
|
|
size_t l, const char *p0)
|
2001-01-30 04:04:00 +08:00
|
|
|
{
|
|
|
|
const char *p;
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
size_t i;
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
p = p0;
|
|
|
|
/* + 1 for terminating \0 */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (p + l + 1 > (const char *)ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < l; i++)
|
2014-04-01 23:42:33 +08:00
|
|
|
safeputchar(ndo, *p++);
|
2001-01-30 04:04:00 +08:00
|
|
|
p++; /* skip terminating \0 */
|
|
|
|
|
|
|
|
return p - p0;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-04-01 23:42:33 +08:00
|
|
|
lwres_printnamelen(netdissect_options *ndo,
|
|
|
|
const char *p)
|
2001-01-30 04:04:00 +08:00
|
|
|
{
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t l;
|
2001-01-30 04:04:00 +08:00
|
|
|
int advance;
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
if (p + 2 > (const char *)ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
|
|
|
l = EXTRACT_16BITS(p);
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printname(ndo, l, p + 2);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
return 2 + advance;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-04-01 23:42:33 +08:00
|
|
|
lwres_printbinlen(netdissect_options *ndo,
|
|
|
|
const char *p0)
|
2001-01-30 04:04:00 +08:00
|
|
|
{
|
|
|
|
const char *p;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t l;
|
2001-01-30 04:04:00 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
p = p0;
|
2014-04-01 23:42:33 +08:00
|
|
|
if (p + 2 > (const char *)ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
|
|
|
l = EXTRACT_16BITS(p);
|
2014-04-01 23:42:33 +08:00
|
|
|
if (p + 2 + l > (const char *)ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
|
|
|
p += 2;
|
|
|
|
for (i = 0; i < l; i++)
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, "%02x", *p++));
|
2001-01-30 04:04:00 +08:00
|
|
|
return p - p0;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-04-01 23:42:33 +08:00
|
|
|
lwres_printaddr(netdissect_options *ndo,
|
2015-04-27 08:24:42 +08:00
|
|
|
const lwres_addr_t *ap)
|
2001-01-29 17:18:46 +08:00
|
|
|
{
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t l;
|
2001-01-30 04:04:00 +08:00
|
|
|
const char *p;
|
|
|
|
int i;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(ap->length);
|
2002-12-11 15:13:49 +08:00
|
|
|
l = EXTRACT_16BITS(&ap->length);
|
2001-01-30 04:04:00 +08:00
|
|
|
/* XXX ap points to packed struct */
|
|
|
|
p = (const char *)&ap->length + sizeof(ap->length);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK2(*p, l);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2002-12-11 15:13:49 +08:00
|
|
|
switch (EXTRACT_32BITS(&ap->family)) {
|
2001-01-30 04:04:00 +08:00
|
|
|
case 1: /* IPv4 */
|
2004-03-24 09:54:29 +08:00
|
|
|
if (l < 4)
|
|
|
|
return -1;
|
2014-04-04 15:43:46 +08:00
|
|
|
ND_PRINT((ndo, " %s", ipaddr_string(ndo, p)));
|
2001-01-30 04:04:00 +08:00
|
|
|
p += sizeof(struct in_addr);
|
|
|
|
break;
|
|
|
|
#ifdef INET6
|
|
|
|
case 2: /* IPv6 */
|
2004-03-24 09:54:29 +08:00
|
|
|
if (l < 16)
|
|
|
|
return -1;
|
2014-04-04 15:43:46 +08:00
|
|
|
ND_PRINT((ndo, " %s", ip6addr_string(ndo, p)));
|
2001-01-30 04:04:00 +08:00
|
|
|
p += sizeof(struct in6_addr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %u/", EXTRACT_32BITS(&ap->family)));
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < l; i++)
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, "%02x", *p++));
|
2001-01-29 17:18:46 +08:00
|
|
|
}
|
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
return p - (const char *)ap;
|
|
|
|
|
|
|
|
trunc:
|
|
|
|
return -1;
|
2001-01-29 17:18:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-04-01 23:42:33 +08:00
|
|
|
lwres_print(netdissect_options *ndo,
|
|
|
|
register const u_char *bp, u_int length)
|
2001-01-29 17:18:46 +08:00
|
|
|
{
|
|
|
|
const struct lwres_lwpacket *np;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t v;
|
2001-01-29 17:18:46 +08:00
|
|
|
const char *s;
|
2001-01-30 04:04:00 +08:00
|
|
|
int response;
|
|
|
|
int advance;
|
2001-02-09 13:16:48 +08:00
|
|
|
int unsupported = 0;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
np = (const struct lwres_lwpacket *)bp;
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(np->authlength);
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " lwres"));
|
2002-12-11 15:13:49 +08:00
|
|
|
v = EXTRACT_16BITS(&np->version);
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
|
|
|
|
ND_PRINT((ndo, " v%u", v));
|
2001-01-30 04:04:00 +08:00
|
|
|
if (v != LWRES_LWPACKETVERSION_0) {
|
2002-12-11 15:13:49 +08:00
|
|
|
s = (const char *)np + EXTRACT_32BITS(&np->length);
|
2001-01-30 04:04:00 +08:00
|
|
|
goto tail;
|
|
|
|
}
|
|
|
|
|
2002-12-11 15:13:49 +08:00
|
|
|
response = EXTRACT_16BITS(&np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
/* opcode and pktflags */
|
2002-12-11 15:13:49 +08:00
|
|
|
v = EXTRACT_32BITS(&np->opcode);
|
2001-01-30 04:04:00 +08:00
|
|
|
s = tok2str(opcode, "#0x%x", v);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %s%s", s, response ? "" : "?"));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* pktflags */
|
2002-12-11 15:13:49 +08:00
|
|
|
v = EXTRACT_16BITS(&np->pktflags);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, "[0x%x]", v));
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 1) {
|
|
|
|
ND_PRINT((ndo, " (")); /*)*/
|
|
|
|
ND_PRINT((ndo, "serial:0x%x", EXTRACT_32BITS(&np->serial)));
|
|
|
|
ND_PRINT((ndo, " result:0x%x", EXTRACT_32BITS(&np->result)));
|
|
|
|
ND_PRINT((ndo, " recvlen:%u", EXTRACT_32BITS(&np->recvlength)));
|
2001-01-30 04:04:00 +08:00
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " authtype:0x%x", EXTRACT_16BITS(&np->authtype)));
|
|
|
|
ND_PRINT((ndo, " authlen:%u", EXTRACT_16BITS(&np->authlength)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
2001-01-29 17:18:46 +08:00
|
|
|
/*(*/
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, ")"));
|
2001-01-29 17:18:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* per-opcode content */
|
2001-01-30 04:04:00 +08:00
|
|
|
if (!response) {
|
|
|
|
/*
|
|
|
|
* queries
|
|
|
|
*/
|
2015-04-27 08:24:42 +08:00
|
|
|
const lwres_gabnrequest_t *gabn;
|
|
|
|
const lwres_gnbarequest_t *gnba;
|
|
|
|
const lwres_grbnrequest_t *grbn;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t l;
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
gabn = NULL;
|
|
|
|
gnba = NULL;
|
|
|
|
grbn = NULL;
|
|
|
|
|
2002-12-11 15:13:49 +08:00
|
|
|
switch (EXTRACT_32BITS(&np->opcode)) {
|
2001-01-30 04:04:00 +08:00
|
|
|
case LWRES_OPCODE_NOOP:
|
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETADDRSBYNAME:
|
2015-04-27 08:24:42 +08:00
|
|
|
gabn = (const lwres_gabnrequest_t *)(np + 1);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(gabn->namelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
/* XXX gabn points to packed struct */
|
|
|
|
s = (const char *)&gabn->namelen +
|
|
|
|
sizeof(gabn->namelen);
|
2002-12-11 15:13:49 +08:00
|
|
|
l = EXTRACT_16BITS(&gabn->namelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " flags:0x%x",
|
|
|
|
EXTRACT_32BITS(&gabn->flags)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2002-12-11 15:13:49 +08:00
|
|
|
v = EXTRACT_32BITS(&gabn->addrtypes);
|
2001-01-30 04:04:00 +08:00
|
|
|
switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
|
|
|
|
case LWRES_ADDRTYPE_V4:
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " IPv4"));
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case LWRES_ADDRTYPE_V6:
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " IPv6"));
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " IPv4/6"));
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, "[0x%x]", v));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printname(ndo, l, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
2001-01-29 17:18:46 +08:00
|
|
|
break;
|
2001-01-30 04:04:00 +08:00
|
|
|
case LWRES_OPCODE_GETNAMEBYADDR:
|
2015-04-27 08:24:42 +08:00
|
|
|
gnba = (const lwres_gnbarequest_t *)(np + 1);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(gnba->addr);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " flags:0x%x",
|
|
|
|
EXTRACT_32BITS(&gnba->flags)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
s = (const char *)&gnba->addr;
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printaddr(ndo, &gnba->addr);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
2001-01-29 17:18:46 +08:00
|
|
|
break;
|
2001-01-30 04:04:00 +08:00
|
|
|
case LWRES_OPCODE_GETRDATABYNAME:
|
|
|
|
/* XXX no trace, not tested */
|
2015-04-27 08:24:42 +08:00
|
|
|
grbn = (const lwres_grbnrequest_t *)(np + 1);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(grbn->namelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " flags:0x%x",
|
|
|
|
EXTRACT_32BITS(&grbn->flags)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d",
|
|
|
|
EXTRACT_16BITS(&grbn->rdtype))));
|
2002-12-11 15:13:49 +08:00
|
|
|
if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) {
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %s", tok2str(ns_class2str, "Class%d",
|
|
|
|
EXTRACT_16BITS(&grbn->rdclass))));
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
}
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* XXX grbn points to packed struct */
|
|
|
|
s = (const char *)&grbn->namelen +
|
|
|
|
sizeof(grbn->namelen);
|
2003-07-31 04:34:58 +08:00
|
|
|
l = EXTRACT_16BITS(&grbn->namelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printname(ndo, l, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unsupported++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* responses
|
|
|
|
*/
|
2015-04-27 08:24:42 +08:00
|
|
|
const lwres_gabnresponse_t *gabn;
|
|
|
|
const lwres_gnbaresponse_t *gnba;
|
|
|
|
const lwres_grbnresponse_t *grbn;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t l, na;
|
|
|
|
uint32_t i;
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
gabn = NULL;
|
|
|
|
gnba = NULL;
|
|
|
|
grbn = NULL;
|
|
|
|
|
2002-12-11 15:13:49 +08:00
|
|
|
switch (EXTRACT_32BITS(&np->opcode)) {
|
2001-01-30 04:04:00 +08:00
|
|
|
case LWRES_OPCODE_NOOP:
|
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETADDRSBYNAME:
|
2015-04-27 08:24:42 +08:00
|
|
|
gabn = (const lwres_gabnresponse_t *)(np + 1);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(gabn->realnamelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
/* XXX gabn points to packed struct */
|
|
|
|
s = (const char *)&gabn->realnamelen +
|
|
|
|
sizeof(gabn->realnamelen);
|
2002-12-11 15:13:49 +08:00
|
|
|
l = EXTRACT_16BITS(&gabn->realnamelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " flags:0x%x",
|
|
|
|
EXTRACT_32BITS(&gabn->flags)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %u/%u", EXTRACT_16BITS(&gabn->naliases),
|
|
|
|
EXTRACT_16BITS(&gabn->naddrs)));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printname(ndo, l, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
|
|
|
|
/* aliases */
|
2002-12-11 15:13:49 +08:00
|
|
|
na = EXTRACT_16BITS(&gabn->naliases);
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < na; i++) {
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printnamelen(ndo, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* addrs */
|
2002-12-11 15:13:49 +08:00
|
|
|
na = EXTRACT_16BITS(&gabn->naddrs);
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < na; i++) {
|
2015-04-27 08:24:42 +08:00
|
|
|
advance = lwres_printaddr(ndo, (const lwres_addr_t *)s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETNAMEBYADDR:
|
2015-04-27 08:24:42 +08:00
|
|
|
gnba = (const lwres_gnbaresponse_t *)(np + 1);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(gnba->realnamelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
/* XXX gnba points to packed struct */
|
|
|
|
s = (const char *)&gnba->realnamelen +
|
|
|
|
sizeof(gnba->realnamelen);
|
2002-12-11 15:13:49 +08:00
|
|
|
l = EXTRACT_16BITS(&gnba->realnamelen);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " flags:0x%x",
|
|
|
|
EXTRACT_32BITS(&gnba->flags)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %u", EXTRACT_16BITS(&gnba->naliases)));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printname(ndo, l, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
|
|
|
|
/* aliases */
|
2002-12-11 15:13:49 +08:00
|
|
|
na = EXTRACT_16BITS(&gnba->naliases);
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < na; i++) {
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printnamelen(ndo, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETRDATABYNAME:
|
|
|
|
/* XXX no trace, not tested */
|
2015-04-27 08:24:42 +08:00
|
|
|
grbn = (const lwres_grbnresponse_t *)(np + 1);
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_TCHECK(grbn->nsigs);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
|
|
|
ND_PRINT((ndo, " flags:0x%x",
|
|
|
|
EXTRACT_32BITS(&grbn->flags)));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %s", tok2str(ns_type2str, "Type%d",
|
|
|
|
EXTRACT_16BITS(&grbn->rdtype))));
|
2002-12-11 15:13:49 +08:00
|
|
|
if (EXTRACT_16BITS(&grbn->rdclass) != C_IN) {
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %s", tok2str(ns_class2str, "Class%d",
|
|
|
|
EXTRACT_16BITS(&grbn->rdclass))));
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
}
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " TTL "));
|
2014-04-03 21:40:30 +08:00
|
|
|
relts_print(ndo, EXTRACT_32BITS(&grbn->ttl));
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " %u/%u", EXTRACT_16BITS(&grbn->nrdatas),
|
|
|
|
EXTRACT_16BITS(&grbn->nsigs)));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* XXX grbn points to packed struct */
|
|
|
|
s = (const char *)&grbn->nsigs+ sizeof(grbn->nsigs);
|
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printnamelen(ndo, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
|
|
|
|
/* rdatas */
|
2002-12-11 15:13:49 +08:00
|
|
|
na = EXTRACT_16BITS(&grbn->nrdatas);
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < na; i++) {
|
|
|
|
/* XXX should decode resource data */
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printbinlen(ndo, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sigs */
|
2002-12-11 15:13:49 +08:00
|
|
|
na = EXTRACT_16BITS(&grbn->nsigs);
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < na; i++) {
|
|
|
|
/* XXX how should we print it? */
|
2014-04-01 23:42:33 +08:00
|
|
|
advance = lwres_printbinlen(ndo, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
unsupported++;
|
2001-01-29 17:18:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
tail:
|
2001-01-29 17:18:46 +08:00
|
|
|
/* length mismatch */
|
2002-12-11 15:13:49 +08:00
|
|
|
if (EXTRACT_32BITS(&np->length) != length) {
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, " [len: %u != %u]", EXTRACT_32BITS(&np->length),
|
|
|
|
length));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
2002-12-11 15:13:49 +08:00
|
|
|
if (!unsupported && s < (const char *)np + EXTRACT_32BITS(&np->length))
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, "[extra]"));
|
2001-01-29 17:18:46 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2014-04-01 23:42:33 +08:00
|
|
|
ND_PRINT((ndo, "[|lwres]"));
|
2001-01-29 17:18:46 +08:00
|
|
|
}
|