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.
|
|
|
|
*/
|
|
|
|
|
2016-08-14 21:42:19 +08:00
|
|
|
/* \summary: BIND9 Lightweight Resolver protocol printer */
|
|
|
|
|
2001-01-29 17:18:46 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2018-01-22 04:27:08 +08:00
|
|
|
#include <config.h>
|
2001-01-29 17:18:46 +08:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 22:59:49 +08:00
|
|
|
#include "netdissect-stdinc.h"
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
#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
|
|
|
|
2017-12-14 01:32:44 +08:00
|
|
|
#include "nameser.h"
|
|
|
|
|
2001-01-29 17:18:46 +08:00
|
|
|
/* BIND9 lib/lwres/include/lwres */
|
2018-01-24 01:29:04 +08:00
|
|
|
/*
|
|
|
|
* Use nd_uint16_t for lwres_uint16_t
|
|
|
|
* Use nd_uint32_t for lwres_uint32_t
|
|
|
|
*/
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
struct lwres_lwpacket {
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t length;
|
|
|
|
nd_uint16_t version;
|
|
|
|
nd_uint16_t pktflags;
|
|
|
|
nd_uint32_t serial;
|
|
|
|
nd_uint32_t opcode;
|
|
|
|
nd_uint32_t result;
|
|
|
|
nd_uint32_t recvlength;
|
|
|
|
nd_uint16_t authtype;
|
|
|
|
nd_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 */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_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 */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_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 {
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t family;
|
|
|
|
nd_uint16_t length;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* address folows */
|
2002-12-11 15:13:49 +08:00
|
|
|
};
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_ADDR_LEN 6
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2001-01-29 17:18:46 +08:00
|
|
|
typedef struct {
|
|
|
|
/* public */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t flags;
|
|
|
|
nd_uint32_t addrtypes;
|
|
|
|
nd_uint16_t namelen;
|
2001-01-29 17:18:46 +08:00
|
|
|
/* name follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_gabnrequest_t;
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_GABNREQUEST_LEN 10
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t flags;
|
|
|
|
nd_uint16_t naliases;
|
|
|
|
nd_uint16_t naddrs;
|
|
|
|
nd_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;
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_GABNRESPONSE_LEN 10
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get name by address
|
|
|
|
*/
|
|
|
|
#define LWRES_OPCODE_GETNAMEBYADDR 0x00010002U
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t flags;
|
2018-01-16 05:37:32 +08:00
|
|
|
/* addr follows */
|
2001-01-29 17:18:46 +08:00
|
|
|
} lwres_gnbarequest_t;
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_GNBAREQUEST_LEN 4
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t flags;
|
|
|
|
nd_uint16_t naliases;
|
|
|
|
nd_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;
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_GNBARESPONSE_LEN 8
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* get rdata by name
|
|
|
|
*/
|
|
|
|
#define LWRES_OPCODE_GETRDATABYNAME 0x00010003U
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t flags;
|
|
|
|
nd_uint16_t rdclass;
|
|
|
|
nd_uint16_t rdtype;
|
|
|
|
nd_uint16_t namelen;
|
2001-01-30 04:04:00 +08:00
|
|
|
/* name follows */
|
2002-12-11 15:13:49 +08:00
|
|
|
} lwres_grbnrequest_t;
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_GRBNREQUEST_LEN 10
|
2001-01-29 17:18:46 +08:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
/* public */
|
2018-01-24 01:29:04 +08:00
|
|
|
nd_uint32_t flags;
|
|
|
|
nd_uint16_t rdclass;
|
|
|
|
nd_uint16_t rdtype;
|
|
|
|
nd_uint32_t ttl;
|
|
|
|
nd_uint16_t nrdatas;
|
|
|
|
nd_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;
|
2018-01-16 05:37:32 +08:00
|
|
|
#define LWRES_GRBNRESPONSE_LEN 16
|
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,
|
2018-01-16 05:37:32 +08:00
|
|
|
size_t l, const u_char *p0)
|
2001-01-30 04:04:00 +08:00
|
|
|
{
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_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 */
|
2018-01-16 05:37:32 +08:00
|
|
|
if (p + l + 1 > ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ");
|
2018-01-29 22:17:15 +08:00
|
|
|
for (i = 0; i < l; i++) {
|
2018-05-02 02:02:42 +08:00
|
|
|
fn_print_char(ndo, EXTRACT_U_1(p));
|
2018-01-29 22:17:15 +08:00
|
|
|
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,
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_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;
|
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
if (p + 2 > ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
2017-11-23 06:54:09 +08:00
|
|
|
l = EXTRACT_BE_U_2(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,
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_char *p0)
|
2001-01-30 04:04:00 +08:00
|
|
|
{
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_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;
|
2018-01-16 05:37:32 +08:00
|
|
|
if (p + 2 > ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
2017-11-23 06:54:09 +08:00
|
|
|
l = EXTRACT_BE_U_2(p);
|
2018-01-16 05:37:32 +08:00
|
|
|
if (p + 2 + l > ndo->ndo_snapend)
|
2001-01-30 04:04:00 +08:00
|
|
|
goto trunc;
|
|
|
|
p += 2;
|
2018-01-29 22:17:15 +08:00
|
|
|
for (i = 0; i < l; i++) {
|
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(p));
|
|
|
|
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,
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_char *p0)
|
2001-01-29 17:18:46 +08:00
|
|
|
{
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_char *p;
|
|
|
|
const lwres_addr_t *ap;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint16_t l;
|
2001-01-30 04:04:00 +08:00
|
|
|
int i;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
p = p0;
|
|
|
|
ap = (const lwres_addr_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(ap->length);
|
2017-12-31 09:07:06 +08:00
|
|
|
l = EXTRACT_BE_U_2(ap->length);
|
2018-01-16 05:37:32 +08:00
|
|
|
p += LWRES_ADDR_LEN;
|
2017-12-11 19:46:51 +08:00
|
|
|
ND_TCHECK_LEN(p, l);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2017-12-31 09:07:06 +08:00
|
|
|
switch (EXTRACT_BE_U_4(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;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", ipaddr_string(ndo, p));
|
2018-01-31 09:29:33 +08:00
|
|
|
p += sizeof(nd_ipv4);
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case 2: /* IPv6 */
|
2004-03-24 09:54:29 +08:00
|
|
|
if (l < 16)
|
|
|
|
return -1;
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", ip6addr_string(ndo, p));
|
2018-01-31 09:29:33 +08:00
|
|
|
p += sizeof(nd_ipv6);
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
default:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u/", EXTRACT_BE_U_4(ap->family));
|
2018-01-29 22:17:15 +08:00
|
|
|
for (i = 0; i < l; i++) {
|
|
|
|
ND_PRINT("%02x", EXTRACT_U_1(p));
|
|
|
|
p++;
|
|
|
|
}
|
2001-01-29 17:18:46 +08:00
|
|
|
}
|
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
return p - p0;
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
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,
|
2017-12-14 02:17:47 +08:00
|
|
|
const u_char *bp, u_int length)
|
2001-01-29 17:18:46 +08:00
|
|
|
{
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_char *p;
|
2001-01-29 17:18:46 +08:00
|
|
|
const struct lwres_lwpacket *np;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t v;
|
2018-01-16 05:37:32 +08:00
|
|
|
const u_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
|
|
|
|
2018-03-14 23:54:17 +08:00
|
|
|
ndo->ndo_protocol = "lwres";
|
2001-01-29 17:18:46 +08:00
|
|
|
np = (const struct lwres_lwpacket *)bp;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(np->authlength);
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" lwres");
|
2017-12-31 09:07:06 +08:00
|
|
|
v = EXTRACT_BE_U_2(np->version);
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag || v != LWRES_LWPACKETVERSION_0)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" v%u", v);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (v != LWRES_LWPACKETVERSION_0) {
|
2018-01-16 05:37:32 +08:00
|
|
|
s = bp + EXTRACT_BE_U_4(np->length);
|
2001-01-30 04:04:00 +08:00
|
|
|
goto tail;
|
|
|
|
}
|
|
|
|
|
2017-12-31 09:07:06 +08:00
|
|
|
response = EXTRACT_BE_U_2(np->pktflags) & LWRES_LWPACKETFLAG_RESPONSE;
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2001-01-30 04:04:00 +08:00
|
|
|
/* opcode and pktflags */
|
2017-12-31 09:07:06 +08:00
|
|
|
v = EXTRACT_BE_U_4(np->opcode);
|
2018-01-16 05:37:32 +08:00
|
|
|
ND_PRINT(" %s%s", tok2str(opcode, "#0x%x", v), response ? "" : "?");
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* pktflags */
|
2017-12-31 09:07:06 +08:00
|
|
|
v = EXTRACT_BE_U_2(np->pktflags);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (v & ~LWRES_LWPACKETFLAG_RESPONSE)
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[0x%x]", v);
|
2001-01-29 17:18:46 +08:00
|
|
|
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 1) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" ("); /*)*/
|
|
|
|
ND_PRINT("serial:0x%x", EXTRACT_BE_U_4(np->serial));
|
|
|
|
ND_PRINT(" result:0x%x", EXTRACT_BE_U_4(np->result));
|
|
|
|
ND_PRINT(" recvlen:%u", EXTRACT_BE_U_4(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) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" authtype:0x%x", EXTRACT_BE_U_2(np->authtype));
|
|
|
|
ND_PRINT(" authlen:%u", EXTRACT_BE_U_2(np->authlength));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
2001-01-29 17:18:46 +08:00
|
|
|
/*(*/
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(")");
|
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;
|
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
p = (const u_char *)(np + 1);
|
2017-12-31 09:07:06 +08:00
|
|
|
switch (EXTRACT_BE_U_4(np->opcode)) {
|
2001-01-30 04:04:00 +08:00
|
|
|
case LWRES_OPCODE_NOOP:
|
2018-01-16 16:23:45 +08:00
|
|
|
s = p;
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETADDRSBYNAME:
|
2018-01-16 05:37:32 +08:00
|
|
|
gabn = (const lwres_gabnrequest_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(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) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" flags:0x%x",
|
|
|
|
EXTRACT_BE_U_4(gabn->flags));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2017-12-31 09:07:06 +08:00
|
|
|
v = EXTRACT_BE_U_4(gabn->addrtypes);
|
2001-01-30 04:04:00 +08:00
|
|
|
switch (v & (LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6)) {
|
|
|
|
case LWRES_ADDRTYPE_V4:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" IPv4");
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case LWRES_ADDRTYPE_V6:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" IPv6");
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6:
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" IPv4/6");
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (v & ~(LWRES_ADDRTYPE_V4 | LWRES_ADDRTYPE_V6))
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[0x%x]", v);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
s = p + LWRES_GABNREQUEST_LEN;
|
|
|
|
l = EXTRACT_BE_U_2(gabn->namelen);
|
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:
|
2018-01-16 05:37:32 +08:00
|
|
|
gnba = (const lwres_gnbarequest_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_4(gnba->flags);
|
2001-01-30 04:04:00 +08:00
|
|
|
|
|
|
|
/* BIND910: not used */
|
2014-04-01 23:42:33 +08:00
|
|
|
if (ndo->ndo_vflag > 2) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" flags:0x%x",
|
|
|
|
EXTRACT_BE_U_4(gnba->flags));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
s = p + LWRES_GNBAREQUEST_LEN;
|
|
|
|
advance = lwres_printaddr(ndo, 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_GETRDATABYNAME:
|
|
|
|
/* XXX no trace, not tested */
|
2018-01-16 05:37:32 +08:00
|
|
|
grbn = (const lwres_grbnrequest_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(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) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" flags:0x%x",
|
|
|
|
EXTRACT_BE_U_4(grbn->flags));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_type2str, "Type%u",
|
|
|
|
EXTRACT_BE_U_2(grbn->rdtype)));
|
2017-12-31 09:07:06 +08:00
|
|
|
if (EXTRACT_BE_U_2(grbn->rdclass) != C_IN) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_class2str, "Class%u",
|
|
|
|
EXTRACT_BE_U_2(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
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
s = p + LWRES_GRBNREQUEST_LEN;
|
2017-12-31 09:07:06 +08:00
|
|
|
l = EXTRACT_BE_U_2(grbn->namelen);
|
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:
|
2018-01-16 16:23:45 +08:00
|
|
|
s = p;
|
2001-01-30 04:04:00 +08:00
|
|
|
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;
|
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
p = (const u_char *)(np + 1);
|
2017-12-31 09:07:06 +08:00
|
|
|
switch (EXTRACT_BE_U_4(np->opcode)) {
|
2001-01-30 04:04:00 +08:00
|
|
|
case LWRES_OPCODE_NOOP:
|
2018-01-16 16:23:45 +08:00
|
|
|
s = p;
|
2001-01-30 04:04:00 +08:00
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETADDRSBYNAME:
|
2018-01-16 05:37:32 +08:00
|
|
|
gabn = (const lwres_gabnresponse_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(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) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" flags:0x%x",
|
|
|
|
EXTRACT_BE_U_4(gabn->flags));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u/%u", EXTRACT_BE_U_2(gabn->naliases),
|
|
|
|
EXTRACT_BE_U_2(gabn->naddrs));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
s = p + LWRES_GABNRESPONSE_LEN;
|
|
|
|
l = EXTRACT_BE_U_2(gabn->realnamelen);
|
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 */
|
2017-12-31 09:07:06 +08:00
|
|
|
na = EXTRACT_BE_U_2(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 */
|
2017-12-31 09:07:06 +08:00
|
|
|
na = EXTRACT_BE_U_2(gabn->naddrs);
|
2001-01-30 04:04:00 +08:00
|
|
|
for (i = 0; i < na; i++) {
|
2018-01-16 05:37:32 +08:00
|
|
|
advance = lwres_printaddr(ndo, s);
|
2001-01-30 04:04:00 +08:00
|
|
|
if (advance < 0)
|
|
|
|
goto trunc;
|
|
|
|
s += advance;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LWRES_OPCODE_GETNAMEBYADDR:
|
2018-01-16 05:37:32 +08:00
|
|
|
gnba = (const lwres_gnbaresponse_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(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) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" flags:0x%x",
|
|
|
|
EXTRACT_BE_U_4(gnba->flags));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u", EXTRACT_BE_U_2(gnba->naliases));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
s = p + LWRES_GNBARESPONSE_LEN;
|
|
|
|
l = EXTRACT_BE_U_2(gnba->realnamelen);
|
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 */
|
2017-12-31 09:07:06 +08:00
|
|
|
na = EXTRACT_BE_U_2(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 */
|
2018-01-16 05:37:32 +08:00
|
|
|
grbn = (const lwres_grbnresponse_t *)p;
|
2018-01-24 01:29:04 +08:00
|
|
|
ND_TCHECK_2(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) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" flags:0x%x",
|
|
|
|
EXTRACT_BE_U_4(grbn->flags));
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
|
|
|
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_type2str, "Type%u",
|
|
|
|
EXTRACT_BE_U_2(grbn->rdtype)));
|
2017-12-31 09:07:06 +08:00
|
|
|
if (EXTRACT_BE_U_2(grbn->rdclass) != C_IN) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %s", tok2str(ns_class2str, "Class%u",
|
|
|
|
EXTRACT_BE_U_2(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
|
|
|
}
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" TTL ");
|
2017-11-18 18:52:52 +08:00
|
|
|
unsigned_relts_print(ndo,
|
2017-12-31 09:07:06 +08:00
|
|
|
EXTRACT_BE_U_4(grbn->ttl));
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" %u/%u", EXTRACT_BE_U_2(grbn->nrdatas),
|
|
|
|
EXTRACT_BE_U_2(grbn->nsigs));
|
2001-01-30 04:04:00 +08:00
|
|
|
|
2018-01-16 05:37:32 +08:00
|
|
|
s = p + LWRES_GRBNRESPONSE_LEN;
|
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 */
|
2017-12-31 09:07:06 +08:00
|
|
|
na = EXTRACT_BE_U_2(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 */
|
2017-12-31 09:07:06 +08:00
|
|
|
na = EXTRACT_BE_U_2(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:
|
2018-01-16 16:23:45 +08:00
|
|
|
s = p;
|
2001-01-30 04:04:00 +08:00
|
|
|
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 */
|
2017-12-31 09:07:06 +08:00
|
|
|
if (EXTRACT_BE_U_4(np->length) != length) {
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT(" [len: %u != %u]", EXTRACT_BE_U_4(np->length),
|
|
|
|
length);
|
2001-01-30 04:04:00 +08:00
|
|
|
}
|
2018-01-16 05:37:32 +08:00
|
|
|
if (!unsupported && s < bp + EXTRACT_BE_U_4(np->length))
|
2018-01-07 18:47:30 +08:00
|
|
|
ND_PRINT("[extra]");
|
2001-01-29 17:18:46 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
trunc:
|
2018-05-11 00:05:56 +08:00
|
|
|
nd_print_trunc(ndo);
|
2001-01-29 17:18:46 +08:00
|
|
|
}
|