17c478bd9Sstevel@tonic-gate /* 2*9525b14bSRao Shoaib * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 3*9525b14bSRao Shoaib * Use is subject to license terms. 47c478bd9Sstevel@tonic-gate */ 57c478bd9Sstevel@tonic-gate 67c478bd9Sstevel@tonic-gate #include <port_before.h> 77c478bd9Sstevel@tonic-gate #include <thread.h> 87c478bd9Sstevel@tonic-gate #include <errno.h> 97c478bd9Sstevel@tonic-gate #include <netdb.h> 107c478bd9Sstevel@tonic-gate #include <malloc.h> 117c478bd9Sstevel@tonic-gate #include <string.h> 127c478bd9Sstevel@tonic-gate #include <resolv_mt.h> 137c478bd9Sstevel@tonic-gate #include <irs.h> 147c478bd9Sstevel@tonic-gate #include <port_after.h> 157c478bd9Sstevel@tonic-gate 167c478bd9Sstevel@tonic-gate /* 17*9525b14bSRao Shoaib * much of the original version of sunw_mtxtxres.c was incorporated into 18*9525b14bSRao Shoaib * ISC libbind as resolv/mtctxres.c. The following bits have not yet made 19*9525b14bSRao Shoaib * it into ISC libbind. 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * There used to be a private, MT-safe resolver interface that used TSD 247c478bd9Sstevel@tonic-gate * to store per-thread _res, h_errno, etc. We continue to provide the 257c478bd9Sstevel@tonic-gate * access functions __res_get_res() and __res_get_h_errno() so that binaries 267c478bd9Sstevel@tonic-gate * that used the private interface will continue to work. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifdef _res 307c478bd9Sstevel@tonic-gate #undef _res 317c478bd9Sstevel@tonic-gate #endif 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate extern struct __res_state *__res_state(void); 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate struct __res_state * 367c478bd9Sstevel@tonic-gate __res_get_res(void) { 377c478bd9Sstevel@tonic-gate return (__res_state()); 387c478bd9Sstevel@tonic-gate } 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #ifdef h_errno 427c478bd9Sstevel@tonic-gate #undef h_errno 437c478bd9Sstevel@tonic-gate #endif 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate extern int *__h_errno(void); 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate int * 487c478bd9Sstevel@tonic-gate __res_get_h_errno(void) { 497c478bd9Sstevel@tonic-gate return (__h_errno()); 507c478bd9Sstevel@tonic-gate } 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #ifdef SUNW_HOSTS_FALLBACK 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * When the name service switch calls libresolv, it doesn't want fallback 577c478bd9Sstevel@tonic-gate * to /etc/hosts, so we provide a method to turn it off. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate void 617c478bd9Sstevel@tonic-gate __res_set_no_hosts_fallback(void) { 627c478bd9Sstevel@tonic-gate ___mtctxres()->no_hosts_fallback_private = 1; 637c478bd9Sstevel@tonic-gate } 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate void 667c478bd9Sstevel@tonic-gate __res_unset_no_hosts_fallback(void) { 677c478bd9Sstevel@tonic-gate ___mtctxres()->no_hosts_fallback_private = 0; 687c478bd9Sstevel@tonic-gate } 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate int 717c478bd9Sstevel@tonic-gate __res_no_hosts_fallback(void) { 727c478bd9Sstevel@tonic-gate return (___mtctxres()->no_hosts_fallback_private); 737c478bd9Sstevel@tonic-gate } 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #endif /* SUNW_HOSTS_FALLBACK */ 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #ifdef SUNW_OVERRIDE_RETRY 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * The NS switch wants to be able to override the number of retries. 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate int 847c478bd9Sstevel@tonic-gate __res_override_retry(int retry) { 857c478bd9Sstevel@tonic-gate ___mtctxres()->retry_private = retry; 867c478bd9Sstevel@tonic-gate /* 877c478bd9Sstevel@tonic-gate * This function doesn't really need a return value; saving the 887c478bd9Sstevel@tonic-gate * old retry setting, and restoring it, is handled by __res_retry() 897c478bd9Sstevel@tonic-gate * and __res_retry_reset() below. However, the nss_dns library 907c478bd9Sstevel@tonic-gate * must have a private version of this function to be used when 917c478bd9Sstevel@tonic-gate * running with an old libresolv. That private nss_dns function 927c478bd9Sstevel@tonic-gate * needs a return value, and a function pointer is used to select 937c478bd9Sstevel@tonic-gate * the right function at runtime. Thus, __res_override_retry 947c478bd9Sstevel@tonic-gate * must have a function prototype consistent with the private 957c478bd9Sstevel@tonic-gate * nss_dns function, i.e., one that returns an int. 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * Given that we do have a return value, that value must be zero. 987c478bd9Sstevel@tonic-gate * That's because retry_private == 0 is used to indicate that 997c478bd9Sstevel@tonic-gate * no override retry value is in effect, and the way we expect 1007c478bd9Sstevel@tonic-gate * nss_dns to call us is: 1017c478bd9Sstevel@tonic-gate * 1027c478bd9Sstevel@tonic-gate * int oldretry = __res_override_retry(N); 1037c478bd9Sstevel@tonic-gate * <whatever> 1047c478bd9Sstevel@tonic-gate * (void)__res_override_retry(old_retry); 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate return (0); 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate int 1107c478bd9Sstevel@tonic-gate __res_retry(int retry) { 1117c478bd9Sstevel@tonic-gate mtctxres_t *mt = ___mtctxres(); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate mt->retry_save = retry; 1147c478bd9Sstevel@tonic-gate return ((mt->retry_private != 0) ? mt->retry_private : retry); 1157c478bd9Sstevel@tonic-gate } 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate int 1187c478bd9Sstevel@tonic-gate __res_retry_reset(void) { 1197c478bd9Sstevel@tonic-gate mtctxres_t *mt = ___mtctxres(); 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate return (mt->retry_save); 1227c478bd9Sstevel@tonic-gate } 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate #endif /* SUNW_OVERRIDE_RETRY */ 125