From 7cbfebb762d0d9ba77699e2c15530278e0e4980e Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Tue, 13 Jun 2000 00:39:35 +0000 Subject: [PATCH] probe for ipv6 before using it --- bin/lwresd/main.c | 49 ++++++++++++++++++++++--------------- bin/tests/byname_test.c | 53 ++++++++++++++++++++++++++--------------- 2 files changed, 64 insertions(+), 38 deletions(-) diff --git a/bin/lwresd/main.c b/bin/lwresd/main.c index 31fc094e9c..a68e876e4c 100644 --- a/bin/lwresd/main.c +++ b/bin/lwresd/main.c @@ -88,7 +88,6 @@ create_view(isc_mem_t *mctx) { isc_result_t result; dns_db_t *rootdb; unsigned int attrs; - isc_sockaddr_t any4, any6; dns_dispatch_t *disp4 = NULL; dns_dispatch_t *disp6 = NULL; @@ -118,28 +117,40 @@ create_view(isc_mem_t *mctx) { * XXXMLG hardwired number of tasks. */ - isc_sockaddr_any(&any4); - isc_sockaddr_any6(&any6); - - attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; - result = dns_dispatch_getudp(dispatchmgr, sockmgr, - taskmgr, &any4, 512, 6, 1024, - 17, 19, attrs, attrs, &disp4); - if (result != ISC_R_SUCCESS) - goto out; - - attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP; - result = dns_dispatch_getudp(dispatchmgr, sockmgr, - taskmgr, &any6, 512, 6, 1024, - 17, 19, attrs, attrs, &disp6); - if (result != ISC_R_SUCCESS) - goto out; + if (isc_net_probeipv4() == ISC_R_SUCCESS) { + isc_sockaddr_t any4; + + isc_sockaddr_any(&any4); + attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; + result = dns_dispatch_getudp(dispatchmgr, sockmgr, + taskmgr, &any4, 512, 6, 1024, + 17, 19, attrs, attrs, &disp4); + if (result != ISC_R_SUCCESS) + goto out; + } + + if (isc_net_probeipv6() == ISC_R_SUCCESS) { + isc_sockaddr_t any6; + + isc_sockaddr_any6(&any6); + + attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP; + result = dns_dispatch_getudp(dispatchmgr, sockmgr, + taskmgr, &any6, 512, 6, 1024, + 17, 19, attrs, attrs, &disp6); + if (result != ISC_R_SUCCESS) + goto out; + } result = dns_view_createresolver(view, taskmgr, 16, sockmgr, timermgr, 0, dispatchmgr, disp4, disp6); - dns_dispatch_detach(&disp4); - dns_dispatch_detach(&disp6); + + if (disp4 != NULL) + dns_dispatch_detach(&disp4); + if (disp6 != NULL) + dns_dispatch_detach(&disp6); + if (result != ISC_R_SUCCESS) goto out; diff --git a/bin/tests/byname_test.c b/bin/tests/byname_test.c index 6577dc556f..3e2b444f7c 100644 --- a/bin/tests/byname_test.c +++ b/bin/tests/byname_test.c @@ -257,26 +257,39 @@ main(int argc, char *argv[]) { { unsigned int attrs; - isc_sockaddr_t any4, any6; dns_dispatch_t *disp4 = NULL; dns_dispatch_t *disp6 = NULL; - - isc_sockaddr_any(&any4); - isc_sockaddr_any6(&any6); - - attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; - RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, - taskmgr, &any4, 512, 6, 1024, - 17, 19, attrs, attrs, &disp4) - == ISC_R_SUCCESS); - INSIST(disp4 != NULL); - attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP; - RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, socketmgr, - taskmgr, &any6, 512, 6, 1024, - 17, 19, attrs, attrs, &disp6) - == ISC_R_SUCCESS); - INSIST(disp6 != NULL); + if (isc_net_probeipv4() == ISC_R_SUCCESS) { + isc_sockaddr_t any4; + isc_sockaddr_any(&any4); + + attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; + RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, + socketmgr, + taskmgr, &any4, + 512, 6, 1024, + 17, 19, attrs, + attrs, &disp4) + == ISC_R_SUCCESS); + INSIST(disp4 != NULL); + } + + if (isc_net_probeipv6() == ISC_R_SUCCESS) { + isc_sockaddr_t any6; + + isc_sockaddr_any6(&any6); + + attrs = DNS_DISPATCHATTR_IPV6 | DNS_DISPATCHATTR_UDP; + RUNTIME_CHECK(dns_dispatch_getudp(dispatchmgr, + socketmgr, + taskmgr, &any6, + 512, 6, 1024, + 17, 19, attrs, + attrs, &disp6) + == ISC_R_SUCCESS); + INSIST(disp6 != NULL); + } RUNTIME_CHECK(dns_view_createresolver(view, taskmgr, 10, socketmgr, @@ -285,8 +298,10 @@ main(int argc, char *argv[]) { disp4, disp6) == ISC_R_SUCCESS); - dns_dispatch_detach(&disp4); - dns_dispatch_detach(&disp6); + if (disp4 != NULL) + dns_dispatch_detach(&disp4); + if (disp6 != NULL) + dns_dispatch_detach(&disp6); } {