From d0ebe1bcb2644b36740075afb058e0246361f764 Mon Sep 17 00:00:00 2001 From: Jilles Tjoelker Date: Sat, 21 Jun 2008 01:52:57 +0200 Subject: [PATCH] ident: obtain port numbers earlier and store them This eliminates two syscalls per ident lookup. It also removes a piece of code that depends on the port fields being in the same location for sockaddr_in and sockaddr_in6. --- src/s_auth.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/s_auth.c b/src/s_auth.c index 672cb6da..927c0d1d 100644 --- a/src/s_auth.c +++ b/src/s_auth.c @@ -58,6 +58,8 @@ struct AuthRequest unsigned int flags; /* current state of request */ rb_fde_t *F; /* file descriptor for auth queries */ time_t timeout; /* time when query expires */ + uint16_t lport; + uint16_t rport; }; /* @@ -344,19 +346,29 @@ start_auth_query(struct AuthRequest *auth) #ifdef RB_IPV6 if(localaddr.ss_family == AF_INET6) { + auth->lport = ntohs(((struct sockaddr_in6 *)&localaddr)->sin6_port); ((struct sockaddr_in6 *)&localaddr)->sin6_port = 0; - } else + } + else #endif - ((struct sockaddr_in *)&localaddr)->sin_port = 0; + { + auth->lport = ntohs(((struct sockaddr_in *)&localaddr)->sin_port); + ((struct sockaddr_in *)&localaddr)->sin_port = 0; + } destaddr = auth->client->localClient->ip; #ifdef RB_IPV6 if(localaddr.ss_family == AF_INET6) { + auth->rport = ntohs(((struct sockaddr_in6 *)&destaddr)->sin6_port); ((struct sockaddr_in6 *)&destaddr)->sin6_port = htons(113); - } else + } + else #endif - ((struct sockaddr_in *)&destaddr)->sin_port = htons(113); + { + auth->rport = ntohs(((struct sockaddr_in *)&destaddr)->sin_port); + ((struct sockaddr_in *)&destaddr)->sin_port = htons(113); + } auth->F = F; SetAuthConnect(auth); @@ -514,11 +526,7 @@ static void auth_connect_callback(rb_fde_t *F, int error, void *data) { struct AuthRequest *auth = data; - struct sockaddr_in us; - struct sockaddr_in them; char authbuf[32]; - socklen_t ulen = sizeof(struct sockaddr_in); - socklen_t tlen = sizeof(struct sockaddr_in); /* Check the error */ if(error != RB_OK) @@ -528,19 +536,8 @@ auth_connect_callback(rb_fde_t *F, int error, void *data) return; } - if(getsockname - (rb_get_fd(auth->client->localClient->F), (struct sockaddr *) &us, - (socklen_t *) & ulen) - || getpeername(rb_get_fd(auth->client->localClient->F), - (struct sockaddr *) &them, (socklen_t *) & tlen)) - { - ilog(L_IOERROR, "auth get{sock,peer}name error for %s:%m", - log_client_name(auth->client, SHOW_IP)); - auth_error(auth); - return; - } rb_snprintf(authbuf, sizeof(authbuf), "%u , %u\r\n", - (unsigned int) ntohs(them.sin_port), (unsigned int) ntohs(us.sin_port)); + auth->rport, auth->lport); if(write(rb_get_fd(auth->F), authbuf, strlen(authbuf)) == -1) {