From ca22af89996483efd820de0084c964fc336ee7c1 Mon Sep 17 00:00:00 2001 From: Thomas Markwalder Date: Mon, 19 Jun 2017 14:44:29 -0400 Subject: [master] Optimized if and when DNS client context and ports are initted Merges in rt45290. --- omapip/isclib.c | 80 ++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 29 deletions(-) (limited to 'omapip') diff --git a/omapip/isclib.c b/omapip/isclib.c index 781db848..3c9c3590 100644 --- a/omapip/isclib.c +++ b/omapip/isclib.c @@ -1,5 +1,5 @@ /* - * Copyright(c) 2009-2010,2013-2014 by Internet Systems Consortium, Inc.("ISC") + * Copyright(c) 2009-2017 by Internet Systems Consortium, Inc.("ISC") * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -226,39 +226,24 @@ dhcp_context_create(int flags, #if defined (NSUPDATE) if ((flags & DHCP_CONTEXT_POST_DB) != 0) { - isc_sockaddr_t localaddr4, *localaddr4_ptr = NULL; - isc_sockaddr_t localaddr6, *localaddr6_ptr = NULL; + /* Setting addresses only. + * All real work will be done later on if needed to avoid + * listening on ddns port if client/server was compiled with + * ddns support but not using it. */ if (local4 != NULL) { - isc_sockaddr_fromin(&localaddr4, local4, 0); - localaddr4_ptr = &localaddr4; + dhcp_gbl_ctx.use_local4 = 1; + isc_sockaddr_fromin(&dhcp_gbl_ctx.local4_sockaddr, + local4, 0); } + if (local6 != NULL) { - isc_sockaddr_fromin6(&localaddr6, local6, 0); - localaddr6_ptr = &localaddr6; + dhcp_gbl_ctx.use_local6 = 1; + isc_sockaddr_fromin6(&dhcp_gbl_ctx.local6_sockaddr, + local6, 0); } - result = dns_client_createx2(dhcp_gbl_ctx.mctx, - dhcp_gbl_ctx.actx, - dhcp_gbl_ctx.taskmgr, - dhcp_gbl_ctx.socketmgr, - dhcp_gbl_ctx.timermgr, - 0, - &dhcp_gbl_ctx.dnsclient, - localaddr4_ptr, - localaddr6_ptr); - if (result != ISC_R_SUCCESS) - goto cleanup; - - /* - * If we can't set up the servers we may not be able to - * do DDNS but we should continue to try and perform - * our basic functions and let the user sort it out. - */ - result = dhcp_dns_client_setservers(); - if (result != ISC_R_SUCCESS) { - log_error("Unable to set resolver from resolv.conf; " - "startup continuing but DDNS support " - "may be affected"); + if (!(flags & DHCP_DNS_CLIENT_LAZY_INIT)) { + result = dns_client_init(); } } #endif @@ -365,3 +350,40 @@ void dhcp_signal_handler(int signal) { (void) isc_app_ctxsuspend(ctx); } } + +isc_result_t dns_client_init() { + isc_result_t result; + if (dhcp_gbl_ctx.dnsclient == NULL) { + result = dns_client_createx2(dhcp_gbl_ctx.mctx, + dhcp_gbl_ctx.actx, + dhcp_gbl_ctx.taskmgr, + dhcp_gbl_ctx.socketmgr, + dhcp_gbl_ctx.timermgr, + 0, + &dhcp_gbl_ctx.dnsclient, + (dhcp_gbl_ctx.use_local4 ? + &dhcp_gbl_ctx.local4_sockaddr + : NULL), + (dhcp_gbl_ctx.use_local6 ? + &dhcp_gbl_ctx.local6_sockaddr + : NULL)); + + if (result != ISC_R_SUCCESS) { + log_error("Unable to create DNS client context:" + " result: %d", result); + return result; + } + + /* If we can't set up the servers we may not be able to + * do DDNS but we should continue to try and perform + * our basic functions and let the user sort it out. */ + result = dhcp_dns_client_setservers(); + if (result != ISC_R_SUCCESS) { + log_error("Unable to set resolver from resolv.conf; " + "startup continuing but DDNS support " + "may be affected: result %d", result); + } + } + + return ISC_R_SUCCESS; +} -- cgit v1.2.1