xref: /onnv-gate/usr/src/lib/libresolv2/common/sunw/sunw_mtctxres.c (revision 11038:74b12212b8a2)
10Sstevel@tonic-gate /*
2*11038SRao.Shoaib@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
3*11038SRao.Shoaib@Sun.COM  * Use is subject to license terms.
40Sstevel@tonic-gate  */
50Sstevel@tonic-gate 
60Sstevel@tonic-gate #include <port_before.h>
70Sstevel@tonic-gate #include <thread.h>
80Sstevel@tonic-gate #include <errno.h>
90Sstevel@tonic-gate #include <netdb.h>
100Sstevel@tonic-gate #include <malloc.h>
110Sstevel@tonic-gate #include <string.h>
120Sstevel@tonic-gate #include <resolv_mt.h>
130Sstevel@tonic-gate #include <irs.h>
140Sstevel@tonic-gate #include <port_after.h>
150Sstevel@tonic-gate 
160Sstevel@tonic-gate /*
17*11038SRao.Shoaib@Sun.COM  * much of the original version of sunw_mtxtxres.c was incorporated into
18*11038SRao.Shoaib@Sun.COM  * ISC libbind as resolv/mtctxres.c. The following bits have not yet made
19*11038SRao.Shoaib@Sun.COM  * it into ISC libbind.
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate 
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate  * There used to be a private, MT-safe resolver interface that used TSD
240Sstevel@tonic-gate  * to store per-thread _res, h_errno, etc. We continue to provide the
250Sstevel@tonic-gate  * access functions __res_get_res() and __res_get_h_errno() so that binaries
260Sstevel@tonic-gate  * that used the private interface will continue to work.
270Sstevel@tonic-gate  */
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	_res
300Sstevel@tonic-gate #undef	_res
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
330Sstevel@tonic-gate extern struct __res_state	*__res_state(void);
340Sstevel@tonic-gate 
350Sstevel@tonic-gate struct __res_state *
__res_get_res(void)360Sstevel@tonic-gate __res_get_res(void) {
370Sstevel@tonic-gate 	return (__res_state());
380Sstevel@tonic-gate }
390Sstevel@tonic-gate 
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #ifdef	h_errno
420Sstevel@tonic-gate #undef	h_errno
430Sstevel@tonic-gate #endif
440Sstevel@tonic-gate 
450Sstevel@tonic-gate extern int			*__h_errno(void);
460Sstevel@tonic-gate 
470Sstevel@tonic-gate int *
__res_get_h_errno(void)480Sstevel@tonic-gate __res_get_h_errno(void) {
490Sstevel@tonic-gate 	return (__h_errno());
500Sstevel@tonic-gate }
510Sstevel@tonic-gate 
520Sstevel@tonic-gate 
530Sstevel@tonic-gate #ifdef SUNW_HOSTS_FALLBACK
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * When the name service switch calls libresolv, it doesn't want fallback
570Sstevel@tonic-gate  * to /etc/hosts, so we provide a method to turn it off.
580Sstevel@tonic-gate  */
590Sstevel@tonic-gate 
600Sstevel@tonic-gate void
__res_set_no_hosts_fallback(void)610Sstevel@tonic-gate __res_set_no_hosts_fallback(void) {
620Sstevel@tonic-gate 	___mtctxres()->no_hosts_fallback_private = 1;
630Sstevel@tonic-gate }
640Sstevel@tonic-gate 
650Sstevel@tonic-gate void
__res_unset_no_hosts_fallback(void)660Sstevel@tonic-gate __res_unset_no_hosts_fallback(void) {
670Sstevel@tonic-gate 	___mtctxres()->no_hosts_fallback_private = 0;
680Sstevel@tonic-gate }
690Sstevel@tonic-gate 
700Sstevel@tonic-gate int
__res_no_hosts_fallback(void)710Sstevel@tonic-gate __res_no_hosts_fallback(void) {
720Sstevel@tonic-gate 	return (___mtctxres()->no_hosts_fallback_private);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate 
750Sstevel@tonic-gate #endif  /* SUNW_HOSTS_FALLBACK */
760Sstevel@tonic-gate 
770Sstevel@tonic-gate #ifdef	SUNW_OVERRIDE_RETRY
780Sstevel@tonic-gate 
790Sstevel@tonic-gate /*
800Sstevel@tonic-gate  * The NS switch wants to be able to override the number of retries.
810Sstevel@tonic-gate  */
820Sstevel@tonic-gate 
830Sstevel@tonic-gate int
__res_override_retry(int retry)840Sstevel@tonic-gate __res_override_retry(int retry) {
850Sstevel@tonic-gate 	___mtctxres()->retry_private = retry;
860Sstevel@tonic-gate 	/*
870Sstevel@tonic-gate 	 * This function doesn't really need a return value; saving the
880Sstevel@tonic-gate 	 * old retry setting, and restoring it, is handled by __res_retry()
890Sstevel@tonic-gate 	 * and __res_retry_reset() below. However, the nss_dns library
900Sstevel@tonic-gate 	 * must have a private version of this function to be used when
910Sstevel@tonic-gate 	 * running with an old libresolv. That private nss_dns function
920Sstevel@tonic-gate 	 * needs a return value, and a function pointer is used to select
930Sstevel@tonic-gate 	 * the right function at runtime. Thus, __res_override_retry
940Sstevel@tonic-gate 	 * must have a function prototype consistent with the private
950Sstevel@tonic-gate 	 * nss_dns function, i.e., one that returns an int.
960Sstevel@tonic-gate 	 *
970Sstevel@tonic-gate 	 * Given that we do have a return value, that value must be zero.
980Sstevel@tonic-gate 	 * That's because retry_private == 0 is used to indicate that
990Sstevel@tonic-gate 	 * no override retry value is in effect, and the way we expect
1000Sstevel@tonic-gate 	 * nss_dns to call us is:
1010Sstevel@tonic-gate 	 *
1020Sstevel@tonic-gate 	 *	int oldretry = __res_override_retry(N);
1030Sstevel@tonic-gate 	 *	<whatever>
1040Sstevel@tonic-gate 	 *	(void)__res_override_retry(old_retry);
1050Sstevel@tonic-gate 	 */
1060Sstevel@tonic-gate 	return (0);
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate int
__res_retry(int retry)1100Sstevel@tonic-gate __res_retry(int retry) {
1110Sstevel@tonic-gate 	mtctxres_t	*mt = ___mtctxres();
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	mt->retry_save = retry;
1140Sstevel@tonic-gate 	return ((mt->retry_private != 0) ? mt->retry_private : retry);
1150Sstevel@tonic-gate }
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate int
__res_retry_reset(void)1180Sstevel@tonic-gate __res_retry_reset(void) {
1190Sstevel@tonic-gate 	mtctxres_t	*mt = ___mtctxres();
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	return (mt->retry_save);
1220Sstevel@tonic-gate }
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate #endif	/* SUNW_OVERRIDE_RETRY */
125