More extensive SRV order tests
Based largely on initial version by Nico.
This commit is contained in:
@@ -31,6 +31,7 @@ check_PROGRAMS = \
|
|||||||
getxxyyy-test \
|
getxxyyy-test \
|
||||||
hex-test \
|
hex-test \
|
||||||
test-readenv \
|
test-readenv \
|
||||||
|
resolve-test \
|
||||||
parse_bytes-test \
|
parse_bytes-test \
|
||||||
parse_reply-test \
|
parse_reply-test \
|
||||||
parse_time-test \
|
parse_time-test \
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1995 - 2004 Kungliga Tekniska Högskolan
|
* Copyright (c) 1995 - 2016 Kungliga Tekniska Högskolan
|
||||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
|
|
||||||
#include "roken.h"
|
#include "roken.h"
|
||||||
#include "getarg.h"
|
#include "getarg.h"
|
||||||
|
#include <assert.h>
|
||||||
#ifdef HAVE_ARPA_NAMESER_H
|
#ifdef HAVE_ARPA_NAMESER_H
|
||||||
#include <arpa/nameser.h>
|
#include <arpa/nameser.h>
|
||||||
#endif
|
#endif
|
||||||
@@ -44,11 +45,15 @@
|
|||||||
#endif
|
#endif
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
|
|
||||||
|
static int srv_rr_order = 1;
|
||||||
static int loop_integer = 1;
|
static int loop_integer = 1;
|
||||||
static int version_flag = 0;
|
static int version_flag = 0;
|
||||||
static int help_flag = 0;
|
static int help_flag = 0;
|
||||||
|
|
||||||
static struct getargs args[] = {
|
static struct getargs args[] = {
|
||||||
|
{"srv-rr-order", 0,
|
||||||
|
arg_negative_flag, &srv_rr_order,
|
||||||
|
"do not test SRV RR ordering", NULL },
|
||||||
{"loop", 0, arg_integer, &loop_integer,
|
{"loop", 0, arg_integer, &loop_integer,
|
||||||
"loop resolving", NULL },
|
"loop resolving", NULL },
|
||||||
{"version", 0, arg_flag, &version_flag,
|
{"version", 0, arg_flag, &version_flag,
|
||||||
@@ -67,6 +72,107 @@ usage (int ret)
|
|||||||
exit (ret);
|
exit (ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define NUMRRS 16
|
||||||
|
|
||||||
|
static
|
||||||
|
int
|
||||||
|
test_rk_dns_srv_order(size_t run)
|
||||||
|
{
|
||||||
|
struct rk_dns_reply reply;
|
||||||
|
struct rk_resource_record rrs[NUMRRS];
|
||||||
|
struct rk_resource_record *rr;
|
||||||
|
struct rk_srv_record srvs[NUMRRS];
|
||||||
|
size_t i, prio0;
|
||||||
|
int fail = 0;
|
||||||
|
|
||||||
|
(void) memset(&reply, 0, sizeof(reply));
|
||||||
|
(void) memset(srvs, 0, sizeof(srvs));
|
||||||
|
(void) memset(rrs, 0, sizeof(rrs));
|
||||||
|
|
||||||
|
/* Test with two equal weight zero SRV records */
|
||||||
|
rrs[0].type = rk_ns_t_srv;
|
||||||
|
rrs[0].u.srv = &srvs[0];
|
||||||
|
rrs[0].next = &rrs[1];
|
||||||
|
srvs[0].priority = 10;
|
||||||
|
srvs[0].weight = 0;
|
||||||
|
|
||||||
|
rrs[1].type = rk_ns_t_srv;
|
||||||
|
rrs[1].u.srv = &srvs[1];
|
||||||
|
rrs[1].next = NULL;
|
||||||
|
srvs[1].priority = 10;
|
||||||
|
srvs[1].weight = 0;
|
||||||
|
reply.head = &rrs[0];
|
||||||
|
|
||||||
|
rk_dns_srv_order(&reply);
|
||||||
|
assert(reply.head != NULL);
|
||||||
|
printf("%p %p\n", &rrs[0], rrs[0].next);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Test four priority groups with priority 1--5 and weigths 0--3 in the
|
||||||
|
* first two groups, and 1--4 in the last two groups. Test multiple zero
|
||||||
|
* weights, by further coercing the weight to zero if <= run/2.
|
||||||
|
*/
|
||||||
|
for (i = 0; i < NUMRRS; i++) {
|
||||||
|
rrs[i].type = rk_ns_t_srv;
|
||||||
|
rrs[i].u.srv = &srvs[i];
|
||||||
|
srvs[i].priority = 1 + i / 4;
|
||||||
|
srvs[i].weight = i % 4 + i / 8;
|
||||||
|
if (srvs[i].weight <= run/2)
|
||||||
|
srvs[i].weight = 0;
|
||||||
|
}
|
||||||
|
/* Shuffle the RRs */
|
||||||
|
for (i = 0; i < NUMRRS - 1; i++) {
|
||||||
|
struct rk_resource_record tmp;
|
||||||
|
size_t j = rk_random() % (NUMRRS - i);
|
||||||
|
|
||||||
|
if (j > 0) {
|
||||||
|
tmp = rrs[i+j];
|
||||||
|
rrs[i+j] = rrs[i];
|
||||||
|
rrs[i] = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < NUMRRS; i++)
|
||||||
|
rrs[i].next = &rrs[i + 1];
|
||||||
|
rrs[i - 1].next = NULL;
|
||||||
|
reply.head = &rrs[0];
|
||||||
|
|
||||||
|
for (i = 0, rr = reply.head; i < NUMRRS; i++) {
|
||||||
|
if (rr == NULL)
|
||||||
|
break;
|
||||||
|
printf("SRV RR order run %lu input: prio %lu weight %lu\n",
|
||||||
|
(unsigned long)run, (unsigned long)rr->u.srv->priority,
|
||||||
|
(unsigned long)rr->u.srv->weight);
|
||||||
|
rr = rr->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
rk_dns_srv_order(&reply);
|
||||||
|
assert(reply.head != NULL);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* After sorting, ensure monotone priority ordering with jumps by 1 at
|
||||||
|
* group boundaries.
|
||||||
|
*/
|
||||||
|
prio0 = 0;
|
||||||
|
for (i = 0, rr = reply.head; i < NUMRRS; i++) {
|
||||||
|
if (rr == NULL)
|
||||||
|
break;
|
||||||
|
if (rr->u.srv->priority < prio0 ||
|
||||||
|
(rr->u.srv->priority != prio0 &&
|
||||||
|
(i % 4 != 0 || rr->u.srv->priority > prio0 + 1))) {
|
||||||
|
printf("SRV RR order run %lu failed\n", run);
|
||||||
|
fail = 1;
|
||||||
|
}
|
||||||
|
prio0 = rr->u.srv->priority;
|
||||||
|
printf("SRV RR order run %lu output: prio %lu weight %lu\n",
|
||||||
|
(unsigned long)run, (unsigned long)rr->u.srv->priority,
|
||||||
|
(unsigned long)rr->u.srv->weight);
|
||||||
|
rr = rr->next;
|
||||||
|
}
|
||||||
|
assert(i == NUMRRS);
|
||||||
|
|
||||||
|
return fail;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@@ -75,6 +181,7 @@ main(int argc, char **argv)
|
|||||||
int optidx = 0, i, exit_code = 0;
|
int optidx = 0, i, exit_code = 0;
|
||||||
|
|
||||||
setprogname (argv[0]);
|
setprogname (argv[0]);
|
||||||
|
rk_random_init();
|
||||||
|
|
||||||
if (getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
|
if (getarg(args, sizeof(args) / sizeof(args[0]), argc, argv, &optidx))
|
||||||
usage(1);
|
usage(1);
|
||||||
@@ -90,6 +197,21 @@ main(int argc, char **argv)
|
|||||||
argc -= optidx;
|
argc -= optidx;
|
||||||
argv += optidx;
|
argv += optidx;
|
||||||
|
|
||||||
|
if (argc != 2 && argc != 0 && !srv_rr_order)
|
||||||
|
usage(1);
|
||||||
|
|
||||||
|
if (srv_rr_order) {
|
||||||
|
exit_code += test_rk_dns_srv_order(0);
|
||||||
|
exit_code += test_rk_dns_srv_order(1);
|
||||||
|
exit_code += test_rk_dns_srv_order(2);
|
||||||
|
exit_code += test_rk_dns_srv_order(3);
|
||||||
|
exit_code += test_rk_dns_srv_order(4);
|
||||||
|
exit_code += test_rk_dns_srv_order(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (srv_rr_order && argc == 0)
|
||||||
|
exit(exit_code ? 1 : 0);
|
||||||
|
|
||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage(1);
|
usage(1);
|
||||||
|
|
||||||
@@ -134,7 +256,9 @@ main(int argc, char **argv)
|
|||||||
struct rk_sig_record *sig = rr->u.sig;
|
struct rk_sig_record *sig = rr->u.sig;
|
||||||
const char *type_string = rk_dns_type_to_string (sig->type);
|
const char *type_string = rk_dns_type_to_string (sig->type);
|
||||||
|
|
||||||
printf ("type %u (%s), algorithm %u, labels %u, orig_ttl %u, sig_expiration %u, sig_inception %u, key_tag %u, signer %s\n",
|
printf("type %u (%s), algorithm %u, labels %u, orig_ttl %u, "
|
||||||
|
"sig_expiration %u, sig_inception %u, key_tag %u, "
|
||||||
|
"signer %s\n",
|
||||||
sig->type, type_string ? type_string : "",
|
sig->type, type_string ? type_string : "",
|
||||||
sig->algorithm, sig->labels, sig->orig_ttl,
|
sig->algorithm, sig->labels, sig->orig_ttl,
|
||||||
sig->sig_expiration, sig->sig_inception, sig->key_tag,
|
sig->sig_expiration, sig->sig_inception, sig->key_tag,
|
||||||
@@ -181,5 +305,5 @@ main(int argc, char **argv)
|
|||||||
rk_dns_free_data(r);
|
rk_dns_free_data(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
return exit_code;
|
return exit_code ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user