summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2006-03-01 16:13:17 +0000
committerume <ume@FreeBSD.org>2006-03-01 16:13:17 +0000
commit2fdbdd84364d5006b597554bbf41641f9a039ec5 (patch)
tree853f3a8a696916e0360c075cd8937d8d349623b3 /libexec
parent5e1521cce366a7a6191c532554259f6f85a9abfa (diff)
downloadFreeBSD-src-2fdbdd84364d5006b597554bbf41641f9a039ec5.zip
FreeBSD-src-2fdbdd84364d5006b597554bbf41641f9a039ec5.tar.gz
- Reduce needless DNS query by lookup only appropriate address
family. [1] - Specify appropriate hints to getaddrinfo(3). [1] - Obtain address family from peername in inet mode. Submitted by: Rostislav Krasny <rosti.bsd__at__gmail.com> [1] Tested by: yar, Rostislav Krasny <rosti.bsd__at__gmail.com> MFC after: 1 week
Diffstat (limited to 'libexec')
-rw-r--r--libexec/ftpd/ftpd.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/libexec/ftpd/ftpd.c b/libexec/ftpd/ftpd.c
index 60779b4..f331a47 100644
--- a/libexec/ftpd/ftpd.c
+++ b/libexec/ftpd/ftpd.c
@@ -239,7 +239,7 @@ static int transflag; /* NB: for debugging only */
}
#ifdef VIRTUAL_HOSTING
-static void inithosts(void);
+static void inithosts(int);
static void selecthost(union sockunion *);
#endif
static void ack(char *);
@@ -423,10 +423,6 @@ main(int argc, char *argv[], char **envp)
}
}
-#ifdef VIRTUAL_HOSTING
- inithosts();
-#endif
-
if (daemon_mode) {
int *ctl_sock, fd, maxfd = -1, nfds, i;
fd_set defreadfds, readfds;
@@ -456,6 +452,10 @@ main(int argc, char *argv[], char **envp)
sa.sa_handler = reapchild;
(void)sigaction(SIGCHLD, &sa, NULL);
+#ifdef VIRTUAL_HOSTING
+ inithosts(family);
+#endif
+
/*
* Open a socket, bind it to the FTP port, and start
* listening.
@@ -525,6 +525,15 @@ main(int argc, char *argv[], char **envp)
syslog(LOG_ERR, "getpeername (%s): %m",argv[0]);
exit(1);
}
+
+#ifdef VIRTUAL_HOSTING
+ if (his_addr.su_family == AF_INET6 &&
+ IN6_IS_ADDR_V4MAPPED(&his_addr.su_sin6.sin6_addr))
+ family = AF_INET;
+ else
+ family = his_addr.su_family;
+ inithosts(family);
+#endif
}
gotchild:
@@ -663,7 +672,7 @@ sigquit(int signo)
*/
static void
-inithosts(void)
+inithosts(int family)
{
int insert;
size_t len;
@@ -688,8 +697,9 @@ inithosts(void)
hrp->hostinfo = NULL;
memset(&hints, 0, sizeof(hints));
- hints.ai_flags = AI_CANONNAME;
- hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = family;
+ hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(hrp->hostname, NULL, &hints, &res) == 0)
hrp->hostinfo = res;
hrp->statfile = _PATH_FTPDSTATFILE;
@@ -759,9 +769,9 @@ inithosts(void)
/* NOTREACHED */
}
- hints.ai_flags = 0;
- hints.ai_family = AF_UNSPEC;
hints.ai_flags = AI_PASSIVE;
+ hints.ai_family = family;
+ hints.ai_socktype = SOCK_STREAM;
if (getaddrinfo(vhost, NULL, &hints, &res) != 0)
goto nextline;
for (ai = res; ai != NULL && ai->ai_addr != NULL;
OpenPOWER on IntegriCloud