Date: Fri, 3 Aug 2007 06:30:20 GMT From: Xin LI <delphij@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 124568 for review Message-ID: <200708030630.l736UKo1043972@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=124568 Change 124568 by delphij@delphij_odin on 2007/08/03 06:30:03 IFC Affected files ... .. //depot/projects/delphij_fork/ObsoleteFiles.inc#7 integrate .. //depot/projects/delphij_fork/contrib/tcpdump/print-bgp.c#2 integrate .. //depot/projects/delphij_fork/etc/namedb/named.conf#2 integrate .. //depot/projects/delphij_fork/include/arpa/tftp.h#2 integrate .. //depot/projects/delphij_fork/lib/libc/net/name6.c#2 integrate .. //depot/projects/delphij_fork/release/doc/en_US.ISO8859-1/relnotes/article.sgml#8 integrate .. //depot/projects/delphij_fork/sbin/ifconfig/ifbridge.c#2 integrate .. //depot/projects/delphij_fork/sbin/ifconfig/ifconfig.8#3 integrate .. //depot/projects/delphij_fork/share/man/man4/Makefile#3 integrate .. //depot/projects/delphij_fork/share/man/man4/crypto.4#2 integrate .. //depot/projects/delphij_fork/share/man/man4/enc.4#2 integrate .. //depot/projects/delphij_fork/share/man/man4/fast_ipsec.4#2 delete .. //depot/projects/delphij_fork/share/man/man4/ipsec.4#2 integrate .. //depot/projects/delphij_fork/share/man/man4/man4.i386/padlock.4#2 integrate .. //depot/projects/delphij_fork/share/man/man4/ng_ppp.4#2 integrate .. //depot/projects/delphij_fork/share/misc/committers-doc.dot#2 integrate .. //depot/projects/delphij_fork/sys/amd64/amd64/local_apic.c#2 integrate .. //depot/projects/delphij_fork/sys/amd64/amd64/mp_machdep.c#2 integrate .. //depot/projects/delphij_fork/sys/arm/arm/trap.c#2 integrate .. //depot/projects/delphij_fork/sys/arm/at91/at91rm92reg.h#2 integrate .. //depot/projects/delphij_fork/sys/arm/at91/kb920x_machdep.c#2 integrate .. //depot/projects/delphij_fork/sys/arm/at91/ohci_atmelarm.c#2 integrate .. //depot/projects/delphij_fork/sys/arm/conf/KB920X#2 integrate .. //depot/projects/delphij_fork/sys/dev/aic7xxx/aic7xxx.c#2 integrate .. //depot/projects/delphij_fork/sys/dev/aic7xxx/aic_osm_lib.c#2 integrate .. //depot/projects/delphij_fork/sys/dev/an/if_an.c#2 integrate .. //depot/projects/delphij_fork/sys/dev/arcmsr/arcmsr.c#2 integrate .. //depot/projects/delphij_fork/sys/dev/nmdm/nmdm.c#2 integrate .. //depot/projects/delphij_fork/sys/fs/tmpfs/tmpfs.h#4 integrate .. //depot/projects/delphij_fork/sys/fs/tmpfs/tmpfs_subr.c#4 integrate .. //depot/projects/delphij_fork/sys/i386/i386/local_apic.c#2 integrate .. //depot/projects/delphij_fork/sys/i386/i386/mp_machdep.c#2 integrate .. //depot/projects/delphij_fork/sys/net/if_bridge.c#3 integrate .. //depot/projects/delphij_fork/sys/net/if_bridgevar.h#3 integrate .. //depot/projects/delphij_fork/sys/netgraph/ng_ppp.c#2 integrate .. //depot/projects/delphij_fork/sys/netgraph/ng_ppp.h#2 integrate .. //depot/projects/delphij_fork/sys/netinet/tcp_subr.c#4 integrate .. //depot/projects/delphij_fork/sys/netinet/tcp_timer.h#2 integrate .. //depot/projects/delphij_fork/sys/pci/viapm.c#2 integrate .. //depot/projects/delphij_fork/usr.bin/tar/bsdtar.c#2 integrate .. //depot/projects/delphij_fork/usr.sbin/nscd/mp_rs_query.h#1 branch .. //depot/projects/delphij_fork/usr.sbin/portsnap/portsnap/portsnap.sh#2 integrate Differences ... ==== //depot/projects/delphij_fork/ObsoleteFiles.inc#7 (text+ko) ==== @@ -1,5 +1,5 @@ # -# $FreeBSD: src/ObsoleteFiles.inc,v 1.107 2007/07/17 17:28:59 delphij Exp $ +# $FreeBSD: src/ObsoleteFiles.inc,v 1.108 2007/08/02 08:04:47 bz Exp $ # # This file lists old files (OLD_FILES), libraries (OLD_LIBS) and # directories (OLD_DIRS) which should get removed at an update. Recently @@ -14,6 +14,8 @@ # The file is partitioned: OLD_FILES first, then OLD_LIBS and OLD_DIRS last. # +# 20070801: fast_ipsec.4 gone +OLD_FILES+=usr/share/man/man4/fast_ipsec.4.gz # 20070715: netatm temporarily disconnected OLD_FILES+=rescue/atm OLD_FILES+=rescue/fore_dnld ==== //depot/projects/delphij_fork/contrib/tcpdump/print-bgp.c#2 (text+ko) ==== @@ -622,6 +622,26 @@ return -2; } +/* + * As I remember, some versions of systems have an snprintf() that + * returns -1 if the buffer would have overflowed. If the return + * value is negative, set buflen to 0, to indicate that we've filled + * the buffer up. + * + * If the return value is greater than buflen, that means that + * the buffer would have overflowed; again, set buflen to 0 in + * that case. + */ +#define UPDATE_BUF_BUFLEN(buf, buflen, strlen) \ + if (strlen<0) \ + buflen=0; \ + else if ((u_int)strlen>buflen) \ + buflen=0; \ + else { \ + buflen-=strlen; \ + buf+=strlen; \ + } + static int decode_labeled_vpn_l2(const u_char *pptr, char *buf, u_int buflen) { @@ -632,11 +652,13 @@ tlen=plen; pptr+=2; TCHECK2(pptr[0],15); + buf[0]='\0'; strlen=snprintf(buf, buflen, "RD: %s, CE-ID: %u, Label-Block Offset: %u, Label Base %u", bgp_vpn_rd_print(pptr), EXTRACT_16BITS(pptr+8), EXTRACT_16BITS(pptr+10), EXTRACT_24BITS(pptr+12)>>4); /* the label is offsetted by 4 bits so lets shift it right */ + UPDATE_BUF_BUFLEN(buf, buflen, strlen); pptr+=15; tlen-=15; @@ -652,23 +674,32 @@ switch(tlv_type) { case 1: - strlen+=snprintf(buf+strlen,buflen-strlen, "\n\t\tcircuit status vector (%u) length: %u: 0x", - tlv_type, - tlv_len); + if (buflen!=0) { + strlen=snprintf(buf,buflen, "\n\t\tcircuit status vector (%u) length: %u: 0x", + tlv_type, + tlv_len); + UPDATE_BUF_BUFLEN(buf, buflen, strlen); + } ttlv_len=ttlv_len/8+1; /* how many bytes do we need to read ? */ while (ttlv_len>0) { TCHECK(pptr[0]); - strlen+=snprintf(buf+strlen,buflen-strlen, "%02x",*pptr++); + if (buflen!=0) { + strlen=snprintf(buf,buflen, "%02x",*pptr++); + UPDATE_BUF_BUFLEN(buf, buflen, strlen); + } ttlv_len--; } break; default: - snprintf(buf+strlen,buflen-strlen, "\n\t\tunknown TLV #%u, length: %u", - tlv_type, - tlv_len); + if (buflen!=0) { + strlen=snprintf(buf,buflen, "\n\t\tunknown TLV #%u, length: %u", + tlv_type, + tlv_len); + UPDATE_BUF_BUFLEN(buf, buflen, strlen); + } break; } - tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it tright */ + tlen-=(tlv_len<<3); /* the tlv-length is expressed in bits so lets shift it right */ } return plen+2; ==== //depot/projects/delphij_fork/etc/namedb/named.conf#2 (text+ko) ==== @@ -1,4 +1,4 @@ -// $FreeBSD: src/etc/namedb/named.conf,v 1.24 2007/06/18 06:29:45 dougb Exp $ +// $FreeBSD: src/etc/namedb/named.conf,v 1.25 2007/08/02 09:18:53 dougb Exp $ // // Refer to the named.conf(5) and named(8) man pages, and the documentation // in /usr/share/doc/bind9 for more details. @@ -15,10 +15,6 @@ dump-file "/var/dump/named_dump.db"; statistics-file "/var/stats/named.stats"; - disable-empty-zone "255.255.255.255.IN-ADDR.ARPA"; - disable-empty-zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA"; - disable-empty-zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA"; - // If named is being used only as a local resolver, this is a safe default. // For named to be accessible to the network, comment this option, specify // the proper IP address, or delete this option. @@ -29,6 +25,12 @@ // an IPv6 address, or the keyword "any". // listen-on-v6 { ::1; }; +// These zones are already covered by the empty zones listed below. +// If you remove the related empty zones below, comment these lines out. + disable-empty-zone "255.255.255.255.IN-ADDR.ARPA"; + disable-empty-zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA"; + disable-empty-zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA"; + // In addition to the "forwarders" clause, you can force your name // server to never initiate queries of its own, but always ask its // forwarders only, by enabling the following line: @@ -57,22 +59,23 @@ // first in your /etc/resolv.conf so this server will be queried. // Also, make sure to enable it in /etc/rc.conf. +// The traditional root hints mechanism. Use this, OR the slave zones below. +zone "." { type hint; file "named.root"; }; + /* Slaving the following zones from the root name servers has some significant advantages: 1. Faster local resolution for your users 2. No spurious traffic will be sent from your network to the roots 3. Greater resilience to any potential root server failure/DDoS - If you do not wish to slave these zones from the root servers - use the entry below instead. - zone "." { type hint; file "named.root"; }; + To use this mechanism, uncomment the entries below, and comment + the hint zone above. */ +/* zone "." { type slave; file "slave/root.slave"; masters { - 192.5.5.241; // F.ROOT-SERVERS.NET. - 192.228.79.201; // B.ROOT-SERVERS.NET. 192.33.4.12; // C.ROOT-SERVERS.NET. 192.112.36.4; // G.ROOT-SERVERS.NET. 193.0.14.129; // K.ROOT-SERVERS.NET. @@ -83,8 +86,6 @@ type slave; file "slave/arpa.slave"; masters { - 192.5.5.241; // F.ROOT-SERVERS.NET. - 192.228.79.201; // B.ROOT-SERVERS.NET. 192.33.4.12; // C.ROOT-SERVERS.NET. 192.112.36.4; // G.ROOT-SERVERS.NET. 193.0.14.129; // K.ROOT-SERVERS.NET. @@ -95,14 +96,13 @@ type slave; file "slave/in-addr.arpa.slave"; masters { - 192.5.5.241; // F.ROOT-SERVERS.NET. - 192.228.79.201; // B.ROOT-SERVERS.NET. 192.33.4.12; // C.ROOT-SERVERS.NET. 192.112.36.4; // G.ROOT-SERVERS.NET. 193.0.14.129; // K.ROOT-SERVERS.NET. }; notify no; }; +*/ /* Serving the following zones locally will prevent any queries for these zones leaving your network and going to the root ==== //depot/projects/delphij_fork/include/arpa/tftp.h#2 (text+ko) ==== @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)tftp.h 8.1 (Berkeley) 6/2/93 - * $FreeBSD: src/include/arpa/tftp.h,v 1.5 2001/09/27 20:50:14 obrien Exp $ + * $FreeBSD: src/include/arpa/tftp.h,v 1.6 2007/08/01 11:59:09 ticso Exp $ */ #ifndef _ARPA_TFTP_H_ @@ -58,9 +58,9 @@ unsigned short tu_block; /* block # */ unsigned short tu_code; /* error code */ char tu_stuff[1]; /* request packet stuff */ - } th_u; + } __packed th_u; char th_data[1]; /* data or error string */ -}; +} __packed; #define th_block th_u.tu_block #define th_code th_u.tu_code ==== //depot/projects/delphij_fork/lib/libc/net/name6.c#2 (text+ko) ==== @@ -88,7 +88,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/lib/libc/net/name6.c,v 1.61 2006/07/26 08:35:46 yar Exp $"); +__FBSDID("$FreeBSD: src/lib/libc/net/name6.c,v 1.62 2007/07/31 16:09:41 bushman Exp $"); #include "namespace.h" #include <sys/param.h> @@ -118,16 +118,8 @@ #include <unistd.h> #include "un-namespace.h" #include "netdb_private.h" -#include "res_config.h" #include "res_private.h" -#ifdef NS_CACHING -#include "nscache.h" -#endif -#ifndef _PATH_HOSTS -#define _PATH_HOSTS "/etc/hosts" -#endif - #ifndef MAXALIASES #define MAXALIASES 10 #endif @@ -153,7 +145,7 @@ } while (0) #define MAPADDRENABLED(flags) \ (((flags) & AI_V4MAPPED) || \ - (((flags) & AI_V4MAPPED_CFG) && _mapped_addr_enabled())) + (((flags) & AI_V4MAPPED_CFG))) union inx_addr { struct in_addr in_addr; @@ -202,14 +194,11 @@ static struct hostent *_hpcopy(struct hostent *, int *); static struct hostent *_hpaddr(int, const char *, void *, int *); +#ifdef INET6 static struct hostent *_hpmerge(struct hostent *, struct hostent *, int *); -#ifdef INET6 static struct hostent *_hpmapv6(struct hostent *, int *); #endif static struct hostent *_hpsort(struct hostent *, res_state); -static struct hostent *_ghbyname(const char *, int, int, int *); -static char *_hgetword(char **); -static int _mapped_addr_enabled(void); static struct hostent *_hpreorder(struct hostent *); static int get_addrselectpolicy(struct policyhead *); @@ -221,325 +210,30 @@ static int comp_dst(const void *, const void *); static int gai_addr2scopetype(struct sockaddr *); -static FILE *_files_open(int *); -static int _files_ghbyname(void *, void *, va_list); -static int _files_ghbyaddr(void *, void *, va_list); -#ifdef YP -static int _nis_ghbyname(void *, void *, va_list); -static int _nis_ghbyaddr(void *, void *, va_list); -#endif -static int _dns_ghbyname(void *, void *, va_list); -static int _dns_ghbyaddr(void *, void *, va_list); -static void _dns_shent(int) __unused; -static void _dns_ehent(void) __unused; -#ifdef ICMPNL -static int _icmp_ghbyaddr(void *, void *, va_list); -#endif /* ICMPNL */ -#ifdef NS_CACHING -static int ipnode_id_func(char *, size_t *, va_list, void *); -static int ipnode_marshal_func(char *, size_t *, void *, va_list, void *); -static int ipnode_unmarshal_func(char *, size_t, void *, va_list, void *); -#endif - -/* Host lookup order if nsswitch.conf is broken or nonexistant */ -static const ns_src default_src[] = { - { NSSRC_FILES, NS_SUCCESS }, - { NSSRC_DNS, NS_SUCCESS }, -#ifdef ICMPNL -#define NSSRC_ICMP "icmp" - { NSSRC_ICMP, NS_SUCCESS }, -#endif - { 0 } -}; - /* - * Check if kernel supports mapped address. - * implementation dependent + * Functions defined in RFC2553 + * getipnodebyname, getipnodebyaddr, freehostent */ -#ifdef __KAME__ -#include <sys/sysctl.h> -#endif /* __KAME__ */ -static int -_mapped_addr_enabled(void) +struct hostent * +getipnodebyname(const char *name, int af, int flags, int *errp) { - /* implementation dependent check */ -#if defined(__KAME__) && defined(IPV6CTL_MAPPED_ADDR) - int mib[4]; - size_t len; - int val; - - mib[0] = CTL_NET; - mib[1] = PF_INET6; - mib[2] = IPPROTO_IPV6; - mib[3] = IPV6CTL_MAPPED_ADDR; - len = sizeof(val); - if (sysctl(mib, 4, &val, &len, 0, 0) == 0 && val != 0) - return 1; -#endif /* __KAME__ && IPV6CTL_MAPPED_ADDR */ - return 0; -} - -#ifdef NS_CACHING -static int -ipnode_id_func(char *buffer, size_t *buffer_size, va_list ap, - void *cache_mdata) -{ + struct hostent *hp; + union inx_addr addrbuf; res_state statp; - u_long res_options; + u_long options; - const int op_id = 2; - char *name; - int af; - size_t len; - void *src; - - char *p; - size_t desired_size, size; - enum nss_lookup_type lookup_type; - int res = NS_UNAVAIL; - - statp = __res_state(); - res_options = statp->options & (RES_RECURSE | RES_DEFNAMES | - RES_DNSRCH | RES_NOALIASES | RES_USE_INET6); - - lookup_type = (enum nss_lookup_type)cache_mdata; - switch (lookup_type) { - case nss_lt_name: - name = va_arg(ap, char *); - af = va_arg(ap, int); - - size = strlen(name); - desired_size = sizeof(res_options) + sizeof(int) + - sizeof(enum nss_lookup_type) + sizeof(int) + size + 1; - - if (desired_size > *buffer_size) { - res = NS_RETURN; - goto fin; - } - - p = buffer; - memcpy(p, &res_options, sizeof(res_options)); - p += sizeof(res_options); - - memcpy(p, &op_id, sizeof(int)); - p += sizeof(int); - - memcpy(p, &lookup_type, sizeof(enum nss_lookup_type)); - p += sizeof(enum nss_lookup_type); - - memcpy(p, &af, sizeof(int)); - p += sizeof(int); - - memcpy(p, name, size + 1); - - res = NS_SUCCESS; + switch (af) { + case AF_INET: +#ifdef INET6 + case AF_INET6: +#endif break; - case nss_lt_id: - src = va_arg(ap, void *); - len = va_arg(ap, size_t); - af = va_arg(ap, int); - - desired_size = sizeof(res_options) + sizeof(int) + - sizeof(enum nss_lookup_type) + sizeof(int) + - sizeof(size_t) + len; - - if (desired_size > *buffer_size) { - res = NS_RETURN; - goto fin; - } - - p = buffer; - memcpy(p, &res_options, sizeof(res_options)); - p += sizeof(res_options); - - memcpy(p, &op_id, sizeof(int)); - p += sizeof(int); - - memcpy(p, &lookup_type, sizeof(enum nss_lookup_type)); - p += sizeof(enum nss_lookup_type); - - memcpy(p, &af, sizeof(int)); - p += sizeof(int); - - memcpy(p, &len, sizeof(size_t)); - p += sizeof(size_t); - - memcpy(p, src, len); - - res = NS_SUCCESS; - break; default: - /* should be unreachable */ - return (NS_UNAVAIL); - } - -fin: - *buffer_size = desired_size; - return (res); -} - -static int -ipnode_marshal_func(char *buffer, size_t *buffer_size, void *retval, - va_list ap, void *cache_mdata) -{ - struct hostent *ht; - - struct hostent new_ht; - size_t desired_size, aliases_size, addr_size, size; - char *p, **iter; - - ht = *((struct hostent **)retval); - - desired_size = _ALIGNBYTES + sizeof(struct hostent) + sizeof(char *); - if (ht->h_name != NULL) - desired_size += strlen(ht->h_name) + 1; - - if (ht->h_aliases != NULL) { - aliases_size = 0; - for (iter = ht->h_aliases; *iter; ++iter) { - desired_size += strlen(*iter) + 1; - ++aliases_size; - } - - desired_size += _ALIGNBYTES + - (aliases_size + 1) * sizeof(char *); - } - - if (ht->h_addr_list != NULL) { - addr_size = 0; - for (iter = ht->h_addr_list; *iter; ++iter) - ++addr_size; - - desired_size += addr_size * _ALIGN(ht->h_length); - desired_size += _ALIGNBYTES + (addr_size + 1) * sizeof(char *); - } - - if (desired_size > *buffer_size) { - /* this assignment is here for future use */ - *buffer_size = desired_size; - return (NS_RETURN); - } - - memcpy(&new_ht, ht, sizeof(struct hostent)); - memset(buffer, 0, desired_size); - - *buffer_size = desired_size; - p = buffer + sizeof(struct hostent) + sizeof(char *); - memcpy(buffer + sizeof(struct hostent), &p, sizeof(char *)); - p = (char *)_ALIGN(p); - - if (new_ht.h_name != NULL) { - size = strlen(new_ht.h_name); - memcpy(p, new_ht.h_name, size); - new_ht.h_name = p; - p += size + 1; - } - - if (new_ht.h_aliases != NULL) { - p = (char *)_ALIGN(p); - memcpy(p, new_ht.h_aliases, sizeof(char *) * aliases_size); - new_ht.h_aliases = (char **)p; - p += sizeof(char *) * (aliases_size + 1); - - for (iter = new_ht.h_aliases; *iter; ++iter) { - size = strlen(*iter); - memcpy(p, *iter, size); - *iter = p; - p += size + 1; - } - } - - if (new_ht.h_addr_list != NULL) { - p = (char *)_ALIGN(p); - memcpy(p, new_ht.h_addr_list, sizeof(char *) * addr_size); - new_ht.h_addr_list = (char **)p; - p += sizeof(char *) * (addr_size + 1); - - size = _ALIGN(new_ht.h_length); - for (iter = new_ht.h_addr_list; *iter; ++iter) { - memcpy(p, *iter, size); - *iter = p; - p += size + 1; - } + *errp = NO_RECOVERY; + return NULL; } - memcpy(buffer, &new_ht, sizeof(struct hostent)); - return (NS_SUCCESS); -} -static int -ipnode_unmarshal_func(char *buffer, size_t buffer_size, void *retval, - va_list ap, void *cache_mdata) -{ - struct hostent new_ht; - struct hostent *ht; - - char *p; - char **iter; - char *orig_buf; - int err; - - ht = &new_ht; - - memcpy(ht, buffer, sizeof(struct hostent)); - memcpy(&p, buffer + sizeof(struct hostent), sizeof(char *)); - - orig_buf = buffer + sizeof(struct hostent) + sizeof(char *) + - _ALIGN(p) - (size_t)p; - p = (char *)_ALIGN(p); - - - NS_APPLY_OFFSET(ht->h_name, orig_buf, p, char *); - if (ht->h_aliases != NULL) { - NS_APPLY_OFFSET(ht->h_aliases, orig_buf, p, char **); - - for (iter = ht->h_aliases; *iter; ++iter) - NS_APPLY_OFFSET(*iter, orig_buf, p, char *); - } - - if (ht->h_addr_list != NULL) { - NS_APPLY_OFFSET(ht->h_addr_list, orig_buf, p, char **); - - for (iter = ht->h_addr_list; *iter; ++iter) - NS_APPLY_OFFSET(*iter, orig_buf, p, char *); - } - - ht = _hpcopy(ht, &err); - if (ht == NULL) - return (NS_UNAVAIL); - - *((struct hostent **)retval) = ht; - return (NS_SUCCESS); -} -#endif - -/* - * Functions defined in RFC2553 - * getipnodebyname, getipnodebyaddr, freehostent - */ - -static struct hostent * -_ghbyname(const char *name, int af, int flags, int *errp) -{ - struct hostent *hp; - int rval; - -#ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - hosts, (void *)nss_lt_name, - ipnode_id_func, ipnode_marshal_func, ipnode_unmarshal_func); -#endif - static const ns_dtab dtab[] = { - NS_FILES_CB(_files_ghbyname, NULL) - { NSSRC_DNS, _dns_ghbyname, NULL }, - NS_NIS_CB(_nis_ghbyname, NULL) -#ifdef NS_CACHING - NS_CACHE_CB(&cache_info) -#endif - { 0 } - }; - if (flags & AI_ADDRCONFIG) { int s; @@ -554,31 +248,8 @@ */ _close(s); } - - rval = _nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyname", default_src, - name, af, errp); - return (rval == NS_SUCCESS) ? hp : NULL; -} - -struct hostent * -getipnodebyname(const char *name, int af, int flags, int *errp) -{ - struct hostent *hp; - union inx_addr addrbuf; - res_state statp; - - switch (af) { - case AF_INET: + #ifdef INET6 - case AF_INET6: -#endif - break; - default: - *errp = NO_RECOVERY; - return NULL; - } - -#ifdef INET6 /* special case for literal address */ if (inet_pton(AF_INET6, name, &addrbuf) == 1) { if (af != AF_INET6) { @@ -600,6 +271,7 @@ return _hpaddr(af, name, &addrbuf, errp); } + statp = __res_state(); if ((statp->options & RES_INIT) == 0) { if (res_ninit(statp) < 0) { @@ -607,25 +279,36 @@ return NULL; } } + + options = statp->options; + statp->options &= ~RES_USE_INET6; + + hp = gethostbyname2(name, af); + hp = _hpcopy(hp, errp); - *errp = HOST_NOT_FOUND; - hp = _ghbyname(name, af, flags, errp); - #ifdef INET6 if (af == AF_INET6 && ((flags & AI_ALL) || hp == NULL) && MAPADDRENABLED(flags)) { - struct hostent *hp2 = _ghbyname(name, AF_INET, flags, errp); + struct hostent *hp2 = gethostbyname2(name, AF_INET); if (hp == NULL) - hp = _hpmapv6(hp2, errp); + if (hp2 == NULL) + *errp = statp->res_h_errno; + else + hp = _hpmapv6(hp2, errp); else { - if (hp2 && strcmp(hp->h_name, hp2->h_name) != 0) { - freehostent(hp2); - hp2 = NULL; + if (hp2 && strcmp(hp->h_name, hp2->h_name) == 0) { + struct hostent *hpb = hp; + hp = _hpmerge(hpb, hp2, errp); + freehostent(hpb); } - hp = _hpmerge(hp, hp2, errp); } } #endif + + if (hp == NULL) + *errp = statp->res_h_errno; + + statp->options = options; return _hpreorder(_hpsort(hp, statp)); } @@ -633,34 +316,15 @@ getipnodebyaddr(const void *src, size_t len, int af, int *errp) { struct hostent *hp; - int rval; + res_state statp; + u_long options; + #ifdef INET6 struct in6_addr addrbuf; #else struct in_addr addrbuf; #endif - -#ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - hosts, (void *)nss_lt_id, - ipnode_id_func, ipnode_marshal_func, ipnode_unmarshal_func); -#endif - static const ns_dtab dtab[] = { - NS_FILES_CB(_files_ghbyaddr, NULL) - { NSSRC_DNS, _dns_ghbyaddr, NULL }, - NS_NIS_CB(_nis_ghbyaddr, NULL) -#ifdef ICMPNL - { NSSRC_ICMP, _icmp_ghbyaddr, NULL }, -#endif -#ifdef NS_CACHING - NS_CACHE_CB(&cache_info) -#endif - { 0 } - }; - - *errp = HOST_NOT_FOUND; - + switch (af) { case AF_INET: if (len != sizeof(struct in_addr)) { @@ -700,9 +364,23 @@ return NULL; } - rval = _nsdispatch(&hp, dtab, NSDB_HOSTS, "ghbyaddr", default_src, - src, len, af, errp); - return (rval == NS_SUCCESS) ? hp : NULL; + statp = __res_state(); + if ((statp->options & RES_INIT) == 0) { + if (res_ninit(statp) < 0) { + RES_SET_H_ERRNO(statp, NETDB_INTERNAL); + return NULL; + } + } + + options = statp->options; + statp->options &= ~RES_USE_INET6; + + hp = gethostbyaddr(src, len, af); + if (hp == NULL) + *errp = statp->res_h_errno; + + statp->options = options; + return (_hpcopy(hp, errp)); } void @@ -811,9 +489,10 @@ hp->h_addr_list = addrs; addrs[0] = (char *)addr; addrs[1] = NULL; - return _hpcopy(hp, errp); + return (_hpcopy(hp, errp)); } +#ifdef INET6 /* * _hpmerge: merge 2 hostent structure, arguments will be freed */ @@ -828,9 +507,9 @@ union inx_addr addrbuf[MAXADDRS]; if (hp1 == NULL) - return hp2; + return _hpcopy(hp2, errp); if (hp2 == NULL) - return hp1; + return _hpcopy(hp1, errp); #define HP(i) (i == 1 ? hp1 : hp2) hp = &hpbuf; @@ -850,17 +529,14 @@ } } aliases[nalias] = NULL; -#ifdef INET6 if (hp1->h_length != hp2->h_length) { hp->h_addrtype = AF_INET6; hp->h_length = sizeof(struct in6_addr); } else { -#endif hp->h_addrtype = hp1->h_addrtype; hp->h_length = hp1->h_length; -#ifdef INET6 } -#endif + hp->h_addr_list = addrs; naddr = 0; for (i = 1; i <= 2; i++) { @@ -879,11 +555,9 @@ } } addrs[naddr] = NULL; - hp = _hpcopy(hp, errp); - freehostent(hp1); - freehostent(hp2); - return hp; + return (_hpcopy(hp, errp)); } +#endif /* * _hpmapv6: convert IPv4 hostent into IPv4-mapped IPv6 addresses @@ -892,24 +566,17 @@ static struct hostent * _hpmapv6(struct hostent *hp, int *errp) { - struct hostent *hp6; + struct hostent hp6; if (hp == NULL) return NULL; if (hp->h_addrtype == AF_INET6) - return hp; + return _hpcopy(hp, errp); - /* make dummy hostent to convert IPv6 address */ - if ((hp6 = (struct hostent *)malloc(sizeof(struct hostent))) == NULL) { - *errp = TRY_AGAIN; - return NULL; - } - hp6->h_name = NULL; - hp6->h_aliases = NULL; - hp6->h_addrtype = AF_INET6; - hp6->h_length = sizeof(struct in6_addr); - hp6->h_addr_list = NULL; - return _hpmerge(hp6, hp, errp); + memset(&hp6, 0, sizeof(struct hostent)); + hp6.h_addrtype = AF_INET6; + hp6.h_length = sizeof(struct in6_addr); + return _hpmerge(&hp6, hp, errp); } #endif @@ -965,37 +632,6 @@ return hp; } -static char * -_hgetword(char **pp) -{ - char c, *p, *ret; - const char *sp; - static const char sep[] = "# \t\n"; - - ret = NULL; - for (p = *pp; (c = *p) != '\0'; p++) { - for (sp = sep; *sp != '\0'; sp++) { - if (c == *sp) - break; - } - if (c == '#') - p[1] = '\0'; /* ignore rest of line */ - if (ret == NULL) { - if (*sp == '\0') - ret = p; - } else { - if (*sp != '\0') { - *p++ = '\0'; - break; - } - } - } - *pp = p; - if (ret == NULL || *ret == '\0') - return NULL; - return ret; -} - /* * _hpreorder: sort address by default address selection */ @@ -1475,954 +1111,3 @@ return(-1); } } - -/* - * FILES (/etc/hosts) - */ - -static FILE * -_files_open(int *errp) -{ - FILE *fp; - fp = fopen(_PATH_HOSTS, "r"); - if (fp == NULL) - *errp = NO_RECOVERY; - return fp; -} - -static int -_files_ghbyname(void *rval, void *cb_data, va_list ap) -{ - const char *name; - int af; - int *errp; - int match, nalias; - char *p, *line, *addrstr, *cname; - FILE *fp; - struct hostent *rethp, *hp, hpbuf; - char *aliases[MAXALIASES + 1], *addrs[2]; - union inx_addr addrbuf; - char buf[BUFSIZ]; - - name = va_arg(ap, const char *); - af = va_arg(ap, int); - errp = va_arg(ap, int *); - - *(struct hostent **)rval = NULL; - - if ((fp = _files_open(errp)) == NULL) - return NS_UNAVAIL; - rethp = hp = NULL; - - while (fgets(buf, sizeof(buf), fp)) { - line = buf; - if ((addrstr = _hgetword(&line)) == NULL - || (cname = _hgetword(&line)) == NULL) - continue; - match = (strcasecmp(cname, name) == 0); - nalias = 0; - while ((p = _hgetword(&line)) != NULL) { - if (!match) - match = (strcasecmp(p, name) == 0); - if (nalias < MAXALIASES) - aliases[nalias++] = p; - } - if (!match) - continue; - switch (af) { - case AF_INET: - if (inet_aton(addrstr, (struct in_addr *)&addrbuf) - != 1) { >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708030630.l736UKo1043972>