From 4b01f04f286ab99a26e81be53e43f8bf46f9496d Mon Sep 17 00:00:00 2001 From: pyr <> Date: Thu, 4 Jun 2009 18:06:35 +0000 Subject: Add a resolv.conf option to specify the order in which getaddrinfo PF_UNSPEC queries are made. While there change the default from inet6 first then inet4 to inet4 first then inet6, this prevents the many people with IPv4 only connectivity from constantly trying to contact IPv6 addresses, and also unbreaks many ports who don't use getaddrinfo right. ok deraadt@, plenty of cheering in the room wrt the idea, not loud enough complaining from the v6 crowd. --- src/lib/libc/net/res_init.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/lib/libc/net/res_init.c') diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c index 42d3b3ca1e..5cb597dad8 100644 --- a/src/lib/libc/net/res_init.c +++ b/src/lib/libc/net/res_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: res_init.c,v 1.37 2008/08/15 14:57:20 djm Exp $ */ +/* $OpenBSD: res_init.c,v 1.38 2009/06/04 18:06:35 pyr Exp $ */ /* * ++Copyright++ 1985, 1989, 1993 @@ -165,6 +165,7 @@ _res_init(int usercall) FILE *fp; char *cp, **pp; int n; + int findex; char buf[BUFSIZ]; int nserv = 0; /* number of nameserver records read from file */ int haveenv = 0; @@ -296,6 +297,33 @@ _res_init(int usercall) *cp = '\0'; if (buf[0] == '\0') continue; + /* set family lookup order */ + if (MATCH(buf, "family")) { + cp = buf + sizeof("family") - 1; + cp += strspn(cp, " \t"); + cp[strcspn(cp, "\n")] = '\0'; + findex = 0; + _resp->family[0] = _resp->family[1] = -1; + while (*cp != '\0' && findex < 2) { + if (!strncmp(cp, "inet6", strlen("inet6"))) { + _resp->family[findex] = AF_INET6; + cp += strlen("inet6"); + } else if (!strncmp(cp, "inet4", + strlen("inet4"))) { + _resp->family[findex] = AF_INET; + cp += strlen("inet4"); + } + if (*cp != ' ' && *cp != '\t' && *cp != '\0') { + _resp->family[findex] = -1; + break; + } + findex++; + cp += strspn(cp, " \t"); + } + + if (_resp->family[0] == _resp->family[1]) + _resp->family[1] = -1; + } /* read default domain name */ if (MATCH(buf, "domain")) { if (haveenv) /* skip if have from environ */ -- cgit v1.2.3-55-g6feb