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

Bug#442157: getaddrinfo() does not prefer IPv6 address over IPv4 one



Package: libc6
Version: 2.3.6.ds1-13
Severity: important

getaddrinfo() does not prefer IPv6 addresses, even though it should
according to RFC 3484.  I have debugged the issue and it all boils down
to match_prefix() in sysdeps/posix/getaddrinfo.c.  The prefix test runs
like this:

      while (bits > 8)
        {
          if (*mask != *val)
            break;

          ++mask;
	  ++val;
	  bits -= 8;
	}

      if (bits < 8)
        {
          if ((*mask & (0xff00 >> bits)) == (*val & (0xff00 >> bits)))
            /* Match!  */
	    break;
	}

Of course, for prefix lengths which are a multiple of 8 the loop ends
prematurely and the subsequent test returns 8, so there is never a match
for these lengths. Since the prefix for IPv4 addresses is 96 bits long
(see default_precedence), IPv4 addresses get the default priority (40)
and not the correct one (10). I was able to fix this by changing the
condition to:

      while (bits >= 8)

Since match_prefix() is used for labels as well, this bug probably also
breaks RFC 3484 rule 5 (Prefer matching label).

-- System Information:
Debian Release: 4.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.20.3
Locale: LANG=cs_CZ.UTF-8, LC_CTYPE=cs_CZ.UTF-8 (charmap=UTF-8)

Versions of packages libc6 depends on:
ii  tzdata                        2007b-1    Time Zone and Daylight Saving Time

libc6 recommends no packages.

-- no debconf information





Reply to: