summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/os/trace.c
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2011-02-13 21:14:00 +0000
committerGreg Hudson <ghudson@mit.edu>2011-02-13 21:14:00 +0000
commit8b9d249e40601047e69c92d7acb578fd0bbafc00 (patch)
treedff77af4a82cae99af17dc0848d44a138968841f /src/lib/krb5/os/trace.c
parent6726c9f5eca0e49cabfdf878c02e5966bdcccd93 (diff)
downloadkrb5-8b9d249e40601047e69c92d7acb578fd0bbafc00.tar.gz
krb5-8b9d249e40601047e69c92d7acb578fd0bbafc00.tar.xz
krb5-8b9d249e40601047e69c92d7acb578fd0bbafc00.zip
Defer hostname lookups in krb5_sendto_kdc
Restructure the locate_kdc and sendto_kdc code to defer getaddrinfo calls until we need the answer. This requires many changes: * struct addrlist is now called struct serverlist, and is declared in os-proto.h instead of k5-int.h. It contains an array of struct server_entry structures which can hold either a name or an address. (Address entries are used for locate_kdc module results.) * The connection state list is now a linked list, and holds address information directly instead of using a struct addrinfo (this simplifies memory management). Each connection entry contains a callback buffer (previously stored in a separate array) and an index into the server list. * The {addrstate} trace formatting primitive is no longer needed, and has been replaced by {connstate}. There is also a new tracing event for resolving hostnames. * locate_server, locate_kdc, free_serverlist, and sendto get their prefixes changed from krb5int_ to k5_ as their prototypes were being adjusted anyway. The family argument is gone from the locate functions as it was never productively used. k5_sendto now receives the socket types of interest. * krb5_sendto_kdc will now pass a 0 socktype to k5_locate_kdc if both socket types are wanted. There were some allowances for this in locate but this was never previously done. In order to be conservative when invoking locate modules, we always pass an explicit socktype, thus calling lookup twice (as we did before, albeit with a separate init/fini cycle) in the common case. When creating hostname entries in serverlist from profile configuration, we preserve the 0 value of socktype, and later create both TCP and UDP addresses from the getaddrinfo results when the host is resolved. * Some accessor functions previously used by libkrb4 have been removed as they impinged upon this work. ticket: 6868 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24635 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/os/trace.c')
-rw-r--r--src/lib/krb5/os/trace.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lib/krb5/os/trace.c b/src/lib/krb5/os/trace.c
index 3138aaf0f9..ae3b20cc29 100644
--- a/src/lib/krb5/os/trace.c
+++ b/src/lib/krb5/os/trace.c
@@ -40,6 +40,7 @@
*/
#include "k5-int.h"
+#include "cm.h"
#ifndef DISABLE_TRACING
@@ -71,7 +72,7 @@ trace_format(krb5_context context, const char *fmt, va_list ap)
krb5_error_code kerr;
size_t len, i;
int err;
- struct addrinfo *ai;
+ struct conn_state *cs;
const krb5_data *d;
krb5_data data;
char addrbuf[NI_MAXHOST], portbuf[NI_MAXSERV], tmpbuf[200], *str;
@@ -136,24 +137,24 @@ trace_format(krb5_context context, const char *fmt, va_list ap)
krb5int_buf_add(&buf, str);
free(str);
}
- } else if (strcmp(tmpbuf, "addrinfo") == 0) {
- ai = va_arg(ap, struct addrinfo *);
- if (ai->ai_socktype == SOCK_DGRAM)
- krb5int_buf_add(&buf, "dgram");
- else if (ai->ai_socktype == SOCK_STREAM)
- krb5int_buf_add(&buf, "stream");
- else
- krb5int_buf_add_fmt(&buf, "socktype%d", ai->ai_socktype);
+ } else if (strcmp(tmpbuf, "connstate") == 0) {
+ cs = va_arg(ap, struct conn_state *);
+ if (cs->socktype == SOCK_DGRAM)
+ krb5int_buf_add(&buf, "dgram");
+ else if (cs->socktype == SOCK_STREAM)
+ krb5int_buf_add(&buf, "stream");
+ else
+ krb5int_buf_add_fmt(&buf, "socktype%d", cs->socktype);
- if (getnameinfo(ai->ai_addr, ai->ai_addrlen,
+ if (getnameinfo((struct sockaddr *)&cs->addr, cs->addrlen,
addrbuf, sizeof(addrbuf), portbuf, sizeof(portbuf),
NI_NUMERICHOST|NI_NUMERICSERV) != 0) {
- if (ai->ai_addr->sa_family == AF_UNSPEC)
- krb5int_buf_add(&buf, " AF_UNSPEC");
- else
- krb5int_buf_add_fmt(&buf, " af%d", ai->ai_addr->sa_family);
- } else
- krb5int_buf_add_fmt(&buf, " %s:%s", addrbuf, portbuf);
+ if (cs->family == AF_UNSPEC)
+ krb5int_buf_add(&buf, " AF_UNSPEC");
+ else
+ krb5int_buf_add_fmt(&buf, " af%d", cs->family);
+ } else
+ krb5int_buf_add_fmt(&buf, " %s:%s", addrbuf, portbuf);
} else if (strcmp(tmpbuf, "data") == 0) {
d = va_arg(ap, krb5_data *);
if (d == NULL || (d->length != 0 && d->data == NULL))