From: Greg Hudson Date: Thu, 23 Jun 2011 04:13:45 +0000 (+0000) Subject: Use AI_ADDRCONFIG for more efficient getaddrinfo X-Git-Tag: krb5-1.10-alpha1~395 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=db143ecacf966a580c0fedd21d413019d0ba0c99;p=krb5.git Use AI_ADDRCONFIG for more efficient getaddrinfo Add AI_ADDRCONFIG to the hint flags for every invocation of getaddrinfo which wasn't already using it. This is often the default behavior when no hints are specified, but we tend to specify hints a lot, so we have to say it ourselves. AI_ADDRCONFIG causes AAAA lookups to be skipped if the system has no public IPv6 interface addresses, usually saving a couple of DNS queries per getaddrinfo call and allowing DNS caching to be much more effective without the need for negative caching. ticket: 6923 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24978 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/appl/sample/sclient/sclient.c b/src/appl/sample/sclient/sclient.c index eb868d2d2..7ec8edd0e 100644 --- a/src/appl/sample/sclient/sclient.c +++ b/src/appl/sample/sclient/sclient.c @@ -125,6 +125,7 @@ main(int argc, char *argv[]) memset(&aihints, 0, sizeof(aihints)); aihints.ai_socktype = SOCK_STREAM; + aihints.ai_flags = AI_ADDRCONFIG; aierr = getaddrinfo(argv[1], portstr, &aihints, &ap); if (aierr) { fprintf(stderr, "%s: error looking up host '%s' port '%s'/tcp: %s\n", diff --git a/src/kadmin/dbutil/kadm5_create.c b/src/kadmin/dbutil/kadm5_create.c index 65cd68be5..9d5ee1da4 100644 --- a/src/kadmin/dbutil/kadm5_create.c +++ b/src/kadmin/dbutil/kadm5_create.c @@ -184,7 +184,7 @@ static int add_admin_princs(void *handle, krb5_context context, char *realm) goto clean_and_exit; } memset(&ai_hints, 0, sizeof(ai_hints)); - ai_hints.ai_flags = AI_CANONNAME; + ai_hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; gai_error = getaddrinfo(localname, (char *)NULL, &ai_hints, &ai); if (gai_error) { ret = EINVAL; diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c index 98231ab33..6537d3025 100644 --- a/src/lib/kadm5/alt_prof.c +++ b/src/lib/kadm5/alt_prof.c @@ -897,7 +897,7 @@ kadm5_get_admin_service_name(krb5_context ctx, } memset(&hint, 0, sizeof(hint)); - hint.ai_flags = AI_CANONNAME; + hint.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; err = getaddrinfo(params_out.admin_server, NULL, &hint, &ai); if (err != 0) { ret = KADM5_CANT_RESOLVE; diff --git a/src/lib/kadm5/clnt/client_init.c b/src/lib/kadm5/clnt/client_init.c index 735ddfd31..d6309979f 100644 --- a/src/lib/kadm5/clnt/client_init.c +++ b/src/lib/kadm5/clnt/client_init.c @@ -563,8 +563,9 @@ connect_to_server(const char *hostname, int port, int *fd) (void) snprintf(portbuf, sizeof(portbuf), "%d", port); memset(&hint, 0, sizeof(hint)); hint.ai_socktype = SOCK_STREAM; + hint.ai_flags = AI_ADDRCONFIG; #ifdef AI_NUMERICSERV - hint.ai_flags = AI_NUMERICSERV; + hint.ai_flags |= AI_NUMERICSERV; #endif err = getaddrinfo(hostname, portbuf, &hint, &addrs); if (err != 0) diff --git a/src/lib/krb5/os/hostaddr.c b/src/lib/krb5/os/hostaddr.c index ccab1d0e4..5046f9b31 100644 --- a/src/lib/krb5/os/hostaddr.c +++ b/src/lib/krb5/os/hostaddr.c @@ -41,7 +41,7 @@ krb5_os_hostaddr(krb5_context context, const char *name, return KRB5_ERR_BAD_HOSTNAME; memset (&hints, 0, sizeof (hints)); - hints.ai_flags = AI_NUMERICHOST; + hints.ai_flags = AI_NUMERICHOST | AI_ADDRCONFIG; /* We don't care what kind at this point, really, but without this, we can get back multiple sockaddrs per address, for SOCK_DGRAM, SOCK_STREAM, and SOCK_RAW. I haven't checked if diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index 33e13e1c5..d780433f8 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -107,7 +107,7 @@ get_fq_hostname(char *buf, size_t bufsize, const char *name) int err; memset (&hints, 0, sizeof (hints)); - hints.ai_flags = AI_CANONNAME; + hints.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; err = getaddrinfo (name, 0, &hints, &ai); if (err) return krb5int_translate_gai_error (err); diff --git a/src/lib/krb5/os/sendto_kdc.c b/src/lib/krb5/os/sendto_kdc.c index a3eb32234..371af9d23 100644 --- a/src/lib/krb5/os/sendto_kdc.c +++ b/src/lib/krb5/os/sendto_kdc.c @@ -725,8 +725,9 @@ resolve_server(krb5_context context, const struct serverlist *servers, memset(&hint, 0, sizeof(hint)); hint.ai_family = entry->family; hint.ai_socktype = (entry->socktype != 0) ? entry->socktype : socktype1; + hint.ai_flags = AI_ADDRCONFIG; #ifdef AI_NUMERICSERV - hint.ai_flags = AI_NUMERICSERV; + hint.ai_flags |= AI_NUMERICSERV; #endif result = snprintf(portbuf, sizeof(portbuf), "%d", ntohs(entry->port)); if (SNPRINTF_OVERFLOW(result, sizeof(portbuf))) diff --git a/src/plugins/locate/python/py-locate.c b/src/plugins/locate/python/py-locate.c index 23b407c63..727302676 100644 --- a/src/plugins/locate/python/py-locate.c +++ b/src/plugins/locate/python/py-locate.c @@ -302,6 +302,7 @@ lookup(void *blob, enum locate_service_type svc, const char *realm, return -1; } aihints.ai_socktype = thissocktype; + aihints.ai_flags = AI_ADDRCONFIG; x = getaddrinfo (hoststr, portstr, &aihints, &airesult); if (x != 0) continue; diff --git a/src/slave/kprop.c b/src/slave/kprop.c index f1b676fb8..1c2a93b17 100644 --- a/src/slave/kprop.c +++ b/src/slave/kprop.c @@ -322,6 +322,7 @@ open_connection(krb5_context context, char *host, int *fd) memset(&hints, 0, sizeof(hints)); hints.ai_family = PF_UNSPEC; hints.ai_socktype = SOCK_STREAM; + hints.ai_flags = AI_ADDRCONFIG; error = getaddrinfo(host, port, &hints, &answers); if (error != 0) { com_err(progname, 0, "%s: %s", host, gai_strerror(error));