[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Mass ipv6 lookups




On Sat, 28 Sep 2002, Herbert Xu wrote:

>
> See http://bugs.debian.org/158036 for a possible solution.
>

Here is a possible fix if someone fell brave enough to test it.
I know that it compiles but i don't have an ipv4 only box where to test.

In bug #158036 it is suggested to cache a socket(2) call but IMHO it
cannot be done for different reasons. First of all ipv6 can be loaded as
module at any time and the cache should be refreshed and handling the
cache can be more painfull than a realtime check. The other solution of
having an option in /etc/resolv.conf (quite nice BTW) requires more code
but it can take much more resources at execution time since it needs to be
dynamic and requires a strong error handling code.

the patch below is in dpatch format used in the libc6 pkg. and it is just
a preliminary test to see if this approch works or not and some of the
comments are useless (just that i love to write stuff while i think ;) ).

The basic idea is to check if AF_INET6 is valid or not in the local
system. If it is not than the af_family is set to AF_INET.
I will deal to spend some time to implement a better error check code in
case this solution solves the problem.

Ofcourse this is just my view of the problem so comments are more than
welcome.. as usual flames & co > /dev/null since my C writing experience
is still far to be good.

Thanks
Fabio

#! /bin/sh -e

# All lines beginning with `# DP:' are a description of the patch.
# DP: bad hack that should avoid uncessary AAAA queries when host is ipv4 only

if [ $# -ne 2 ]; then
    echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
    exit 1
fi
case "$1" in
    -patch) patch -d "$2" -f --no-backup-if-mismatch -p1 < $0;;
    -unpatch) patch -d "$2" -f --no-backup-if-mismatch -R -p1 < $0;;
    *)
	echo >&2 "`basename $0`: script expects -patch|-unpatch as argument"
	exit 1
esac
exit 0

diff -Naurd glibc-2.2.5.ORG/sysdeps/posix/getaddrinfo.c glibc-2.2.5/sysdeps/posix/getaddrinfo.c
--- glibc-2.2.5.ORG/sysdeps/posix/getaddrinfo.c	2002-09-28 05:34:42.000000000 +0000
+++ glibc-2.2.5/sysdeps/posix/getaddrinfo.c	2002-09-28 06:48:31.000000000 +0000
@@ -741,7 +741,7 @@
 getaddrinfo (const char *name, const char *service,
 	     const struct addrinfo *hints, struct addrinfo **pai)
 {
-  int i = 0, j = 0, last_i = 0;
+  int i = 0, j = 0, last_i = 0, tmpsock = 0;
   struct addrinfo *p = NULL, **end;
   struct gaih *g = gaih, *pg = NULL;
   struct gaih_service gaih_service, *pservice;
@@ -758,6 +758,27 @@
   if (hints == NULL)
     hints = &default_hints;

+/* sanity ?? check for AF_INET AF_INET6 AF_UNSPEC
+   if i can open an ipv6 socket locally then hints->ai_family
+   can be everything otherwise only AF_INET
+   but isn't a bit overkilling do it every time????
+   i don't have a clue where it can be called once and cached
+   and as far as i can see this kind of code can be object of
+   local DoS filling up too quickly the socket list.
+   Another point is that i don't check the reason why i can't open
+   the sock. I just assume that if i can't open there is no ipv6 */
+
+  if (hints->ai_family == AF_UNSPEC || hints->ai_family == AF_INET6)
+    {
+      tmpsock = socket(PF_INET6,SOCK_DGRAM,0);
+      if (tmpsock == -1)
+	{
+	   hints->ai_family = AF_INET;
+	}
+      else
+	close(tmpsock);
+    }
+
   if (hints->ai_flags & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST))
     return EAI_BADFLAGS;




Reply to: