Skip to content

Commit

Permalink
DNS/DHCP: Add DHCP option 119 parsing
Browse files Browse the repository at this point in the history
Also fix some minor bugs in dhcp6 and hncp handling
of domain names

Closes the-tcpdump-group#400
  • Loading branch information
fenner committed Oct 2, 2020
1 parent 5ba8290 commit 27632e1
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 32 deletions.
1 change: 1 addition & 0 deletions netdissect.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ extern void nfsreply_print(netdissect_options *, const u_char *, u_int, const u_
extern void nfsreply_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern void nfsreq_noaddr_print(netdissect_options *, const u_char *, u_int, const u_char *);
extern const u_char *fqdn_print(netdissect_options *, const u_char *, const u_char *);
extern const u_char *fqdn_print2(netdissect_options *, const u_char *, const u_char *, const u_char *);
extern void domain_print(netdissect_options *, const u_char *, u_int, int, int);
extern void nsh_print(netdissect_options *, const u_char *, u_int);
extern void ntp_print(netdissect_options *, const u_char *, u_int);
Expand Down
17 changes: 17 additions & 0 deletions print-bootp.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ struct bootp {
#define TAG_NETINFO_PARENT ((uint8_t) 112)
#define TAG_NETINFO_PARENT_TAG ((uint8_t) 113)
#define TAG_URL ((uint8_t) 114)
/* RFC 3397 */
#define TAG_DOMAIN_SEARCH ((uint8_t) 119)
#define TAG_MUDURL ((uint8_t) 161)

/* DHCP Message types (values for TAG_DHCP_MESSAGE option) */
Expand Down Expand Up @@ -514,6 +516,7 @@ static const struct tok tag2str[] = {
{ TAG_NETINFO_PARENT, "iNI" },
{ TAG_NETINFO_PARENT_TAG, "aNITAG" },
{ TAG_URL, "aURL" },
{ TAG_DOMAIN_SEARCH, "$Domain-Search" },
{ TAG_MUDURL, "aMUD-URL" },
{ 0, NULL }
};
Expand Down Expand Up @@ -989,6 +992,20 @@ rfc1048_print(netdissect_options *ndo,
break;
}

case TAG_DOMAIN_SEARCH:
{
const u_char *np = bp;
const u_char *ep = bp + len;
while ( np && np < ep ) {
np = fqdn_print2(ndo, np, bp, ep);
if ( np && np < ep ) {
ND_PRINT( " " );
}
}
bp += len;
len = 0;
break;
}
default:
ND_PRINT("[unknown special tag %u, size %u]",
tag, len);
Expand Down
2 changes: 1 addition & 1 deletion print-dhcp6.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ dhcp6opt_print(netdissect_options *ndo,
tp = (const u_char *)(dh6o + 1);
while (tp < cp + sizeof(*dh6o) + optlen) {
ND_PRINT(" ");
if ((tp = fqdn_print(ndo, tp, cp + sizeof(*dh6o) + optlen)) == NULL)
if ((tp = fqdn_print2(ndo, tp, NULL, cp + sizeof(*dh6o) + optlen)) == NULL)
goto trunc;
}
ND_PRINT(")");
Expand Down
29 changes: 23 additions & 6 deletions print-domain.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ labellen(netdissect_options *ndo,
return(i);
}

/* print a <domain-name> */
/* print a <domain-name> with an explicit end-pointer */
const u_char *
fqdn_print(netdissect_options *ndo,
const u_char *cp, const u_char *bp)
fqdn_print2(netdissect_options *ndo,
const u_char *cp, const u_char *bp,
const u_char *ep)
{
u_int i, l;
const u_char *rp = NULL;
Expand All @@ -170,7 +171,15 @@ fqdn_print(netdissect_options *ndo,
return(NULL);
if (!ND_TTEST_1(cp))
return(NULL);
max_offset = (u_int)(cp - bp);
if (bp) {
max_offset = (u_int)(cp - bp);
} else {
/*
* compression not supported in
* this context (e.g., DHCP6)
*/
max_offset = 0;
}
i = GET_U_1(cp);
cp++;
if ((i & INDIR_MASK) != INDIR_MASK) {
Expand All @@ -179,7 +188,7 @@ fqdn_print(netdissect_options *ndo,
}

if (i != 0)
while (i && cp < ndo->ndo_snapend) {
while (i && cp < ep) {
if ((i & INDIR_MASK) == INDIR_MASK) {
if (!compress) {
rp = cp + 1;
Expand Down Expand Up @@ -225,7 +234,7 @@ fqdn_print(netdissect_options *ndo,
return(NULL);
}
} else {
if (nd_printn(ndo, cp, l, ndo->ndo_snapend))
if (nd_printn(ndo, cp, l, ep))
return(NULL);
}

Expand All @@ -245,6 +254,14 @@ fqdn_print(netdissect_options *ndo,
return (rp);
}

/* print a <domain-name> */
const u_char *
fqdn_print(netdissect_options *ndo,
const u_char *cp, const u_char *bp)
{
return fqdn_print2(ndo, cp, bp, ndo->ndo_snapend);
}

/* print a <character-string> */
static const u_char *
ns_cprint(netdissect_options *ndo,
Expand Down
2 changes: 1 addition & 1 deletion print-hncp.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ dhcpv4_print(netdissect_options *ndo,
const u_char *tp = value;
while (tp < value + optlen) {
ND_PRINT(" ");
if ((tp = fqdn_print(ndo, tp, value + optlen)) == NULL)
if ((tp = fqdn_print2(ndo, tp, value, value + optlen)) == NULL)
return -1;
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/TESTLIST
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ dhcpv6-ntp-server dhcpv6-ntp-server.pcap dhcpv6-ntp-server.out -v
dhcpv6-sip-server-d dhcpv6-sip-server-d.pcap dhcpv6-sip-server-d.out -v
dhcpv6-domain-list dhcpv6-domain-list.pcap dhcpv6-domain-list.out -v
dhcpv6-mud dhcpv6-mud.pcap dhcpv6-mud.out -vv
dhcp-option119 dhcp-option119.pcap dhcp-option119.out -vv

# ZeroMQ/PGM tests
# ZMTP/1.0 over TCP
Expand Down
32 changes: 16 additions & 16 deletions tests/dcb_ets.out
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
3 04:02:58.010903 LLDP, length 135
Expand Down Expand Up @@ -75,7 +75,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
5 04:03:14.455118 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
Expand All @@ -87,7 +87,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
6 04:03:25.996519 IP6 (hlim 1, next-header Options (0) payload length: 76) :: > ff02::16: HBH (rtalert: 0x0000) (padn) [icmp6 sum ok] ICMP6, multicast listener report v2, 3 group record(s) [gaddr ff02::1:ff46:e884 to_ex { }] [gaddr ff02::2 to_ex { }] [gaddr ff02::202 to_ex { }]
Expand All @@ -100,7 +100,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
8 04:03:26.350998 IP6 (hlim 255, next-header ICMPv6 (58) payload length: 24) :: > ff02::1:ff46:e884: [icmp6 sum ok] ICMP6, neighbor solicitation, length 24, who has fe80::a00:27ff:fe46:e884
Expand Down Expand Up @@ -176,7 +176,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
17 04:03:35.582218 IP6 (hlim 1, next-header Options (0) payload length: 36) fe80::a00:27ff:fe42:ba59 > ff02::16: HBH (rtalert: 0x0000) (padn) [icmp6 sum ok] ICMP6, multicast listener report v2, 1 group record(s) [gaddr ff02::1:ff00:0 to_ex { }]
Expand All @@ -189,7 +189,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
19 04:03:58.207517 LLDP, length 135
Expand Down Expand Up @@ -256,7 +256,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
21 04:04:15.044685 IP6 (hlim 1, next-header Options (0) payload length: 76) :: > ff02::16: HBH (rtalert: 0x0000) (padn) [icmp6 sum ok] ICMP6, multicast listener report v2, 3 group record(s) [gaddr ff02::1:ff46:e884 to_ex { }] [gaddr ff02::2 to_ex { }] [gaddr ff02::202 to_ex { }]
Expand All @@ -269,7 +269,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
23 04:04:15.831624 IP6 (hlim 255, next-header ICMPv6 (58) payload length: 24) :: > ff02::1:ff46:e884: [icmp6 sum ok] ICMP6, neighbor solicitation, length 24, who has fe80::a00:27ff:fe46:e884
Expand All @@ -286,7 +286,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
27 04:04:18.745823 IP6 (hlim 1, next-header Options (0) payload length: 36) fe80::a00:27ff:fe46:e884 > ff02::16: HBH (rtalert: 0x0000) (padn) [icmp6 sum ok] ICMP6, multicast listener report v2, 1 group record(s) [gaddr ff02::1:ff00:0 to_ex { }]
Expand Down Expand Up @@ -409,7 +409,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
31 04:04:28.323921 LLDP, length 135
Expand Down Expand Up @@ -531,7 +531,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
34 04:04:51.930199 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
Expand All @@ -543,7 +543,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
35 04:04:53.780244 LLDP, length 135
Expand Down Expand Up @@ -777,7 +777,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
42 04:05:04.283851 IP6 (hlim 255, next-header ICMPv6 (58) payload length: 16) fe80::a00:27ff:fe46:e884 > ff02::2: [icmp6 sum ok] ICMP6, router solicitation, length 16
Expand All @@ -794,7 +794,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
46 04:05:20.296407 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
Expand All @@ -806,7 +806,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
47 04:05:23.875146 LLDP, length 135
Expand Down Expand Up @@ -1038,7 +1038,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
52 04:05:54.004592 LLDP, length 135
Expand Down
2 changes: 1 addition & 1 deletion tests/dcb_pfc.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
2 05:02:46.292912 LLDP, length 87
Expand Down
12 changes: 6 additions & 6 deletions tests/dcb_qcn.out
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
2 06:05:25.354704 IP (tos 0x10, ttl 128, id 0, offset 0, flags [none], proto UDP (17), length 328)
Expand All @@ -19,7 +19,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
3 06:05:30.544746 LLDP, length 86
Expand Down Expand Up @@ -93,7 +93,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
6 06:05:37.009281 LLDP, length 94
Expand Down Expand Up @@ -185,7 +185,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
9 06:05:56.022134 IP6 (hlim 1, next-header Options (0) payload length: 76) :: > ff02::16: HBH (rtalert: 0x0000) (padn) [icmp6 sum ok] ICMP6, multicast listener report v2, 3 group record(s) [gaddr ff02::1:ff46:e884 to_ex { }] [gaddr ff02::2 to_ex { }] [gaddr ff02::202 to_ex { }]
Expand All @@ -198,7 +198,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
11 06:05:56.498519 IP6 (hlim 255, next-header ICMPv6 (58) payload length: 24) :: > ff02::1:ff46:e884: [icmp6 sum ok] ICMP6, neighbor solicitation, length 24, who has fe80::a00:27ff:fe46:e884
Expand Down Expand Up @@ -277,7 +277,7 @@
Parameter-Request (55), length 17:
Subnet-Mask (1), BR (28), Time-Zone (2), Classless-Static-Route (121)
Domain-Name (15), Domain-Name-Server (6), Hostname (12), YD (40)
YS (41), NTP (42), MTU (26), Unknown (119)
YS (41), NTP (42), MTU (26), Domain-Search (119)
Default-Gateway (3), Classless-Static-Route (121), Classless-Static-Route-Microsoft (249), Unknown (252)
NTP (42)
17 06:06:04.106458 IP6 (hlim 1, next-header Options (0) payload length: 36) fe80::a00:27ff:fe46:e884 > ff02::16: HBH (rtalert: 0x0000) (padn) [icmp6 sum ok] ICMP6, multicast listener report v2, 1 group record(s) [gaddr ff02::1:ff00:0 to_ex { }]
Expand Down
2 changes: 1 addition & 1 deletion tests/dhcp-mud.out
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Subnet-Mask (1), Classless-Static-Route (121), Static-Route (33), Default-Gateway (3)
Domain-Name-Server (6), Hostname (12), Domain-Name (15), BR (28)
NTP (42), Lease-Time (51), Server-ID (54), RN (58)
RB (59), POSIX-TZ (100), TZ-Name (101), Unknown (119)
RB (59), POSIX-TZ (100), TZ-Name (101), Domain-Search (119)
2 12:28:41.318491 IP (tos 0x0, ttl 64, id 10305, offset 0, flags [DF], proto UDP (17), length 338)
62.12.173.114.67 > 62.12.173.121.67: [udp sum ok] BOOTP/DHCP, Reply, length 310, hops 1, xid 0x68c4847, Flags [none] (0x0000)
Client-IP 62.12.173.123
Expand Down
Loading

0 comments on commit 27632e1

Please sign in to comment.