[PATCH] getaddrinfo(): option to not sort IPv4 addresses
Aurelien Jarno
aurelien@aurel32.net
Thu Aug 16 21:24:00 GMT 2007
Hi,
Some people are unhappy about the way getaddrinfo() sorts IPv4 adresses,
even if it is strictly following rule 9 of the RFC 3484:
Rule 9: Use longest matching prefix.
When DA and DB belong to the same address family (both are IPv6 or
both are IPv4): If CommonPrefixLen(DA, Source(DA)) >
CommonPrefixLen(DB, Source(DB)), then prefer DA. Similarly, if
CommonPrefixLen(DA, Source(DA)) < CommonPrefixLen(DB, Source(DB)),
then prefer DB.
In Debian we have added a new option to /etc/gai.conf (disabled by
default) to ignore this rule for IPv4 addresses. Please find the patch
below in case you are also unhappy about this behaviour.
Regards,
Aurelien
2007-08-16 Aurelien Jarno <aurelien@aurel32.net>
* sysdeps/posix/getaddrinfo.c (gaiconf_reload_flag): Move
to the top of the file.
(gaiconf_mtime): Likewise.
(sortv4): New configuration variable.
(gaiconf_init): Parse the sortv4 option in the configuration
file.
(rfc3484_sort): Ignore rule 9 for IPv4 adresses if sortv4
is false.
* posix/gai.conf: Add the new sortv4 option.
--- posix/gai.conf 2007-08-16 22:59:03.000000000 +0200
+++ posix/gai.conf 2007-08-16 22:58:48.000000000 +0200
@@ -15,6 +15,11 @@
# changed and if necessary reload. This option should not really be
# used. There are possible runtime problems. The default is no.
#
+# sortv4 <yes|no>
+# If set to no, getaddrinfo(3) will ignore IPv4 adresses in rule 9. See
+# section 6 in RFC 3484. The default is yes. Setting this option to
+# no breaks conformance to RFC 3484.
+#
# label <mask> <value>
# Add another rule to the RFC 3484 label table. See section 2.1 in
# RFC 3484. The default is:
--- sysdeps/posix/getaddrinfo.c 2007-08-16 23:02:34.000000000 +0200
+++ sysdeps/posix/getaddrinfo.c 2007-08-16 22:31:53.000000000 +0200
@@ -79,6 +79,16 @@
# define UNIX_PATH_MAX 108
#endif
+/* Nozero if we are supposed to reload the config file automatically
+ whenever it changed. */
+static int gaiconf_reload_flag;
+
+/* Zero if we are supposed to ignore rule 9 for IPv4 addresses */
+static int gaiconf_sortv4_flag = 1;
+
+/* Last modification time. */
+static struct timespec gaiconf_mtime;
+
struct gaih_service
{
const char *name;
@@ -1344,7 +1354,7 @@
int bit1 = 0;
int bit2 = 0;
- if (a1->dest_addr->ai_family == PF_INET)
+ if (a1->dest_addr->ai_family == PF_INET && gaiconf_sortv4_flag)
{
assert (a1->source_addr.ss_family == PF_INET);
assert (a2->source_addr.ss_family == PF_INET);
@@ -1422,14 +1432,6 @@
#define GAICONF_FNAME "/etc/gai.conf"
-/* Nozero if we are supposed to reload the config file automatically
- whenever it changed. */
-static int gaiconf_reload_flag;
-
-/* Last modification time. */
-static struct timespec gaiconf_mtime;
-
-
libc_freeres_fn(fini)
{
if (labels != default_labels)
@@ -1608,6 +1610,8 @@
case 6:
if (strcmp (cmd, "reload") == 0)
gaiconf_reload_flag = strcmp (val1, "yes") == 0;
+ else if (strcmp (cmd, "sortv4") == 0)
+ gaiconf_sortv4_flag = strcmp (val1, "no") != 0;
break;
case 10:
--
.''`. Aurelien Jarno | GPG: 1024D/F1BCDB73
: :' : Debian developer | Electrical Engineer
`. `' aurel32@debian.org | aurelien@aurel32.net
`- people.debian.org/~aurel32 | www.aurel32.net
More information about the Libc-alpha
mailing list