| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2018-02-23 09:53:12 +01:00
										 |  |  |  * Copyright (C) Internet Systems Consortium, Inc. ("ISC") | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2016-06-27 14:56:38 +10:00
										 |  |  |  * This Source Code Form is subject to the terms of the Mozilla Public | 
					
						
							|  |  |  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | 
					
						
							|  |  |  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | 
					
						
							| 
									
										
										
										
											2018-02-23 09:53:12 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * See the COPYRIGHT file distributed with this work for additional | 
					
						
							|  |  |  |  * information regarding copyright ownership. | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*! \file
 | 
					
						
							|  |  |  |  *  \note | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  |  * Notice to programmers:  Do not use this code as an example of how to | 
					
						
							|  |  |  |  * use the ISC library to perform DNS lookups.  Dig and Host both operate | 
					
						
							|  |  |  |  * on the request level, since they allow fine-tuning of output and are | 
					
						
							|  |  |  |  * intended as debugging tools.  As a result, they perform many of the | 
					
						
							|  |  |  |  * functions which could be better handled using the dns_resolver | 
					
						
							|  |  |  |  * functions in most applications. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | #include <config.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-15 19:05:30 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2000-07-06 01:02:42 +00:00
										 |  |  | #include <limits.h>
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | #ifdef HAVE_LOCALE_H
 | 
					
						
							|  |  |  | #include <locale.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | #ifdef WITH_LIBIDN2
 | 
					
						
							|  |  |  | #include <idn2.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #endif /* WITH_IDN_SUPPORT */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | #include <dns/byaddr.h>
 | 
					
						
							| 
									
										
										
										
											2000-10-11 17:44:18 +00:00
										 |  |  | #include <dns/fixedname.h>
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | #include <dns/log.h>
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | #include <dns/message.h>
 | 
					
						
							| 
									
										
										
										
											2000-05-30 22:27:27 +00:00
										 |  |  | #include <dns/name.h>
 | 
					
						
							| 
									
										
										
										
											2014-10-01 10:01:54 +10:00
										 |  |  | #include <dns/rcode.h>
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | #include <dns/rdata.h>
 | 
					
						
							|  |  |  | #include <dns/rdataclass.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-21 17:48:32 +00:00
										 |  |  | #include <dns/rdatalist.h>
 | 
					
						
							| 
									
										
										
										
											2000-05-08 14:38:29 +00:00
										 |  |  | #include <dns/rdataset.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-21 17:48:32 +00:00
										 |  |  | #include <dns/rdatastruct.h>
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | #include <dns/rdatatype.h>
 | 
					
						
							|  |  |  | #include <dns/result.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-06 00:43:17 +00:00
										 |  |  | #include <dns/tsig.h>
 | 
					
						
							| 
									
										
										
										
											2000-10-11 17:44:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-12 19:33:30 +00:00
										 |  |  | #include <dst/dst.h>
 | 
					
						
							| 
									
										
										
										
											2011-11-06 23:18:07 +00:00
										 |  |  | #include <dst/result.h>
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-21 17:48:32 +00:00
										 |  |  | #include <isc/app.h>
 | 
					
						
							|  |  |  | #include <isc/base64.h>
 | 
					
						
							| 
									
										
										
										
											2005-09-01 02:25:06 +00:00
										 |  |  | #include <isc/file.h>
 | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | #include <isc/hex.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-21 17:48:32 +00:00
										 |  |  | #include <isc/lang.h>
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | #include <isc/log.h>
 | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | #include <isc/netaddr.h>
 | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | #include <isc/netdb.h>
 | 
					
						
							| 
									
										
										
										
											2018-05-28 15:22:23 +02:00
										 |  |  | #include <isc/nonce.h>
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | #include <isc/parseint.h>
 | 
					
						
							| 
									
										
										
										
											2000-11-20 13:02:18 +00:00
										 |  |  | #include <isc/print.h>
 | 
					
						
							| 
									
										
										
										
											2004-04-08 01:21:16 +00:00
										 |  |  | #include <isc/random.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-23 20:57:19 +00:00
										 |  |  | #include <isc/result.h>
 | 
					
						
							| 
									
										
										
										
											2015-08-17 18:26:44 -07:00
										 |  |  | #include <isc/safe.h>
 | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | #include <isc/serial.h>
 | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | #include <isc/sockaddr.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-21 17:48:32 +00:00
										 |  |  | #include <isc/string.h>
 | 
					
						
							|  |  |  | #include <isc/task.h>
 | 
					
						
							|  |  |  | #include <isc/timer.h>
 | 
					
						
							|  |  |  | #include <isc/types.h>
 | 
					
						
							|  |  |  | #include <isc/util.h>
 | 
					
						
							| 
									
										
										
										
											2000-06-12 19:33:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 08:02:51 +10:00
										 |  |  | #include <pk11/site.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | #include <isccfg/namedconf.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | #include <irs/resconf.h>
 | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-14 22:08:38 +00:00
										 |  |  | #include <bind9/getaddresses.h>
 | 
					
						
							| 
									
										
										
										
											2001-01-18 22:21:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-14 22:08:38 +00:00
										 |  |  | #include <dig/dig.h>
 | 
					
						
							| 
									
										
										
										
											2001-01-18 22:21:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 15:24:37 +02:00
										 |  |  | #if HAVE_PKCS11
 | 
					
						
							| 
									
										
										
										
											2014-08-22 10:40:43 -07:00
										 |  |  | #include <pk11/result.h>
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-01-12 03:39:29 +00:00
										 |  |  | #if ! defined(NS_INADDRSZ)
 | 
					
						
							|  |  |  | #define NS_INADDRSZ	 4
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if ! defined(NS_IN6ADDRSZ)
 | 
					
						
							|  |  |  | #define NS_IN6ADDRSZ	16
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-04 03:03:21 +00:00
										 |  |  | dig_lookuplist_t lookup_list; | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | dig_serverlist_t server_list; | 
					
						
							| 
									
										
										
										
											2005-07-04 03:03:21 +00:00
										 |  |  | dig_searchlistlist_t search_list; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | isc_boolean_t | 
					
						
							| 
									
										
										
										
											2005-08-25 00:40:50 +00:00
										 |  |  | 	check_ra = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2000-11-21 21:35:32 +00:00
										 |  |  | 	have_ipv4 = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	have_ipv6 = ISC_FALSE, | 
					
						
							|  |  |  | 	specified_source = ISC_FALSE, | 
					
						
							|  |  |  | 	free_now = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	cancel_now = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	usesearch = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2005-08-25 00:17:46 +00:00
										 |  |  | 	showsearch = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2013-11-07 10:50:01 +11:00
										 |  |  | 	is_dst_up = ISC_FALSE, | 
					
						
							| 
									
										
										
										
											2014-04-17 17:04:51 -07:00
										 |  |  | 	keep_open = ISC_FALSE, | 
					
						
							|  |  |  | 	verbose = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-05-03 20:27:13 +00:00
										 |  |  | in_port_t port = 53; | 
					
						
							| 
									
										
										
										
											2000-07-10 17:25:59 +00:00
										 |  |  | unsigned int timeout = 0; | 
					
						
							| 
									
										
										
										
											2005-07-04 03:03:21 +00:00
										 |  |  | unsigned int extrabytes; | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | isc_mem_t *mctx = NULL; | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | isc_log_t *lctx = NULL; | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | isc_taskmgr_t *taskmgr = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-26 22:03:00 +00:00
										 |  |  | isc_task_t *global_task = NULL; | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | isc_timermgr_t *timermgr = NULL; | 
					
						
							|  |  |  | isc_socketmgr_t *socketmgr = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-19 17:54:04 +00:00
										 |  |  | isc_sockaddr_t bind_address; | 
					
						
							| 
									
										
										
										
											2000-06-08 21:18:24 +00:00
										 |  |  | isc_sockaddr_t bind_any; | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | int sendcount = 0; | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | int recvcount = 0; | 
					
						
							| 
									
										
										
										
											2000-05-24 23:39:30 +00:00
										 |  |  | int sockcount = 0; | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | int ndots = -1; | 
					
						
							| 
									
										
										
										
											2001-09-18 18:16:08 +00:00
										 |  |  | int tries = 3; | 
					
						
							| 
									
										
										
										
											2000-05-06 01:16:07 +00:00
										 |  |  | int lookup_counter = 0; | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | static char servercookie[256]; | 
					
						
							| 
									
										
										
										
											2015-04-06 23:13:35 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							|  |  |  | static void idn_initialize(void); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | static isc_result_t idn_locale_to_ace(const char *from, | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | 		char *to, | 
					
						
							|  |  |  | 		size_t tolen); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #endif /* WITH_IDN_SUPPORT */
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef WITH_IDN_OUT_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | static isc_result_t idn_ace_to_locale(const char *from, | 
					
						
							|  |  |  | 		char *to, | 
					
						
							|  |  |  | 		size_t tolen); | 
					
						
							|  |  |  | static isc_result_t output_filter(isc_buffer_t *buffer, | 
					
						
							|  |  |  | 		unsigned int used_org, | 
					
						
							|  |  |  | 		isc_boolean_t absolute); | 
					
						
							|  |  |  | #define MAXDLEN 256
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #endif /* WITH_IDN_OUT_SUPPORT */
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-07 10:50:01 +11:00
										 |  |  | isc_socket_t *keep = NULL; | 
					
						
							|  |  |  | isc_sockaddr_t keepaddr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  |  * Exit Codes: | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  |  *\li	0   Everything went well, including things like NXDOMAIN | 
					
						
							|  |  |  |  *\li	1   Usage error | 
					
						
							|  |  |  |  *\li	7   Got too many RR's or Names | 
					
						
							|  |  |  |  *\li	8   Couldn't open batch file | 
					
						
							|  |  |  |  *\li	9   No reply from server | 
					
						
							|  |  |  |  *\li	10  Internal error | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | int exitcode = 0; | 
					
						
							| 
									
										
										
										
											2002-09-26 11:17:06 +00:00
										 |  |  | int fatalexit = 0; | 
					
						
							| 
									
										
										
										
											2000-06-06 00:43:17 +00:00
										 |  |  | char keynametext[MXNAME]; | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | char keyfile[MXNAME] = ""; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | char keysecret[MXNAME] = ""; | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | unsigned char cookie_secret[33]; | 
					
						
							|  |  |  | unsigned char cookie[8]; | 
					
						
							| 
									
										
										
										
											2016-12-30 15:45:08 +11:00
										 |  |  | const dns_name_t *hmacname = NULL; | 
					
						
							| 
									
										
										
										
											2006-01-27 02:35:15 +00:00
										 |  |  | unsigned int digestbits = 0; | 
					
						
							| 
									
										
										
										
											2000-06-06 00:43:17 +00:00
										 |  |  | isc_buffer_t *namebuf = NULL; | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | dns_tsigkey_t *tsigkey = NULL; | 
					
						
							| 
									
										
										
										
											2000-06-06 18:49:06 +00:00
										 |  |  | isc_boolean_t validated = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-07-13 01:49:44 +00:00
										 |  |  | isc_mempool_t *commctx = NULL; | 
					
						
							| 
									
										
										
										
											2000-06-06 22:50:44 +00:00
										 |  |  | isc_boolean_t debugging = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | isc_boolean_t debugtiming = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-10-13 22:55:50 +00:00
										 |  |  | isc_boolean_t memdebugging = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | char *progname = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | isc_mutex_t lookup_lock; | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | dig_lookup_t *current_lookup = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | #define DIG_MAX_ADDRESSES 20
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  |  * Apply and clear locks at the event level in global task. | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  |  * Can I get rid of these using shutdown events?  XXX | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | #define LOCK_LOOKUP {\
 | 
					
						
							| 
									
										
										
										
											2000-12-11 19:24:30 +00:00
										 |  |  | 	debug("lock_lookup %s:%d", __FILE__, __LINE__);\ | 
					
						
							|  |  |  | 	check_result(isc_mutex_lock((&lookup_lock)), "isc_mutex_lock");\ | 
					
						
							|  |  |  | 	debug("success");\ | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | } | 
					
						
							|  |  |  | #define UNLOCK_LOOKUP {\
 | 
					
						
							| 
									
										
										
										
											2000-12-11 19:24:30 +00:00
										 |  |  | 	debug("unlock_lookup %s:%d", __FILE__, __LINE__);\ | 
					
						
							|  |  |  | 	check_result(isc_mutex_unlock((&lookup_lock)),\ | 
					
						
							|  |  |  | 		     "isc_mutex_unlock");\ | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-06-06 22:50:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | /* dynamic callbacks */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | isc_result_t | 
					
						
							|  |  |  | (*dighost_printmessage)(dig_query_t *query, dns_message_t *msg, | 
					
						
							|  |  |  | 	isc_boolean_t headers); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							| 
									
										
										
										
											2018-02-14 17:41:30 +11:00
										 |  |  | (*dighost_received)(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query); | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | (*dighost_trying)(char *frm, dig_lookup_t *lookup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | (*dighost_shutdown)(void); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* forward declarations */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | cancel_lookup(dig_lookup_t *lookup); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | recv_done(isc_task_t *task, isc_event_t *event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-01 00:49:02 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | send_udp(dig_query_t *query); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | connect_timeout(isc_task_t *task, isc_event_t *event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-15 01:26:14 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | launch_next_query(dig_query_t *query, isc_boolean_t include_question); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | static void | 
					
						
							|  |  |  | check_next_lookup(dig_lookup_t *lookup); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static isc_boolean_t | 
					
						
							|  |  |  | next_origin(dig_lookup_t *oldlookup); | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | static int | 
					
						
							|  |  |  | count_dots(char *string) { | 
					
						
							|  |  |  | 	char *s; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	int i = 0; | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	s = string; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	while (*s != '\0') { | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		if (*s == '.') | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		s++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return (i); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-04-26 19:36:40 +00:00
										 |  |  | hex_dump(isc_buffer_t *b) { | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 	unsigned int len, i; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	isc_region_t r; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-13 00:55:13 +00:00
										 |  |  | 	isc_buffer_usedregion(b, &r); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 17:41:30 +11:00
										 |  |  | 	printf("%u bytes\n", r.length); | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	for (len = 0; len < r.length; len++) { | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		printf("%02x ", r.base[len]); | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 		if (len % 16 == 15) { | 
					
						
							|  |  |  | 			fputs("         ", stdout); | 
					
						
							|  |  |  | 			for (i = len - 15; i <= len; i++) { | 
					
						
							|  |  |  | 				if (r.base[i] >= '!' && r.base[i] <= '}') | 
					
						
							|  |  |  | 					putchar(r.base[i]); | 
					
						
							| 
									
										
										
										
											2009-02-16 23:48:04 +00:00
										 |  |  | 				else | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 					putchar('.'); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 			printf("\n"); | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 	if (len % 16 != 0) { | 
					
						
							|  |  |  | 		for (i = len; (i % 16) != 0; i++) | 
					
						
							|  |  |  | 			fputs("   ", stdout); | 
					
						
							|  |  |  | 		fputs("         ", stdout); | 
					
						
							|  |  |  | 		for (i = ((len>>4)<<4); i < len; i++) { | 
					
						
							|  |  |  | 			if (r.base[i] >= '!' && r.base[i] <= '}') | 
					
						
							|  |  |  | 				putchar(r.base[i]); | 
					
						
							| 
									
										
										
										
											2009-02-16 23:48:04 +00:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 				putchar('.'); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		printf("\n"); | 
					
						
							| 
									
										
										
										
											2009-02-16 00:01:37 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  |  * Append 'len' bytes of 'text' at '*p', failing with | 
					
						
							|  |  |  |  * ISC_R_NOSPACE if that would advance p past 'end'. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static isc_result_t | 
					
						
							| 
									
										
										
										
											2017-07-04 11:51:36 +01:00
										 |  |  | append(const char *text, size_t len, char **p, char *end) { | 
					
						
							| 
									
										
										
										
											2017-07-04 12:12:11 +01:00
										 |  |  | 	if (*p + len > end) | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 		return (ISC_R_NOSPACE); | 
					
						
							| 
									
										
										
										
											2014-01-08 16:27:10 -08:00
										 |  |  | 	memmove(*p, text, len); | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	*p += len; | 
					
						
							|  |  |  | 	return (ISC_R_SUCCESS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static isc_result_t | 
					
						
							|  |  |  | reverse_octets(const char *in, char **p, char *end) { | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 	const char *dot = strchr(in, '.'); | 
					
						
							| 
									
										
										
										
											2017-07-04 11:51:36 +01:00
										 |  |  | 	size_t len; | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	if (dot != NULL) { | 
					
						
							|  |  |  | 		isc_result_t result; | 
					
						
							|  |  |  | 		result = reverse_octets(dot + 1, p, end); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			return (result); | 
					
						
							|  |  |  | 		result = append(".", 1, p, end); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			return (result); | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 		len = (int) (dot - in); | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 		len = (int) strlen(in); | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	return (append(in, len, p, end)); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | isc_result_t | 
					
						
							| 
									
										
										
										
											2003-07-25 04:02:54 +00:00
										 |  |  | get_reverse(char *reverse, size_t len, char *value, isc_boolean_t ip6_int, | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	    isc_boolean_t strict) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int r; | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	isc_netaddr_t addr; | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	addr.family = AF_INET6; | 
					
						
							| 
									
										
										
										
											2001-10-31 20:39:39 +00:00
										 |  |  | 	r = inet_pton(AF_INET6, value, &addr.type.in6); | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 	if (r > 0) { | 
					
						
							|  |  |  | 		/* This is a valid IPv6 address. */ | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | 		dns_fixedname_t fname; | 
					
						
							|  |  |  | 		dns_name_t *name; | 
					
						
							| 
									
										
										
										
											2002-08-27 04:53:43 +00:00
										 |  |  | 		unsigned int options = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-07-25 05:46:07 +00:00
										 |  |  | 		if (ip6_int) | 
					
						
							|  |  |  | 			options |= DNS_BYADDROPT_IPV6INT; | 
					
						
							| 
									
										
										
										
											2018-03-28 14:38:09 +02:00
										 |  |  | 		name = dns_fixedname_initname(&fname); | 
					
						
							| 
									
										
										
										
											2018-04-03 13:10:07 +02:00
										 |  |  | 		result = dns_byaddr_createptrname(&addr, options, name); | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			return (result); | 
					
						
							| 
									
										
										
										
											2013-12-04 12:47:23 +11:00
										 |  |  | 		dns_name_format(name, reverse, (unsigned int)len); | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 		return (ISC_R_SUCCESS); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Not a valid IPv6 address.  Assume IPv4. | 
					
						
							|  |  |  | 		 * If 'strict' is not set, construct the | 
					
						
							|  |  |  | 		 * in-addr.arpa name by blindly reversing | 
					
						
							|  |  |  | 		 * octets whether or not they look like integers, | 
					
						
							|  |  |  | 		 * so that this can be used for RFC2317 names | 
					
						
							|  |  |  | 		 * and such. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		char *p = reverse; | 
					
						
							| 
									
										
										
										
											2003-07-25 04:02:54 +00:00
										 |  |  | 		char *end = reverse + len; | 
					
						
							| 
									
										
										
										
											2002-11-12 23:08:27 +00:00
										 |  |  | 		if (strict && inet_pton(AF_INET, value, &addr.type.in) != 1) | 
					
						
							|  |  |  | 			return (DNS_R_BADDOTTEDQUAD); | 
					
						
							| 
									
										
										
										
											2001-08-29 18:57:28 +00:00
										 |  |  | 		result = reverse_octets(value, &p, end); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			return (result); | 
					
						
							|  |  |  | 		/* Append .in-addr.arpa. and a terminating NUL. */ | 
					
						
							|  |  |  | 		result = append(".in-addr.arpa.", 15, &p, end); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			return (result); | 
					
						
							|  |  |  | 		return (ISC_R_SUCCESS); | 
					
						
							| 
									
										
										
										
											2000-10-23 23:13:21 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | void (*dighost_pre_exit_hook)(void) = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if TARGET_OS_IPHONE
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | warn(const char *format, ...) { | 
					
						
							|  |  |  | 	va_list args; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fflush(stdout); | 
					
						
							|  |  |  | 	fprintf(stderr, ";; Warning: "); | 
					
						
							|  |  |  | 	va_start(args, format); | 
					
						
							|  |  |  | 	vfprintf(stderr, format, args); | 
					
						
							|  |  |  | 	va_end(args); | 
					
						
							|  |  |  | 	fprintf(stderr, "\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | warn(const char *format, ...) { | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	va_list args; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-17 21:46:33 +00:00
										 |  |  | 	fflush(stdout); | 
					
						
							| 
									
										
										
										
											2000-07-13 02:14:17 +00:00
										 |  |  | 	fprintf(stderr, "%s: ", progname); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	va_start(args, format); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	vfprintf(stderr, format, args); | 
					
						
							|  |  |  | 	va_end(args); | 
					
						
							|  |  |  | 	fprintf(stderr, "\n"); | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | digexit(void) { | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 	if (exitcode < 10) | 
					
						
							|  |  |  | 		exitcode = 10; | 
					
						
							| 
									
										
										
										
											2002-09-26 11:17:06 +00:00
										 |  |  | 	if (fatalexit != 0) | 
					
						
							|  |  |  | 		exitcode = fatalexit; | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | 	if (dighost_pre_exit_hook != NULL) { | 
					
						
							|  |  |  | 		dighost_pre_exit_hook(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 	exit(exitcode); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | void | 
					
						
							|  |  |  | fatal(const char *format, ...) { | 
					
						
							|  |  |  | 	va_list args; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	fflush(stdout); | 
					
						
							|  |  |  | 	fprintf(stderr, "%s: ", progname); | 
					
						
							|  |  |  | 	va_start(args, format); | 
					
						
							|  |  |  | 	vfprintf(stderr, format, args); | 
					
						
							|  |  |  | 	va_end(args); | 
					
						
							|  |  |  | 	fprintf(stderr, "\n"); | 
					
						
							|  |  |  | 	digexit(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2000-06-01 18:49:22 +00:00
										 |  |  | debug(const char *format, ...) { | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	va_list args; | 
					
						
							| 
									
										
										
										
											2013-11-18 15:46:24 -08:00
										 |  |  | 	isc_time_t t; | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-06 22:50:44 +00:00
										 |  |  | 	if (debugging) { | 
					
						
							| 
									
										
										
										
											2008-01-17 21:46:33 +00:00
										 |  |  | 		fflush(stdout); | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 		if (debugtiming) { | 
					
						
							| 
									
										
										
										
											2013-11-18 15:46:24 -08:00
										 |  |  | 			TIME_NOW(&t); | 
					
						
							| 
									
										
										
										
											2018-02-14 17:41:30 +11:00
										 |  |  | 			fprintf(stderr, "%u.%06u: ", isc_time_seconds(&t), | 
					
						
							| 
									
										
										
										
											2013-11-18 15:59:53 -08:00
										 |  |  | 				isc_time_nanoseconds(&t) / 1000); | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 		va_start(args, format); | 
					
						
							| 
									
										
										
										
											2000-06-06 22:50:44 +00:00
										 |  |  | 		vfprintf(stderr, format, args); | 
					
						
							|  |  |  | 		va_end(args); | 
					
						
							|  |  |  | 		fprintf(stderr, "\n"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-05 18:22:16 +00:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2000-06-01 18:49:22 +00:00
										 |  |  | check_result(isc_result_t result, const char *msg) { | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		fatal("%s: %s", msg, isc_result_totext(result)); | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Create a server structure, which is part of the lookup structure. | 
					
						
							|  |  |  |  * This is little more than a linked list of servers to query in hopes | 
					
						
							|  |  |  |  * of finding the answer the user is looking for | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | dig_server_t * | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | make_server(const char *servname, const char *userarg) { | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	dig_server_t *srv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	REQUIRE(servname != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-20 02:21:58 +00:00
										 |  |  | 	debug("make_server(%s)", servname); | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	srv = isc_mem_allocate(mctx, sizeof(struct dig_server)); | 
					
						
							|  |  |  | 	if (srv == NULL) | 
					
						
							| 
									
										
										
										
											2001-09-26 00:38:39 +00:00
										 |  |  | 		fatal("memory allocation failure in %s:%d", | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 		      __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2011-02-21 07:34:57 +00:00
										 |  |  | 	strlcpy(srv->servername, servname, MXNAME); | 
					
						
							|  |  |  | 	strlcpy(srv->userarg, userarg, MXNAME); | 
					
						
							| 
									
										
										
										
											2000-10-20 02:21:58 +00:00
										 |  |  | 	ISC_LINK_INIT(srv, link); | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	return (srv); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  |  * Create a copy of the server list from the resolver configuration structure. | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  |  * The dest list must have already had ISC_LIST_INIT applied. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2002-08-28 07:04:48 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | get_server_list(irs_resconf_t *resconf) { | 
					
						
							|  |  |  | 	isc_sockaddrlist_t *servers; | 
					
						
							|  |  |  | 	isc_sockaddr_t *sa; | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 	dig_server_t *newsrv; | 
					
						
							| 
									
										
										
										
											2014-07-30 23:26:37 +10:00
										 |  |  | 	char tmp[sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255") + | 
					
						
							|  |  |  | 		 sizeof("%4000000000")]; | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 	debug("get_server_list()"); | 
					
						
							|  |  |  | 	servers = irs_resconf_getnameservers(resconf); | 
					
						
							|  |  |  | 	for (sa = ISC_LIST_HEAD(*servers); | 
					
						
							|  |  |  | 	     sa != NULL; | 
					
						
							|  |  |  | 	     sa = ISC_LIST_NEXT(sa, link)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		int pf = isc_sockaddr_pf(sa); | 
					
						
							|  |  |  | 		isc_netaddr_t na; | 
					
						
							|  |  |  | 		isc_result_t result; | 
					
						
							|  |  |  | 		isc_buffer_t b; | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 		if (pf == AF_INET && !have_ipv4) | 
					
						
							| 
									
										
										
										
											2008-12-13 02:43:25 +00:00
										 |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 		if (pf == AF_INET6 && !have_ipv6) | 
					
						
							| 
									
										
										
										
											2008-12-13 02:43:25 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 		isc_buffer_init(&b, tmp, sizeof(tmp)); | 
					
						
							|  |  |  | 		isc_netaddr_fromsockaddr(&na, sa); | 
					
						
							|  |  |  | 		result = isc_netaddr_totext(&na, &b); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		isc_buffer_putuint8(&b, 0); | 
					
						
							|  |  |  | 		if (pf == AF_INET6 && na.zone != 0) { | 
					
						
							| 
									
										
										
										
											2014-07-30 23:26:37 +10:00
										 |  |  | 			char buf[sizeof("%4000000000")]; | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 			snprintf(buf, sizeof(buf), "%%%u", na.zone); | 
					
						
							| 
									
										
										
										
											2014-07-30 23:26:37 +10:00
										 |  |  | 			strlcat(tmp, buf, sizeof(tmp)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 		newsrv = make_server(tmp, tmp); | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 		ISC_LINK_INIT(newsrv, link); | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 		ISC_LIST_APPEND(server_list, newsrv, link); | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | void | 
					
						
							|  |  |  | flush_server_list(void) { | 
					
						
							|  |  |  | 	dig_server_t *s, *ps; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("flush_server_list()"); | 
					
						
							|  |  |  | 	s = ISC_LIST_HEAD(server_list); | 
					
						
							|  |  |  | 	while (s != NULL) { | 
					
						
							|  |  |  | 		ps = s; | 
					
						
							|  |  |  | 		s = ISC_LIST_NEXT(s, link); | 
					
						
							|  |  |  | 		ISC_LIST_DEQUEUE(server_list, ps, link); | 
					
						
							|  |  |  | 		isc_mem_free(mctx, ps); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | void | 
					
						
							|  |  |  | set_nameserver(char *opt) { | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; | 
					
						
							|  |  |  | 	isc_netaddr_t netaddr; | 
					
						
							| 
									
										
										
										
											2004-09-16 01:01:27 +00:00
										 |  |  | 	int count, i; | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 	dig_server_t *srv; | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 	char tmp[ISC_NETADDR_FORMATSIZE]; | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (opt == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 	result = bind9_getaddresses(opt, 0, sockaddrs, | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 				    DIG_MAX_ADDRESSES, &count); | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 		fatal("couldn't get address for '%s': %s", | 
					
						
							|  |  |  | 		      opt, isc_result_totext(result)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 	flush_server_list(); | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 	for (i = 0; i < count; i++) { | 
					
						
							|  |  |  | 		isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]); | 
					
						
							|  |  |  | 		isc_netaddr_format(&netaddr, tmp, sizeof(tmp)); | 
					
						
							|  |  |  | 		srv = make_server(tmp, opt); | 
					
						
							|  |  |  | 		if (srv == NULL) | 
					
						
							|  |  |  | 			fatal("memory allocation failure"); | 
					
						
							|  |  |  | 		ISC_LIST_APPEND(server_list, srv, link); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Produce a cloned server list.  The dest list must have already had | 
					
						
							|  |  |  |  * ISC_LIST_INIT applied. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2001-07-28 00:55:15 +00:00
										 |  |  | clone_server_list(dig_serverlist_t src, dig_serverlist_t *dest) { | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	dig_server_t *srv, *newsrv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("clone_server_list()"); | 
					
						
							|  |  |  | 	srv = ISC_LIST_HEAD(src); | 
					
						
							|  |  |  | 	while (srv != NULL) { | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 		newsrv = make_server(srv->servername, srv->userarg); | 
					
						
							| 
									
										
										
										
											2000-10-23 17:49:05 +00:00
										 |  |  | 		ISC_LINK_INIT(newsrv, link); | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 		ISC_LIST_ENQUEUE(*dest, newsrv, link); | 
					
						
							|  |  |  | 		srv = ISC_LIST_NEXT(srv, link); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Create an empty lookup structure, which holds all the information needed | 
					
						
							|  |  |  |  * to get an answer to a user's question.  This structure contains two | 
					
						
							|  |  |  |  * linked lists: the server list (servers to query) and the query list | 
					
						
							|  |  |  |  * (outstanding queries which have been made to the listed servers). | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | dig_lookup_t * | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | make_empty_lookup(void) { | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	dig_lookup_t *looknew; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	debug("make_empty_lookup()"); | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-05-22 22:56:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	looknew = isc_mem_allocate(mctx, sizeof(struct dig_lookup)); | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	if (looknew == NULL) | 
					
						
							| 
									
										
										
										
											2001-09-26 00:38:39 +00:00
										 |  |  | 		fatal("memory allocation failure in %s:%d", | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 		       __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->pending = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-09-30 00:06:08 +00:00
										 |  |  | 	looknew->textname[0] = 0; | 
					
						
							| 
									
										
										
										
											2001-02-15 23:44:08 +00:00
										 |  |  | 	looknew->cmdline[0] = 0; | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 	looknew->rdtype = dns_rdatatype_a; | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	looknew->qrdtype = dns_rdatatype_a; | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 	looknew->rdclass = dns_rdataclass_in; | 
					
						
							| 
									
										
										
										
											2000-12-08 17:06:52 +00:00
										 |  |  | 	looknew->rdtypeset = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->rdclassset = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-13 01:22:38 +00:00
										 |  |  | 	looknew->sendspace = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	looknew->sendmsg = NULL; | 
					
						
							|  |  |  | 	looknew->name = NULL; | 
					
						
							|  |  |  | 	looknew->oname = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->xfr_q = NULL; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	looknew->current_query = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->doing_xfr = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 	looknew->ixfr_serial = 0; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->trace = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->trace_root = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->identify = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 	looknew->identify_previous_line = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-09-13 00:03:28 +00:00
										 |  |  | 	looknew->ignore = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-11-14 06:31:38 +00:00
										 |  |  | 	looknew->servfail_stops = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-10-13 17:54:00 +00:00
										 |  |  | 	looknew->besteffort = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-11-13 21:34:03 +00:00
										 |  |  | 	looknew->dnssec = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | 	looknew->ednsflags = 0; | 
					
						
							| 
									
										
										
										
											2015-05-19 12:46:06 +10:00
										 |  |  | 	looknew->opcode = dns_opcode_query; | 
					
						
							| 
									
										
										
										
											2014-02-20 14:56:20 +11:00
										 |  |  | 	looknew->expire = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2008-04-03 02:01:08 +00:00
										 |  |  | 	looknew->nsid = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 	looknew->tcp_keepalive = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->padding = 0; | 
					
						
							| 
									
										
										
										
											2014-10-30 11:42:02 +11:00
										 |  |  | 	looknew->header_only = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	looknew->sendcookie = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->seenbadcookie = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->badcookie = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2016-10-10 11:55:59 +11:00
										 |  |  | 	looknew->multiline = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->nottl = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->noclass = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->onesoa = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->use_usec = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->nocrypto = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->ttlunits = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->ttlunits = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->qr = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							|  |  |  | 	looknew->idnin = ISC_TRUE; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	looknew->idnin = ISC_FALSE; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | #ifdef WITH_IDN_OUT_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2016-10-28 12:05:19 +11:00
										 |  |  | 	looknew->idnout = ISC_TRUE; | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | 	looknew->idnout = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->udpsize = 0; | 
					
						
							| 
									
										
										
										
											2005-06-07 00:16:01 +00:00
										 |  |  | 	looknew->edns = -1; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->recurse = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-07-13 21:12:21 +00:00
										 |  |  | 	looknew->aaonly = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->adflag = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->cdflag = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2018-04-18 09:18:41 +10:00
										 |  |  | 	looknew->raflag = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->tcflag = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2016-02-09 15:38:34 +05:30
										 |  |  | 	looknew->print_unknown_format = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2014-10-31 10:16:00 +11:00
										 |  |  | 	looknew->zflag = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->ns_search_only = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->origin = NULL; | 
					
						
							| 
									
										
										
										
											2001-10-11 00:38:56 +00:00
										 |  |  | 	looknew->tsigctx = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->querysig = NULL; | 
					
						
							|  |  |  | 	looknew->retries = tries; | 
					
						
							|  |  |  | 	looknew->nsfound = 0; | 
					
						
							|  |  |  | 	looknew->tcp_mode = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2014-05-14 09:59:02 +10:00
										 |  |  | 	looknew->tcp_mode_set = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2002-07-25 05:46:07 +00:00
										 |  |  | 	looknew->ip6_int = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	looknew->comments = ISC_TRUE; | 
					
						
							|  |  |  | 	looknew->stats = ISC_TRUE; | 
					
						
							|  |  |  | 	looknew->section_question = ISC_TRUE; | 
					
						
							|  |  |  | 	looknew->section_answer = ISC_TRUE; | 
					
						
							|  |  |  | 	looknew->section_authority = ISC_TRUE; | 
					
						
							|  |  |  | 	looknew->section_additional = ISC_TRUE; | 
					
						
							|  |  |  | 	looknew->new_search = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 	looknew->done_as_is = ISC_FALSE; | 
					
						
							|  |  |  | 	looknew->need_search = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	looknew->ecs_addr = NULL; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	looknew->cookie = NULL; | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 	looknew->ednsopts = NULL; | 
					
						
							|  |  |  | 	looknew->ednsoptscnt = 0; | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | 	looknew->ednsneg = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 	looknew->mapped = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2014-07-15 23:27:14 +10:00
										 |  |  | 	looknew->dscp = -1; | 
					
						
							| 
									
										
										
										
											2016-10-10 11:55:59 +11:00
										 |  |  | 	looknew->rrcomments = 0; | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 	looknew->eoferr = 0; | 
					
						
							| 
									
										
										
										
											2014-03-01 15:32:25 -08:00
										 |  |  | 	dns_fixedname_init(&looknew->fdomain); | 
					
						
							| 
									
										
										
										
											2000-10-20 02:21:58 +00:00
										 |  |  | 	ISC_LINK_INIT(looknew, link); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	ISC_LIST_INIT(looknew->q); | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 	ISC_LIST_INIT(looknew->connecting); | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	ISC_LIST_INIT(looknew->my_server_list); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	return (looknew); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 16:10:35 +11:00
										 |  |  | #define EDNSOPT_OPTIONS 100U
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | cloneopts(dig_lookup_t *looknew, dig_lookup_t *lookold) { | 
					
						
							|  |  |  | 	size_t len = sizeof(looknew->ednsopts[0]) * EDNSOPT_OPTIONS; | 
					
						
							|  |  |  | 	size_t i; | 
					
						
							|  |  |  | 	looknew->ednsopts = isc_mem_allocate(mctx, len); | 
					
						
							|  |  |  | 	if (looknew->ednsopts == NULL) | 
					
						
							|  |  |  | 		fatal("out of memory"); | 
					
						
							|  |  |  | 	for (i = 0; i < EDNSOPT_OPTIONS; i++) { | 
					
						
							|  |  |  | 		looknew->ednsopts[i].code = 0; | 
					
						
							|  |  |  | 		looknew->ednsopts[i].length = 0; | 
					
						
							|  |  |  | 		looknew->ednsopts[i].value = NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	looknew->ednsoptscnt = 0; | 
					
						
							|  |  |  | 	if (lookold == NULL || lookold->ednsopts == NULL) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < lookold->ednsoptscnt; i++) { | 
					
						
							|  |  |  | 		len = lookold->ednsopts[i].length; | 
					
						
							|  |  |  | 		if (len != 0) { | 
					
						
							|  |  |  | 			INSIST(lookold->ednsopts[i].value != NULL); | 
					
						
							|  |  |  | 			looknew->ednsopts[i].value = | 
					
						
							|  |  |  | 				 isc_mem_allocate(mctx, len); | 
					
						
							|  |  |  | 			if (looknew->ednsopts[i].value == NULL) | 
					
						
							|  |  |  | 				fatal("out of memory"); | 
					
						
							|  |  |  | 			memmove(looknew->ednsopts[i].value, | 
					
						
							|  |  |  | 				lookold->ednsopts[i].value, len); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		looknew->ednsopts[i].code = lookold->ednsopts[i].code; | 
					
						
							|  |  |  | 		looknew->ednsopts[i].length = len; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	looknew->ednsoptscnt = lookold->ednsoptscnt; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Clone a lookup, perhaps copying the server list.  This does not clone | 
					
						
							|  |  |  |  * the query list, since it will be regenerated by the setup_lookup() | 
					
						
							|  |  |  |  * function, nor does it queue up the new lookup for processing. | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  |  * Caution: If you don't clone the servers, you MUST clone the server | 
					
						
							| 
									
										
										
										
											2009-01-17 10:15:38 +00:00
										 |  |  |  * list separately from somewhere else, or construct it by hand. | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | dig_lookup_t * | 
					
						
							|  |  |  | clone_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { | 
					
						
							|  |  |  | 	dig_lookup_t *looknew; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("clone_lookup()"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INSIST(!free_now); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	looknew = make_empty_lookup(); | 
					
						
							|  |  |  | 	INSIST(looknew != NULL); | 
					
						
							| 
									
										
										
										
											2012-10-02 23:44:03 -07:00
										 |  |  | 	strlcpy(looknew->textname, lookold->textname, MXNAME); | 
					
						
							|  |  |  | 	strlcpy(looknew->cmdline, lookold->cmdline, MXNAME); | 
					
						
							| 
									
										
										
										
											2001-01-08 23:50:34 +00:00
										 |  |  | 	looknew->textname[MXNAME-1] = 0; | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	looknew->rdtype = lookold->rdtype; | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	looknew->qrdtype = lookold->qrdtype; | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	looknew->rdclass = lookold->rdclass; | 
					
						
							| 
									
										
										
										
											2000-12-08 17:50:47 +00:00
										 |  |  | 	looknew->rdtypeset = lookold->rdtypeset; | 
					
						
							|  |  |  | 	looknew->rdclassset = lookold->rdclassset; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->doing_xfr = lookold->doing_xfr; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	looknew->ixfr_serial = lookold->ixfr_serial; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->trace = lookold->trace; | 
					
						
							|  |  |  | 	looknew->trace_root = lookold->trace_root; | 
					
						
							|  |  |  | 	looknew->identify = lookold->identify; | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 	looknew->identify_previous_line = lookold->identify_previous_line; | 
					
						
							| 
									
										
										
										
											2000-09-13 00:03:28 +00:00
										 |  |  | 	looknew->ignore = lookold->ignore; | 
					
						
							| 
									
										
										
										
											2000-09-28 23:02:28 +00:00
										 |  |  | 	looknew->servfail_stops = lookold->servfail_stops; | 
					
						
							| 
									
										
										
										
											2000-10-13 17:54:00 +00:00
										 |  |  | 	looknew->besteffort = lookold->besteffort; | 
					
						
							| 
									
										
										
										
											2000-11-13 21:34:03 +00:00
										 |  |  | 	looknew->dnssec = lookold->dnssec; | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | 	looknew->ednsflags = lookold->ednsflags; | 
					
						
							| 
									
										
										
										
											2015-05-19 12:46:06 +10:00
										 |  |  | 	looknew->opcode = lookold->opcode; | 
					
						
							| 
									
										
										
										
											2014-02-20 14:56:20 +11:00
										 |  |  | 	looknew->expire = lookold->expire; | 
					
						
							| 
									
										
										
										
											2008-04-03 02:01:08 +00:00
										 |  |  | 	looknew->nsid = lookold->nsid; | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 	looknew->tcp_keepalive = lookold->tcp_keepalive; | 
					
						
							| 
									
										
										
										
											2014-10-30 11:42:02 +11:00
										 |  |  | 	looknew->header_only = lookold->header_only; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	looknew->sendcookie = lookold->sendcookie; | 
					
						
							|  |  |  | 	looknew->seenbadcookie = lookold->seenbadcookie; | 
					
						
							|  |  |  | 	looknew->badcookie = lookold->badcookie; | 
					
						
							|  |  |  | 	looknew->cookie = lookold->cookie; | 
					
						
							| 
									
										
										
										
											2017-11-13 16:10:35 +11:00
										 |  |  | 	if (lookold->ednsopts != NULL) { | 
					
						
							|  |  |  | 		cloneopts(looknew, lookold); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		looknew->ednsopts = NULL; | 
					
						
							|  |  |  | 		looknew->ednsoptscnt = 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | 	looknew->ednsneg = lookold->ednsneg; | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 	looknew->padding = lookold->padding; | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 	looknew->mapped = lookold->mapped; | 
					
						
							| 
									
										
										
										
											2016-10-10 11:55:59 +11:00
										 |  |  | 	looknew->multiline = lookold->multiline; | 
					
						
							|  |  |  | 	looknew->nottl = lookold->nottl; | 
					
						
							|  |  |  | 	looknew->noclass = lookold->noclass; | 
					
						
							|  |  |  | 	looknew->onesoa = lookold->onesoa; | 
					
						
							|  |  |  | 	looknew->use_usec = lookold->use_usec; | 
					
						
							|  |  |  | 	looknew->nocrypto = lookold->nocrypto; | 
					
						
							|  |  |  | 	looknew->ttlunits = lookold->ttlunits; | 
					
						
							|  |  |  | 	looknew->qr = lookold->qr; | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	looknew->idnin = lookold->idnin; | 
					
						
							| 
									
										
										
										
											2016-10-28 12:05:19 +11:00
										 |  |  | 	looknew->idnout = lookold->idnout; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->udpsize = lookold->udpsize; | 
					
						
							| 
									
										
										
										
											2005-06-07 00:16:01 +00:00
										 |  |  | 	looknew->edns = lookold->edns; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->recurse = lookold->recurse; | 
					
						
							| 
									
										
										
										
											2000-12-11 19:24:30 +00:00
										 |  |  | 	looknew->aaonly = lookold->aaonly; | 
					
						
							| 
									
										
										
										
											2000-06-16 18:00:05 +00:00
										 |  |  | 	looknew->adflag = lookold->adflag; | 
					
						
							|  |  |  | 	looknew->cdflag = lookold->cdflag; | 
					
						
							| 
									
										
										
										
											2018-04-18 09:18:41 +10:00
										 |  |  | 	looknew->raflag = lookold->raflag; | 
					
						
							|  |  |  | 	looknew->tcflag = lookold->tcflag; | 
					
						
							| 
									
										
										
										
											2016-02-09 15:38:34 +05:30
										 |  |  | 	looknew->print_unknown_format = lookold->print_unknown_format; | 
					
						
							| 
									
										
										
										
											2014-10-31 10:16:00 +11:00
										 |  |  | 	looknew->zflag = lookold->zflag; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->ns_search_only = lookold->ns_search_only; | 
					
						
							|  |  |  | 	looknew->tcp_mode = lookold->tcp_mode; | 
					
						
							| 
									
										
										
										
											2014-05-14 09:59:02 +10:00
										 |  |  | 	looknew->tcp_mode_set = lookold->tcp_mode_set; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	looknew->comments = lookold->comments; | 
					
						
							|  |  |  | 	looknew->stats = lookold->stats; | 
					
						
							|  |  |  | 	looknew->section_question = lookold->section_question; | 
					
						
							|  |  |  | 	looknew->section_answer = lookold->section_answer; | 
					
						
							|  |  |  | 	looknew->section_authority = lookold->section_authority; | 
					
						
							|  |  |  | 	looknew->section_additional = lookold->section_additional; | 
					
						
							| 
									
										
										
										
											2017-09-11 10:10:16 -07:00
										 |  |  | 	looknew->origin = lookold->origin; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	looknew->retries = lookold->retries; | 
					
						
							| 
									
										
										
										
											2001-10-11 00:38:56 +00:00
										 |  |  | 	looknew->tsigctx = NULL; | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 	looknew->need_search = lookold->need_search; | 
					
						
							|  |  |  | 	looknew->done_as_is = lookold->done_as_is; | 
					
						
							| 
									
										
										
										
											2014-07-15 23:27:14 +10:00
										 |  |  | 	looknew->dscp = lookold->dscp; | 
					
						
							| 
									
										
										
										
											2016-10-10 11:55:59 +11:00
										 |  |  | 	looknew->rrcomments = lookold->rrcomments; | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 	looknew->eoferr = lookold->eoferr; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	if (lookold->ecs_addr != NULL) { | 
					
						
							|  |  |  | 		size_t len = sizeof(isc_sockaddr_t); | 
					
						
							|  |  |  | 		looknew->ecs_addr = isc_mem_allocate(mctx, len); | 
					
						
							| 
									
										
										
										
											2015-04-29 03:16:50 +10:00
										 |  |  | 		if (looknew->ecs_addr == NULL) | 
					
						
							|  |  |  | 			fatal("out of memory"); | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 		memmove(looknew->ecs_addr, lookold->ecs_addr, len); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-01 15:32:25 -08:00
										 |  |  | 	dns_name_copy(dns_fixedname_name(&lookold->fdomain), | 
					
						
							|  |  |  | 		      dns_fixedname_name(&looknew->fdomain), NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	if (servers) | 
					
						
							|  |  |  | 		clone_server_list(lookold->my_server_list, | 
					
						
							|  |  |  | 				  &looknew->my_server_list); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	return (looknew); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Requeue a lookup for further processing, perhaps copying the server | 
					
						
							|  |  |  |  * list.  The new lookup structure is returned to the caller, and is | 
					
						
							|  |  |  |  * queued for processing.  If servers are not cloned in the requeue, they | 
					
						
							|  |  |  |  * must be added before allowing the current event to complete, since the | 
					
						
							|  |  |  |  * completion of the event may result in the next entry on the lookup | 
					
						
							|  |  |  |  * queue getting run. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | dig_lookup_t * | 
					
						
							|  |  |  | requeue_lookup(dig_lookup_t *lookold, isc_boolean_t servers) { | 
					
						
							|  |  |  | 	dig_lookup_t *looknew; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("requeue_lookup()"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	lookup_counter++; | 
					
						
							|  |  |  | 	if (lookup_counter > LOOKUP_LIMIT) | 
					
						
							| 
									
										
										
										
											2001-09-26 00:38:39 +00:00
										 |  |  | 		fatal("too many lookups"); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	looknew = clone_lookup(lookold, servers); | 
					
						
							|  |  |  | 	INSIST(looknew != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 	debug("before insertion, init@%p -> %p, new@%p -> %p", | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	      lookold, lookold->link.next, looknew, looknew->link.next); | 
					
						
							| 
									
										
										
										
											2000-07-14 21:33:03 +00:00
										 |  |  | 	ISC_LIST_PREPEND(lookup_list, looknew, link); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 	debug("after insertion, init -> %p, new = %p, new -> %p", | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	      lookold, looknew, looknew->link.next); | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	return (looknew); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 07:27:50 -07:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | setup_text_key(void) { | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2001-07-27 06:11:10 +00:00
										 |  |  | 	dns_name_t keyname; | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	isc_buffer_t secretbuf; | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 	unsigned int secretsize; | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	unsigned char *secretstore; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("setup_text_key()"); | 
					
						
							|  |  |  | 	result = isc_buffer_allocate(mctx, &namebuf, MXNAME); | 
					
						
							|  |  |  | 	check_result(result, "isc_buffer_allocate"); | 
					
						
							|  |  |  | 	dns_name_init(&keyname, NULL); | 
					
						
							|  |  |  | 	check_result(result, "dns_name_init"); | 
					
						
							|  |  |  | 	isc_buffer_putstr(namebuf, keynametext); | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 	secretsize = (unsigned int) strlen(keysecret) * 3 / 4; | 
					
						
							| 
									
										
										
										
											2000-07-20 17:58:59 +00:00
										 |  |  | 	secretstore = isc_mem_allocate(mctx, secretsize); | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	if (secretstore == NULL) | 
					
						
							| 
									
										
										
										
											2001-09-26 00:38:39 +00:00
										 |  |  | 		fatal("memory allocation failure in %s:%d", | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 		      __FILE__, __LINE__); | 
					
						
							|  |  |  | 	isc_buffer_init(&secretbuf, secretstore, secretsize); | 
					
						
							| 
									
										
										
										
											2001-03-22 00:07:07 +00:00
										 |  |  | 	result = isc_base64_decodestring(keysecret, &secretbuf); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:52:45 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 		goto failure; | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	secretsize = isc_buffer_usedlength(&secretbuf); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 23:18:07 +00:00
										 |  |  | 	if (hmacname == NULL) { | 
					
						
							|  |  |  | 		result = DST_R_UNSUPPORTEDALG; | 
					
						
							|  |  |  | 		goto failure; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-01 00:22:28 +00:00
										 |  |  | 	result = dns_name_fromtext(&keyname, namebuf, dns_rootname, 0, namebuf); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:52:45 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 		goto failure; | 
					
						
							| 
									
										
										
										
											2001-07-27 05:52:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-27 02:35:15 +00:00
										 |  |  | 	result = dns_tsigkey_create(&keyname, hmacname, secretstore, | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 				    (int)secretsize, ISC_FALSE, NULL, 0, 0, | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 				    mctx, NULL, &tsigkey); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:52:45 +00:00
										 |  |  |  failure: | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 		printf(";; Couldn't create key %s: %s\n", | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 		       keynametext, isc_result_totext(result)); | 
					
						
							| 
									
										
										
										
											2006-01-27 02:35:15 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 		dst_key_setbits(tsigkey->key, digestbits); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:52:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-20 17:58:59 +00:00
										 |  |  | 	isc_mem_free(mctx, secretstore); | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	dns_name_invalidate(&keyname); | 
					
						
							|  |  |  | 	isc_buffer_free(&namebuf); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | static isc_result_t | 
					
						
							|  |  |  | parse_uint_helper(isc_uint32_t *uip, const char *value, isc_uint32_t max, | 
					
						
							|  |  |  | 		  const char *desc, int base) { | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	isc_uint32_t n; | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | 	isc_result_t result = isc_parse_uint32(&n, value, base); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	if (result == ISC_R_SUCCESS && n > max) | 
					
						
							|  |  |  | 		result = ISC_R_RANGE; | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		printf("invalid %s '%s': %s\n", desc, | 
					
						
							|  |  |  | 		       value, isc_result_totext(result)); | 
					
						
							|  |  |  | 		return (result); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	*uip = n; | 
					
						
							|  |  |  | 	return (ISC_R_SUCCESS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | isc_result_t | 
					
						
							|  |  |  | parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max, | 
					
						
							|  |  |  | 	   const char *desc) { | 
					
						
							|  |  |  | 	return (parse_uint_helper(uip, value, max, desc, 10)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | isc_result_t | 
					
						
							|  |  |  | parse_xint(isc_uint32_t *uip, const char *value, isc_uint32_t max, | 
					
						
							|  |  |  | 	   const char *desc) { | 
					
						
							|  |  |  | 	return (parse_uint_helper(uip, value, max, desc, 0)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | static isc_uint32_t | 
					
						
							|  |  |  | parse_bits(char *arg, const char *desc, isc_uint32_t max) { | 
					
						
							| 
									
										
										
										
											2009-09-15 23:48:09 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	isc_uint32_t tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = parse_uint(&tmp, arg, max, desc); | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 		fatal("couldn't parse digest bits"); | 
					
						
							|  |  |  | 	tmp = (tmp + 7) & ~0x7U; | 
					
						
							|  |  |  | 	return (tmp); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | isc_result_t | 
					
						
							|  |  |  | parse_netprefix(isc_sockaddr_t **sap, const char *value) { | 
					
						
							|  |  |  | 	isc_result_t result = ISC_R_SUCCESS; | 
					
						
							|  |  |  | 	isc_sockaddr_t *sa = NULL; | 
					
						
							|  |  |  | 	struct in_addr in4; | 
					
						
							|  |  |  | 	struct in6_addr in6; | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 	isc_uint32_t prefix_length = 0xffffffff; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	char *slash = NULL; | 
					
						
							|  |  |  | 	isc_boolean_t parsed = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 	isc_boolean_t prefix_parsed = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 	char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX/128")]; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-14 15:52:40 +11:00
										 |  |  | 	REQUIRE(sap != NULL && *sap == NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 	if (strlcpy(buf, value, sizeof(buf)) >= sizeof(buf)) | 
					
						
							|  |  |  | 		fatal("invalid prefix '%s'\n", value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 	sa = isc_mem_allocate(mctx, sizeof(*sa)); | 
					
						
							|  |  |  | 	if (sa == NULL) | 
					
						
							|  |  |  | 		fatal("out of memory"); | 
					
						
							|  |  |  | 	memset(sa, 0, sizeof(*sa)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (strcmp(buf, "0") == 0) { | 
					
						
							|  |  |  | 		sa->type.sa.sa_family = AF_UNSPEC; | 
					
						
							|  |  |  | 		prefix_length = 0; | 
					
						
							|  |  |  | 		goto done; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 	slash = strchr(buf, '/'); | 
					
						
							|  |  |  | 	if (slash != NULL) { | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 		*slash = '\0'; | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 		result = isc_parse_uint32(&prefix_length, slash + 1, 10); | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 		if (result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 			fatal("invalid prefix length in '%s': %s\n", | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			      value, isc_result_totext(result)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 		prefix_parsed = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2016-03-23 15:00:30 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 	if (inet_pton(AF_INET6, buf, &in6) == 1) { | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 		parsed = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 		isc_sockaddr_fromin6(sa, &in6, 0); | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 		if (prefix_length > 128) | 
					
						
							|  |  |  | 			prefix_length = 128; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:38:24 +11:00
										 |  |  | 	} else if (inet_pton(AF_INET, buf, &in4) == 1) { | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 		parsed = ISC_TRUE; | 
					
						
							|  |  |  | 		isc_sockaddr_fromin(sa, &in4, 0); | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 		if (prefix_length > 32) | 
					
						
							|  |  |  | 			prefix_length = 32; | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 	} else if (prefix_parsed) { | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 		int i; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 		for (i = 0; i < 3 && strlen(buf) < sizeof(buf) - 2; i++) { | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			strlcat(buf, ".0", sizeof(buf)); | 
					
						
							|  |  |  | 			if (inet_pton(AF_INET, buf, &in4) == 1) { | 
					
						
							|  |  |  | 				parsed = ISC_TRUE; | 
					
						
							|  |  |  | 				isc_sockaddr_fromin(sa, &in4, 0); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-01-27 19:00:36 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 		if (prefix_length > 32) | 
					
						
							|  |  |  | 			prefix_length = 32; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!parsed) | 
					
						
							|  |  |  | 		fatal("invalid address '%s'", value); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | done: | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 	sa->length = prefix_length; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	*sap = sa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (ISC_R_SUCCESS); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Parse HMAC algorithm specification | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | parse_hmac(const char *hmac) { | 
					
						
							|  |  |  | 	char buf[20]; | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 	size_t len; | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	REQUIRE(hmac != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = strlen(hmac); | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 	if (len >= sizeof(buf)) | 
					
						
							|  |  |  | 		fatal("unknown key type '%.*s'", (int)len, hmac); | 
					
						
							| 
									
										
										
										
											2012-10-02 23:44:03 -07:00
										 |  |  | 	strlcpy(buf, hmac, sizeof(buf)); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	digestbits = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-19 08:02:51 +10:00
										 |  |  | #ifndef PK11_MD5_DISABLE
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	if (strcasecmp(buf, "hmac-md5") == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACMD5_NAME; | 
					
						
							|  |  |  | 	} else if (strncasecmp(buf, "hmac-md5-", 9) == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACMD5_NAME; | 
					
						
							|  |  |  | 		digestbits = parse_bits(&buf[9], "digest-bits [0..128]", 128); | 
					
						
							| 
									
										
										
										
											2016-08-19 08:02:51 +10:00
										 |  |  | 	} else | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	if (strcasecmp(buf, "hmac-sha1") == 0) { | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 		hmacname = DNS_TSIG_HMACSHA1_NAME; | 
					
						
							|  |  |  | 		digestbits = 0; | 
					
						
							|  |  |  | 	} else if (strncasecmp(buf, "hmac-sha1-", 10) == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA1_NAME; | 
					
						
							|  |  |  | 		digestbits = parse_bits(&buf[10], "digest-bits [0..160]", 160); | 
					
						
							|  |  |  | 	} else if (strcasecmp(buf, "hmac-sha224") == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA224_NAME; | 
					
						
							|  |  |  | 	} else if (strncasecmp(buf, "hmac-sha224-", 12) == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA224_NAME; | 
					
						
							|  |  |  | 		digestbits = parse_bits(&buf[12], "digest-bits [0..224]", 224); | 
					
						
							|  |  |  | 	} else if (strcasecmp(buf, "hmac-sha256") == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA256_NAME; | 
					
						
							|  |  |  | 	} else if (strncasecmp(buf, "hmac-sha256-", 12) == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA256_NAME; | 
					
						
							|  |  |  | 		digestbits = parse_bits(&buf[12], "digest-bits [0..256]", 256); | 
					
						
							|  |  |  | 	} else if (strcasecmp(buf, "hmac-sha384") == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA384_NAME; | 
					
						
							|  |  |  | 	} else if (strncasecmp(buf, "hmac-sha384-", 12) == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA384_NAME; | 
					
						
							|  |  |  | 		digestbits = parse_bits(&buf[12], "digest-bits [0..384]", 384); | 
					
						
							|  |  |  | 	} else if (strcasecmp(buf, "hmac-sha512") == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA512_NAME; | 
					
						
							|  |  |  | 	} else if (strncasecmp(buf, "hmac-sha512-", 12) == 0) { | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA512_NAME; | 
					
						
							|  |  |  | 		digestbits = parse_bits(&buf[12], "digest-bits [0..512]", 512); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		fprintf(stderr, ";; Warning, ignoring " | 
					
						
							|  |  |  | 			"invalid TSIG algorithm %s\n", buf); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Get a key from a named.conf format keyfile | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static isc_result_t | 
					
						
							|  |  |  | read_confkey(void) { | 
					
						
							|  |  |  | 	cfg_parser_t *pctx = NULL; | 
					
						
							|  |  |  | 	cfg_obj_t *file = NULL; | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	const cfg_obj_t *keyobj = NULL; | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	const cfg_obj_t *secretobj = NULL; | 
					
						
							|  |  |  | 	const cfg_obj_t *algorithmobj = NULL; | 
					
						
							|  |  |  | 	const char *keyname; | 
					
						
							|  |  |  | 	const char *secretstr; | 
					
						
							|  |  |  | 	const char *algorithm; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (! isc_file_exists(keyfile)) | 
					
						
							|  |  |  | 		return (ISC_R_FILENOTFOUND); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	result = cfg_parser_create(mctx, NULL, &pctx); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 		goto cleanup; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = cfg_parse_file(pctx, keyfile, &cfg_type_sessionkey, | 
					
						
							|  |  |  | 				&file); | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 		goto cleanup; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	result = cfg_map_get(file, "key", &keyobj); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 		goto cleanup; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	(void) cfg_map_get(keyobj, "secret", &secretobj); | 
					
						
							|  |  |  | 	(void) cfg_map_get(keyobj, "algorithm", &algorithmobj); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	if (secretobj == NULL || algorithmobj == NULL) | 
					
						
							|  |  |  | 		fatal("key must have algorithm and secret"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	keyname = cfg_obj_asstring(cfg_map_getname(keyobj)); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	secretstr = cfg_obj_asstring(secretobj); | 
					
						
							|  |  |  | 	algorithm = cfg_obj_asstring(algorithmobj); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 23:44:03 -07:00
										 |  |  | 	strlcpy(keynametext, keyname, sizeof(keynametext)); | 
					
						
							|  |  |  | 	strlcpy(keysecret, secretstr, sizeof(keysecret)); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	parse_hmac(algorithm); | 
					
						
							|  |  |  | 	setup_text_key(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  cleanup: | 
					
						
							|  |  |  | 	if (pctx != NULL) { | 
					
						
							|  |  |  | 		if (file != NULL) | 
					
						
							|  |  |  | 			cfg_obj_destroy(pctx, &file); | 
					
						
							|  |  |  | 		cfg_parser_destroy(&pctx); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (result); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 07:27:50 -07:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | setup_file_key(void) { | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	dst_key_t *dstkey = NULL; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	debug("setup_file_key()"); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Try reading the key from a K* pair */ | 
					
						
							| 
									
										
										
										
											2009-07-19 04:18:05 +00:00
										 |  |  | 	result = dst_key_fromnamedfile(keyfile, NULL, | 
					
						
							|  |  |  | 				       DST_TYPE_PRIVATE | DST_TYPE_KEY, mctx, | 
					
						
							|  |  |  | 				       &dstkey); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* If that didn't work, try reading it as a session.key keyfile */ | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		result = read_confkey(); | 
					
						
							|  |  |  | 		if (result == ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		fprintf(stderr, "Couldn't read key from %s: %s\n", | 
					
						
							|  |  |  | 			keyfile, isc_result_totext(result)); | 
					
						
							|  |  |  | 		goto failure; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-27 05:52:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-27 02:35:15 +00:00
										 |  |  | 	switch (dst_key_alg(dstkey)) { | 
					
						
							| 
									
										
										
										
											2016-08-19 08:02:51 +10:00
										 |  |  | #ifndef PK11_MD5_DISABLE
 | 
					
						
							| 
									
										
										
										
											2006-01-27 02:35:15 +00:00
										 |  |  | 	case DST_ALG_HMACMD5: | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACMD5_NAME; | 
					
						
							|  |  |  | 		break; | 
					
						
							| 
									
										
										
										
											2016-08-19 08:02:51 +10:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-01-27 02:35:15 +00:00
										 |  |  | 	case DST_ALG_HMACSHA1: | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA1_NAME; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case DST_ALG_HMACSHA224: | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA224_NAME; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case DST_ALG_HMACSHA256: | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA256_NAME; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case DST_ALG_HMACSHA384: | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA384_NAME; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case DST_ALG_HMACSHA512: | 
					
						
							|  |  |  | 		hmacname = DNS_TSIG_HMACSHA512_NAME; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		printf(";; Couldn't create key %s: bad algorithm\n", | 
					
						
							|  |  |  | 		       keynametext); | 
					
						
							|  |  |  | 		goto failure; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	result = dns_tsigkey_createfromkey(dst_key_name(dstkey), hmacname, | 
					
						
							| 
									
										
										
										
											2010-12-09 00:54:34 +00:00
										 |  |  | 					   dstkey, ISC_FALSE, NULL, 0, 0, | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 					   mctx, NULL, &tsigkey); | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		printf(";; Couldn't create key %s: %s\n", | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 		       keynametext, isc_result_totext(result)); | 
					
						
							| 
									
										
										
										
											2001-09-27 17:53:39 +00:00
										 |  |  | 		goto failure; | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  |  failure: | 
					
						
							|  |  |  | 	if (dstkey != NULL) | 
					
						
							|  |  |  | 		dst_key_free(&dstkey); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  | static dig_searchlist_t * | 
					
						
							|  |  |  | make_searchlist_entry(char *domain) { | 
					
						
							|  |  |  | 	dig_searchlist_t *search; | 
					
						
							|  |  |  | 	search = isc_mem_allocate(mctx, sizeof(*search)); | 
					
						
							|  |  |  | 	if (search == NULL) | 
					
						
							| 
									
										
										
										
											2001-09-26 00:38:39 +00:00
										 |  |  | 		fatal("memory allocation failure in %s:%d", | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  | 		      __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2012-10-02 23:44:03 -07:00
										 |  |  | 	strlcpy(search->origin, domain, MXNAME); | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  | 	search->origin[MXNAME-1] = 0; | 
					
						
							|  |  |  | 	ISC_LINK_INIT(search, link); | 
					
						
							|  |  |  | 	return (search); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-05-18 01:48:13 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | clear_searchlist(void) { | 
					
						
							|  |  |  | 	dig_searchlist_t *search; | 
					
						
							|  |  |  | 	while ((search = ISC_LIST_HEAD(search_list)) != NULL) { | 
					
						
							|  |  |  | 		ISC_LIST_UNLINK(search_list, search, link); | 
					
						
							|  |  |  | 		isc_mem_free(mctx, search); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-28 07:04:48 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | create_search_list(irs_resconf_t *resconf) { | 
					
						
							|  |  |  | 	irs_resconf_searchlist_t *list; | 
					
						
							|  |  |  | 	irs_resconf_search_t *entry; | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 	dig_searchlist_t *search; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("create_search_list()"); | 
					
						
							| 
									
										
										
										
											2010-05-18 01:48:13 +00:00
										 |  |  | 	clear_searchlist(); | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 	list = irs_resconf_getsearchlist(resconf); | 
					
						
							|  |  |  | 	for (entry = ISC_LIST_HEAD(*list); | 
					
						
							|  |  |  | 	     entry != NULL; | 
					
						
							|  |  |  | 	     entry = ISC_LIST_NEXT(entry, link)) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		search = make_searchlist_entry(entry->domain); | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 		ISC_LIST_APPEND(search_list, search, link); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Setup the system as a whole, reading key information and resolv.conf | 
					
						
							|  |  |  |  * settings. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-05-09 18:05:13 +00:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2015-08-12 12:50:15 +10:00
										 |  |  | setup_system(isc_boolean_t ipv4only, isc_boolean_t ipv6only) { | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 	irs_resconf_t *resconf = NULL; | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("setup_system()"); | 
					
						
							| 
									
										
										
										
											2000-06-21 01:40:42 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-12 12:50:15 +10:00
										 |  |  | 	if (ipv4only) { | 
					
						
							|  |  |  | 		if (have_ipv4) { | 
					
						
							|  |  |  | 			isc_net_disableipv6(); | 
					
						
							|  |  |  | 			have_ipv6 = ISC_FALSE; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			fatal("can't find IPv4 networking"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ipv6only) { | 
					
						
							|  |  |  | 		if (have_ipv6) { | 
					
						
							|  |  |  | 			isc_net_disableipv4(); | 
					
						
							|  |  |  | 			have_ipv4 = ISC_FALSE; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			fatal("can't find IPv6 networking"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 	result = irs_resconf_load(mctx, RESOLV_CONF, &resconf); | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) { | 
					
						
							| 
									
										
										
										
											2005-06-07 01:00:00 +00:00
										 |  |  | 		fatal("parse of %s failed", RESOLV_CONF); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 	create_search_list(resconf); | 
					
						
							| 
									
										
										
										
											2005-09-08 23:59:45 +00:00
										 |  |  | 	if (ndots == -1) { | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 		ndots = irs_resconf_getndots(resconf); | 
					
						
							| 
									
										
										
										
											2005-09-08 23:59:45 +00:00
										 |  |  | 		debug("ndots is %d.", ndots); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-24 02:51:29 +00:00
										 |  |  | 	/* If user doesn't specify server use nameservers from resolv.conf. */ | 
					
						
							| 
									
										
										
										
											2008-12-13 02:43:25 +00:00
										 |  |  | 	if (ISC_LIST_EMPTY(server_list)) { | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 		get_server_list(resconf); | 
					
						
							| 
									
										
										
										
											2008-12-13 02:43:25 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 13:39:09 -07:00
										 |  |  | 	irs_resconf_destroy(&resconf); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-22 17:11:18 +01:00
										 |  |  | #ifdef HAVE_SETLOCALE
 | 
					
						
							|  |  |  | 	/* Set locale */ | 
					
						
							|  |  |  | 	(void)setlocale(LC_ALL, ""); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							|  |  |  | 	idn_initialize(); | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #ifdef WITH_IDN_OUT_SUPPORT
 | 
					
						
							|  |  |  | 	/* Set domain name -> text post-conversion filter. */ | 
					
						
							|  |  |  | 	result = dns_name_settotextfilter(output_filter); | 
					
						
							|  |  |  | 	check_result(result, "dns_name_settotextfilter"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-19 17:52:27 +00:00
										 |  |  | 	if (keyfile[0] != 0) | 
					
						
							|  |  |  | 		setup_file_key(); | 
					
						
							|  |  |  | 	else if (keysecret[0] != 0) | 
					
						
							|  |  |  | 		setup_text_key(); | 
					
						
							| 
									
										
										
										
											2018-04-22 14:56:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 15:22:23 +02:00
										 |  |  | 	isc_nonce_buf(cookie_secret, sizeof(cookie_secret)); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  |  * Override the search list derived from resolv.conf by 'domain'. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | set_search_domain(char *domain) { | 
					
						
							|  |  |  | 	dig_searchlist_t *search; | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  | 	clear_searchlist(); | 
					
						
							|  |  |  | 	search = make_searchlist_entry(domain); | 
					
						
							|  |  |  | 	ISC_LIST_APPEND(search_list, search, link); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Setup the ISC and DNS libraries for use by the system. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-05-09 18:05:13 +00:00
										 |  |  | void | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | setup_libs(void) { | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	isc_logconfig_t *logconfig = NULL; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("setup_libs()"); | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-22 15:24:37 +02:00
										 |  |  | #if HAVE_PKCS11
 | 
					
						
							| 
									
										
										
										
											2014-08-22 10:40:43 -07:00
										 |  |  | 	pk11_result_register(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	dns_result_register(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	result = isc_net_probeipv4(); | 
					
						
							| 
									
										
										
										
											2000-11-21 21:35:32 +00:00
										 |  |  | 	if (result == ISC_R_SUCCESS) | 
					
						
							|  |  |  | 		have_ipv4 = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result = isc_net_probeipv6(); | 
					
						
							|  |  |  | 	if (result == ISC_R_SUCCESS) | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 		have_ipv6 = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-11-21 21:35:32 +00:00
										 |  |  | 	if (!have_ipv6 && !have_ipv4) | 
					
						
							|  |  |  | 		fatal("can't find either v4 or v6 networking"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	result = isc_mem_create(0, 0, &mctx); | 
					
						
							|  |  |  | 	check_result(result, "isc_mem_create"); | 
					
						
							| 
									
										
										
										
											2013-12-02 13:34:23 -08:00
										 |  |  | 	isc_mem_setname(mctx, "dig", NULL); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	result = isc_log_create(mctx, &lctx, &logconfig); | 
					
						
							|  |  |  | 	check_result(result, "isc_log_create"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	isc_log_setcontext(lctx); | 
					
						
							|  |  |  | 	dns_log_init(lctx); | 
					
						
							|  |  |  | 	dns_log_setcontext(lctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL); | 
					
						
							|  |  |  | 	check_result(result, "isc_log_usechannel"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	isc_log_setdebuglevel(lctx, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	result = isc_taskmgr_create(mctx, 1, 0, &taskmgr); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "isc_taskmgr_create"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	result = isc_task_create(taskmgr, 0, &global_task); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "isc_task_create"); | 
					
						
							| 
									
										
										
										
											2013-12-02 13:34:23 -08:00
										 |  |  | 	isc_task_setname(global_task, "dig", NULL); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	result = isc_timermgr_create(mctx, &timermgr); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "isc_timermgr_create"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	result = isc_socketmgr_create(mctx, &socketmgr); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "isc_socketmgr_create"); | 
					
						
							| 
									
										
										
										
											2000-06-12 19:33:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-22 14:56:28 +02:00
										 |  |  | 	result = dst_lib_init(mctx, NULL); | 
					
						
							| 
									
										
										
										
											2000-06-12 19:33:30 +00:00
										 |  |  | 	check_result(result, "dst_lib_init"); | 
					
						
							|  |  |  | 	is_dst_up = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-07-13 01:49:44 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result = isc_mempool_create(mctx, COMMSIZE, &commctx); | 
					
						
							|  |  |  | 	check_result(result, "isc_mempool_create"); | 
					
						
							|  |  |  | 	isc_mempool_setname(commctx, "COMMPOOL"); | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * 6 and 2 set as reasonable parameters for 3 or 4 nameserver | 
					
						
							|  |  |  | 	 * systems. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isc_mempool_setfreemax(commctx, 6); | 
					
						
							|  |  |  | 	isc_mempool_setfillcount(commctx, 2); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result = isc_mutex_init(&lookup_lock); | 
					
						
							|  |  |  | 	check_result(result, "isc_mutex_init"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 23:46:37 -08:00
										 |  |  | typedef struct dig_ednsoptname { | 
					
						
							|  |  |  | 	isc_uint32_t code; | 
					
						
							|  |  |  | 	const char  *name; | 
					
						
							|  |  |  | } dig_ednsoptname_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | dig_ednsoptname_t optnames[] = { | 
					
						
							|  |  |  | 	{ 3, "NSID" },		/* RFC 5001 */ | 
					
						
							|  |  |  | 	{ 5, "DAU" },		/* RFC 6975 */ | 
					
						
							|  |  |  | 	{ 6, "DHU" },		/* RFC 6975 */ | 
					
						
							|  |  |  | 	{ 7, "N3U" },		/* RFC 6975 */ | 
					
						
							|  |  |  | 	{ 8, "ECS" },		/* RFC 7871 */ | 
					
						
							|  |  |  | 	{ 9, "EXPIRE" },	/* RFC 7314 */ | 
					
						
							|  |  |  | 	{ 10, "COOKIE" },	/* RFC 7873 */ | 
					
						
							|  |  |  | 	{ 11, "KEEPALIVE" },	/* RFC 7828 */ | 
					
						
							|  |  |  | 	{ 12, "PADDING" },	/* RFC 7830 */ | 
					
						
							|  |  |  | 	{ 12, "PAD" },		/* shorthand */ | 
					
						
							|  |  |  | 	{ 13, "CHAIN" },	/* RFC 7901 */ | 
					
						
							| 
									
										
										
										
											2017-08-25 08:38:19 +10:00
										 |  |  | 	{ 14, "KEY-TAG" },	/* RFC 8145 */ | 
					
						
							| 
									
										
										
										
											2017-01-19 23:46:37 -08:00
										 |  |  | 	{ 26946, "DEVICEID" },	/* Brian Hartvigsen */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define N_EDNS_OPTNAMES  (sizeof(optnames) / sizeof(optnames[0]))
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | void | 
					
						
							|  |  |  | save_opt(dig_lookup_t *lookup, char *code, char *value) { | 
					
						
							| 
									
										
										
										
											2017-01-19 23:46:37 -08:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2017-11-27 10:16:55 +00:00
										 |  |  | 	isc_uint32_t num = 0; | 
					
						
							| 
									
										
										
										
											2014-04-22 23:45:19 +00:00
										 |  |  | 	isc_buffer_t b; | 
					
						
							| 
									
										
										
										
											2017-01-19 23:46:37 -08:00
										 |  |  | 	isc_boolean_t found = ISC_FALSE; | 
					
						
							|  |  |  | 	unsigned int i; | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 16:10:35 +11:00
										 |  |  | 	if (lookup->ednsoptscnt >= EDNSOPT_OPTIONS) | 
					
						
							| 
									
										
										
										
											2014-04-22 23:45:19 +00:00
										 |  |  | 		fatal("too many ednsopts"); | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 23:46:37 -08:00
										 |  |  | 	for (i = 0; i < N_EDNS_OPTNAMES; i++) { | 
					
						
							|  |  |  | 		if (strcasecmp(code, optnames[i].name) == 0) { | 
					
						
							|  |  |  | 			num = optnames[i].code; | 
					
						
							|  |  |  | 			found = ISC_TRUE; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!found) { | 
					
						
							|  |  |  | 		result = parse_uint(&num, code, 65535, "ednsopt"); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			fatal("bad edns code point: %s", code); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 16:10:35 +11:00
										 |  |  | 	if (lookup->ednsopts == NULL) { | 
					
						
							|  |  |  | 		cloneopts(lookup, NULL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (lookup->ednsopts[lookup->ednsoptscnt].value != NULL) | 
					
						
							|  |  |  | 		isc_mem_free(mctx, lookup->ednsopts[lookup->ednsoptscnt].value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	lookup->ednsopts[lookup->ednsoptscnt].code = num; | 
					
						
							|  |  |  | 	lookup->ednsopts[lookup->ednsoptscnt].length = 0; | 
					
						
							|  |  |  | 	lookup->ednsopts[lookup->ednsoptscnt].value = NULL; | 
					
						
							| 
									
										
										
										
											2014-04-22 23:45:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (value != NULL) { | 
					
						
							|  |  |  | 		char *buf; | 
					
						
							|  |  |  | 		buf = isc_mem_allocate(mctx, strlen(value)/2 + 1); | 
					
						
							|  |  |  | 		if (buf == NULL) | 
					
						
							|  |  |  | 			fatal("out of memory"); | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 		isc_buffer_init(&b, buf, (unsigned int) strlen(value)/2 + 1); | 
					
						
							| 
									
										
										
										
											2014-04-22 23:45:19 +00:00
										 |  |  | 		result = isc_hex_decodestring(value, &b); | 
					
						
							|  |  |  | 		check_result(result, "isc_hex_decodestring"); | 
					
						
							| 
									
										
										
										
											2017-11-13 16:10:35 +11:00
										 |  |  | 		lookup->ednsopts[lookup->ednsoptscnt].value = | 
					
						
							|  |  |  | 						 isc_buffer_base(&b); | 
					
						
							|  |  |  | 		lookup->ednsopts[lookup->ednsoptscnt].length = | 
					
						
							|  |  |  | 						 isc_buffer_usedlength(&b); | 
					
						
							| 
									
										
										
										
											2014-04-22 23:45:19 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	lookup->ednsoptscnt++; | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Add EDNS0 option record to a message.  Currently, the only supported | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  |  * options are UDP buffer size, the DO bit, and EDNS options | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  |  * (e.g., NSID, COOKIE, client-subnet) | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2005-06-07 00:16:01 +00:00
										 |  |  | add_opt(dns_message_t *msg, isc_uint16_t udpsize, isc_uint16_t edns, | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	unsigned int flags, dns_ednsopt_t *opts, size_t count) | 
					
						
							| 
									
										
										
										
											2005-06-07 00:16:01 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 	dns_rdataset_t *rdataset = NULL; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("add_opt()"); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	result = dns_message_buildopt(msg, &rdataset, edns, udpsize, flags, | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 				      opts, count); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	check_result(result, "dns_message_buildopt"); | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 	result = dns_message_setopt(msg, rdataset); | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	check_result(result, "dns_message_setopt"); | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  |  * Add a question section to a message, asking for the specified name, | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * type, and class. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | add_question(dns_message_t *message, dns_name_t *name, | 
					
						
							|  |  |  | 	     dns_rdataclass_t rdclass, dns_rdatatype_t rdtype) | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	dns_rdataset_t *rdataset; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	debug("add_question()"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	rdataset = NULL; | 
					
						
							|  |  |  | 	result = dns_message_gettemprdataset(message, &rdataset); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_gettemprdataset()"); | 
					
						
							|  |  |  | 	dns_rdataset_makequestion(rdataset, rdclass, rdtype); | 
					
						
							|  |  |  | 	ISC_LIST_APPEND(name->list, rdataset, link); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Check if we're done with all the queued lookups, which is true iff | 
					
						
							|  |  |  |  * all sockets, sends, and recvs are accounted for (counters == 0), | 
					
						
							|  |  |  |  * and the lookup list is empty. | 
					
						
							|  |  |  |  * If we are done, pass control back out to dighost_shutdown() (which is | 
					
						
							|  |  |  |  * part of dig.c, host.c, or nslookup.c) to either shutdown the system as | 
					
						
							|  |  |  |  * a whole or reseed the lookup list. | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | check_if_done(void) { | 
					
						
							|  |  |  | 	debug("check_if_done()"); | 
					
						
							| 
									
										
										
										
											2000-08-02 22:39:01 +00:00
										 |  |  | 	debug("list %s", ISC_LIST_EMPTY(lookup_list) ? "empty" : "full"); | 
					
						
							| 
									
										
										
										
											2000-08-03 18:23:16 +00:00
										 |  |  | 	if (ISC_LIST_EMPTY(lookup_list) && current_lookup == NULL && | 
					
						
							|  |  |  | 	    sendcount == 0) { | 
					
						
							| 
									
										
										
										
											2000-08-02 14:38:51 +00:00
										 |  |  | 		INSIST(sockcount == 0); | 
					
						
							|  |  |  | 		INSIST(recvcount == 0); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		debug("shutting down"); | 
					
						
							|  |  |  | 		dighost_shutdown(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  |  * Clear out a query when we're done with it.  WARNING: This routine | 
					
						
							|  |  |  |  * WILL invalidate the query pointer. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | clear_query(dig_query_t *query) { | 
					
						
							|  |  |  | 	dig_lookup_t *lookup; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	REQUIRE(query != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-11-21 20:52:24 +00:00
										 |  |  | 	debug("clear_query(%p)", query); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	if (query->timer != NULL) | 
					
						
							|  |  |  | 		isc_timer_detach(&query->timer); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	lookup = query->lookup; | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	if (lookup->current_query == query) | 
					
						
							|  |  |  | 		lookup->current_query = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 	if (ISC_LINK_LINKED(query, link)) | 
					
						
							|  |  |  | 		ISC_LIST_UNLINK(lookup->q, query, link); | 
					
						
							|  |  |  | 	if (ISC_LINK_LINKED(query, clink)) | 
					
						
							|  |  |  | 		ISC_LIST_UNLINK(lookup->connecting, query, clink); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	if (ISC_LINK_LINKED(&query->recvbuf, link)) | 
					
						
							|  |  |  | 		ISC_LIST_DEQUEUE(query->recvlist, &query->recvbuf, | 
					
						
							|  |  |  | 				 link); | 
					
						
							|  |  |  | 	if (ISC_LINK_LINKED(&query->lengthbuf, link)) | 
					
						
							|  |  |  | 		ISC_LIST_DEQUEUE(query->lengthlist, &query->lengthbuf, | 
					
						
							|  |  |  | 				 link); | 
					
						
							| 
									
										
										
										
											2000-07-13 01:22:38 +00:00
										 |  |  | 	INSIST(query->recvspace != NULL); | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 	if (query->sock != NULL) { | 
					
						
							|  |  |  | 		isc_socket_detach(&query->sock); | 
					
						
							|  |  |  | 		sockcount--; | 
					
						
							|  |  |  | 		debug("sockcount=%d", sockcount); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-13 01:49:44 +00:00
										 |  |  | 	isc_mempool_put(commctx, query->recvspace); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	isc_buffer_invalidate(&query->recvbuf); | 
					
						
							|  |  |  | 	isc_buffer_invalidate(&query->lengthbuf); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	if (query->waiting_senddone) | 
					
						
							| 
									
										
										
										
											2006-10-02 03:08:34 +00:00
										 |  |  | 		query->pending_free = ISC_TRUE; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		isc_mem_free(mctx, query); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Try and clear out a lookup if we're done with it.  Return ISC_TRUE if | 
					
						
							|  |  |  |  * the lookup was successfully cleared.  If ISC_TRUE is returned, the | 
					
						
							|  |  |  |  * lookup pointer has been invalidated. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | static isc_boolean_t | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | try_clear_lookup(dig_lookup_t *lookup) { | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 	dig_query_t *q; | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	REQUIRE(lookup != NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	debug("try_clear_lookup(%p)", lookup); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 	if (ISC_LIST_HEAD(lookup->q) != NULL || | 
					
						
							|  |  |  | 	    ISC_LIST_HEAD(lookup->connecting) != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 		if (debugging) { | 
					
						
							|  |  |  | 			q = ISC_LIST_HEAD(lookup->q); | 
					
						
							|  |  |  | 			while (q != NULL) { | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 				debug("query to %s still pending", q->servname); | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 				q = ISC_LIST_NEXT(q, link); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			q = ISC_LIST_HEAD(lookup->connecting); | 
					
						
							|  |  |  | 			while (q != NULL) { | 
					
						
							|  |  |  | 				debug("query to %s still connecting", | 
					
						
							|  |  |  | 				      q->servname); | 
					
						
							|  |  |  | 				q = ISC_LIST_NEXT(q, clink); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-10-02 03:08:34 +00:00
										 |  |  | 		return (ISC_FALSE); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * At this point, we know there are no queries on the lookup, | 
					
						
							|  |  |  | 	 * so can make it go away also. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2007-04-03 23:06:39 +00:00
										 |  |  | 	destroy_lookup(lookup); | 
					
						
							|  |  |  | 	return (ISC_TRUE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | destroy_lookup(dig_lookup_t *lookup) { | 
					
						
							|  |  |  | 	dig_server_t *s; | 
					
						
							|  |  |  | 	void *ptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("destroy"); | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	s = ISC_LIST_HEAD(lookup->my_server_list); | 
					
						
							|  |  |  | 	while (s != NULL) { | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 		debug("freeing server %p belonging to %p", s, lookup); | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 		ptr = s; | 
					
						
							|  |  |  | 		s = ISC_LIST_NEXT(s, link); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 		ISC_LIST_DEQUEUE(lookup->my_server_list, | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 				 (dig_server_t *)ptr, link); | 
					
						
							|  |  |  | 		isc_mem_free(mctx, ptr); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (lookup->sendmsg != NULL) | 
					
						
							|  |  |  | 		dns_message_destroy(&lookup->sendmsg); | 
					
						
							|  |  |  | 	if (lookup->querysig != NULL) { | 
					
						
							|  |  |  | 		debug("freeing buffer %p", lookup->querysig); | 
					
						
							|  |  |  | 		isc_buffer_free(&lookup->querysig); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	if (lookup->sendspace != NULL) | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 		isc_mempool_put(commctx, lookup->sendspace); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-09-11 22:34:21 +00:00
										 |  |  | 	if (lookup->tsigctx != NULL) | 
					
						
							|  |  |  | 		dst_context_destroy(&lookup->tsigctx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	if (lookup->ecs_addr != NULL) | 
					
						
							|  |  |  | 		isc_mem_free(mctx, lookup->ecs_addr); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-13 16:10:35 +11:00
										 |  |  | 	if (lookup->ednsopts != NULL) { | 
					
						
							|  |  |  | 		size_t i; | 
					
						
							|  |  |  | 		for (i = 0; i < EDNSOPT_OPTIONS; i++) { | 
					
						
							|  |  |  | 			if (lookup->ednsopts[i].value != NULL) | 
					
						
							|  |  |  | 				isc_mem_free(mctx, lookup->ednsopts[i].value); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		isc_mem_free(mctx, lookup->ednsopts); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	isc_mem_free(mctx, lookup); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  |  * If we can, start the next lookup in the queue running. | 
					
						
							|  |  |  |  * This assumes that the lookup on the head of the queue hasn't been | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  |  * started yet.  It also removes the lookup from the head of the queue, | 
					
						
							|  |  |  |  * setting the current_lookup pointer pointing to it. | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | void | 
					
						
							|  |  |  | start_lookup(void) { | 
					
						
							|  |  |  | 	debug("start_lookup()"); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	if (cancel_now) | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If there's a current lookup running, we really shouldn't get | 
					
						
							|  |  |  | 	 * here. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	INSIST(current_lookup == NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	current_lookup = ISC_LIST_HEAD(lookup_list); | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Put the current lookup somewhere so cancel_all can find it | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	if (current_lookup != NULL) { | 
					
						
							|  |  |  | 		ISC_LIST_DEQUEUE(lookup_list, current_lookup, link); | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 		if (setup_lookup(current_lookup)) | 
					
						
							|  |  |  | 			do_lookup(current_lookup); | 
					
						
							|  |  |  | 		else if (next_origin(current_lookup)) | 
					
						
							|  |  |  | 			check_next_lookup(current_lookup); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		check_if_done(); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * If we can, clear the current lookup and start the next one running. | 
					
						
							|  |  |  |  * This calls try_clear_lookup, so may invalidate the lookup pointer. | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | check_next_lookup(dig_lookup_t *lookup) { | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-05-22 22:56:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 	debug("check_next_lookup(%p)", lookup); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-27 19:06:12 +00:00
										 |  |  | 	if (ISC_LIST_HEAD(lookup->q) != NULL) { | 
					
						
							|  |  |  | 		debug("still have a worker"); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2000-07-27 19:06:12 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	if (try_clear_lookup(lookup)) { | 
					
						
							|  |  |  | 		current_lookup = NULL; | 
					
						
							|  |  |  | 		start_lookup(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Create and queue a new lookup as a followup to the current lookup, | 
					
						
							|  |  |  |  * based on the supplied message and section.  This is used in trace and | 
					
						
							|  |  |  |  * name server search modes to start a new lookup using servers from | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  |  * NS records in a reply. Returns the number of followup lookups made. | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 	dig_lookup_t *lookup = NULL; | 
					
						
							|  |  |  | 	dig_server_t *srv = NULL; | 
					
						
							|  |  |  | 	dns_rdataset_t *rdataset = NULL; | 
					
						
							| 
									
										
										
										
											2000-10-25 04:26:57 +00:00
										 |  |  | 	dns_rdata_t rdata = DNS_RDATA_INIT; | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 	dns_name_t *name = NULL; | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2000-05-06 01:16:07 +00:00
										 |  |  | 	isc_boolean_t success = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 	int numLookups = 0; | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 	int num; | 
					
						
							|  |  |  | 	isc_result_t lresult, addresses_result; | 
					
						
							|  |  |  | 	char bad_namestr[DNS_NAME_FORMATSIZE]; | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 	dns_name_t *domain; | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	isc_boolean_t horizontal = ISC_FALSE, bad = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 	debug("following up %s", query->lookup->textname); | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 	addresses_result = ISC_R_SUCCESS; | 
					
						
							|  |  |  | 	bad_namestr[0] = '\0'; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	for (result = dns_message_firstname(msg, section); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 	     result == ISC_R_SUCCESS; | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 	     result = dns_message_nextname(msg, section)) { | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 		name = NULL; | 
					
						
							| 
									
										
										
										
											2000-05-06 01:16:07 +00:00
										 |  |  | 		dns_message_currentname(msg, section, &name); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-09-16 02:10:42 +00:00
										 |  |  | 		if (section == DNS_SECTION_AUTHORITY) { | 
					
						
							|  |  |  | 			rdataset = NULL; | 
					
						
							|  |  |  | 			result = dns_message_findtype(name, dns_rdatatype_soa, | 
					
						
							|  |  |  | 						      0, &rdataset); | 
					
						
							|  |  |  | 			if (result == ISC_R_SUCCESS) | 
					
						
							|  |  |  | 				return (0); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		rdataset = NULL; | 
					
						
							|  |  |  | 		result = dns_message_findtype(name, dns_rdatatype_ns, 0, | 
					
						
							|  |  |  | 					      &rdataset); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		debug("found NS set"); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 		if (query->lookup->trace && !query->lookup->trace_root) { | 
					
						
							|  |  |  | 			dns_namereln_t namereln; | 
					
						
							|  |  |  | 			unsigned int nlabels; | 
					
						
							|  |  |  | 			int order; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			domain = dns_fixedname_name(&query->lookup->fdomain); | 
					
						
							|  |  |  | 			namereln = dns_name_fullcompare(name, domain, | 
					
						
							|  |  |  | 							&order, &nlabels); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 			if (namereln == dns_namereln_equal) { | 
					
						
							|  |  |  | 				if (!horizontal) | 
					
						
							|  |  |  | 					printf(";; BAD (HORIZONTAL) REFERRAL\n"); | 
					
						
							|  |  |  | 				horizontal = ISC_TRUE; | 
					
						
							|  |  |  | 			} else if (namereln != dns_namereln_subdomain) { | 
					
						
							|  |  |  | 				if (!bad) | 
					
						
							|  |  |  | 					printf(";; BAD REFERRAL\n"); | 
					
						
							|  |  |  | 				bad = ISC_TRUE; | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		for (result = dns_rdataset_first(rdataset); | 
					
						
							|  |  |  | 		     result == ISC_R_SUCCESS; | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 		     result = dns_rdataset_next(rdataset)) { | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			char namestr[DNS_NAME_FORMATSIZE]; | 
					
						
							|  |  |  | 			dns_rdata_ns_t ns; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (query->lookup->trace_root && | 
					
						
							|  |  |  | 			    query->lookup->nsfound >= MXSERV) | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dns_rdataset_current(rdataset, &rdata); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			query->lookup->nsfound++; | 
					
						
							| 
									
										
										
										
											2008-01-14 23:24:24 +00:00
										 |  |  | 			result = dns_rdata_tostruct(&rdata, &ns, NULL); | 
					
						
							|  |  |  | 			check_result(result, "dns_rdata_tostruct"); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			dns_name_format(&ns.name, namestr, sizeof(namestr)); | 
					
						
							|  |  |  | 			dns_rdata_freestruct(&ns); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			/* Initialize lookup if we've not yet */ | 
					
						
							| 
									
										
										
										
											2011-02-25 23:11:13 +00:00
										 |  |  | 			debug("found NS %s", namestr); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			if (!success) { | 
					
						
							|  |  |  | 				success = ISC_TRUE; | 
					
						
							|  |  |  | 				lookup_counter++; | 
					
						
							|  |  |  | 				lookup = requeue_lookup(query->lookup, | 
					
						
							|  |  |  | 							ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2001-10-31 21:55:31 +00:00
										 |  |  | 				cancel_lookup(query->lookup); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 				lookup->doing_xfr = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 				if (!lookup->trace_root && | 
					
						
							|  |  |  | 				    section == DNS_SECTION_ANSWER) | 
					
						
							|  |  |  | 					lookup->trace = ISC_FALSE; | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					lookup->trace = query->lookup->trace; | 
					
						
							| 
									
										
										
										
											2001-07-28 00:55:15 +00:00
										 |  |  | 				lookup->ns_search_only = | 
					
						
							|  |  |  | 					query->lookup->ns_search_only; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 				lookup->trace_root = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2005-03-31 02:36:05 +00:00
										 |  |  | 				if (lookup->ns_search_only) | 
					
						
							|  |  |  | 					lookup->recurse = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 				domain = dns_fixedname_name(&lookup->fdomain); | 
					
						
							|  |  |  | 				dns_name_copy(name, domain, NULL); | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-02-25 23:11:13 +00:00
										 |  |  | 			debug("adding server %s", namestr); | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 			num = getaddresses(lookup, namestr, &lresult); | 
					
						
							|  |  |  | 			if (lresult != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2013-02-07 14:14:26 -08:00
										 |  |  | 				printf("couldn't get address for '%s': %s\n", | 
					
						
							|  |  |  | 				       namestr, isc_result_totext(lresult)); | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 				if (addresses_result == ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 					addresses_result = lresult; | 
					
						
							| 
									
										
										
										
											2017-09-13 00:14:37 -07:00
										 |  |  | 					strlcpy(bad_namestr, namestr, | 
					
						
							|  |  |  | 						sizeof(bad_namestr)); | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			numLookups += num; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			dns_rdata_reset(&rdata); | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 	if (numLookups == 0 && addresses_result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		fatal("couldn't get address for '%s': %s", | 
					
						
							|  |  |  | 		      bad_namestr, isc_result_totext(result)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (lookup == NULL && | 
					
						
							|  |  |  | 	    section == DNS_SECTION_ANSWER && | 
					
						
							| 
									
										
										
										
											2000-06-22 22:37:31 +00:00
										 |  |  | 	    (query->lookup->trace || query->lookup->ns_search_only)) | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		return (followup_lookup(msg, query, DNS_SECTION_AUTHORITY)); | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Randomize the order the nameserver will be tried. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (numLookups > 1) { | 
					
						
							|  |  |  | 		isc_uint32_t i, j; | 
					
						
							|  |  |  | 		dig_serverlist_t my_server_list; | 
					
						
							| 
									
										
										
										
											2011-03-11 06:11:27 +00:00
										 |  |  | 		dig_server_t *next; | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		ISC_LIST_INIT(my_server_list); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-11 06:11:27 +00:00
										 |  |  | 		i = numLookups; | 
					
						
							|  |  |  | 		for (srv = ISC_LIST_HEAD(lookup->my_server_list); | 
					
						
							|  |  |  | 		     srv != NULL; | 
					
						
							|  |  |  | 		     srv = ISC_LIST_HEAD(lookup->my_server_list)) { | 
					
						
							|  |  |  | 			INSIST(i > 0); | 
					
						
							| 
									
										
										
										
											2018-05-28 15:22:23 +02:00
										 |  |  | 			j = isc_random_uniform(i); | 
					
						
							| 
									
										
										
										
											2011-03-11 06:11:27 +00:00
										 |  |  | 			next = ISC_LIST_NEXT(srv, link); | 
					
						
							|  |  |  | 			while (j-- > 0 && next != NULL) { | 
					
						
							|  |  |  | 				srv = next; | 
					
						
							|  |  |  | 				next = ISC_LIST_NEXT(srv, link); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 			ISC_LIST_DEQUEUE(lookup->my_server_list, srv, link); | 
					
						
							|  |  |  | 			ISC_LIST_APPEND(my_server_list, srv, link); | 
					
						
							| 
									
										
										
										
											2011-03-11 06:11:27 +00:00
										 |  |  | 			i--; | 
					
						
							| 
									
										
										
										
											2004-10-07 02:21:48 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		ISC_LIST_APPENDLIST(lookup->my_server_list, | 
					
						
							|  |  |  | 				    my_server_list, link); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (numLookups); | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  |  * Create and queue a new lookup using the next origin from the search | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * list, read in setup_system(). | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Return ISC_TRUE iff there was another searchlist entry. | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-24 18:07:03 +00:00
										 |  |  | static isc_boolean_t | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | next_origin(dig_lookup_t *oldlookup) { | 
					
						
							|  |  |  | 	dig_lookup_t *newlookup; | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 	dig_searchlist_t *search; | 
					
						
							| 
									
										
										
										
											2013-09-04 13:24:11 +10:00
										 |  |  | 	dns_fixedname_t fixed; | 
					
						
							|  |  |  | 	dns_name_t *name; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	debug("next_origin()"); | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 	debug("following up %s", oldlookup->textname); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-24 18:07:03 +00:00
										 |  |  | 	if (!usesearch) | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * We're not using a search list, so don't even think | 
					
						
							|  |  |  | 		 * about finding the next entry. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		return (ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2013-09-04 23:46:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-04 13:24:11 +10:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Check for a absolute name or ndots being met. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-03-28 14:38:09 +02:00
										 |  |  | 	name = dns_fixedname_initname(&fixed); | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 	result = dns_name_fromstring2(name, oldlookup->textname, NULL, | 
					
						
							| 
									
										
										
										
											2013-09-04 13:24:11 +10:00
										 |  |  | 				      0, NULL); | 
					
						
							|  |  |  | 	if (result == ISC_R_SUCCESS && | 
					
						
							|  |  |  | 	    (dns_name_isabsolute(name) || | 
					
						
							|  |  |  | 	     (int)dns_name_countlabels(name) > ndots)) | 
					
						
							|  |  |  | 		return (ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2013-09-04 23:46:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 	if (oldlookup->origin == NULL && !oldlookup->need_search) | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Then we just did rootorg; there's nothing left. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2000-07-24 18:07:03 +00:00
										 |  |  | 		return (ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 	if (oldlookup->origin == NULL && oldlookup->need_search) { | 
					
						
							|  |  |  | 		newlookup = requeue_lookup(oldlookup, ISC_TRUE); | 
					
						
							|  |  |  | 		newlookup->origin = ISC_LIST_HEAD(search_list); | 
					
						
							|  |  |  | 		newlookup->need_search = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 		search = ISC_LIST_NEXT(oldlookup->origin, link); | 
					
						
							|  |  |  | 		if (search == NULL && oldlookup->done_as_is) | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 			return (ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 		newlookup = requeue_lookup(oldlookup, ISC_TRUE); | 
					
						
							|  |  |  | 		newlookup->origin = search; | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 	cancel_lookup(oldlookup); | 
					
						
							| 
									
										
										
										
											2000-07-24 18:07:03 +00:00
										 |  |  | 	return (ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Insert an SOA record into the sendmessage in a lookup.  Used for | 
					
						
							|  |  |  |  * creating IXFR queries. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | insert_soa(dig_lookup_t *lookup) { | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	dns_rdata_soa_t soa; | 
					
						
							|  |  |  | 	dns_rdata_t *rdata = NULL; | 
					
						
							|  |  |  | 	dns_rdatalist_t *rdatalist = NULL; | 
					
						
							|  |  |  | 	dns_rdataset_t *rdataset = NULL; | 
					
						
							|  |  |  | 	dns_name_t *soaname = NULL; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("insert_soa()"); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	soa.mctx = mctx; | 
					
						
							|  |  |  | 	soa.serial = lookup->ixfr_serial; | 
					
						
							| 
									
										
										
										
											2001-07-28 00:55:15 +00:00
										 |  |  | 	soa.refresh = 0; | 
					
						
							|  |  |  | 	soa.retry = 0; | 
					
						
							|  |  |  | 	soa.expire = 0; | 
					
						
							|  |  |  | 	soa.minimum = 0; | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	soa.common.rdclass = lookup->rdclass; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	soa.common.rdtype = dns_rdatatype_soa; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dns_name_init(&soa.origin, NULL); | 
					
						
							| 
									
										
										
										
											2001-07-30 01:09:14 +00:00
										 |  |  | 	dns_name_init(&soa.contact, NULL); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-28 00:55:15 +00:00
										 |  |  | 	dns_name_clone(dns_rootname, &soa.origin); | 
					
						
							| 
									
										
										
										
											2001-07-30 01:09:14 +00:00
										 |  |  | 	dns_name_clone(dns_rootname, &soa.contact); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	isc_buffer_init(&lookup->rdatabuf, lookup->rdatastore, | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 			sizeof(lookup->rdatastore)); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result = dns_message_gettemprdata(lookup->sendmsg, &rdata); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_gettemprdata"); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result = dns_rdata_fromstruct(rdata, lookup->rdclass, | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				      dns_rdatatype_soa, &soa, | 
					
						
							|  |  |  | 				      &lookup->rdatabuf); | 
					
						
							|  |  |  | 	check_result(result, "isc_rdata_fromstruct"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = dns_message_gettemprdatalist(lookup->sendmsg, &rdatalist); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_gettemprdatalist"); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	result = dns_message_gettemprdataset(lookup->sendmsg, &rdataset); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_gettemprdataset"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dns_rdatalist_init(rdatalist); | 
					
						
							|  |  |  | 	rdatalist->type = dns_rdatatype_soa; | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	rdatalist->rdclass = lookup->rdclass; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	ISC_LIST_APPEND(rdatalist->rdata, rdata, link); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dns_rdatalist_tordataset(rdatalist, rdataset); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = dns_message_gettempname(lookup->sendmsg, &soaname); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_gettempname"); | 
					
						
							|  |  |  | 	dns_name_init(soaname, NULL); | 
					
						
							|  |  |  | 	dns_name_clone(lookup->name, soaname); | 
					
						
							|  |  |  | 	ISC_LIST_INIT(soaname->list); | 
					
						
							|  |  |  | 	ISC_LIST_APPEND(soaname->list, rdataset, link); | 
					
						
							|  |  |  | 	dns_message_addname(lookup->sendmsg, soaname, DNS_SECTION_AUTHORITY); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | compute_cookie(unsigned char *clientcookie, size_t len) { | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	/* XXXMPA need to fix, should be per server. */ | 
					
						
							|  |  |  | 	INSIST(len >= 8U); | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	memmove(clientcookie, cookie_secret, 8); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Setup the supplied lookup structure, making it ready to start sending | 
					
						
							|  |  |  |  * queries to servers.  Create and initialize the message to be sent as | 
					
						
							|  |  |  |  * well as the query structures and buffer space for the replies.  If the | 
					
						
							|  |  |  |  * server list is empty, clone it from the system default list. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | isc_boolean_t | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | setup_lookup(dig_lookup_t *lookup) { | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2016-07-21 15:53:43 -07:00
										 |  |  | 	unsigned int len; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	dig_server_t *serv; | 
					
						
							|  |  |  | 	dig_query_t *query; | 
					
						
							|  |  |  | 	isc_buffer_t b; | 
					
						
							| 
									
										
										
										
											2001-03-05 21:15:47 +00:00
										 |  |  | 	dns_compress_t cctx; | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 	char store[MXNAME]; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	char ecsbuf[20]; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	char cookiebuf[256]; | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	char *origin = NULL; | 
					
						
							|  |  |  | 	char *textname = NULL; | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	char idn_origin[MXNAME], idn_textname[MXNAME]; | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #ifdef WITH_IDN_OUT_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2016-10-28 12:05:19 +11:00
										 |  |  | 	result = dns_name_settotextfilter(lookup->idnout ? | 
					
						
							|  |  |  | 					  output_filter : NULL); | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 	check_result(result, "dns_name_settotextfilter"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	REQUIRE(lookup != NULL); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	debug("setup_lookup(%p)", lookup); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, | 
					
						
							|  |  |  | 				    &lookup->sendmsg); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "dns_message_create"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-24 23:39:30 +00:00
										 |  |  | 	if (lookup->new_search) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("resetting lookup counter."); | 
					
						
							| 
									
										
										
										
											2000-05-24 19:49:51 +00:00
										 |  |  | 		lookup_counter = 0; | 
					
						
							| 
									
										
										
										
											2000-05-24 23:39:30 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 16:35:30 +00:00
										 |  |  | 	if (ISC_LIST_EMPTY(lookup->my_server_list)) { | 
					
						
							|  |  |  | 		debug("cloning server list"); | 
					
						
							|  |  |  | 		clone_server_list(server_list, &lookup->my_server_list); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	result = dns_message_gettempname(lookup->sendmsg, &lookup->name); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "dns_message_gettempname"); | 
					
						
							|  |  |  | 	dns_name_init(lookup->name, NULL); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-21 11:52:24 +10:00
										 |  |  | 	isc_buffer_init(&lookup->namebuf, lookup->name_space, | 
					
						
							|  |  |  | 			sizeof(lookup->name_space)); | 
					
						
							|  |  |  | 	isc_buffer_init(&lookup->onamebuf, lookup->oname_space, | 
					
						
							|  |  |  | 			sizeof(lookup->oname_space)); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * We cannot convert `textname' and `origin' separately. | 
					
						
							|  |  |  | 	 * `textname' doesn't contain TLD, but local mapping needs | 
					
						
							|  |  |  | 	 * TLD. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	textname = lookup->textname; | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	if (lookup->idnin) { | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 		result = idn_locale_to_ace(textname, idn_textname, sizeof(idn_textname)); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 		check_result(result, "convert textname to IDN encoding"); | 
					
						
							|  |  |  | 		debug("idn_textname: %s", idn_textname); | 
					
						
							|  |  |  | 		textname = idn_textname; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-24 18:07:03 +00:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	 * If the name has too many dots, force the origin to be NULL | 
					
						
							|  |  |  | 	 * (which produces an absolute lookup).  Otherwise, take the origin | 
					
						
							| 
									
										
										
										
											2000-07-24 18:07:03 +00:00
										 |  |  | 	 * we have if there's one in the struct already.  If it's NULL, | 
					
						
							|  |  |  | 	 * take the first entry in the searchlist iff either usesearch | 
					
						
							|  |  |  | 	 * is TRUE or we got a domain line in the resolv.conf file. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 	if (lookup->new_search) { | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 		if ((count_dots(textname) >= ndots) || !usesearch) | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 			lookup->origin = NULL; /* Force abs lookup */ | 
					
						
							|  |  |  | 			lookup->done_as_is = ISC_TRUE; | 
					
						
							|  |  |  | 			lookup->need_search = usesearch; | 
					
						
							|  |  |  | 		} else if (lookup->origin == NULL && usesearch) { | 
					
						
							|  |  |  | 			lookup->origin = ISC_LIST_HEAD(search_list); | 
					
						
							|  |  |  | 			lookup->need_search = ISC_FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 	if (lookup->origin != NULL) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("trying origin %s", lookup->origin->origin); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		result = dns_message_gettempname(lookup->sendmsg, | 
					
						
							|  |  |  | 						 &lookup->oname); | 
					
						
							|  |  |  | 		check_result(result, "dns_message_gettempname"); | 
					
						
							|  |  |  | 		dns_name_init(lookup->oname, NULL); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 		/* XXX Helper funct to conv char* to name? */ | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 		origin = lookup->origin->origin; | 
					
						
							|  |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							|  |  |  | 		if (lookup->idnin) { | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 			result = idn_locale_to_ace(origin, idn_origin, sizeof(idn_origin)); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 			check_result(result, "convert origin to IDN encoding"); | 
					
						
							|  |  |  | 			debug("trying idn origin %s", idn_origin); | 
					
						
							|  |  |  | 			origin = idn_origin; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		len = (unsigned int) strlen(origin); | 
					
						
							|  |  |  | 		isc_buffer_init(&b, origin, len); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		isc_buffer_add(&b, len); | 
					
						
							| 
									
										
										
										
											2000-05-03 23:07:30 +00:00
										 |  |  | 		result = dns_name_fromtext(lookup->oname, &b, dns_rootname, | 
					
						
							| 
									
										
										
										
											2009-09-01 00:22:28 +00:00
										 |  |  | 					   0, &lookup->onamebuf); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		if (result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 			dns_message_puttempname(lookup->sendmsg, | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 						&lookup->name); | 
					
						
							|  |  |  | 			dns_message_puttempname(lookup->sendmsg, | 
					
						
							|  |  |  | 						&lookup->oname); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 			fatal("'%s' is not in legal name syntax (%s)", | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 			      origin, | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 			      isc_result_totext(result)); | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 		if (lookup->trace && lookup->trace_root) { | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 			dns_name_clone(dns_rootname, lookup->name); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 			dns_fixedname_t fixed; | 
					
						
							|  |  |  | 			dns_name_t *name; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-28 14:38:09 +02:00
										 |  |  | 			name = dns_fixedname_initname(&fixed); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 			len = (unsigned int) strlen(textname); | 
					
						
							|  |  |  | 			isc_buffer_init(&b, textname, len); | 
					
						
							| 
									
										
										
										
											2000-05-06 01:16:07 +00:00
										 |  |  | 			isc_buffer_add(&b, len); | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 			result = dns_name_fromtext(name, &b, NULL, 0, NULL); | 
					
						
							|  |  |  | 			if (result == ISC_R_SUCCESS && | 
					
						
							|  |  |  | 			    !dns_name_isabsolute(name)) | 
					
						
							|  |  |  | 				result = dns_name_concatenate(name, | 
					
						
							|  |  |  | 							      lookup->oname, | 
					
						
							|  |  |  | 							      lookup->name, | 
					
						
							|  |  |  | 							      &lookup->namebuf); | 
					
						
							|  |  |  | 			else if (result == ISC_R_SUCCESS) | 
					
						
							|  |  |  | 				result = dns_name_copy(name, lookup->name, | 
					
						
							|  |  |  | 						       &lookup->namebuf); | 
					
						
							|  |  |  | 			if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 				dns_message_puttempname(lookup->sendmsg, | 
					
						
							|  |  |  | 							&lookup->name); | 
					
						
							|  |  |  | 				dns_message_puttempname(lookup->sendmsg, | 
					
						
							|  |  |  | 							&lookup->oname); | 
					
						
							|  |  |  | 				if (result == DNS_R_NAMETOOLONG) | 
					
						
							|  |  |  | 					return (ISC_FALSE); | 
					
						
							|  |  |  | 				fatal("'%s' is not in legal name syntax (%s)", | 
					
						
							|  |  |  | 				      lookup->textname, | 
					
						
							|  |  |  | 				      isc_result_totext(result)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		dns_message_puttempname(lookup->sendmsg, &lookup->oname); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("using root origin"); | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 		if (lookup->trace && lookup->trace_root) | 
					
						
							|  |  |  | 			dns_name_clone(dns_rootname, lookup->name); | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 			len = (unsigned int) strlen(textname); | 
					
						
							|  |  |  | 			isc_buffer_init(&b, textname, len); | 
					
						
							| 
									
										
										
										
											2000-05-06 01:16:07 +00:00
										 |  |  | 			isc_buffer_add(&b, len); | 
					
						
							|  |  |  | 			result = dns_name_fromtext(lookup->name, &b, | 
					
						
							| 
									
										
										
										
											2009-09-01 00:22:28 +00:00
										 |  |  | 						   dns_rootname, 0, | 
					
						
							| 
									
										
										
										
											2000-05-06 01:16:07 +00:00
										 |  |  | 						   &lookup->namebuf); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 			dns_message_puttempname(lookup->sendmsg, | 
					
						
							|  |  |  | 						&lookup->name); | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | 			warn("'%s' is not a legal name " | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 			      "(%s)", lookup->textname, | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 			      isc_result_totext(result)); | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | #if TARGET_OS_IPHONE
 | 
					
						
							|  |  |  | 			check_next_lookup(current_lookup); | 
					
						
							|  |  |  | 			return (ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2017-12-12 13:43:55 +11:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 			digexit(); | 
					
						
							| 
									
										
										
										
											2017-11-23 16:58:12 +11:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 	dns_name_format(lookup->name, store, sizeof(store)); | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 	dighost_trying(store, lookup); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	INSIST(dns_name_isabsolute(lookup->name)); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-28 15:22:23 +02:00
										 |  |  | 	lookup->sendmsg->id = (dns_messageid_t)isc_random16(); | 
					
						
							| 
									
										
										
										
											2015-05-19 12:46:06 +10:00
										 |  |  | 	lookup->sendmsg->opcode = lookup->opcode; | 
					
						
							| 
									
										
										
										
											2000-06-07 00:13:57 +00:00
										 |  |  | 	lookup->msgcounter = 0; | 
					
						
							| 
									
										
										
										
											2000-05-24 03:10:24 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If this is a trace request, completely disallow recursion, since | 
					
						
							|  |  |  | 	 * it's meaningless for traces. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	if (lookup->trace || (lookup->ns_search_only && !lookup->trace_root)) | 
					
						
							|  |  |  | 		lookup->recurse = ISC_FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-06 05:50:20 +00:00
										 |  |  | 	if (lookup->recurse && | 
					
						
							|  |  |  | 	    lookup->rdtype != dns_rdatatype_axfr && | 
					
						
							|  |  |  | 	    lookup->rdtype != dns_rdatatype_ixfr) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("recursive query"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RD; | 
					
						
							| 
									
										
										
										
											2000-05-03 20:27:13 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	/* XXX aaflag */ | 
					
						
							| 
									
										
										
										
											2000-07-13 21:12:21 +00:00
										 |  |  | 	if (lookup->aaonly) { | 
					
						
							|  |  |  | 		debug("AA query"); | 
					
						
							|  |  |  | 		lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AA; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-16 18:00:05 +00:00
										 |  |  | 	if (lookup->adflag) { | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 		debug("AD query"); | 
					
						
							| 
									
										
										
										
											2000-06-16 18:00:05 +00:00
										 |  |  | 		lookup->sendmsg->flags |= DNS_MESSAGEFLAG_AD; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (lookup->cdflag) { | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 		debug("CD query"); | 
					
						
							| 
									
										
										
										
											2000-06-16 18:00:05 +00:00
										 |  |  | 		lookup->sendmsg->flags |= DNS_MESSAGEFLAG_CD; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-31 10:16:00 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-18 09:18:41 +10:00
										 |  |  | 	if (lookup->raflag) { | 
					
						
							|  |  |  | 		debug("RA query"); | 
					
						
							|  |  |  | 		lookup->sendmsg->flags |= DNS_MESSAGEFLAG_RA; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (lookup->tcflag) { | 
					
						
							|  |  |  | 		debug("TC query"); | 
					
						
							|  |  |  | 		lookup->sendmsg->flags |= DNS_MESSAGEFLAG_TC; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 10:16:00 +11:00
										 |  |  | 	if (lookup->zflag) { | 
					
						
							|  |  |  | 		debug("Z query"); | 
					
						
							|  |  |  | 		lookup->sendmsg->flags |= 0x0040U; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-06-16 18:00:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	dns_message_addname(lookup->sendmsg, lookup->name, | 
					
						
							|  |  |  | 			    DNS_SECTION_QUESTION); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	if (lookup->trace && lookup->trace_root) { | 
					
						
							|  |  |  | 		lookup->qrdtype = lookup->rdtype; | 
					
						
							|  |  |  | 		lookup->rdtype = dns_rdatatype_ns; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	if ((lookup->rdtype == dns_rdatatype_axfr) || | 
					
						
							|  |  |  | 	    (lookup->rdtype == dns_rdatatype_ixfr)) { | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		/*
 | 
					
						
							| 
									
										
										
										
											2007-12-03 00:21:48 +00:00
										 |  |  | 		 * Force TCP mode if we're doing an axfr. | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2007-12-03 00:21:48 +00:00
										 |  |  | 		if (lookup->rdtype == dns_rdatatype_axfr) { | 
					
						
							|  |  |  | 			lookup->doing_xfr = ISC_TRUE; | 
					
						
							|  |  |  | 			lookup->tcp_mode = ISC_TRUE; | 
					
						
							|  |  |  | 		} else if (lookup->tcp_mode) { | 
					
						
							|  |  |  | 			lookup->doing_xfr = ISC_TRUE; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-12-08 17:06:52 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 11:42:02 +11:00
										 |  |  | 	if (!lookup->header_only) | 
					
						
							|  |  |  | 		add_question(lookup->sendmsg, lookup->name, lookup->rdclass, | 
					
						
							|  |  |  | 			     lookup->rdtype); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	/* add_soa */ | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	if (lookup->rdtype == dns_rdatatype_ixfr) | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 		insert_soa(lookup); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	/* XXX Insist this? */ | 
					
						
							|  |  |  | 	lookup->tsigctx = NULL; | 
					
						
							|  |  |  | 	lookup->querysig = NULL; | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 	if (tsigkey != NULL) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("initializing keys"); | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 		result = dns_message_settsigkey(lookup->sendmsg, tsigkey); | 
					
						
							| 
									
										
										
										
											2000-06-06 00:43:17 +00:00
										 |  |  | 		check_result(result, "dns_message_settsigkey"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 01:49:44 +00:00
										 |  |  | 	lookup->sendspace = isc_mempool_get(commctx); | 
					
						
							| 
									
										
										
										
											2000-07-13 01:22:38 +00:00
										 |  |  | 	if (lookup->sendspace == NULL) | 
					
						
							|  |  |  | 		fatal("memory allocation failure"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-05 21:15:47 +00:00
										 |  |  | 	result = dns_compress_init(&cctx, -1, mctx); | 
					
						
							|  |  |  | 	check_result(result, "dns_compress_init"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 	debug("starting to render the message"); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	isc_buffer_init(&lookup->renderbuf, lookup->sendspace, COMMSIZE); | 
					
						
							| 
									
										
										
										
											2001-03-05 21:15:47 +00:00
										 |  |  | 	result = dns_message_renderbegin(lookup->sendmsg, &cctx, | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 					 &lookup->renderbuf); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "dns_message_renderbegin"); | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 	if (lookup->udpsize > 0 || lookup->dnssec || | 
					
						
							|  |  |  | 	    lookup->edns > -1 || lookup->ecs_addr != NULL) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | #define MAXOPTS (EDNSOPT_OPTIONS + DNS_EDNSOPTIONS)
 | 
					
						
							|  |  |  | 		dns_ednsopt_t opts[MAXOPTS]; | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | 		unsigned int flags; | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 		unsigned int i = 0; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * There can't be more than MAXOPTS options to send: | 
					
						
							|  |  |  | 		 * a maximum of EDNSOPT_OPTIONS set by +ednsopt | 
					
						
							|  |  |  | 		 * and DNS_EDNSOPTIONS set by other arguments | 
					
						
							|  |  |  | 		 * (+nsid, +cookie, etc). | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2000-10-11 17:44:18 +00:00
										 |  |  | 		if (lookup->udpsize == 0) | 
					
						
							| 
									
										
										
										
											2006-02-17 00:10:42 +00:00
										 |  |  | 			lookup->udpsize = 4096; | 
					
						
							| 
									
										
										
										
											2005-06-07 00:16:01 +00:00
										 |  |  | 		if (lookup->edns < 0) | 
					
						
							|  |  |  | 			lookup->edns = 0; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		if (lookup->nsid) { | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			INSIST(i < MAXOPTS); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 			opts[i].code = DNS_OPT_NSID; | 
					
						
							|  |  |  | 			opts[i].length = 0; | 
					
						
							|  |  |  | 			opts[i].value = NULL; | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (lookup->ecs_addr != NULL) { | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 			isc_uint8_t addr[16]; | 
					
						
							|  |  |  | 			isc_uint16_t family; | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 			isc_uint32_t plen; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			struct sockaddr *sa; | 
					
						
							|  |  |  | 			struct sockaddr_in *sin; | 
					
						
							|  |  |  | 			struct sockaddr_in6 *sin6; | 
					
						
							|  |  |  | 			size_t addrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			sa = &lookup->ecs_addr->type.sa; | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 			plen = lookup->ecs_addr->length; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			/* Round up prefix len to a multiple of 8 */ | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 			addrl = (plen + 7) / 8; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			INSIST(i < MAXOPTS); | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			opts[i].code = DNS_OPT_CLIENT_SUBNET; | 
					
						
							| 
									
										
										
										
											2014-02-19 22:58:09 -08:00
										 |  |  | 			opts[i].length = (isc_uint16_t) addrl + 4; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			check_result(result, "isc_buffer_allocate"); | 
					
						
							| 
									
										
										
										
											2016-03-23 15:00:30 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 			/*
 | 
					
						
							|  |  |  | 			 * XXXMUKS: According to RFC7871, "If there is | 
					
						
							|  |  |  | 			 * no ADDRESS set, i.e., SOURCE PREFIX-LENGTH is | 
					
						
							|  |  |  | 			 * set to 0, then FAMILY SHOULD be set to the | 
					
						
							|  |  |  | 			 * transport over which the query is sent." | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * However, at this point we don't know what | 
					
						
							|  |  |  | 			 * transport(s) we'll be using, so we can't | 
					
						
							|  |  |  | 			 * set the value now. For now, we're using | 
					
						
							|  |  |  | 			 * IPv4 as the default the +subnet option | 
					
						
							|  |  |  | 			 * used an IPv4 prefix, or for +subnet=0, | 
					
						
							|  |  |  | 			 * and IPv6 if the +subnet option used an | 
					
						
							|  |  |  | 			 * IPv6 prefix. | 
					
						
							|  |  |  | 			 * | 
					
						
							|  |  |  | 			 * (For future work: preserve the offset into | 
					
						
							|  |  |  | 			 * the buffer where the family field is; | 
					
						
							|  |  |  | 			 * that way we can update it in send_udp() | 
					
						
							|  |  |  | 			 * or send_tcp_connect() once we know | 
					
						
							|  |  |  | 			 * what it outght to be.) | 
					
						
							|  |  |  | 			 */ | 
					
						
							|  |  |  | 			switch (sa->sa_family) { | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 			case AF_UNSPEC: | 
					
						
							|  |  |  | 				INSIST(plen == 0); | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 				family = 1; | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			case AF_INET: | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 				INSIST(plen <= 32); | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 				family = 1; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 				sin = (struct sockaddr_in *) sa; | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 				memmove(addr, &sin->sin_addr, addrl); | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			case AF_INET6: | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 				INSIST(plen <= 128); | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 				family = 2; | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 				sin6 = (struct sockaddr_in6 *) sa; | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 				memmove(addr, &sin6->sin6_addr, addrl); | 
					
						
							| 
									
										
										
										
											2016-03-23 09:29:57 -07:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				INSIST(0); | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 			isc_buffer_init(&b, ecsbuf, sizeof(ecsbuf)); | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 			/* family */ | 
					
						
							|  |  |  | 			isc_buffer_putuint16(&b, family); | 
					
						
							|  |  |  | 			/* source prefix-length */ | 
					
						
							|  |  |  | 			isc_buffer_putuint8(&b, plen); | 
					
						
							|  |  |  | 			/* scope prefix-length */ | 
					
						
							|  |  |  | 			isc_buffer_putuint8(&b, 0); | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 			/* address */ | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 			if (addrl > 0) { | 
					
						
							|  |  |  | 				/* Mask off last address byte */ | 
					
						
							|  |  |  | 				if ((plen % 8) != 0) | 
					
						
							|  |  |  | 					addr[addrl - 1] &= | 
					
						
							|  |  |  | 						~0U << (8 - (plen % 8)); | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 				isc_buffer_putmem(&b, addr, | 
					
						
							|  |  |  | 						  (unsigned)addrl); | 
					
						
							| 
									
										
										
										
											2016-09-14 08:22:15 +10:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-01-29 17:41:29 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 			opts[i].value = (isc_uint8_t *) ecsbuf; | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		if (lookup->sendcookie) { | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			INSIST(i < MAXOPTS); | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 			opts[i].code = DNS_OPT_COOKIE; | 
					
						
							|  |  |  | 			if (lookup->cookie != NULL) { | 
					
						
							|  |  |  | 				isc_buffer_init(&b, cookiebuf, | 
					
						
							|  |  |  | 						sizeof(cookiebuf)); | 
					
						
							|  |  |  | 				result = isc_hex_decodestring(lookup->cookie, | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 							      &b); | 
					
						
							|  |  |  | 				check_result(result, "isc_hex_decodestring"); | 
					
						
							|  |  |  | 				opts[i].value = isc_buffer_base(&b); | 
					
						
							|  |  |  | 				opts[i].length = isc_buffer_usedlength(&b); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				compute_cookie(cookie, sizeof(cookie)); | 
					
						
							|  |  |  | 				opts[i].length = 8; | 
					
						
							|  |  |  | 				opts[i].value = cookie; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-20 14:56:20 +11:00
										 |  |  | 		if (lookup->expire) { | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			INSIST(i < MAXOPTS); | 
					
						
							| 
									
										
										
										
											2014-02-20 14:56:20 +11:00
										 |  |  | 			opts[i].code = DNS_OPT_EXPIRE; | 
					
						
							|  |  |  | 			opts[i].length = 0; | 
					
						
							|  |  |  | 			opts[i].value = NULL; | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 		if (lookup->tcp_keepalive) { | 
					
						
							|  |  |  | 			INSIST(i < MAXOPTS); | 
					
						
							|  |  |  | 			opts[i].code = DNS_OPT_TCP_KEEPALIVE; | 
					
						
							|  |  |  | 			opts[i].length = 0; | 
					
						
							|  |  |  | 			opts[i].value = NULL; | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 		if (lookup->ednsoptscnt != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			INSIST(i + lookup->ednsoptscnt <= MAXOPTS); | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 			memmove(&opts[i], lookup->ednsopts, | 
					
						
							| 
									
										
										
										
											2014-04-22 23:45:19 +00:00
										 |  |  | 				sizeof(dns_ednsopt_t) * lookup->ednsoptscnt); | 
					
						
							| 
									
										
										
										
											2014-04-18 09:52:12 +10:00
										 |  |  | 			i += lookup->ednsoptscnt; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 23:52:41 -08:00
										 |  |  | 		if (lookup->padding != 0 && (i >= MAXOPTS)) { | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			debug("turned off padding because of EDNS overflow"); | 
					
						
							|  |  |  | 			lookup->padding = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-19 23:52:41 -08:00
										 |  |  | 		if (lookup->padding != 0) { | 
					
						
							| 
									
										
										
										
											2017-01-04 09:16:30 -08:00
										 |  |  | 			INSIST(i < MAXOPTS); | 
					
						
							|  |  |  | 			opts[i].code = DNS_OPT_PAD; | 
					
						
							|  |  |  | 			opts[i].length = 0; | 
					
						
							|  |  |  | 			opts[i].value = NULL; | 
					
						
							|  |  |  | 			i++; | 
					
						
							|  |  |  | 			dns_message_setpadding(lookup->sendmsg, | 
					
						
							|  |  |  | 					       lookup->padding); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | 		flags = lookup->ednsflags; | 
					
						
							|  |  |  | 		flags &= ~DNS_MESSAGEEXTFLAG_DO; | 
					
						
							|  |  |  | 		if (lookup->dnssec) | 
					
						
							|  |  |  | 			flags |= DNS_MESSAGEEXTFLAG_DO; | 
					
						
							| 
									
										
										
										
											2005-06-07 00:16:01 +00:00
										 |  |  | 		add_opt(lookup->sendmsg, lookup->udpsize, | 
					
						
							| 
									
										
										
										
											2014-09-13 19:13:59 +10:00
										 |  |  | 			lookup->edns, flags, opts, i); | 
					
						
							| 
									
										
										
										
											2000-10-11 17:44:18 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	result = dns_message_rendersection(lookup->sendmsg, | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 					   DNS_SECTION_QUESTION, 0); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_rendersection"); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	result = dns_message_rendersection(lookup->sendmsg, | 
					
						
							|  |  |  | 					   DNS_SECTION_AUTHORITY, 0); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_rendersection"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	result = dns_message_renderend(lookup->sendmsg); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "dns_message_renderend"); | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 	debug("done rendering"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-03-05 21:15:47 +00:00
										 |  |  | 	dns_compress_invalidate(&cctx); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-08 20:50:04 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Force TCP mode if the request is larger than 512 bytes. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	if (isc_buffer_usedlength(&lookup->renderbuf) > 512) | 
					
						
							| 
									
										
										
										
											2001-01-08 20:50:04 +00:00
										 |  |  | 		lookup->tcp_mode = ISC_TRUE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	lookup->pending = ISC_FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	for (serv = ISC_LIST_HEAD(lookup->my_server_list); | 
					
						
							|  |  |  | 	     serv != NULL; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	     serv = ISC_LIST_NEXT(serv, link)) { | 
					
						
							|  |  |  | 		query = isc_mem_allocate(mctx, sizeof(dig_query_t)); | 
					
						
							|  |  |  | 		if (query == NULL) | 
					
						
							| 
									
										
										
										
											2001-09-26 00:38:39 +00:00
										 |  |  | 			fatal("memory allocation failure in %s:%d", | 
					
						
							| 
									
										
										
										
											2000-05-24 03:10:24 +00:00
										 |  |  | 			      __FILE__, __LINE__); | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("create query %p linked to lookup %p", | 
					
						
							| 
									
										
										
										
											2000-06-29 07:43:46 +00:00
										 |  |  | 		       query, lookup); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->lookup = lookup; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		query->timer = NULL; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 		query->waiting_senddone = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2006-10-02 03:08:34 +00:00
										 |  |  | 		query->pending_free = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		query->recv_made = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->first_pass = ISC_TRUE; | 
					
						
							|  |  |  | 		query->first_soa_rcvd = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 		query->second_rr_rcvd = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-04-26 17:20:07 +00:00
										 |  |  | 		query->first_repeat_rcvd = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 		query->warn_id = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		query->timedout = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-04-26 05:27:18 +00:00
										 |  |  | 		query->first_rr_serial = 0; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 		query->second_rr_serial = 0; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->servname = serv->servername; | 
					
						
							| 
									
										
										
										
											2004-09-06 01:24:44 +00:00
										 |  |  | 		query->userarg = serv->userarg; | 
					
						
							| 
									
										
										
										
											2000-07-20 19:41:44 +00:00
										 |  |  | 		query->rr_count = 0; | 
					
						
							| 
									
										
										
										
											2002-05-29 05:31:05 +00:00
										 |  |  | 		query->msg_count = 0; | 
					
						
							| 
									
										
										
										
											2004-10-21 01:44:24 +00:00
										 |  |  | 		query->byte_count = 0; | 
					
						
							| 
									
										
										
										
											2014-01-06 06:22:30 +11:00
										 |  |  | 		query->ixfr_axfr = ISC_FALSE; | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		ISC_LIST_INIT(query->recvlist); | 
					
						
							|  |  |  | 		ISC_LIST_INIT(query->lengthlist); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->sock = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-13 01:49:44 +00:00
										 |  |  | 		query->recvspace = isc_mempool_get(commctx); | 
					
						
							| 
									
										
										
										
											2000-07-13 01:22:38 +00:00
										 |  |  | 		if (query->recvspace == NULL) | 
					
						
							|  |  |  | 			fatal("memory allocation failure"); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		isc_buffer_init(&query->recvbuf, query->recvspace, COMMSIZE); | 
					
						
							|  |  |  | 		isc_buffer_init(&query->lengthbuf, query->lengthspace, 2); | 
					
						
							|  |  |  | 		isc_buffer_init(&query->slbuf, query->slspace, 2); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 		query->sendbuf = lookup->renderbuf; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 		ISC_LINK_INIT(query, clink); | 
					
						
							| 
									
										
										
										
											2000-10-23 17:49:05 +00:00
										 |  |  | 		ISC_LINK_INIT(query, link); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		ISC_LIST_ENQUEUE(lookup->q, query, link); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-19 15:51:02 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 	/* XXX qrflag, print_query, etc... */ | 
					
						
							| 
									
										
										
										
											2016-10-10 11:55:59 +11:00
										 |  |  | 	if (!ISC_LIST_EMPTY(lookup->q) && lookup->qr) { | 
					
						
							| 
									
										
										
										
											2005-07-04 03:03:21 +00:00
										 |  |  | 		extrabytes = 0; | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 		dighost_printmessage(ISC_LIST_HEAD(lookup->q), | 
					
						
							|  |  |  | 				     lookup->sendmsg, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2014-04-22 12:38:53 -07:00
										 |  |  | 		if (lookup->stats) | 
					
						
							|  |  |  | 			printf(";; QUERY SIZE: %u\n\n", | 
					
						
							|  |  |  | 			       isc_buffer_usedlength(&lookup->renderbuf)); | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 	return (ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Event handler for send completion.  Track send counter, and clear out | 
					
						
							|  |  |  |  * the query if the send was canceled. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-08-02 19:49:57 +00:00
										 |  |  | send_done(isc_task_t *_task, isc_event_t *event) { | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 	isc_socketevent_t *sevent = (isc_socketevent_t *)event; | 
					
						
							|  |  |  | 	isc_buffer_t *b = NULL; | 
					
						
							| 
									
										
										
										
											2006-08-01 00:49:02 +00:00
										 |  |  | 	dig_query_t *query, *next; | 
					
						
							|  |  |  | 	dig_lookup_t *l; | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 	REQUIRE(event->ev_type == ISC_SOCKEVENT_SENDDONE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-02 19:49:57 +00:00
										 |  |  | 	UNUSED(_task); | 
					
						
							| 
									
										
										
										
											2000-05-26 00:48:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-01 00:49:02 +00:00
										 |  |  | 	debug("send_done()"); | 
					
						
							|  |  |  | 	sendcount--; | 
					
						
							|  |  |  | 	debug("sendcount=%d", sendcount); | 
					
						
							|  |  |  | 	INSIST(sendcount >= 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 	for  (b = ISC_LIST_HEAD(sevent->bufferlist); | 
					
						
							|  |  |  | 	      b != NULL; | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 	      b = ISC_LIST_HEAD(sevent->bufferlist)) { | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 		ISC_LIST_DEQUEUE(sevent->bufferlist, b, link); | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 		isc_mem_free(mctx, b); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-01 00:49:02 +00:00
										 |  |  | 	query = event->ev_arg; | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	query->waiting_senddone = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2006-08-01 00:49:02 +00:00
										 |  |  | 	l = query->lookup; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 	if (l->ns_search_only && !l->trace_root && !l->tcp_mode) { | 
					
						
							| 
									
										
										
										
											2006-08-01 00:49:02 +00:00
										 |  |  | 		debug("sending next, since searching"); | 
					
						
							|  |  |  | 		next = ISC_LIST_NEXT(query, link); | 
					
						
							|  |  |  | 		if (next != NULL) | 
					
						
							|  |  |  | 			send_udp(next); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-02 03:08:34 +00:00
										 |  |  | 	if (query->pending_free) | 
					
						
							|  |  |  | 		isc_mem_free(mctx, query); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-03 18:26:22 +00:00
										 |  |  | 	check_if_done(); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Cancel a lookup, sending isc_socket_cancel() requests to all outstanding | 
					
						
							|  |  |  |  * IO sockets.  The cancel handlers should take care of cleaning up the | 
					
						
							|  |  |  |  * query and lookup structures | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-09-26 17:21:25 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-04-26 19:36:40 +00:00
										 |  |  | cancel_lookup(dig_lookup_t *lookup) { | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	dig_query_t *query, *next; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	debug("cancel_lookup()"); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	query = ISC_LIST_HEAD(lookup->q); | 
					
						
							|  |  |  | 	while (query != NULL) { | 
					
						
							|  |  |  | 		next = ISC_LIST_NEXT(query, link); | 
					
						
							| 
									
										
										
										
											2000-05-24 23:39:30 +00:00
										 |  |  | 		if (query->sock != NULL) { | 
					
						
							| 
									
										
										
										
											2000-05-26 22:03:00 +00:00
										 |  |  | 			isc_socket_cancel(query->sock, global_task, | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 					  ISC_SOCKCANCEL_ALL); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 			check_if_done(); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			clear_query(query); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		query = next; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 	lookup->pending = ISC_FALSE; | 
					
						
							|  |  |  | 	lookup->retries = 0; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | bringup_timer(dig_query_t *query, unsigned int default_timeout) { | 
					
						
							|  |  |  | 	dig_lookup_t *l; | 
					
						
							| 
									
										
										
										
											2000-07-10 17:25:59 +00:00
										 |  |  | 	unsigned int local_timeout; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	debug("bringup_timer()"); | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If the timer already exists, that means we're calling this | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	 * a second time (for a retry).  Don't need to recreate it, | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	 * just reset it. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	l = query->lookup; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	if (ISC_LINK_LINKED(query, link) && ISC_LIST_NEXT(query, link) != NULL) | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		local_timeout = SERVER_TIMEOUT; | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 		if (timeout == 0) | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 			local_timeout = default_timeout; | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 			local_timeout = timeout; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	debug("have local timeout of %d", local_timeout); | 
					
						
							|  |  |  | 	isc_interval_set(&l->interval, local_timeout, 0); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	if (query->timer != NULL) | 
					
						
							|  |  |  | 		isc_timer_detach(&query->timer); | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 	result = isc_timer_create(timermgr, isc_timertype_once, NULL, | 
					
						
							|  |  |  | 				  &l->interval, global_task, connect_timeout, | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 				  query, &query->timer); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	check_result(result, "isc_timer_create"); | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | force_timeout(dig_query_t *query) { | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 	isc_event_t *event; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 	debug("force_timeout ()"); | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 	event = isc_event_allocate(mctx, query, ISC_TIMEREVENT_IDLE, | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 				   connect_timeout, query, | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 				   sizeof(isc_event_t)); | 
					
						
							|  |  |  | 	if (event == NULL) { | 
					
						
							|  |  |  | 		fatal("isc_event_allocate: %s", | 
					
						
							|  |  |  | 		      isc_result_totext(ISC_R_NOMEMORY)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	isc_task_send(global_task, &event); | 
					
						
							| 
									
										
										
										
											2010-06-24 07:22:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * The timer may have expired if, for example, get_address() takes | 
					
						
							|  |  |  | 	 * long time and the timer was running on a different thread. | 
					
						
							|  |  |  | 	 * We need to cancel the possible timeout event not to confuse | 
					
						
							|  |  |  | 	 * ourselves due to the duplicate events. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	if (query->timer != NULL) | 
					
						
							|  |  |  | 		isc_timer_detach(&query->timer); | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | connect_done(isc_task_t *task, isc_event_t *event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  |  * Unlike send_udp, this can't be called multiple times with the same | 
					
						
							|  |  |  |  * query.  When we retry TCP, we requeue the whole lookup, which should | 
					
						
							|  |  |  |  * start anew. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | send_tcp_connect(dig_query_t *query) { | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	dig_query_t *next; | 
					
						
							|  |  |  | 	dig_lookup_t *l; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-08 22:54:55 +00:00
										 |  |  | 	debug("send_tcp_connect(%p)", query); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	l = query->lookup; | 
					
						
							|  |  |  | 	query->waiting_connect = ISC_TRUE; | 
					
						
							|  |  |  | 	query->lookup->current_query = query; | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 	result = get_address(query->servname, port, &query->sockaddr); | 
					
						
							| 
									
										
										
										
											2010-06-24 07:22:18 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * This servname doesn't have an address.  Try the next server | 
					
						
							|  |  |  | 		 * by triggering an immediate 'timeout' (we lie, but the effect | 
					
						
							|  |  |  | 		 * is the same). | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		force_timeout(query); | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 	if (!l->mapped && isc_sockaddr_pf(&query->sockaddr) == AF_INET6 && | 
					
						
							|  |  |  | 	    IN6_IS_ADDR_V4MAPPED(&query->sockaddr.type.sin6.sin6_addr)) { | 
					
						
							|  |  |  | 		isc_netaddr_t netaddr; | 
					
						
							|  |  |  | 		char buf[ISC_NETADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		isc_netaddr_fromsockaddr(&netaddr, &query->sockaddr); | 
					
						
							|  |  |  | 		isc_netaddr_format(&netaddr, buf, sizeof(buf)); | 
					
						
							|  |  |  | 		printf(";; Skipping mapped address '%s'\n", buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		if (ISC_LINK_LINKED(query, link)) | 
					
						
							|  |  |  | 			next = ISC_LIST_NEXT(query, link); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			next = NULL; | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 		l = query->lookup; | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		if (next == NULL) { | 
					
						
							|  |  |  | 			printf(";; No acceptable nameservers\n"); | 
					
						
							|  |  |  | 			check_next_lookup(l); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		send_tcp_connect(next); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	if (specified_source && | 
					
						
							|  |  |  | 	    (isc_sockaddr_pf(&query->sockaddr) != | 
					
						
							|  |  |  | 	     isc_sockaddr_pf(&bind_address))) { | 
					
						
							|  |  |  | 		printf(";; Skipping server %s, incompatible " | 
					
						
							|  |  |  | 		       "address family\n", query->servname); | 
					
						
							|  |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		if (ISC_LINK_LINKED(query, link)) | 
					
						
							|  |  |  | 			next = ISC_LIST_NEXT(query, link); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			next = NULL; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		l = query->lookup; | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		if (next == NULL) { | 
					
						
							|  |  |  | 			printf(";; No acceptable nameservers\n"); | 
					
						
							|  |  |  | 			check_next_lookup(l); | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		send_tcp_connect(next); | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-18 23:46:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	INSIST(query->sock == NULL); | 
					
						
							| 
									
										
										
										
											2013-11-07 10:50:01 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (keep != NULL && isc_sockaddr_equal(&keepaddr, &query->sockaddr)) { | 
					
						
							|  |  |  | 		sockcount++; | 
					
						
							|  |  |  | 		isc_socket_attach(keep, &query->sock); | 
					
						
							|  |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							|  |  |  | 		launch_next_query(query, ISC_TRUE); | 
					
						
							|  |  |  | 		goto search; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-07 23:46:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	result = isc_socket_create(socketmgr, | 
					
						
							|  |  |  | 				   isc_sockaddr_pf(&query->sockaddr), | 
					
						
							| 
									
										
										
										
											2001-11-27 00:56:32 +00:00
										 |  |  | 				   isc_sockettype_tcp, &query->sock); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	check_result(result, "isc_socket_create"); | 
					
						
							|  |  |  | 	sockcount++; | 
					
						
							| 
									
										
										
										
											2000-11-21 20:52:24 +00:00
										 |  |  | 	debug("sockcount=%d", sockcount); | 
					
						
							| 
									
										
										
										
											2014-07-15 23:27:14 +10:00
										 |  |  | 	if (query->lookup->dscp != -1) | 
					
						
							|  |  |  | 		isc_socket_dscp(query->sock, query->lookup->dscp); | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 	isc_socket_ipv6only(query->sock, ISC_TF(!query->lookup->mapped)); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	if (specified_source) | 
					
						
							| 
									
										
										
										
											2008-07-23 23:27:54 +00:00
										 |  |  | 		result = isc_socket_bind(query->sock, &bind_address, | 
					
						
							|  |  |  | 					 ISC_SOCKET_REUSEADDRESS); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2000-11-21 21:35:32 +00:00
										 |  |  | 		if ((isc_sockaddr_pf(&query->sockaddr) == AF_INET) && | 
					
						
							|  |  |  | 		    have_ipv4) | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 			isc_sockaddr_any(&bind_any); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			isc_sockaddr_any6(&bind_any); | 
					
						
							| 
									
										
										
										
											2008-07-22 03:43:04 +00:00
										 |  |  | 		result = isc_socket_bind(query->sock, &bind_any, 0); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	check_result(result, "isc_socket_bind"); | 
					
						
							|  |  |  | 	bringup_timer(query, TCP_TIMEOUT); | 
					
						
							|  |  |  | 	result = isc_socket_connect(query->sock, &query->sockaddr, | 
					
						
							|  |  |  | 				    global_task, connect_done, query); | 
					
						
							|  |  |  | 	check_result(result, "isc_socket_connect"); | 
					
						
							| 
									
										
										
										
											2013-11-07 10:50:01 +11:00
										 |  |  |  search: | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2001-02-13 23:12:17 +00:00
										 |  |  | 	 * If we're at the endgame of a nameserver search, we need to | 
					
						
							|  |  |  | 	 * immediately bring up all the queries.  Do it here. | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	if (l->ns_search_only && !l->trace_root) { | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		debug("sending next, since searching"); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		if (ISC_LINK_LINKED(query, link)) { | 
					
						
							|  |  |  | 			next = ISC_LIST_NEXT(query, link); | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 			ISC_LIST_DEQUEUE(l->q, query, link); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		} else | 
					
						
							|  |  |  | 			next = NULL; | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 		ISC_LIST_ENQUEUE(l->connecting, query, clink); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		if (next != NULL) | 
					
						
							|  |  |  | 			send_tcp_connect(next); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | static isc_buffer_t * | 
					
						
							|  |  |  | clone_buffer(isc_buffer_t *source) { | 
					
						
							|  |  |  | 	isc_buffer_t *buffer; | 
					
						
							|  |  |  | 	buffer = isc_mem_allocate(mctx, sizeof(*buffer)); | 
					
						
							|  |  |  | 	if (buffer == NULL) | 
					
						
							|  |  |  | 		fatal("memory allocation failure in %s:%d", | 
					
						
							|  |  |  | 		      __FILE__, __LINE__); | 
					
						
							|  |  |  | 	*buffer = *source; | 
					
						
							|  |  |  | 	return (buffer); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  |  * Send a UDP packet to the remote nameserver, possible starting the | 
					
						
							|  |  |  |  * recv action as well.  Also make sure that the timer is running and | 
					
						
							|  |  |  |  * is properly reset. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | send_udp(dig_query_t *query) { | 
					
						
							|  |  |  | 	dig_lookup_t *l = NULL; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 	isc_buffer_t *sendbuf; | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 	dig_query_t *next; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-08-08 22:54:55 +00:00
										 |  |  | 	debug("send_udp(%p)", query); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	l = query->lookup; | 
					
						
							|  |  |  | 	bringup_timer(query, UDP_TIMEOUT); | 
					
						
							|  |  |  | 	l->current_query = query; | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 	debug("working on lookup %p, query %p", query->lookup, query); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	if (!query->recv_made) { | 
					
						
							|  |  |  | 		/* XXX Check the sense of this, need assertion? */ | 
					
						
							|  |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 		result = get_address(query->servname, port, &query->sockaddr); | 
					
						
							| 
									
										
										
										
											2010-06-24 07:22:18 +00:00
										 |  |  | 		if (result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 			/* This servname doesn't have an address. */ | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 			force_timeout(query); | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 		if (!l->mapped && | 
					
						
							|  |  |  | 		    isc_sockaddr_pf(&query->sockaddr) == AF_INET6 && | 
					
						
							|  |  |  | 		    IN6_IS_ADDR_V4MAPPED(&query->sockaddr.type.sin6.sin6_addr)) { | 
					
						
							|  |  |  | 			isc_netaddr_t netaddr; | 
					
						
							|  |  |  | 			char buf[ISC_NETADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			isc_netaddr_fromsockaddr(&netaddr, &query->sockaddr); | 
					
						
							|  |  |  | 			isc_netaddr_format(&netaddr, buf, sizeof(buf)); | 
					
						
							|  |  |  | 			printf(";; Skipping mapped address '%s'\n", buf); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			next = ISC_LIST_NEXT(query, link); | 
					
						
							|  |  |  | 			l = query->lookup; | 
					
						
							|  |  |  | 			clear_query(query); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 			if (next == NULL) { | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 				printf(";; No acceptable nameservers\n"); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 				check_next_lookup(l); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				send_udp(next); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		result = isc_socket_create(socketmgr, | 
					
						
							|  |  |  | 					   isc_sockaddr_pf(&query->sockaddr), | 
					
						
							|  |  |  | 					   isc_sockettype_udp, &query->sock); | 
					
						
							|  |  |  | 		check_result(result, "isc_socket_create"); | 
					
						
							|  |  |  | 		sockcount++; | 
					
						
							|  |  |  | 		debug("sockcount=%d", sockcount); | 
					
						
							| 
									
										
										
										
											2014-07-15 23:27:14 +10:00
										 |  |  | 		if (query->lookup->dscp != -1) | 
					
						
							|  |  |  | 			isc_socket_dscp(query->sock, query->lookup->dscp); | 
					
						
							| 
									
										
										
										
											2015-12-19 09:47:11 +11:00
										 |  |  | 		isc_socket_ipv6only(query->sock, | 
					
						
							|  |  |  | 				    ISC_TF(!query->lookup->mapped)); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		if (specified_source) { | 
					
						
							| 
									
										
										
										
											2008-07-23 23:27:54 +00:00
										 |  |  | 			result = isc_socket_bind(query->sock, &bind_address, | 
					
						
							|  |  |  | 						 ISC_SOCKET_REUSEADDRESS); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			isc_sockaddr_anyofpf(&bind_any, | 
					
						
							|  |  |  | 					isc_sockaddr_pf(&query->sockaddr)); | 
					
						
							| 
									
										
										
										
											2008-07-22 03:43:04 +00:00
										 |  |  | 			result = isc_socket_bind(query->sock, &bind_any, 0); | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		check_result(result, "isc_socket_bind"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		query->recv_made = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-10-23 17:49:05 +00:00
										 |  |  | 		ISC_LINK_INIT(&query->recvbuf, link); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 				 link); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		debug("recving with lookup=%p, query=%p, sock=%p", | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 		      query->lookup, query, query->sock); | 
					
						
							|  |  |  | 		result = isc_socket_recvv(query->sock, &query->recvlist, 1, | 
					
						
							|  |  |  | 					  global_task, recv_done, query); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		check_result(result, "isc_socket_recvv"); | 
					
						
							|  |  |  | 		recvcount++; | 
					
						
							|  |  |  | 		debug("recvcount=%d", recvcount); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ISC_LIST_INIT(query->sendlist); | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 	sendbuf = clone_buffer(&query->sendbuf); | 
					
						
							|  |  |  | 	ISC_LIST_ENQUEUE(query->sendlist, sendbuf, link); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	debug("sending a request"); | 
					
						
							| 
									
										
										
										
											2001-11-30 01:59:49 +00:00
										 |  |  | 	TIME_NOW(&query->time_sent); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	INSIST(query->sock != NULL); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	query->waiting_senddone = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 	result = isc_socket_sendtov2(query->sock, &query->sendlist, | 
					
						
							|  |  |  | 				     global_task, send_done, query, | 
					
						
							|  |  |  | 				     &query->sockaddr, NULL, | 
					
						
							|  |  |  | 				     ISC_SOCKFLAG_NORETRY); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	check_result(result, "isc_socket_sendtov"); | 
					
						
							|  |  |  | 	sendcount++; | 
					
						
							| 
									
										
										
										
											2000-05-02 23:23:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * IO timeout handler, used for both connect and recv timeouts.  If | 
					
						
							|  |  |  |  * retries are still allowed, either resend the UDP packet or queue a | 
					
						
							|  |  |  |  * new TCP lookup.  Otherwise, cancel the lookup. | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-04-26 19:36:40 +00:00
										 |  |  | connect_timeout(isc_task_t *task, isc_event_t *event) { | 
					
						
							| 
									
										
										
										
											2005-10-14 01:14:08 +00:00
										 |  |  | 	dig_lookup_t *l = NULL; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	dig_query_t *query = NULL, *cq; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	UNUSED(task); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	debug("connect_timeout()"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	query = event->ev_arg; | 
					
						
							|  |  |  | 	l = query->lookup; | 
					
						
							| 
									
										
										
										
											2000-05-25 19:32:11 +00:00
										 |  |  | 	isc_event_free(&event); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((query != NULL) && (query->lookup->current_query != NULL) && | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	    ISC_LINK_LINKED(query->lookup->current_query, link) && | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	    (ISC_LIST_NEXT(query->lookup->current_query, link) != NULL)) { | 
					
						
							|  |  |  | 		debug("trying next server..."); | 
					
						
							|  |  |  | 		cq = query->lookup->current_query; | 
					
						
							|  |  |  | 		if (!l->tcp_mode) | 
					
						
							|  |  |  | 			send_udp(ISC_LIST_NEXT(cq, link)); | 
					
						
							| 
									
										
										
										
											2009-11-10 17:27:40 +00:00
										 |  |  | 		else { | 
					
						
							|  |  |  | 			if (query->sock != NULL) | 
					
						
							|  |  |  | 				isc_socket_cancel(query->sock, NULL, | 
					
						
							|  |  |  | 						  ISC_SOCKCANCEL_ALL); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 			send_tcp_connect(ISC_LIST_NEXT(cq, link)); | 
					
						
							| 
									
										
										
										
											2009-02-25 02:34:21 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	if (l->tcp_mode && query->sock != NULL) { | 
					
						
							|  |  |  | 		query->timedout = ISC_TRUE; | 
					
						
							|  |  |  | 		isc_socket_cancel(query->sock, NULL, ISC_SOCKCANCEL_ALL); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	if (l->retries > 1) { | 
					
						
							|  |  |  | 		if (!l->tcp_mode) { | 
					
						
							|  |  |  | 			l->retries--; | 
					
						
							|  |  |  | 			debug("resending UDP request to first server"); | 
					
						
							|  |  |  | 			send_udp(ISC_LIST_HEAD(l->q)); | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 			debug("making new TCP request, %d tries left", | 
					
						
							|  |  |  | 			      l->retries); | 
					
						
							|  |  |  | 			l->retries--; | 
					
						
							| 
									
										
										
										
											2005-10-14 01:14:08 +00:00
										 |  |  | 			requeue_lookup(l, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2001-10-31 21:55:31 +00:00
										 |  |  | 			cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 			check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-06-11 18:08:16 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2018-02-15 16:11:52 -08:00
										 |  |  | 		if (l->ns_search_only) { | 
					
						
							|  |  |  | 			isc_netaddr_t netaddr; | 
					
						
							|  |  |  | 			char buf[ISC_NETADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			isc_netaddr_fromsockaddr(&netaddr, &query->sockaddr); | 
					
						
							|  |  |  | 			isc_netaddr_format(&netaddr, buf, sizeof(buf)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			printf(";; no response from %s\n", buf); | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 			fputs(l->cmdline, stdout); | 
					
						
							|  |  |  | 			printf(";; connection timed out; no servers could be " | 
					
						
							|  |  |  | 			       "reached\n"); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 		check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2001-06-11 18:20:43 +00:00
										 |  |  | 		if (exitcode < 9) | 
					
						
							|  |  |  | 			exitcode = 9; | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Event handler for the TCP recv which gets the length header of TCP | 
					
						
							|  |  |  |  * packets.  Start the next recv of length bytes. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | tcp_length_done(isc_task_t *task, isc_event_t *event) { | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	isc_socketevent_t *sevent; | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 	isc_buffer_t *b = NULL; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 	dig_query_t *query = NULL; | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 	dig_lookup_t *l, *n; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	isc_uint16_t length; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	UNUSED(task); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	debug("tcp_length_done()"); | 
					
						
							| 
									
										
										
										
											2000-05-22 22:56:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	sevent = (isc_socketevent_t *)event; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	query = event->ev_arg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 	recvcount--; | 
					
						
							|  |  |  | 	INSIST(recvcount >= 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 	b = ISC_LIST_HEAD(sevent->bufferlist); | 
					
						
							|  |  |  | 	INSIST(b ==  &query->lengthbuf); | 
					
						
							|  |  |  | 	ISC_LIST_DEQUEUE(sevent->bufferlist, b, link); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	if (sevent->result == ISC_R_CANCELED) { | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-13 18:52:58 +00:00
										 |  |  | 		l = query->lookup; | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-07-14 21:33:03 +00:00
										 |  |  | 		UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (sevent->result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 		char sockstr[ISC_SOCKADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 		isc_sockaddr_format(&query->sockaddr, sockstr, | 
					
						
							|  |  |  | 				    sizeof(sockstr)); | 
					
						
							|  |  |  | 		printf(";; communications error to %s: %s\n", | 
					
						
							|  |  |  | 		       sockstr, isc_result_totext(sevent->result)); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 		if (keep != NULL) | 
					
						
							|  |  |  | 			isc_socket_detach(&keep); | 
					
						
							| 
									
										
										
										
											2000-07-27 18:36:59 +00:00
										 |  |  | 		l = query->lookup; | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		isc_socket_detach(&query->sock); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		sockcount--; | 
					
						
							| 
									
										
										
										
											2000-11-21 20:52:24 +00:00
										 |  |  | 		debug("sockcount=%d", sockcount); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		INSIST(sockcount >= 0); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 		if (sevent->result == ISC_R_EOF && l->eoferr == 0U) { | 
					
						
							|  |  |  | 			n = requeue_lookup(l, ISC_TRUE); | 
					
						
							|  |  |  | 			n->eoferr++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-05-26 00:48:18 +00:00
										 |  |  | 		isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-27 18:36:59 +00:00
										 |  |  | 		clear_query(query); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 		cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-07-27 18:36:59 +00:00
										 |  |  | 		check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-07-14 21:33:03 +00:00
										 |  |  | 		UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	length = isc_buffer_getuint16(b); | 
					
						
							| 
									
										
										
										
											2001-06-14 21:40:02 +00:00
										 |  |  | 	if (length == 0) { | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 		isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2001-06-14 21:40:02 +00:00
										 |  |  | 		launch_next_query(query, ISC_FALSE); | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-06-14 21:40:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Even though the buffer was already init'ed, we need | 
					
						
							|  |  |  | 	 * to redo it now, to force the length we want. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	isc_buffer_invalidate(&query->recvbuf); | 
					
						
							|  |  |  | 	isc_buffer_init(&query->recvbuf, query->recvspace, length); | 
					
						
							|  |  |  | 	ENSURE(ISC_LIST_EMPTY(query->recvlist)); | 
					
						
							| 
									
										
										
										
											2000-10-23 17:49:05 +00:00
										 |  |  | 	ISC_LINK_INIT(&query->recvbuf, link); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link); | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 	debug("recving with lookup=%p, query=%p", query->lookup, query); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	result = isc_socket_recvv(query->sock, &query->recvlist, length, task, | 
					
						
							|  |  |  | 				  recv_done, query); | 
					
						
							|  |  |  | 	check_result(result, "isc_socket_recvv"); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	recvcount++; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 	debug("resubmitted recv request with length %d, recvcount=%d", | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	      length, recvcount); | 
					
						
							| 
									
										
										
										
											2000-05-26 00:48:18 +00:00
										 |  |  | 	isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * For transfers that involve multiple recvs (XFR's in particular), | 
					
						
							|  |  |  |  * launch the next recv. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							|  |  |  | launch_next_query(dig_query_t *query, isc_boolean_t include_question) { | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 	dig_lookup_t *l; | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 	isc_buffer_t *buffer; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	debug("launch_next_query()"); | 
					
						
							| 
									
										
										
										
											2000-05-22 22:56:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	if (!query->lookup->pending) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("ignoring launch_next_query because !pending"); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		isc_socket_detach(&query->sock); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		sockcount--; | 
					
						
							|  |  |  | 		debug("sockcount=%d", sockcount); | 
					
						
							|  |  |  | 		INSIST(sockcount >= 0); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 		l = query->lookup; | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	isc_buffer_clear(&query->slbuf); | 
					
						
							|  |  |  | 	isc_buffer_clear(&query->lengthbuf); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 	isc_buffer_putuint16(&query->slbuf, (isc_uint16_t) query->sendbuf.used); | 
					
						
							| 
									
										
										
										
											2000-07-18 01:28:20 +00:00
										 |  |  | 	ISC_LIST_INIT(query->sendlist); | 
					
						
							| 
									
										
										
										
											2000-10-23 17:49:05 +00:00
										 |  |  | 	ISC_LINK_INIT(&query->slbuf, link); | 
					
						
							| 
									
										
										
										
											2013-10-26 10:04:36 +11:00
										 |  |  | 	if (!query->first_soa_rcvd) { | 
					
						
							|  |  |  | 		buffer = clone_buffer(&query->slbuf); | 
					
						
							| 
									
										
										
										
											2013-10-24 23:46:20 +00:00
										 |  |  | 		ISC_LIST_ENQUEUE(query->sendlist, buffer, link); | 
					
						
							| 
									
										
										
										
											2013-10-26 10:04:36 +11:00
										 |  |  | 		if (include_question) { | 
					
						
							|  |  |  | 			buffer = clone_buffer(&query->sendbuf); | 
					
						
							|  |  |  | 			ISC_LIST_ENQUEUE(query->sendlist, buffer, link); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-10-25 10:09:33 +11:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-10-23 17:49:05 +00:00
										 |  |  | 	ISC_LINK_INIT(&query->lengthbuf, link); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	ISC_LIST_ENQUEUE(query->lengthlist, &query->lengthbuf, link); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 22:03:00 +00:00
										 |  |  | 	result = isc_socket_recvv(query->sock, &query->lengthlist, 0, | 
					
						
							|  |  |  | 				  global_task, tcp_length_done, query); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	check_result(result, "isc_socket_recvv"); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	recvcount++; | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 	debug("recvcount=%d", recvcount); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	if (!query->first_soa_rcvd) { | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | 		debug("sending a request in launch_next_query"); | 
					
						
							| 
									
										
										
										
											2001-11-30 01:59:49 +00:00
										 |  |  | 		TIME_NOW(&query->time_sent); | 
					
						
							| 
									
										
										
										
											2006-12-07 01:21:04 +00:00
										 |  |  | 		query->waiting_senddone = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-05-26 22:03:00 +00:00
										 |  |  | 		result = isc_socket_sendv(query->sock, &query->sendlist, | 
					
						
							|  |  |  | 					  global_task, send_done, query); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		check_result(result, "isc_socket_sendv"); | 
					
						
							|  |  |  | 		sendcount++; | 
					
						
							|  |  |  | 		debug("sendcount=%d", sendcount); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	check_next_lookup(query->lookup); | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Event handler for TCP connect complete.  Make sure the connection was | 
					
						
							|  |  |  |  * successful, then pass into launch_next_query to actually send the | 
					
						
							|  |  |  |  * question. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2000-04-26 19:36:40 +00:00
										 |  |  | connect_done(isc_task_t *task, isc_event_t *event) { | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	char sockstr[ISC_SOCKADDR_FORMATSIZE]; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	isc_socketevent_t *sevent = NULL; | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	dig_query_t *query = NULL, *next; | 
					
						
							| 
									
										
										
										
											2000-07-13 21:01:00 +00:00
										 |  |  | 	dig_lookup_t *l; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	UNUSED(task); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	REQUIRE(event->ev_type == ISC_SOCKEVENT_CONNECT); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("connect_done()"); | 
					
						
							| 
									
										
										
										
											2000-05-25 19:32:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	sevent = (isc_socketevent_t *)event; | 
					
						
							|  |  |  | 	query = sevent->ev_arg; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	INSIST(query->waiting_connect); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	query->waiting_connect = ISC_FALSE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-09-14 20:11:48 +00:00
										 |  |  | 	if (sevent->result == ISC_R_CANCELED) { | 
					
						
							|  |  |  | 		debug("in cancel handler"); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		isc_sockaddr_format(&query->sockaddr, sockstr, sizeof(sockstr)); | 
					
						
							|  |  |  | 		if (query->timedout) | 
					
						
							|  |  |  | 			printf(";; Connection to %s(%s) for %s failed: %s.\n", | 
					
						
							|  |  |  | 			       sockstr, query->servname, | 
					
						
							|  |  |  | 			       query->lookup->textname, | 
					
						
							|  |  |  | 			       isc_result_totext(ISC_R_TIMEDOUT)); | 
					
						
							| 
									
										
										
										
											2000-09-14 20:11:48 +00:00
										 |  |  | 		isc_socket_detach(&query->sock); | 
					
						
							| 
									
										
										
										
											2009-11-10 17:27:40 +00:00
										 |  |  | 		INSIST(sockcount > 0); | 
					
						
							| 
									
										
										
										
											2000-09-14 20:11:48 +00:00
										 |  |  | 		sockcount--; | 
					
						
							|  |  |  | 		debug("sockcount=%d", sockcount); | 
					
						
							|  |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							|  |  |  | 		isc_event_free(&event); | 
					
						
							|  |  |  | 		l = query->lookup; | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	if (sevent->result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 		debug("unsuccessful connection: %s", | 
					
						
							|  |  |  | 		      isc_result_totext(sevent->result)); | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 		isc_sockaddr_format(&query->sockaddr, sockstr, sizeof(sockstr)); | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 		if (sevent->result != ISC_R_CANCELED) | 
					
						
							| 
									
										
										
										
											2001-07-27 05:41:46 +00:00
										 |  |  | 			printf(";; Connection to %s(%s) for %s failed: " | 
					
						
							|  |  |  | 			       "%s.\n", sockstr, | 
					
						
							| 
									
										
										
										
											2000-07-13 22:53:51 +00:00
										 |  |  | 			       query->servname, query->lookup->textname, | 
					
						
							|  |  |  | 			       isc_result_totext(sevent->result)); | 
					
						
							| 
									
										
										
										
											2000-07-13 21:01:00 +00:00
										 |  |  | 		isc_socket_detach(&query->sock); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		INSIST(sockcount > 0); | 
					
						
							| 
									
										
										
										
											2000-07-13 21:01:00 +00:00
										 |  |  | 		sockcount--; | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 		/* XXX Clean up exitcodes */ | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 		if (exitcode < 9) | 
					
						
							| 
									
										
										
										
											2000-05-08 22:51:08 +00:00
										 |  |  | 			exitcode = 9; | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 		debug("sockcount=%d", sockcount); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-05-26 00:48:18 +00:00
										 |  |  | 		isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-13 21:01:00 +00:00
										 |  |  | 		l = query->lookup; | 
					
						
							| 
									
										
										
										
											2014-12-03 16:04:28 +05:30
										 |  |  | 		if ((l->current_query != NULL) && | 
					
						
							|  |  |  | 		    (ISC_LINK_LINKED(l->current_query, link))) | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 			next = ISC_LIST_NEXT(l->current_query, link); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			next = NULL; | 
					
						
							| 
									
										
										
										
											2000-07-13 21:01:00 +00:00
										 |  |  | 		clear_query(query); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 		if (next != NULL) { | 
					
						
							|  |  |  | 			bringup_timer(next, TCP_TIMEOUT); | 
					
						
							|  |  |  | 			send_tcp_connect(next); | 
					
						
							| 
									
										
										
										
											2012-10-18 17:50:07 -05:00
										 |  |  | 		} else | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 			check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 		UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-11-07 10:50:01 +11:00
										 |  |  | 	if (keep_open) { | 
					
						
							|  |  |  | 		if (keep != NULL) | 
					
						
							|  |  |  | 			isc_socket_detach(&keep); | 
					
						
							|  |  |  | 		isc_socket_attach(query->sock, &keep); | 
					
						
							|  |  |  | 		keepaddr = query->sockaddr; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	launch_next_query(query, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2000-05-26 00:48:18 +00:00
										 |  |  | 	isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Check if the ongoing XFR needs more data before it's complete, using | 
					
						
							|  |  |  |  * the semantics of IXFR and AXFR protocols.  Much of the complexity of | 
					
						
							|  |  |  |  * this routine comes from determining when an IXFR is complete. | 
					
						
							| 
									
										
										
										
											2000-07-20 19:41:44 +00:00
										 |  |  |  * ISC_FALSE means more data is on the way, and the recv has been issued. | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | static isc_boolean_t | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | check_for_more_data(dig_query_t *query, dns_message_t *msg, | 
					
						
							|  |  |  | 		    isc_socketevent_t *sevent) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	dns_rdataset_t *rdataset = NULL; | 
					
						
							| 
									
										
										
										
											2000-10-25 04:26:57 +00:00
										 |  |  | 	dns_rdata_t rdata = DNS_RDATA_INIT; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	dns_rdata_soa_t soa; | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 	isc_uint32_t ixfr_serial = query->lookup->ixfr_serial, serial; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 	isc_boolean_t ixfr = query->lookup->rdtype == dns_rdatatype_ixfr; | 
					
						
							|  |  |  | 	isc_boolean_t axfr = query->lookup->rdtype == dns_rdatatype_axfr; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-06 06:22:30 +11:00
										 |  |  | 	if (ixfr) | 
					
						
							|  |  |  | 		axfr = query->ixfr_axfr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("check_for_more_data()"); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * By the time we're in this routine, we know we're doing | 
					
						
							|  |  |  | 	 * either an AXFR or IXFR.  If there's no second_rr_type, | 
					
						
							|  |  |  | 	 * then we don't yet know which kind of answer we got back | 
					
						
							|  |  |  | 	 * from the server.  Here, we're going to walk through the | 
					
						
							|  |  |  | 	 * rr's in the message, acting as necessary whenever we hit | 
					
						
							|  |  |  | 	 * an SOA rr. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-05-29 05:31:05 +00:00
										 |  |  | 	query->msg_count++; | 
					
						
							| 
									
										
										
										
											2004-10-21 01:44:24 +00:00
										 |  |  | 	query->byte_count += sevent->n; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	result = dns_message_firstname(msg, DNS_SECTION_ANSWER); | 
					
						
							| 
									
										
										
										
											2000-06-06 22:50:44 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		puts("; Transfer failed."); | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  | 		return (ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2000-06-06 22:50:44 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 	do { | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 		dns_name_t *name; | 
					
						
							|  |  |  | 		name = NULL; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 		dns_message_currentname(msg, DNS_SECTION_ANSWER, | 
					
						
							|  |  |  | 					&name); | 
					
						
							| 
									
										
										
										
											2000-11-08 01:23:27 +00:00
										 |  |  | 		for (rdataset = ISC_LIST_HEAD(name->list); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 		     rdataset != NULL; | 
					
						
							|  |  |  | 		     rdataset = ISC_LIST_NEXT(rdataset, link)) { | 
					
						
							|  |  |  | 			result = dns_rdataset_first(rdataset); | 
					
						
							|  |  |  | 			if (result != ISC_R_SUCCESS) | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			do { | 
					
						
							| 
									
										
										
										
											2000-07-20 19:41:44 +00:00
										 |  |  | 				query->rr_count++; | 
					
						
							| 
									
										
										
										
											2000-10-31 03:22:05 +00:00
										 |  |  | 				dns_rdata_reset(&rdata); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				dns_rdataset_current(rdataset, &rdata); | 
					
						
							|  |  |  | 				/*
 | 
					
						
							|  |  |  | 				 * If this is the first rr, make sure | 
					
						
							|  |  |  | 				 * it's an SOA | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				if ((!query->first_soa_rcvd) && | 
					
						
							|  |  |  | 				    (rdata.type != dns_rdatatype_soa)) { | 
					
						
							|  |  |  | 					puts("; Transfer failed.  " | 
					
						
							| 
									
										
										
										
											2005-08-25 00:56:08 +00:00
										 |  |  | 					     "Didn't start with SOA answer."); | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  | 					return (ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				if ((!query->second_rr_rcvd) && | 
					
						
							|  |  |  | 				    (rdata.type != dns_rdatatype_soa)) { | 
					
						
							|  |  |  | 					query->second_rr_rcvd = ISC_TRUE; | 
					
						
							|  |  |  | 					query->second_rr_serial = 0; | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 					debug("got the second rr as nonsoa"); | 
					
						
							| 
									
										
										
										
											2014-01-06 06:22:30 +11:00
										 |  |  | 					axfr = query->ixfr_axfr = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 					goto next_rdata; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				/*
 | 
					
						
							|  |  |  | 				 * If the record is anything except an SOA | 
					
						
							|  |  |  | 				 * now, just continue on... | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				if (rdata.type != dns_rdatatype_soa) | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 					goto next_rdata; | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				/* Now we have an SOA.  Work with it. */ | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 				debug("got an SOA"); | 
					
						
							| 
									
										
										
										
											2008-01-14 23:24:24 +00:00
										 |  |  | 				result = dns_rdata_tostruct(&rdata, &soa, NULL); | 
					
						
							|  |  |  | 				check_result(result, "dns_rdata_tostruct"); | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 				serial = soa.serial; | 
					
						
							|  |  |  | 				dns_rdata_freestruct(&soa); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				if (!query->first_soa_rcvd) { | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 					query->first_soa_rcvd = ISC_TRUE; | 
					
						
							|  |  |  | 					query->first_rr_serial = serial; | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 					debug("this is the first serial %u", | 
					
						
							|  |  |  | 					      serial); | 
					
						
							|  |  |  | 					if (ixfr && isc_serial_ge(ixfr_serial, | 
					
						
							|  |  |  | 								  serial)) { | 
					
						
							|  |  |  | 						debug("got up to date " | 
					
						
							|  |  |  | 						      "response"); | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 						goto doexit; | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 					goto next_rdata; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 				if (axfr) { | 
					
						
							| 
									
										
										
										
											2000-07-28 21:56:53 +00:00
										 |  |  | 					debug("doing axfr, got second SOA"); | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 					goto doexit; | 
					
						
							| 
									
										
										
										
											2000-07-28 21:56:53 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				if (!query->second_rr_rcvd) { | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 					if (query->first_rr_serial == serial) { | 
					
						
							| 
									
										
										
										
											2000-07-28 21:56:53 +00:00
										 |  |  | 						debug("doing ixfr, got " | 
					
						
							|  |  |  | 						      "empty zone"); | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 						goto doexit; | 
					
						
							| 
									
										
										
										
											2000-07-28 21:56:53 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 					debug("this is the second serial %u", | 
					
						
							|  |  |  | 					      serial); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 					query->second_rr_rcvd = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 					query->second_rr_serial = serial; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 					goto next_rdata; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				/*
 | 
					
						
							|  |  |  | 				 * If we get to this point, we're doing an | 
					
						
							|  |  |  | 				 * IXFR and have to start really looking | 
					
						
							|  |  |  | 				 * at serial numbers. | 
					
						
							|  |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2001-07-27 05:26:38 +00:00
										 |  |  | 				if (query->first_rr_serial == serial) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 					debug("got a match for ixfr"); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 					if (!query->first_repeat_rcvd) { | 
					
						
							|  |  |  | 						query->first_repeat_rcvd = | 
					
						
							|  |  |  | 							ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 						goto next_rdata; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 					debug("done with ixfr"); | 
					
						
							| 
									
										
										
										
											2000-08-03 17:43:06 +00:00
										 |  |  | 					goto doexit; | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2011-12-01 00:53:58 +00:00
										 |  |  | 				debug("meaningless soa %u", serial); | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 			next_rdata: | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | 				result = dns_rdataset_next(rdataset); | 
					
						
							|  |  |  | 			} while (result == ISC_R_SUCCESS); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		result = dns_message_nextname(msg, DNS_SECTION_ANSWER); | 
					
						
							|  |  |  | 	} while (result == ISC_R_SUCCESS); | 
					
						
							|  |  |  | 	launch_next_query(query, ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  | 	return (ISC_FALSE); | 
					
						
							| 
									
										
										
										
											2001-03-28 03:09:47 +00:00
										 |  |  |  doexit: | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 	dighost_received(sevent->n, &sevent->address, query); | 
					
						
							| 
									
										
										
										
											2001-03-28 03:09:47 +00:00
										 |  |  | 	return (ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2000-06-02 18:45:33 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | static void | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | process_cookie(dig_lookup_t *l, dns_message_t *msg, | 
					
						
							|  |  |  | 	       isc_buffer_t *optbuf, size_t optlen) | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	char bb[256]; | 
					
						
							|  |  |  | 	isc_buffer_t hexbuf; | 
					
						
							|  |  |  | 	size_t len; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	const unsigned char *sent; | 
					
						
							|  |  |  | 	isc_boolean_t copy = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	if (l->cookie != NULL) { | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		isc_buffer_init(&hexbuf, bb, sizeof(bb)); | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		result = isc_hex_decodestring(l->cookie, &hexbuf); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		check_result(result, "isc_hex_decodestring"); | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		sent = isc_buffer_base(&hexbuf); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		len = isc_buffer_usedlength(&hexbuf); | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		sent = cookie; | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		len = sizeof(cookie); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	INSIST(msg->cc_ok == 0 && msg->cc_bad == 0); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	if (optlen >= len && optlen >= 8U) { | 
					
						
							| 
									
										
										
										
											2015-08-17 18:26:44 -07:00
										 |  |  | 		if (isc_safe_memequal(isc_buffer_current(optbuf), sent, 8)) { | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 			msg->cc_ok = 1; | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 			printf(";; Warning: Client COOKIE mismatch\n"); | 
					
						
							|  |  |  | 			msg->cc_bad = 1; | 
					
						
							|  |  |  | 			copy = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		printf(";; Warning: COOKIE bad token (too short)\n"); | 
					
						
							|  |  |  | 		msg->cc_bad = 1; | 
					
						
							|  |  |  | 		copy = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2015-04-06 23:13:35 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	if (copy) { | 
					
						
							| 
									
										
										
										
											2015-04-06 23:13:35 -07:00
										 |  |  | 		isc_region_t r; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		r.base = isc_buffer_current(optbuf); | 
					
						
							|  |  |  | 		r.length = (unsigned int)optlen; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		isc_buffer_init(&hexbuf, servercookie, sizeof(servercookie)); | 
					
						
							| 
									
										
										
										
											2015-04-06 23:13:35 -07:00
										 |  |  | 		result = isc_hex_totext(&r, 2, "", &hexbuf); | 
					
						
							|  |  |  | 		check_result(result, "isc_hex_totext"); | 
					
						
							|  |  |  | 		if (isc_buffer_availablelength(&hexbuf) > 0) { | 
					
						
							|  |  |  | 			isc_buffer_putuint8(&hexbuf, 0); | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 			l->cookie = servercookie; | 
					
						
							| 
									
										
										
										
											2015-04-06 23:13:35 -07:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-19 23:17:52 +01:00
										 |  |  | 	isc_buffer_forward(optbuf, (unsigned int)optlen); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | process_opt(dig_lookup_t *l, dns_message_t *msg) { | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 	dns_rdata_t rdata; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	isc_buffer_t optbuf; | 
					
						
							|  |  |  | 	isc_uint16_t optcode, optlen; | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | 	dns_rdataset_t *opt = msg->opt; | 
					
						
							| 
									
										
										
										
											2016-02-27 11:23:50 +11:00
										 |  |  | 	isc_boolean_t seen_cookie = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-19 23:46:31 +00:00
										 |  |  | 	result = dns_rdataset_first(opt); | 
					
						
							|  |  |  | 	if (result == ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		dns_rdata_init(&rdata); | 
					
						
							|  |  |  | 		dns_rdataset_current(opt, &rdata); | 
					
						
							|  |  |  | 		isc_buffer_init(&optbuf, rdata.data, rdata.length); | 
					
						
							|  |  |  | 		isc_buffer_add(&optbuf, rdata.length); | 
					
						
							|  |  |  | 		while (isc_buffer_remaininglength(&optbuf) >= 4) { | 
					
						
							|  |  |  | 			optcode = isc_buffer_getuint16(&optbuf); | 
					
						
							|  |  |  | 			optlen = isc_buffer_getuint16(&optbuf); | 
					
						
							|  |  |  | 			switch (optcode) { | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 			case DNS_OPT_COOKIE: | 
					
						
							| 
									
										
										
										
											2016-02-27 11:23:50 +11:00
										 |  |  | 				/*
 | 
					
						
							|  |  |  | 				 * Only process the first cookie option. | 
					
						
							|  |  |  | 				 */ | 
					
						
							|  |  |  | 				if (seen_cookie) { | 
					
						
							|  |  |  | 					isc_buffer_forward(&optbuf, optlen); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 				process_cookie(l, msg, &optbuf, optlen); | 
					
						
							| 
									
										
										
										
											2016-02-27 11:23:50 +11:00
										 |  |  | 				seen_cookie = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2014-02-19 23:46:31 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				isc_buffer_forward(&optbuf, optlen); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | static int | 
					
						
							|  |  |  | ednsvers(dns_rdataset_t *opt) { | 
					
						
							|  |  |  | 	return ((opt->ttl >> 16) & 0xff); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Event handler for recv complete.  Perform whatever actions are necessary, | 
					
						
							|  |  |  |  * based on the specifics of the user's request. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | static void | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | recv_done(isc_task_t *task, isc_event_t *event) { | 
					
						
							|  |  |  | 	isc_socketevent_t *sevent = NULL; | 
					
						
							|  |  |  | 	dig_query_t *query = NULL; | 
					
						
							|  |  |  | 	isc_buffer_t *b = NULL; | 
					
						
							|  |  |  | 	dns_message_t *msg = NULL; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	dig_lookup_t *n, *l; | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  | 	isc_boolean_t docancel = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2002-04-19 04:06:53 +00:00
										 |  |  | 	isc_boolean_t match = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	unsigned int parseflags; | 
					
						
							| 
									
										
										
										
											2002-02-21 04:48:00 +00:00
										 |  |  | 	dns_messageid_t id; | 
					
						
							|  |  |  | 	unsigned int msgflags; | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | 	int newedns; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	UNUSED(task); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("recv_done()"); | 
					
						
							| 
									
										
										
										
											2000-05-25 19:32:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	recvcount--; | 
					
						
							|  |  |  | 	debug("recvcount=%d", recvcount); | 
					
						
							|  |  |  | 	INSIST(recvcount >= 0); | 
					
						
							| 
									
										
										
										
											2000-05-22 22:56:31 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-12 18:45:38 +00:00
										 |  |  | 	query = event->ev_arg; | 
					
						
							| 
									
										
										
										
											2014-07-31 07:39:59 +10:00
										 |  |  | 	TIME_NOW(&query->time_recv); | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 	debug("lookup=%p, query=%p", query->lookup, query); | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	l = query->lookup; | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 	REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	sevent = (isc_socketevent_t *)event; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-06 00:53:36 +00:00
										 |  |  | 	b = ISC_LIST_HEAD(sevent->bufferlist); | 
					
						
							|  |  |  | 	INSIST(b == &query->recvbuf); | 
					
						
							|  |  |  | 	ISC_LIST_DEQUEUE(sevent->bufferlist, &query->recvbuf, link); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 	if ((l->tcp_mode) && (query->timer != NULL)) | 
					
						
							|  |  |  | 		isc_timer_touch(query->timer); | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	if ((!l->pending && !l->ns_search_only) || cancel_now) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("no longer pending.  Got %s", | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 			isc_result_totext(sevent->result)); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-05-26 00:48:18 +00:00
										 |  |  | 		isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 		UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-18 23:46:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	if (sevent->result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		if (sevent->result == ISC_R_CANCELED) { | 
					
						
							|  |  |  | 			debug("in recv cancel handler"); | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 			query->waiting_connect = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			printf(";; communications error: %s\n", | 
					
						
							|  |  |  | 			       isc_result_totext(sevent->result)); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 			if (keep != NULL) | 
					
						
							|  |  |  | 				isc_socket_detach(&keep); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			isc_socket_detach(&query->sock); | 
					
						
							|  |  |  | 			sockcount--; | 
					
						
							|  |  |  | 			debug("sockcount=%d", sockcount); | 
					
						
							|  |  |  | 			INSIST(sockcount >= 0); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 		if (sevent->result == ISC_R_EOF && l->eoferr == 0U) { | 
					
						
							|  |  |  | 			n = requeue_lookup(l, ISC_TRUE); | 
					
						
							|  |  |  | 			n->eoferr++; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		isc_event_free(&event); | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 		cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		check_next_lookup(l); | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-04-19 04:06:53 +00:00
										 |  |  | 	if (!l->tcp_mode && | 
					
						
							| 
									
										
										
										
											2004-11-22 23:29:10 +00:00
										 |  |  | 	    !isc_sockaddr_compare(&sevent->address, &query->sockaddr, | 
					
						
							|  |  |  | 				  ISC_SOCKADDR_CMPADDR| | 
					
						
							|  |  |  | 				  ISC_SOCKADDR_CMPPORT| | 
					
						
							|  |  |  | 				  ISC_SOCKADDR_CMPSCOPE| | 
					
						
							|  |  |  | 				  ISC_SOCKADDR_CMPSCOPEZERO)) { | 
					
						
							| 
									
										
										
										
											2002-04-19 04:06:53 +00:00
										 |  |  | 		char buf1[ISC_SOCKADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 		char buf2[ISC_SOCKADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 		isc_sockaddr_t any; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 		if (isc_sockaddr_pf(&query->sockaddr) == AF_INET) | 
					
						
							| 
									
										
										
										
											2002-04-19 04:06:53 +00:00
										 |  |  | 			isc_sockaddr_any(&any); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			isc_sockaddr_any6(&any); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/*
 | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 		* We don't expect a match when the packet is | 
					
						
							| 
									
										
										
										
											2002-04-19 04:06:53 +00:00
										 |  |  | 		* sent to 0.0.0.0, :: or to a multicast addresses. | 
					
						
							|  |  |  | 		* XXXMPA broadcast needs to be handled here as well. | 
					
						
							|  |  |  | 		*/ | 
					
						
							|  |  |  | 		if ((!isc_sockaddr_eqaddr(&query->sockaddr, &any) && | 
					
						
							|  |  |  | 		     !isc_sockaddr_ismulticast(&query->sockaddr)) || | 
					
						
							|  |  |  | 		    isc_sockaddr_getport(&query->sockaddr) != | 
					
						
							|  |  |  | 		    isc_sockaddr_getport(&sevent->address)) { | 
					
						
							|  |  |  | 			isc_sockaddr_format(&sevent->address, buf1, | 
					
						
							|  |  |  | 			sizeof(buf1)); | 
					
						
							|  |  |  | 			isc_sockaddr_format(&query->sockaddr, buf2, | 
					
						
							|  |  |  | 			sizeof(buf2)); | 
					
						
							|  |  |  | 			printf(";; reply from unexpected source: %s," | 
					
						
							|  |  |  | 			" expected %s\n", buf1, buf2); | 
					
						
							|  |  |  | 			match = ISC_FALSE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 	result = dns_message_peekheader(b, &id, &msgflags); | 
					
						
							| 
									
										
										
										
											2002-02-21 04:48:00 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS || l->sendmsg->id != id) { | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 		match = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2002-02-21 04:48:00 +00:00
										 |  |  | 		if (l->tcp_mode) { | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 			isc_boolean_t fail = ISC_TRUE; | 
					
						
							|  |  |  | 			if (result == ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 				if (!query->first_soa_rcvd || | 
					
						
							|  |  |  | 				     query->warn_id) | 
					
						
							|  |  |  | 					printf(";; %s: ID mismatch: " | 
					
						
							|  |  |  | 					       "expected ID %u, got %u\n", | 
					
						
							|  |  |  | 					       query->first_soa_rcvd ? | 
					
						
							|  |  |  | 					       "WARNING" : "ERROR", | 
					
						
							|  |  |  | 					       l->sendmsg->id, id); | 
					
						
							|  |  |  | 				if (query->first_soa_rcvd) | 
					
						
							|  |  |  | 					fail = ISC_FALSE; | 
					
						
							|  |  |  | 				query->warn_id = ISC_FALSE; | 
					
						
							|  |  |  | 			} else | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 				printf(";; ERROR: short " | 
					
						
							|  |  |  | 				       "(< header size) message\n"); | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 			if (fail) { | 
					
						
							|  |  |  | 				isc_event_free(&event); | 
					
						
							|  |  |  | 				clear_query(query); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 				cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2003-07-17 07:42:00 +00:00
										 |  |  | 				check_next_lookup(l); | 
					
						
							|  |  |  | 				UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			match = ISC_TRUE; | 
					
						
							|  |  |  | 		} else if (result == ISC_R_SUCCESS) | 
					
						
							| 
									
										
										
										
											2002-03-14 18:11:38 +00:00
										 |  |  | 			printf(";; Warning: ID mismatch: " | 
					
						
							|  |  |  | 			       "expected ID %u, got %u\n", l->sendmsg->id, id); | 
					
						
							| 
									
										
										
										
											2002-02-21 04:48:00 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 			printf(";; Warning: short " | 
					
						
							|  |  |  | 			       "(< header size) message received\n"); | 
					
						
							| 
									
										
										
										
											2002-04-19 04:06:53 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-06 00:54:21 +00:00
										 |  |  | 	if (result == ISC_R_SUCCESS && (msgflags & DNS_MESSAGEFLAG_QR) == 0) | 
					
						
							|  |  |  | 		printf(";; Warning: query response not set\n"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 04:39:29 +00:00
										 |  |  | 	if (!match) | 
					
						
							|  |  |  | 		goto udp_mismatch; | 
					
						
							| 
									
										
										
										
											2002-02-21 04:48:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg); | 
					
						
							|  |  |  | 	check_result(result, "dns_message_create"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 	if (tsigkey != NULL) { | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		if (l->querysig == NULL) { | 
					
						
							|  |  |  | 			debug("getting initial querysig"); | 
					
						
							|  |  |  | 			result = dns_message_getquerytsig(l->sendmsg, mctx, | 
					
						
							|  |  |  | 							  &l->querysig); | 
					
						
							|  |  |  | 			check_result(result, "dns_message_getquerytsig"); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		result = dns_message_setquerytsig(msg, l->querysig); | 
					
						
							|  |  |  | 		check_result(result, "dns_message_setquerytsig"); | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 		result = dns_message_settsigkey(msg, tsigkey); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		check_result(result, "dns_message_settsigkey"); | 
					
						
							|  |  |  | 		msg->tsigctx = l->tsigctx; | 
					
						
							| 
									
										
										
										
											2001-09-11 22:34:21 +00:00
										 |  |  | 		l->tsigctx = NULL; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		if (l->msgcounter != 0) | 
					
						
							|  |  |  | 			msg->tcp_continuation = 1; | 
					
						
							|  |  |  | 		l->msgcounter++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	debug("before parse starts"); | 
					
						
							|  |  |  | 	parseflags = DNS_MESSAGEPARSE_PRESERVEORDER; | 
					
						
							| 
									
										
										
										
											2002-02-12 02:10:33 +00:00
										 |  |  | 	if (l->besteffort) { | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		parseflags |= DNS_MESSAGEPARSE_BESTEFFORT; | 
					
						
							| 
									
										
										
										
											2002-02-12 02:10:33 +00:00
										 |  |  | 		parseflags |= DNS_MESSAGEPARSE_IGNORETRUNCATION; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	result = dns_message_parse(msg, b, parseflags); | 
					
						
							|  |  |  | 	if (result == DNS_R_RECOVERABLE) { | 
					
						
							|  |  |  | 		printf(";; Warning: Message parser reports malformed " | 
					
						
							|  |  |  | 		       "message packet.\n"); | 
					
						
							|  |  |  | 		result = ISC_R_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		printf(";; Got bad packet: %s\n", isc_result_totext(result)); | 
					
						
							|  |  |  | 		hex_dump(b); | 
					
						
							|  |  |  | 		query->waiting_connect = ISC_FALSE; | 
					
						
							|  |  |  | 		dns_message_destroy(&msg); | 
					
						
							|  |  |  | 		isc_event_free(&event); | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		cancel_lookup(l); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-20 04:39:29 +00:00
										 |  |  | 	if (msg->counts[DNS_SECTION_QUESTION] != 0) { | 
					
						
							|  |  |  | 		match = ISC_TRUE; | 
					
						
							|  |  |  | 		for (result = dns_message_firstname(msg, DNS_SECTION_QUESTION); | 
					
						
							|  |  |  | 		     result == ISC_R_SUCCESS && match; | 
					
						
							|  |  |  | 		     result = dns_message_nextname(msg, DNS_SECTION_QUESTION)) { | 
					
						
							|  |  |  | 			dns_name_t *name = NULL; | 
					
						
							|  |  |  | 			dns_rdataset_t *rdataset; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			dns_message_currentname(msg, DNS_SECTION_QUESTION, | 
					
						
							|  |  |  | 						&name); | 
					
						
							|  |  |  | 			for (rdataset = ISC_LIST_HEAD(name->list); | 
					
						
							|  |  |  | 			     rdataset != NULL; | 
					
						
							|  |  |  | 			     rdataset = ISC_LIST_NEXT(rdataset, link)) { | 
					
						
							|  |  |  | 				if (l->rdtype != rdataset->type || | 
					
						
							|  |  |  | 				    l->rdclass != rdataset->rdclass || | 
					
						
							|  |  |  | 				    !dns_name_equal(l->name, name)) { | 
					
						
							|  |  |  | 					char namestr[DNS_NAME_FORMATSIZE]; | 
					
						
							|  |  |  | 					char typebuf[DNS_RDATATYPE_FORMATSIZE]; | 
					
						
							|  |  |  | 					char classbuf[DNS_RDATACLASS_FORMATSIZE]; | 
					
						
							|  |  |  | 					dns_name_format(name, namestr, | 
					
						
							|  |  |  | 							sizeof(namestr)); | 
					
						
							|  |  |  | 					dns_rdatatype_format(rdataset->type, | 
					
						
							|  |  |  | 							     typebuf, | 
					
						
							|  |  |  | 							     sizeof(typebuf)); | 
					
						
							|  |  |  | 					dns_rdataclass_format(rdataset->rdclass, | 
					
						
							|  |  |  | 							      classbuf, | 
					
						
							|  |  |  | 							      sizeof(classbuf)); | 
					
						
							|  |  |  | 					printf(";; Question section mismatch: " | 
					
						
							|  |  |  | 					       "got %s/%s/%s\n", | 
					
						
							|  |  |  | 					       namestr, typebuf, classbuf); | 
					
						
							|  |  |  | 					match = ISC_FALSE; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!match) { | 
					
						
							|  |  |  | 			dns_message_destroy(&msg); | 
					
						
							|  |  |  | 			if (l->tcp_mode) { | 
					
						
							|  |  |  | 				isc_event_free(&event); | 
					
						
							|  |  |  | 				clear_query(query); | 
					
						
							| 
									
										
										
										
											2017-10-05 09:42:31 +02:00
										 |  |  | 				cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2009-01-20 04:39:29 +00:00
										 |  |  | 				check_next_lookup(l); | 
					
						
							|  |  |  | 				UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				goto udp_mismatch; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | 	if (msg->rcode == dns_rcode_badvers && msg->opt != NULL && | 
					
						
							|  |  |  | 	    (newedns = ednsvers(msg->opt)) < l->edns && l->ednsneg) { | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Add minimum EDNS version required checks here if needed. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (l->comments) | 
					
						
							|  |  |  | 			printf(";; BADVERS, retrying with EDNS version %u.\n", | 
					
						
							| 
									
										
										
										
											2018-02-14 17:41:30 +11:00
										 |  |  | 			       (unsigned int)newedns); | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | 		l->edns = newedns; | 
					
						
							|  |  |  | 		n = requeue_lookup(l, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2015-09-12 09:04:37 +10:00
										 |  |  | 		if (l->trace && l->trace_root) | 
					
						
							|  |  |  | 			n->rdtype = l->qrdtype; | 
					
						
							| 
									
										
										
										
											2014-10-30 23:13:12 +11:00
										 |  |  | 		dns_message_destroy(&msg); | 
					
						
							|  |  |  | 		isc_event_free(&event); | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		cancel_lookup(l); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-08-25 00:40:50 +00:00
										 |  |  | 	if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0 && | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 	    !l->ignore && !l->tcp_mode) { | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 		if (l->cookie == NULL && l->sendcookie && msg->opt != NULL) | 
					
						
							| 
									
										
										
										
											2015-04-06 23:13:35 -07:00
										 |  |  | 			process_opt(l, msg); | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		if (l->comments) | 
					
						
							|  |  |  | 			printf(";; Truncated, retrying in TCP mode.\n"); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		n = requeue_lookup(l, ISC_TRUE); | 
					
						
							|  |  |  | 		n->tcp_mode = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2015-09-12 09:04:37 +10:00
										 |  |  | 		if (l->trace && l->trace_root) | 
					
						
							|  |  |  | 			n->rdtype = l->qrdtype; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		dns_message_destroy(&msg); | 
					
						
							|  |  |  | 		isc_event_free(&event); | 
					
						
							|  |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		cancel_lookup(l); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	if (msg->rcode == dns_rcode_badcookie && !l->tcp_mode && | 
					
						
							|  |  |  | 	    l->sendcookie && l->badcookie) { | 
					
						
							|  |  |  | 		process_opt(l, msg); | 
					
						
							|  |  |  | 		if (msg->cc_ok) { | 
					
						
							|  |  |  | 			if (l->comments) | 
					
						
							|  |  |  | 				printf(";; BADCOOKIE, retrying%s.\n", | 
					
						
							|  |  |  | 				       l->seenbadcookie ? " in TCP mode" : ""); | 
					
						
							|  |  |  | 			n = requeue_lookup(l, ISC_TRUE); | 
					
						
							|  |  |  | 			if (l->seenbadcookie) | 
					
						
							|  |  |  | 				n->tcp_mode = ISC_TRUE; | 
					
						
							|  |  |  | 			n->seenbadcookie = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2015-09-12 09:04:37 +10:00
										 |  |  | 			if (l->trace && l->trace_root) | 
					
						
							|  |  |  | 				n->rdtype = l->qrdtype; | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 			dns_message_destroy(&msg); | 
					
						
							|  |  |  | 			isc_event_free(&event); | 
					
						
							|  |  |  | 			clear_query(query); | 
					
						
							|  |  |  | 			cancel_lookup(l); | 
					
						
							|  |  |  | 			check_next_lookup(l); | 
					
						
							|  |  |  | 			UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-08-25 00:40:50 +00:00
										 |  |  | 	if ((msg->rcode == dns_rcode_servfail && !l->servfail_stops) || | 
					
						
							|  |  |  | 	    (check_ra && (msg->flags & DNS_MESSAGEFLAG_RA) == 0 && l->recurse)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		dig_query_t *next = ISC_LIST_NEXT(query, link); | 
					
						
							|  |  |  | 		if (l->current_query == query) | 
					
						
							|  |  |  | 			l->current_query = NULL; | 
					
						
							|  |  |  | 		if (next != NULL) { | 
					
						
							| 
									
										
										
										
											2001-08-08 22:54:55 +00:00
										 |  |  | 			debug("sending query %p\n", next); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			if (l->tcp_mode) | 
					
						
							|  |  |  | 				send_tcp_connect(next); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				send_udp(next); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * If our query is at the head of the list and there | 
					
						
							|  |  |  | 		 * is no next, we're the only one left, so fall | 
					
						
							|  |  |  | 		 * through to print the message. | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if ((ISC_LIST_HEAD(l->q) != query) || | 
					
						
							|  |  |  | 		    (ISC_LIST_NEXT(query, link) != NULL)) { | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 			if (l->comments) | 
					
						
							| 
									
										
										
										
											2005-08-25 00:40:50 +00:00
										 |  |  | 				printf(";; Got %s from %s, " | 
					
						
							|  |  |  | 				       "trying next server\n", | 
					
						
							|  |  |  | 				       msg->rcode == dns_rcode_servfail ? | 
					
						
							|  |  |  | 				       "SERVFAIL reply" : | 
					
						
							|  |  |  | 				       "recursion not available", | 
					
						
							|  |  |  | 				       query->servname); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 			clear_query(query); | 
					
						
							|  |  |  | 			check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-09-11 19:38:22 +00:00
										 |  |  | 			dns_message_destroy(&msg); | 
					
						
							|  |  |  | 			isc_event_free(&event); | 
					
						
							|  |  |  | 			UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2000-09-25 23:10:00 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-09-11 19:38:22 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 	if (tsigkey != NULL) { | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		result = dns_tsig_verify(&query->recvbuf, msg, NULL, NULL); | 
					
						
							|  |  |  | 		if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 			printf(";; Couldn't verify signature: %s\n", | 
					
						
							|  |  |  | 			       isc_result_totext(result)); | 
					
						
							|  |  |  | 			validated = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2000-06-06 18:49:06 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		l->tsigctx = msg->tsigctx; | 
					
						
							| 
									
										
										
										
											2001-09-11 22:34:21 +00:00
										 |  |  | 		msg->tsigctx = NULL; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		if (l->querysig != NULL) { | 
					
						
							|  |  |  | 			debug("freeing querysig buffer %p", l->querysig); | 
					
						
							|  |  |  | 			isc_buffer_free(&l->querysig); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		result = dns_message_getquerytsig(msg, mctx, &l->querysig); | 
					
						
							|  |  |  | 		check_result(result,"dns_message_getquerytsig"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-04 03:03:21 +00:00
										 |  |  | 	extrabytes = isc_buffer_remaininglength(b); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	debug("after parse"); | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	if (l->doing_xfr && l->xfr_q == NULL) { | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 		l->xfr_q = query; | 
					
						
							|  |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * Once we are in the XFR message, increase | 
					
						
							|  |  |  | 		 * the timeout to much longer, so brief network | 
					
						
							|  |  |  | 		 * outages won't cause the XFR to abort | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 		if (timeout != INT_MAX && query->timer != NULL) { | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 			unsigned int local_timeout; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			if (timeout == 0) { | 
					
						
							|  |  |  | 				if (l->tcp_mode) | 
					
						
							| 
									
										
										
										
											2001-10-15 20:40:36 +00:00
										 |  |  | 					local_timeout = TCP_TIMEOUT * 4; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 				else | 
					
						
							| 
									
										
										
										
											2001-10-15 20:40:36 +00:00
										 |  |  | 					local_timeout = UDP_TIMEOUT * 4; | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			} else { | 
					
						
							|  |  |  | 				if (timeout < (INT_MAX / 4)) | 
					
						
							|  |  |  | 					local_timeout = timeout * 4; | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					local_timeout = INT_MAX; | 
					
						
							| 
									
										
										
										
											2000-07-10 17:25:59 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			debug("have local timeout of %d", local_timeout); | 
					
						
							|  |  |  | 			isc_interval_set(&l->interval, local_timeout, 0); | 
					
						
							| 
									
										
										
										
											2016-12-14 15:42:43 +11:00
										 |  |  | 			result = isc_timer_reset(query->timer, | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 						 isc_timertype_once, | 
					
						
							|  |  |  | 						 NULL, | 
					
						
							|  |  |  | 						 &l->interval, | 
					
						
							|  |  |  | 						 ISC_FALSE); | 
					
						
							|  |  |  | 			check_result(result, "isc_timer_reset"); | 
					
						
							| 
									
										
										
										
											2000-07-10 17:25:59 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	if (l->cookie != NULL) { | 
					
						
							| 
									
										
										
										
											2014-02-19 12:53:42 +11:00
										 |  |  | 		if (msg->opt == NULL) | 
					
						
							|  |  |  | 			printf(";; expected opt record in response\n"); | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | 			process_opt(l, msg); | 
					
						
							| 
									
										
										
										
											2015-07-06 09:44:24 +10:00
										 |  |  | 	} else if (l->sendcookie && msg->opt != NULL) | 
					
						
							| 
									
										
										
										
											2014-02-20 15:55:09 +11:00
										 |  |  | 		process_opt(l, msg); | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	if (!l->doing_xfr || l->xfr_q == query) { | 
					
						
							| 
									
										
										
										
											2013-09-04 13:24:11 +10:00
										 |  |  | 		if (msg->rcode == dns_rcode_nxdomain && | 
					
						
							| 
									
										
										
										
											2006-12-07 05:52:16 +00:00
										 |  |  | 		    (l->origin != NULL || l->need_search)) { | 
					
						
							| 
									
										
										
										
											2014-08-21 18:05:55 +10:00
										 |  |  | 			if (!next_origin(query->lookup) || showsearch) { | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 				dighost_printmessage(query, msg, ISC_TRUE); | 
					
						
							|  |  |  | 				dighost_received(b->used, &sevent->address, | 
					
						
							|  |  |  | 						 query); | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 		} else if (!l->trace && !l->ns_search_only) { | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 			dighost_printmessage(query, msg, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 		} else if (l->trace) { | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 			int nl = 0; | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 			int count = msg->counts[DNS_SECTION_ANSWER]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			debug("in TRACE code"); | 
					
						
							|  |  |  | 			if (!l->ns_search_only) | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 				dighost_printmessage(query, msg, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			l->rdtype = l->qrdtype; | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 			if (l->trace_root || (l->ns_search_only && count > 0)) { | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 				if (!l->trace_root) | 
					
						
							|  |  |  | 					l->rdtype = dns_rdatatype_soa; | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 				nl = followup_lookup(msg, query, | 
					
						
							|  |  |  | 						     DNS_SECTION_ANSWER); | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 				l->trace_root = ISC_FALSE; | 
					
						
							|  |  |  | 			} else if (count == 0) | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 				nl = followup_lookup(msg, query, | 
					
						
							|  |  |  | 						     DNS_SECTION_AUTHORITY); | 
					
						
							|  |  |  | 			if (nl == 0) | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 				docancel = ISC_TRUE; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 			debug("in NSSEARCH code"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (l->trace_root) { | 
					
						
							|  |  |  | 				/*
 | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 				 * This is the initial NS query. | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 				 */ | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 				int nl; | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				l->rdtype = dns_rdatatype_soa; | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 				nl = followup_lookup(msg, query, | 
					
						
							|  |  |  | 						     DNS_SECTION_ANSWER); | 
					
						
							|  |  |  | 				if (nl == 0) | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 					docancel = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2001-07-29 23:23:42 +00:00
										 |  |  | 				l->trace_root = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2012-10-16 10:42:24 +11:00
										 |  |  | 				usesearch = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2017-08-09 11:03:27 -07:00
										 |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 				dighost_printmessage(query, msg, ISC_TRUE); | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	if (l->pending) | 
					
						
							|  |  |  | 		debug("still pending."); | 
					
						
							|  |  |  | 	if (l->doing_xfr) { | 
					
						
							|  |  |  | 		if (query != l->xfr_q) { | 
					
						
							|  |  |  | 			dns_message_destroy(&msg); | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 			isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			query->waiting_connect = ISC_FALSE; | 
					
						
							|  |  |  | 			UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!docancel) | 
					
						
							|  |  |  | 			docancel = check_for_more_data(query, msg, sevent); | 
					
						
							|  |  |  | 		if (docancel) { | 
					
						
							|  |  |  | 			dns_message_destroy(&msg); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 			clear_query(query); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			cancel_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 			check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (msg->rcode == dns_rcode_noerror || l->origin == NULL) { | 
					
						
							| 
									
										
										
										
											2017-08-10 22:51:24 -07:00
										 |  |  | 			dighost_received(b->used, &sevent->address, query); | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 		if (!query->lookup->ns_search_only) | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			query->lookup->pending = ISC_FALSE; | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 		if (!query->lookup->ns_search_only || | 
					
						
							| 
									
										
										
										
											2017-08-09 11:03:27 -07:00
										 |  |  | 		    query->lookup->trace_root || docancel) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			dns_message_destroy(&msg); | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 			cancel_lookup(l); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 		clear_query(query); | 
					
						
							|  |  |  | 		check_next_lookup(l); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 	if (msg != NULL) { | 
					
						
							| 
									
										
										
										
											2017-08-09 11:03:27 -07:00
										 |  |  | 		dns_message_destroy(&msg); | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2001-07-28 00:11:15 +00:00
										 |  |  | 	isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-08-02 14:38:51 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2009-01-20 04:39:29 +00:00
										 |  |  | 	return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  udp_mismatch: | 
					
						
							|  |  |  | 	isc_buffer_invalidate(&query->recvbuf); | 
					
						
							|  |  |  | 	isc_buffer_init(&query->recvbuf, query->recvspace, COMMSIZE); | 
					
						
							|  |  |  | 	ISC_LIST_ENQUEUE(query->recvlist, &query->recvbuf, link); | 
					
						
							|  |  |  | 	result = isc_socket_recvv(query->sock, &query->recvlist, 1, | 
					
						
							|  |  |  | 				  global_task, recv_done, query); | 
					
						
							|  |  |  | 	check_result(result, "isc_socket_recvv"); | 
					
						
							|  |  |  | 	recvcount++; | 
					
						
							|  |  |  | 	isc_event_free(&event); | 
					
						
							|  |  |  | 	UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 	return; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Turn a name into an address, using system-supplied routines.  This is | 
					
						
							|  |  |  |  * used in looking up server names, etc... and needs to use system-supplied | 
					
						
							|  |  |  |  * routines, since they may be using a non-DNS system for these lookups. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | isc_result_t | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | get_address(char *host, in_port_t myport, isc_sockaddr_t *sockaddr) { | 
					
						
							| 
									
										
										
										
											2001-11-14 22:08:38 +00:00
										 |  |  | 	int count; | 
					
						
							|  |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2015-02-26 14:00:57 +05:30
										 |  |  | 	isc_boolean_t is_running; | 
					
						
							| 
									
										
										
										
											2000-04-29 00:12:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-26 14:00:57 +05:30
										 |  |  | 	is_running = isc_app_isrunning(); | 
					
						
							|  |  |  | 	if (is_running) | 
					
						
							|  |  |  | 		isc_app_block(); | 
					
						
							| 
									
										
										
										
											2015-01-20 13:29:18 -08:00
										 |  |  | 	result = bind9_getaddresses(host, myport, sockaddr, 1, &count); | 
					
						
							| 
									
										
										
										
											2015-02-26 14:00:57 +05:30
										 |  |  | 	if (is_running) | 
					
						
							|  |  |  | 		isc_app_unblock(); | 
					
						
							| 
									
										
										
										
											2001-11-14 22:08:38 +00:00
										 |  |  | 	if (result != ISC_R_SUCCESS) | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 		return (result); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-11-14 22:08:38 +00:00
										 |  |  | 	INSIST(count == 1); | 
					
						
							| 
									
										
										
										
											2008-12-16 02:57:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return (ISC_R_SUCCESS); | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-25 23:11:13 +00:00
										 |  |  | int | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) { | 
					
						
							| 
									
										
										
										
											2011-02-25 23:11:13 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | 	isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; | 
					
						
							|  |  |  | 	isc_netaddr_t netaddr; | 
					
						
							|  |  |  | 	int count, i; | 
					
						
							|  |  |  | 	dig_server_t *srv; | 
					
						
							|  |  |  | 	char tmp[ISC_NETADDR_FORMATSIZE]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	result = bind9_getaddresses(host, 0, sockaddrs, | 
					
						
							|  |  |  | 				    DIG_MAX_ADDRESSES, &count); | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 	if (resultp != NULL) | 
					
						
							|  |  |  | 		*resultp = result; | 
					
						
							|  |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							|  |  |  | 		if (resultp == NULL) | 
					
						
							|  |  |  | 			fatal("couldn't get address for '%s': %s", | 
					
						
							|  |  |  | 			      host, isc_result_totext(result)); | 
					
						
							| 
									
										
										
										
											2017-09-13 00:14:37 -07:00
										 |  |  | 		return (0); | 
					
						
							| 
									
										
										
										
											2011-12-07 17:23:28 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-02-25 23:11:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < count; i++) { | 
					
						
							|  |  |  | 		isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]); | 
					
						
							|  |  |  | 		isc_netaddr_format(&netaddr, tmp, sizeof(tmp)); | 
					
						
							|  |  |  | 		srv = make_server(tmp, host); | 
					
						
							|  |  |  | 		ISC_LIST_APPEND(lookup->my_server_list, srv, link); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-13 00:14:37 -07:00
										 |  |  | 	return (count); | 
					
						
							| 
									
										
										
										
											2011-02-25 23:11:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Initiate either a TCP or UDP lookup | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | void | 
					
						
							|  |  |  | do_lookup(dig_lookup_t *lookup) { | 
					
						
							| 
									
										
										
										
											2012-10-06 14:20:45 +10:00
										 |  |  | 	dig_query_t *query; | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	REQUIRE(lookup != NULL); | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-05 19:31:26 +00:00
										 |  |  | 	debug("do_lookup()"); | 
					
						
							| 
									
										
										
										
											2000-09-21 22:46:39 +00:00
										 |  |  | 	lookup->pending = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2012-10-06 14:20:45 +10:00
										 |  |  | 	query = ISC_LIST_HEAD(lookup->q); | 
					
						
							|  |  |  | 	if (query != NULL) { | 
					
						
							|  |  |  | 		if (lookup->tcp_mode) | 
					
						
							|  |  |  | 			send_tcp_connect(query); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			send_udp(query); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-05-12 01:02:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Start everything in action upon task startup. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-10 18:02:31 +00:00
										 |  |  | void | 
					
						
							|  |  |  | onrun_callback(isc_task_t *task, isc_event_t *event) { | 
					
						
							|  |  |  | 	UNUSED(task); | 
					
						
							| 
									
										
										
										
											2000-08-01 00:53:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-10 18:02:31 +00:00
										 |  |  | 	isc_event_free(&event); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-07-10 18:02:31 +00:00
										 |  |  | 	start_lookup(); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-07-10 18:02:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * Make everything on the lookup queue go away.  Mainly used by the | 
					
						
							|  |  |  |  * SIGINT handler. | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | void | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | cancel_all(void) { | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	dig_lookup_t *l, *n; | 
					
						
							| 
									
										
										
										
											2000-09-22 23:21:32 +00:00
										 |  |  | 	dig_query_t *q, *nq; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 02:14:17 +00:00
										 |  |  | 	debug("cancel_all()"); | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							|  |  |  | 	if (free_now) { | 
					
						
							|  |  |  | 		UNLOCK_LOOKUP; | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	cancel_now = ISC_TRUE; | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	if (current_lookup != NULL) { | 
					
						
							| 
									
										
										
										
											2013-12-02 13:34:23 -08:00
										 |  |  | 		for (q = ISC_LIST_HEAD(current_lookup->q); | 
					
						
							|  |  |  | 		     q != NULL; | 
					
						
							|  |  |  | 		     q = nq) | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2000-09-22 23:21:32 +00:00
										 |  |  | 			nq = ISC_LIST_NEXT(q, link); | 
					
						
							| 
									
										
										
										
											2013-12-02 13:34:23 -08:00
										 |  |  | 			debug("canceling pending query %p, belonging to %p", | 
					
						
							|  |  |  | 			      q, current_lookup); | 
					
						
							|  |  |  | 			if (q->sock != NULL) | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 				isc_socket_cancel(q->sock, NULL, | 
					
						
							|  |  |  | 						  ISC_SOCKCANCEL_ALL); | 
					
						
							| 
									
										
										
										
											2013-12-02 13:34:23 -08:00
										 |  |  | 			else | 
					
						
							|  |  |  | 				clear_query(q); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		for (q = ISC_LIST_HEAD(current_lookup->connecting); | 
					
						
							|  |  |  | 		     q != NULL; | 
					
						
							|  |  |  | 		     q = nq) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			nq = ISC_LIST_NEXT(q, clink); | 
					
						
							|  |  |  | 			debug("canceling connecting query %p, belonging to %p", | 
					
						
							|  |  |  | 			      q, current_lookup); | 
					
						
							|  |  |  | 			if (q->sock != NULL) | 
					
						
							|  |  |  | 				isc_socket_cancel(q->sock, NULL, | 
					
						
							|  |  |  | 						  ISC_SOCKCANCEL_ALL); | 
					
						
							|  |  |  | 			else | 
					
						
							| 
									
										
										
										
											2001-07-27 22:07:10 +00:00
										 |  |  | 				clear_query(q); | 
					
						
							| 
									
										
										
										
											2000-04-28 21:41:19 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	l = ISC_LIST_HEAD(lookup_list); | 
					
						
							|  |  |  | 	while (l != NULL) { | 
					
						
							|  |  |  | 		n = ISC_LIST_NEXT(l, link); | 
					
						
							|  |  |  | 		ISC_LIST_DEQUEUE(lookup_list, l, link); | 
					
						
							|  |  |  | 		try_clear_lookup(l); | 
					
						
							|  |  |  | 		l = n; | 
					
						
							| 
									
										
										
										
											2000-04-26 18:34:17 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-27 04:57:32 +00:00
										 |  |  | /*%
 | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  |  * Destroy all of the libs we are using, and get everything ready for a | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  |  * clean shutdown. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void | 
					
						
							|  |  |  | destroy_libs(void) { | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2005-09-18 07:16:24 +00:00
										 |  |  | 	isc_result_t result; | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-07 10:50:01 +11:00
										 |  |  | 	if (keep != NULL) | 
					
						
							|  |  |  | 		isc_socket_detach(&keep); | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | 	debug("destroy_libs()"); | 
					
						
							|  |  |  | 	if (global_task != NULL) { | 
					
						
							|  |  |  | 		debug("freeing task"); | 
					
						
							|  |  |  | 		isc_task_detach(&global_task); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * The taskmgr_destroy() call blocks until all events are cleared | 
					
						
							|  |  |  | 	 * from the task. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	if (taskmgr != NULL) { | 
					
						
							| 
									
										
										
										
											2000-07-21 23:04:44 +00:00
										 |  |  | 		debug("freeing taskmgr"); | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | 		isc_taskmgr_destroy(&taskmgr); | 
					
						
							| 
									
										
										
										
											2000-12-11 19:24:30 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-18 18:51:40 +00:00
										 |  |  | 	LOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	REQUIRE(sockcount == 0); | 
					
						
							|  |  |  | 	REQUIRE(recvcount == 0); | 
					
						
							|  |  |  | 	REQUIRE(sendcount == 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	INSIST(ISC_LIST_HEAD(lookup_list) == NULL); | 
					
						
							| 
									
										
										
										
											2000-07-14 20:14:36 +00:00
										 |  |  | 	INSIST(current_lookup == NULL); | 
					
						
							| 
									
										
										
										
											2000-07-13 00:32:20 +00:00
										 |  |  | 	INSIST(!free_now); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	free_now = ISC_TRUE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-08-12 18:25:25 +00:00
										 |  |  | 	flush_server_list(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-18 05:12:44 +00:00
										 |  |  | 	clear_searchlist(); | 
					
						
							| 
									
										
										
										
											2005-09-18 07:16:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2008-01-18 23:46:58 +00:00
										 |  |  | 	result = dns_name_settotextfilter(NULL); | 
					
						
							|  |  |  | 	check_result(result, "dns_name_settotextfilter"); | 
					
						
							| 
									
										
										
										
											2005-09-18 07:16:24 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 	dns_name_destroy(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-07-13 01:49:44 +00:00
										 |  |  | 	if (commctx != NULL) { | 
					
						
							|  |  |  | 		debug("freeing commctx"); | 
					
						
							|  |  |  | 		isc_mempool_destroy(&commctx); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-06-06 18:49:06 +00:00
										 |  |  | 	if (socketmgr != NULL) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("freeing socketmgr"); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		isc_socketmgr_destroy(&socketmgr); | 
					
						
							| 
									
										
										
										
											2000-06-06 18:49:06 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (timermgr != NULL) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("freeing timermgr"); | 
					
						
							| 
									
										
											  
											
												 103.   [func]          libisc buffer API changes for <isc/buffer.h>:
                        Added:
                                isc_buffer_base(b)          (pointer)
                                isc_buffer_current(b)       (pointer)
                                isc_buffer_active(b)        (pointer)
                                isc_buffer_used(b)          (pointer)
                                isc_buffer_length(b)            (int)
                                isc_buffer_usedlength(b)        (int)
                                isc_buffer_consumedlength(b)    (int)
                                isc_buffer_remaininglength(b)   (int)
                                isc_buffer_activelength(b)      (int)
                                isc_buffer_availablelength(b)   (int)
                        Removed:
                                ISC_BUFFER_USEDCOUNT(b)
                                ISC_BUFFER_AVAILABLECOUNT(b)
                                isc_buffer_type(b)
                        Changed names:
                                isc_buffer_used(b, r) ->
                                        isc_buffer_usedregion(b, r)
                                isc_buffer_available(b, r) ->
                                        isc_buffer_available_region(b, r)
                                isc_buffer_consumed(b, r) ->
                                        isc_buffer_consumedregion(b, r)
                                isc_buffer_active(b, r) ->
                                        isc_buffer_activeregion(b, r)
                                isc_buffer_remaining(b, r) ->
                                        isc_buffer_remainingregion(b, r)
                        Buffer types were removed, so the ISC_BUFFERTYPE_*
                        macros are no more, and the type argument to
                        isc_buffer_init and isc_buffer_allocate were removed.
                        isc_buffer_putstr is now void (instead of isc_result_t)
                        and requires that the caller ensure that there
                        is enough available buffer space for the string.
											
										 
											2000-04-27 00:03:12 +00:00
										 |  |  | 		isc_timermgr_destroy(&timermgr); | 
					
						
							| 
									
										
										
										
											2000-06-06 18:49:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-03-19 22:16:10 +00:00
										 |  |  | 	if (tsigkey != NULL) { | 
					
						
							|  |  |  | 		debug("freeing key %p", tsigkey); | 
					
						
							|  |  |  | 		dns_tsigkey_detach(&tsigkey); | 
					
						
							| 
									
										
										
										
											2000-06-06 18:49:06 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-06-06 00:43:17 +00:00
										 |  |  | 	if (namebuf != NULL) | 
					
						
							|  |  |  | 		isc_buffer_free(&namebuf); | 
					
						
							| 
									
										
										
										
											2000-06-12 19:33:30 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  | 	if (is_dst_up) { | 
					
						
							| 
									
										
										
										
											2000-07-05 23:28:32 +00:00
										 |  |  | 		debug("destroy DST lib"); | 
					
						
							| 
									
										
										
										
											2000-06-30 22:53:07 +00:00
										 |  |  | 		dst_lib_destroy(); | 
					
						
							|  |  |  | 		is_dst_up = ISC_FALSE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2000-08-28 05:06:18 +00:00
										 |  |  | 	UNLOCK_LOOKUP; | 
					
						
							| 
									
										
										
										
											2000-08-26 01:42:34 +00:00
										 |  |  | 	DESTROYLOCK(&lookup_lock); | 
					
						
							| 
									
										
										
										
											2009-09-15 03:13:44 +00:00
										 |  |  | 	debug("Removing log context"); | 
					
						
							|  |  |  | 	isc_log_destroy(&lctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	debug("Destroy memory"); | 
					
						
							| 
									
										
										
										
											2000-10-19 22:49:34 +00:00
										 |  |  | 	if (memdebugging != 0) | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | 		isc_mem_stats(mctx, stderr); | 
					
						
							|  |  |  | 	if (mctx != NULL) | 
					
						
							| 
									
										
										
										
											2000-08-01 01:33:37 +00:00
										 |  |  | 		isc_mem_destroy(&mctx); | 
					
						
							| 
									
										
										
										
											2000-07-14 17:57:27 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2004-04-13 02:39:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #ifdef WITH_IDN_OUT_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | static isc_result_t | 
					
						
							|  |  |  | output_filter(isc_buffer_t *buffer, unsigned int used_org, | 
					
						
							|  |  |  | 	      isc_boolean_t absolute) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char tmp1[MAXDLEN], tmp2[MAXDLEN]; | 
					
						
							|  |  |  | 	size_t fromlen, tolen; | 
					
						
							|  |  |  | 	isc_boolean_t end_with_dot; | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | 	isc_result_t result; | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Copy contents of 'buffer' to 'tmp1', supply trailing dot | 
					
						
							|  |  |  | 	 * if 'absolute' is true, and terminate with NUL. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	fromlen = isc_buffer_usedlength(buffer) - used_org; | 
					
						
							|  |  |  | 	if (fromlen >= MAXDLEN) | 
					
						
							|  |  |  | 		return (ISC_R_SUCCESS); | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-08 16:27:10 -08:00
										 |  |  | 	memmove(tmp1, (char *)isc_buffer_base(buffer) + used_org, fromlen); | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 	end_with_dot = (tmp1[fromlen - 1] == '.') ? ISC_TRUE : ISC_FALSE; | 
					
						
							|  |  |  | 	if (absolute && !end_with_dot) { | 
					
						
							|  |  |  | 		fromlen++; | 
					
						
							|  |  |  | 		if (fromlen >= MAXDLEN) | 
					
						
							|  |  |  | 			return (ISC_R_SUCCESS); | 
					
						
							|  |  |  | 		tmp1[fromlen - 1] = '.'; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 	tmp1[fromlen] = '\0'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Convert contents of 'tmp1' to local encoding. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | 	result = idn_ace_to_locale(tmp1, tmp2, sizeof(tmp2)); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	if (result != ISC_R_SUCCESS) { | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 		return (ISC_R_SUCCESS); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Copy the converted contents in 'tmp1' back to 'buffer'. | 
					
						
							|  |  |  | 	 * If we have appended trailing dot, remove it. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 	tolen = strlen(tmp2); | 
					
						
							|  |  |  | 	if (absolute && !end_with_dot && tmp2[tolen - 1] == '.') | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 		tolen--; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (isc_buffer_length(buffer) < used_org + tolen) | 
					
						
							|  |  |  | 		return (ISC_R_NOSPACE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	isc_buffer_subtract(buffer, isc_buffer_usedlength(buffer) - used_org); | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 	memmove(isc_buffer_used(buffer), tmp2, tolen); | 
					
						
							| 
									
										
										
										
											2013-12-04 12:47:23 +11:00
										 |  |  | 	isc_buffer_add(buffer, (unsigned int)tolen); | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return (ISC_R_SUCCESS); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-09-09 06:17:03 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-22 17:11:18 +01:00
										 |  |  | #ifdef WITH_IDN_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | #ifdef WITH_LIBIDN2
 | 
					
						
							| 
									
										
										
										
											2018-02-22 17:11:18 +01:00
										 |  |  | static void | 
					
						
							|  |  |  | idn_initialize(void) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | static isc_result_t | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | idn_locale_to_ace(const char *from, char *to, size_t tolen) { | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 	char *tmp_str = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 	res = idn2_to_ascii_lz(from, &tmp_str, IDN2_NONTRANSITIONAL|IDN2_NFC_INPUT); | 
					
						
							|  |  |  | 	if (res == IDN2_DISALLOWED) { | 
					
						
							|  |  |  | 		res = idn2_to_ascii_lz(from, &tmp_str, IDN2_TRANSITIONAL|IDN2_NFC_INPUT); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (res == IDN2_OK) { | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 		/*
 | 
					
						
							|  |  |  | 		 * idn2_to_ascii_lz() normalizes all strings to lowerl case, | 
					
						
							|  |  |  | 		 * but we generally don't want to lowercase all input strings; | 
					
						
							|  |  |  | 		 * make sure to return the original case if the two strings | 
					
						
							|  |  |  | 		 * differ only in case | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		if (!strcasecmp(from, tmp_str)) { | 
					
						
							|  |  |  | 			if (strlen(from) >= tolen) { | 
					
						
							|  |  |  | 				debug("from string is too long"); | 
					
						
							|  |  |  | 				idn2_free(tmp_str); | 
					
						
							|  |  |  | 				return ISC_R_NOSPACE; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			idn2_free(tmp_str); | 
					
						
							|  |  |  | 			(void) strlcpy(to, from, tolen); | 
					
						
							|  |  |  | 			return ISC_R_SUCCESS; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 		/* check the length */ | 
					
						
							|  |  |  | 		if (strlen(tmp_str) >= tolen) { | 
					
						
							|  |  |  | 			debug("ACE string is too long"); | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 			idn2_free(tmp_str); | 
					
						
							|  |  |  | 			return ISC_R_NOSPACE; | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | 		(void) strlcpy(to, tmp_str, tolen); | 
					
						
							|  |  |  | 		idn2_free(tmp_str); | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 		return ISC_R_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 	fatal("'%s' is not a legal IDN name (%s), use +noidnin", from, idn2_strerror(res)); | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 	return ISC_R_FAILURE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #ifdef WITH_IDN_OUT_SUPPORT
 | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | static isc_result_t | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | idn_ace_to_locale(const char *from, char *to, size_t tolen) { | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 	char *tmp_str = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res = idn2_to_unicode_8zlz(from, &tmp_str, | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 				   IDN2_NONTRANSITIONAL|IDN2_NFC_INPUT); | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (res == IDN2_OK) { | 
					
						
							|  |  |  | 		/* check the length */ | 
					
						
							|  |  |  | 		if (strlen(tmp_str) >= tolen) { | 
					
						
							|  |  |  | 			debug("encoded ASC string is too long"); | 
					
						
							|  |  |  | 			idn2_free(tmp_str); | 
					
						
							|  |  |  | 			return ISC_R_FAILURE; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 		(void) strlcpy(to, tmp_str, tolen); | 
					
						
							|  |  |  | 		idn2_free(tmp_str); | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 		return ISC_R_SUCCESS; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-19 16:09:04 +00:00
										 |  |  | 	fatal("'%s' is not a legal IDN name (%s), use +noidnout", from, idn2_strerror(res)); | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | 	return ISC_R_FAILURE; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-08-15 14:36:59 +02:00
										 |  |  | #endif /* WITH_IDN_OUT_SUPPORT */
 | 
					
						
							| 
									
										
										
										
											2015-09-23 16:47:37 +02:00
										 |  |  | #endif /* WITH_LIBIDN2 */
 | 
					
						
							| 
									
										
										
										
											2015-09-23 14:37:16 +02:00
										 |  |  | #endif /* WITH_IDN_SUPPORT */
 |