mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-22 13:33:56 +03:00
test-dns-packet: add framework to read and dump packets
Packets are stored in a simple format: <size> <packet-wire-format> <size> <packet-wire-format> ... Packets for some example domains are dumped, to test rr code for various record types. Currently: A AAAA CAA DNSKEY LOC MX NS NSEC OPENPGPKEY SOA SPF TXT The hashing code is executed, but results are not checked. Also build other tests in src/resolve only with --enable-resolve.
This commit is contained in:
parent
e18a3c7314
commit
6d99904f5a
1
.gitignore
vendored
1
.gitignore
vendored
@ -184,6 +184,7 @@
|
|||||||
/test-dhcp-server
|
/test-dhcp-server
|
||||||
/test-dhcp6-client
|
/test-dhcp6-client
|
||||||
/test-dns-domain
|
/test-dns-domain
|
||||||
|
/test-dns-packet
|
||||||
/test-dnssec
|
/test-dnssec
|
||||||
/test-efi-disk.img
|
/test-efi-disk.img
|
||||||
/test-ellipsize
|
/test-ellipsize
|
||||||
|
91
Makefile.am
91
Makefile.am
@ -1501,6 +1501,7 @@ tests += \
|
|||||||
test-af-list \
|
test-af-list \
|
||||||
test-arphrd-list \
|
test-arphrd-list \
|
||||||
test-dns-domain \
|
test-dns-domain \
|
||||||
|
test-dns-packet \
|
||||||
test-resolve-tables \
|
test-resolve-tables \
|
||||||
test-install-root \
|
test-install-root \
|
||||||
test-rlimit-util \
|
test-rlimit-util \
|
||||||
@ -1666,16 +1667,6 @@ test_dns_domain_LDADD = \
|
|||||||
libsystemd-network.la \
|
libsystemd-network.la \
|
||||||
libshared.la
|
libshared.la
|
||||||
|
|
||||||
test_resolve_tables_SOURCES = \
|
|
||||||
src/resolve/test-resolve-tables.c \
|
|
||||||
src/shared/test-tables.h \
|
|
||||||
src/resolve/dns-type.c \
|
|
||||||
src/resolve/dns-type.h \
|
|
||||||
src/resolve/dns_type-from-name.h \
|
|
||||||
src/resolve/dns_type-to-name.h
|
|
||||||
|
|
||||||
test_resolve_tables_LDADD = \
|
|
||||||
libshared.la
|
|
||||||
|
|
||||||
if ENABLE_EFI
|
if ENABLE_EFI
|
||||||
manual_tests += \
|
manual_tests += \
|
||||||
@ -5166,6 +5157,20 @@ EXTRA_DIST += \
|
|||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
if ENABLE_RESOLVED
|
if ENABLE_RESOLVED
|
||||||
|
|
||||||
|
basic_dns_sources = \
|
||||||
|
src/resolve/resolved-dns-dnssec.c \
|
||||||
|
src/resolve/resolved-dns-dnssec.h \
|
||||||
|
src/resolve/resolved-dns-packet.c \
|
||||||
|
src/resolve/resolved-dns-packet.h \
|
||||||
|
src/resolve/resolved-dns-rr.c \
|
||||||
|
src/resolve/resolved-dns-rr.h \
|
||||||
|
src/resolve/resolved-dns-answer.c \
|
||||||
|
src/resolve/resolved-dns-answer.h \
|
||||||
|
src/resolve/resolved-dns-question.c \
|
||||||
|
src/resolve/resolved-dns-question.h \
|
||||||
|
src/resolve/dns-type.c \
|
||||||
|
src/resolve/dns-type.h
|
||||||
|
|
||||||
systemd_resolved_SOURCES = \
|
systemd_resolved_SOURCES = \
|
||||||
src/resolve/resolved.c \
|
src/resolve/resolved.c \
|
||||||
src/resolve/resolved-manager.c \
|
src/resolve/resolved-manager.c \
|
||||||
@ -5185,14 +5190,7 @@ systemd_resolved_SOURCES = \
|
|||||||
src/resolve/resolved-mdns.h \
|
src/resolve/resolved-mdns.h \
|
||||||
src/resolve/resolved-mdns.c \
|
src/resolve/resolved-mdns.c \
|
||||||
src/resolve/resolved-def.h \
|
src/resolve/resolved-def.h \
|
||||||
src/resolve/resolved-dns-rr.h \
|
$(basic_dns_sources) \
|
||||||
src/resolve/resolved-dns-rr.c \
|
|
||||||
src/resolve/resolved-dns-question.h \
|
|
||||||
src/resolve/resolved-dns-question.c \
|
|
||||||
src/resolve/resolved-dns-answer.h \
|
|
||||||
src/resolve/resolved-dns-answer.c \
|
|
||||||
src/resolve/resolved-dns-packet.h \
|
|
||||||
src/resolve/resolved-dns-packet.c \
|
|
||||||
src/resolve/resolved-dns-query.h \
|
src/resolve/resolved-dns-query.h \
|
||||||
src/resolve/resolved-dns-query.c \
|
src/resolve/resolved-dns-query.c \
|
||||||
src/resolve/resolved-dns-synthesize.h \
|
src/resolve/resolved-dns-synthesize.h \
|
||||||
@ -5211,14 +5209,10 @@ systemd_resolved_SOURCES = \
|
|||||||
src/resolve/resolved-dns-zone.c \
|
src/resolve/resolved-dns-zone.c \
|
||||||
src/resolve/resolved-dns-stream.h \
|
src/resolve/resolved-dns-stream.h \
|
||||||
src/resolve/resolved-dns-stream.c \
|
src/resolve/resolved-dns-stream.c \
|
||||||
src/resolve/resolved-dns-dnssec.h \
|
|
||||||
src/resolve/resolved-dns-dnssec.c \
|
|
||||||
src/resolve/resolved-dns-trust-anchor.h \
|
src/resolve/resolved-dns-trust-anchor.h \
|
||||||
src/resolve/resolved-dns-trust-anchor.c \
|
src/resolve/resolved-dns-trust-anchor.c \
|
||||||
src/resolve/resolved-etc-hosts.h \
|
src/resolve/resolved-etc-hosts.h \
|
||||||
src/resolve/resolved-etc-hosts.c \
|
src/resolve/resolved-etc-hosts.c \
|
||||||
src/resolve/dns-type.c \
|
|
||||||
src/resolve/dns-type.h \
|
|
||||||
src/shared/gcrypt-util.c \
|
src/shared/gcrypt-util.c \
|
||||||
src/shared/gcrypt-util.h
|
src/shared/gcrypt-util.h
|
||||||
|
|
||||||
@ -5280,18 +5274,7 @@ lib_LTLIBRARIES += \
|
|||||||
|
|
||||||
systemd_resolve_SOURCES = \
|
systemd_resolve_SOURCES = \
|
||||||
src/resolve/resolve-tool.c \
|
src/resolve/resolve-tool.c \
|
||||||
src/resolve/resolved-dns-dnssec.c \
|
$(basic_dns_sources) \
|
||||||
src/resolve/resolved-dns-dnssec.h \
|
|
||||||
src/resolve/resolved-dns-packet.c \
|
|
||||||
src/resolve/resolved-dns-packet.h \
|
|
||||||
src/resolve/resolved-dns-rr.c \
|
|
||||||
src/resolve/resolved-dns-rr.h \
|
|
||||||
src/resolve/resolved-dns-answer.c \
|
|
||||||
src/resolve/resolved-dns-answer.h \
|
|
||||||
src/resolve/resolved-dns-question.c \
|
|
||||||
src/resolve/resolved-dns-question.h \
|
|
||||||
src/resolve/dns-type.c \
|
|
||||||
src/resolve/dns-type.h \
|
|
||||||
src/shared/gcrypt-util.c \
|
src/shared/gcrypt-util.c \
|
||||||
src/shared/gcrypt-util.h
|
src/shared/gcrypt-util.h
|
||||||
|
|
||||||
@ -5312,20 +5295,36 @@ tests += \
|
|||||||
manual_tests += \
|
manual_tests += \
|
||||||
test-dnssec-complex
|
test-dnssec-complex
|
||||||
|
|
||||||
|
test_resolve_tables_SOURCES = \
|
||||||
|
src/resolve/test-resolve-tables.c \
|
||||||
|
src/resolve/dns_type-from-name.h \
|
||||||
|
src/resolve/dns_type-to-name.h \
|
||||||
|
$(basic_dns_sources) \
|
||||||
|
src/shared/test-tables.h
|
||||||
|
|
||||||
|
test_resolve_tables_LDADD = \
|
||||||
|
libshared.la
|
||||||
|
|
||||||
|
test_dns_packet_SOURCES = \
|
||||||
|
src/resolve/test-dns-packet.c \
|
||||||
|
$(basic_dns_sources)
|
||||||
|
|
||||||
|
test_dns_packet_LDADD = \
|
||||||
|
libshared.la
|
||||||
|
|
||||||
|
EXTRA_DIST += \
|
||||||
|
src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts \
|
||||||
|
src/resolve/test-data/fedoraproject.org.pkts \
|
||||||
|
src/resolve/test-data/gandi.net.pkts \
|
||||||
|
src/resolve/test-data/google.com.pkts \
|
||||||
|
src/resolve/test-data/root.pkts \
|
||||||
|
src/resolve/test-data/sw1a1aa-sw1a2aa-sw1a2ab-sw1a2ac.find.me.uk.pkts \
|
||||||
|
src/resolve/test-data/teamits.com.pkts \
|
||||||
|
src/resolve/test-data/zbyszek@fedoraproject.org.pkts
|
||||||
|
|
||||||
test_dnssec_SOURCES = \
|
test_dnssec_SOURCES = \
|
||||||
src/resolve/test-dnssec.c \
|
src/resolve/test-dnssec.c \
|
||||||
src/resolve/resolved-dns-packet.c \
|
$(basic_dns_sources)
|
||||||
src/resolve/resolved-dns-packet.h \
|
|
||||||
src/resolve/resolved-dns-rr.c \
|
|
||||||
src/resolve/resolved-dns-rr.h \
|
|
||||||
src/resolve/resolved-dns-answer.c \
|
|
||||||
src/resolve/resolved-dns-answer.h \
|
|
||||||
src/resolve/resolved-dns-question.c \
|
|
||||||
src/resolve/resolved-dns-question.h \
|
|
||||||
src/resolve/resolved-dns-dnssec.c \
|
|
||||||
src/resolve/resolved-dns-dnssec.h \
|
|
||||||
src/resolve/dns-type.c \
|
|
||||||
src/resolve/dns-type.h
|
|
||||||
|
|
||||||
test_dnssec_LDADD = \
|
test_dnssec_LDADD = \
|
||||||
libshared.la
|
libshared.la
|
||||||
|
@ -1302,7 +1302,7 @@ int dns_resource_record_is_synthetic(DnsResourceRecord *rr) {
|
|||||||
return !r;
|
return !r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dns_resource_record_hash_func(const void *i, struct siphash *state) {
|
void dns_resource_record_hash_func(const void *i, struct siphash *state) {
|
||||||
const DnsResourceRecord *rr = i;
|
const DnsResourceRecord *rr = i;
|
||||||
|
|
||||||
assert(rr);
|
assert(rr);
|
||||||
|
@ -325,6 +325,8 @@ int dns_resource_record_is_synthetic(DnsResourceRecord *rr);
|
|||||||
DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
|
DnsTxtItem *dns_txt_item_free_all(DnsTxtItem *i);
|
||||||
bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
|
bool dns_txt_item_equal(DnsTxtItem *a, DnsTxtItem *b);
|
||||||
|
|
||||||
|
void dns_resource_record_hash_func(const void *i, struct siphash *state);
|
||||||
|
|
||||||
extern const struct hash_ops dns_resource_key_hash_ops;
|
extern const struct hash_ops dns_resource_key_hash_ops;
|
||||||
extern const struct hash_ops dns_resource_record_hash_ops;
|
extern const struct hash_ops dns_resource_record_hash_ops;
|
||||||
|
|
||||||
|
BIN
src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts
Normal file
BIN
src/resolve/test-data/_openpgpkey.fedoraproject.org.pkts
Normal file
Binary file not shown.
BIN
src/resolve/test-data/fedoraproject.org.pkts
Normal file
BIN
src/resolve/test-data/fedoraproject.org.pkts
Normal file
Binary file not shown.
BIN
src/resolve/test-data/gandi.net.pkts
Normal file
BIN
src/resolve/test-data/gandi.net.pkts
Normal file
Binary file not shown.
BIN
src/resolve/test-data/google.com.pkts
Normal file
BIN
src/resolve/test-data/google.com.pkts
Normal file
Binary file not shown.
BIN
src/resolve/test-data/root.pkts
Normal file
BIN
src/resolve/test-data/root.pkts
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/resolve/test-data/teamits.com.pkts
Normal file
BIN
src/resolve/test-data/teamits.com.pkts
Normal file
Binary file not shown.
BIN
src/resolve/test-data/zbyszek@fedoraproject.org.pkts
Normal file
BIN
src/resolve/test-data/zbyszek@fedoraproject.org.pkts
Normal file
Binary file not shown.
100
src/resolve/test-dns-packet.c
Normal file
100
src/resolve/test-dns-packet.c
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
/***
|
||||||
|
This file is part of systemd
|
||||||
|
|
||||||
|
Copyright 2016 Zbigniew Jędrzejewski-Szmek
|
||||||
|
|
||||||
|
systemd is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU Lesser General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
systemd is distributed in the hope that it will be useful, but
|
||||||
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#include <net/if.h>
|
||||||
|
|
||||||
|
#include "alloc-util.h"
|
||||||
|
#include "fileio.h"
|
||||||
|
#include "macro.h"
|
||||||
|
#include "log.h"
|
||||||
|
#include "resolved-dns-packet.h"
|
||||||
|
#include "resolved-dns-rr.h"
|
||||||
|
#include "string-util.h"
|
||||||
|
|
||||||
|
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,90,4b,fa,4c,fe,af,9d,d5,a1,d7,2e,8a,b1)
|
||||||
|
|
||||||
|
static uint64_t hash(DnsResourceRecord *rr) {
|
||||||
|
struct siphash state;
|
||||||
|
|
||||||
|
siphash24_init(&state, HASH_KEY.bytes);
|
||||||
|
dns_resource_record_hash_func(rr, &state);
|
||||||
|
return siphash24_finalize(&state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_packet_from_file(const char* filename, bool canonical) {
|
||||||
|
_cleanup_free_ char *data = NULL;
|
||||||
|
size_t data_size, packet_size, offset;
|
||||||
|
|
||||||
|
assert_se(read_full_file(filename, &data, &data_size) >= 0);
|
||||||
|
assert_se(data);
|
||||||
|
assert_se(data_size > 8);
|
||||||
|
|
||||||
|
log_info("============== %s %s==============", filename, canonical ? "canonical " : "");
|
||||||
|
|
||||||
|
for (offset = 0; offset < data_size; offset += 8 + packet_size) {
|
||||||
|
_cleanup_(dns_packet_unrefp) DnsPacket *p = NULL, *p2 = NULL;
|
||||||
|
_cleanup_(dns_resource_record_unrefp) DnsResourceRecord *rr = NULL, *rr2 = NULL;
|
||||||
|
const char *s, *s2;
|
||||||
|
uint64_t hash1, hash2;
|
||||||
|
|
||||||
|
packet_size = le64toh( *(uint64_t*)(data + offset) );
|
||||||
|
assert_se(packet_size > 0);
|
||||||
|
assert_se(offset + 8 + packet_size <= data_size);
|
||||||
|
|
||||||
|
assert_se(dns_packet_new(&p, DNS_PROTOCOL_DNS, 0) >= 0);
|
||||||
|
|
||||||
|
assert_se(dns_packet_append_blob(p, data + offset + 8, packet_size, NULL) >= 0);
|
||||||
|
assert_se(dns_packet_read_rr(p, &rr, NULL, NULL) >= 0);
|
||||||
|
|
||||||
|
s = dns_resource_record_to_string(rr);
|
||||||
|
assert_se(s);
|
||||||
|
puts(s);
|
||||||
|
|
||||||
|
hash1 = hash(rr);
|
||||||
|
|
||||||
|
assert_se(dns_resource_record_to_wire_format(rr, canonical) >= 0);
|
||||||
|
|
||||||
|
assert_se(dns_packet_new(&p2, DNS_PROTOCOL_DNS, 0) >= 0);
|
||||||
|
assert_se(dns_packet_append_blob(p2, rr->wire_format, rr->wire_format_size, NULL) >= 0);
|
||||||
|
assert_se(dns_packet_read_rr(p2, &rr2, NULL, NULL) >= 0);
|
||||||
|
|
||||||
|
s2 = dns_resource_record_to_string(rr);
|
||||||
|
assert_se(s2);
|
||||||
|
assert_se(streq(s, s2));
|
||||||
|
|
||||||
|
hash2 = hash(rr);
|
||||||
|
assert_se(hash1 == hash2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
int i;
|
||||||
|
|
||||||
|
log_parse_environment();
|
||||||
|
|
||||||
|
for (i = 1; i < argc; i++) {
|
||||||
|
test_packet_from_file(argv[i], false);
|
||||||
|
puts("");
|
||||||
|
test_packet_from_file(argv[i], true);
|
||||||
|
if (i + 1 < argc)
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user