From d75247e5fc7eef60f0bf00635ee7bc0b808596fe Mon Sep 17 00:00:00 2001 From: Yuri Schaeffer Date: Thu, 24 Jan 2013 11:48:52 +0000 Subject: [PATCH] Test only if compiled with CLIENT_SUBNET. Fix assertion when running regular tests. git-svn-id: file:///svn/unbound/branches/edns-subnet@2819 be551aaa-1e26-0410-a405-d3ace91eadb9 --- services/mesh.c | 17 +++++++++++++++-- testcode/fake_event.c | 4 ++++ testcode/testbound.c | 12 +++++++++++- ...et_format_ip4.rpl => subnet_format_ip4.crpl} | 0 util/config_file.c | 4 ++++ 5 files changed, 34 insertions(+), 3 deletions(-) rename testdata/{subnet_format_ip4.rpl => subnet_format_ip4.crpl} (100%) diff --git a/services/mesh.c b/services/mesh.c index 1c0b0a1ff..f785e7a9b 100644 --- a/services/mesh.c +++ b/services/mesh.c @@ -376,15 +376,28 @@ void mesh_new_client(struct mesh_area* mesh, struct query_info* qinfo, edns->subnet_source_mask = MAX_CLIENT_SUBNET_IP4; edns->subnet_addr_fam = IANA_ADDRFAM_IP4; sinaddr = &((struct sockaddr_in*)ss)->sin_addr; +#ifndef unbound_testbound memcpy(edns->subnet_addr, (uint8_t *)sinaddr, INET_SIZE); +#else + /* sinaddr does not contain any valid data when running + * testbound. Provide a constant so we can do our tests */ + memcpy(edns->subnet_addr, (uint8_t *)[5,0,15,10], INET_SIZE); +#endif /* unbound_testbound */ edns->subnet_validdata = 1; - } + } #ifdef INET6 else { edns->subnet_source_mask = MAX_CLIENT_SUBNET_IP6; edns->subnet_addr_fam = IANA_ADDRFAM_IP6; sinaddr = &((struct sockaddr_in6*)ss)->sin6_addr; +#ifndef unbound_testbound memcpy(edns->subnet_addr, (uint8_t *)sinaddr, INET6_SIZE); +#else + /* sinaddr does not contain any valid data when running + * testbound. Provide a constant so we can do our tests */ + memcpy(edns->subnet_addr, (uint8_t *)[5,0,15,10, 5,0,15,10, + 5,0,15,10, 5,0,15,10], INET6_SIZE); +#endif /* unbound_testbound */ edns->subnet_validdata = 1; } #else @@ -444,7 +457,7 @@ mesh_new_callback(struct mesh_area* mesh, struct query_info* qinfo, #ifdef UNBOUND_DEBUG n = #else - (void) + (void) #endif rbtree_insert(&mesh->all, &s->node); log_assert(n != NULL); diff --git a/testcode/fake_event.c b/testcode/fake_event.c index cd42b7406..f1636dd52 100644 --- a/testcode/fake_event.c +++ b/testcode/fake_event.c @@ -60,7 +60,9 @@ #include "testcode/ldns-testpkts.h" #include "util/log.h" #include "util/fptr_wlist.h" +#ifdef CLIENT_SUBNET #include "edns-subnet/edns-subnet.h" +#endif #include struct worker; struct daemon_remote; @@ -1106,6 +1108,8 @@ struct serviced_query* outnet_serviced_query(struct outside_network* outnet, memcpy(&edns, edns_out, sizeof(edns)); /* This tells our module we've appened the option*/ edns.subnet_sent = 1; + } else { + edns.subnet_validdata = 0; } #endif edns.edns_present = 1; diff --git a/testcode/testbound.c b/testcode/testbound.c index 6e88edf22..3fa22391b 100644 --- a/testcode/testbound.c +++ b/testcode/testbound.c @@ -71,6 +71,7 @@ testbound_usage() printf("-2 detect SHA256 support (exit code 0 or 1)\n"); printf("-g detect GOST support (exit code 0 or 1)\n"); printf("-e detect ECDSA support (exit code 0 or 1)\n"); + printf("-c detect CLIENT_SUBNET support (exit code 0 or 1)\n"); printf("-s testbound self-test - unit test of testbound parts.\n"); printf("-o str unbound commandline options separated by spaces.\n"); printf("Version %s\n", PACKAGE_VERSION); @@ -273,7 +274,7 @@ main(int argc, char* argv[]) pass_argc = 1; pass_argv[0] = "unbound"; add_opts("-d", &pass_argc, pass_argv); - while( (c=getopt(argc, argv, "2egho:p:s")) != -1) { + while( (c=getopt(argc, argv, "2cegho:p:s")) != -1) { switch(c) { case 's': free(pass_argv[1]); @@ -310,6 +311,15 @@ main(int argc, char* argv[]) #else printf("GOST not supported\n"); exit(1); +#endif + break; + case 'c': +#ifdef CLIENT_SUBNET + printf("CLIENT_SUBNET supported\n"); + exit(0); +#else + printf("CLIENT_SUBNET not supported\n"); + exit(1); #endif break; case 'p': diff --git a/testdata/subnet_format_ip4.rpl b/testdata/subnet_format_ip4.crpl similarity index 100% rename from testdata/subnet_format_ip4.rpl rename to testdata/subnet_format_ip4.crpl diff --git a/util/config_file.c b/util/config_file.c index cca2d8f59..c11070be4 100644 --- a/util/config_file.c +++ b/util/config_file.c @@ -218,7 +218,11 @@ config_create(void) if(!(cfg->control_cert_file = strdup(RUN_DIR"/unbound_control.pem"))) goto error_exit; +#if CLIENT_SUBNET + if(!(cfg->module_conf = strdup("subnetcache validator iterator"))) goto error_exit; +#else if(!(cfg->module_conf = strdup("validator iterator"))) goto error_exit; +#endif if(!(cfg->val_nsec3_key_iterations = strdup("1024 150 2048 500 4096 2500"))) goto error_exit; return cfg; -- 2.47.2