Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/net IPv6 DNS transport support for resolver.



details:   https://anonhg.NetBSD.org/src/rev/a82b9d9b91a9
branches:  trunk
changeset: 474207:a82b9d9b91a9
user:      itojun <itojun%NetBSD.org@localhost>
date:      Thu Jul 01 18:19:35 1999 +0000

description:
IPv6 DNS transport support for resolver.
Now you can write
        nameserver 3ffe:0501:4819::42
in /etc/resolv.conf for DNS query over IPv6 network.
(the above address is alive as DNS server)

diffstat:

 lib/libc/net/res_init.c |  111 +++++++++++++++++++++++++++++++++++++++++++-
 lib/libc/net/res_send.c |  118 +++++++++++++++++++++++++++++++++++++----------
 2 files changed, 199 insertions(+), 30 deletions(-)

diffs (truncated from 466 to 300 lines):

diff -r 91d90dc71655 -r a82b9d9b91a9 lib/libc/net/res_init.c
--- a/lib/libc/net/res_init.c   Thu Jul 01 18:18:27 1999 +0000
+++ b/lib/libc/net/res_init.c   Thu Jul 01 18:19:35 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: res_init.c,v 1.23 1999/01/16 07:48:24 lukem Exp $      */
+/*     $NetBSD: res_init.c,v 1.24 1999/07/01 18:19:35 itojun Exp $     */
 
 /*-
  * Copyright (c) 1985, 1989, 1993
@@ -59,7 +59,7 @@
 static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
 static char rcsid[] = "Id: res_init.c,v 8.8 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: res_init.c,v 1.23 1999/01/16 07:48:24 lukem Exp $");
+__RCSID("$NetBSD: res_init.c,v 1.24 1999/07/01 18:19:35 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -78,6 +78,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <netdb.h>
 
 #if defined(_LIBC) && defined(__weak_alias)
 __weak_alias(res_init,_res_init);
@@ -98,6 +99,9 @@
        RES_DEFAULT,                    /* options flags */
        1,                              /* number of name servers */
 };
+#ifdef INET6
+struct __res_state_ext _res_ext;
+#endif /* INET6 */
 
 /*
  * Set up default settings.  If the configuration file exist, the values
@@ -134,8 +138,27 @@
 #ifdef SEARCH_LOCAL_DOMAINS
        int dots;
 #endif
+#ifdef INET6
+       struct sockaddr_in6 *sin6;
+       struct addrinfo *ai;
+       static char nsport[32];
+       struct addrinfo hints;
+#endif
 
        _res.id = res_randomid();
+#ifdef INET6
+       if (nsport[0] == '\0')
+               sprintf(nsport, "%u", NAMESERVER_PORT);
+       sin6 = (struct sockaddr_in6 *)&_res_ext.nsaddr;
+       sin6->sin6_len = sizeof(struct sockaddr_in6);
+       sin6->sin6_family = AF_INET6;
+       sin6->sin6_port = htons(NAMESERVER_PORT);
+#ifdef USELOOPBACK
+       sin6->sin6_addr = in6addr_loopback;
+#else
+       sin6->sin6_addr = in6addr_any;
+#endif
+#endif
        _res.nsaddr.sin_len = sizeof(struct sockaddr_in);
        _res.nsaddr.sin_family = AF_INET;
        _res.nsaddr.sin_port = htons(NAMESERVER_PORT);
@@ -253,11 +276,37 @@
                }
                /* read nameservers to query */
                if (MATCH(buf, "nameserver") && nserv < MAXNS) {
-                  struct in_addr a;
+#ifdef INET6
+                   char *q;
+#else /* INET6 */
+                   struct in_addr a;
+#endif /* INET6 */
 
                    cp = buf + sizeof("nameserver") - 1;
                    while (*cp == ' ' || *cp == '\t')
                        cp++;
+#ifdef INET6
+                   if ((*cp == '\0') || (*cp == '\n'))
+                       continue;
+                   for (q = cp; *q; q++) {
+                       if (isspace(*q)) {
+                           *q = '\0';
+                           break;
+                       }
+                   }
+                   memset(&hints, 0, sizeof(hints));
+                   hints.ai_flags = AI_NUMERICHOST;
+                   if (getaddrinfo(cp, nsport, &hints, &ai) == 0) {
+                       memcpy(&_res_ext.nsaddr_list[nserv],
+                               ai->ai_addr, ai->ai_addrlen);
+                       /* for compatibility */
+                       if (ai->ai_family == AF_INET)
+                           memcpy(&_res.nsaddr_list[nserv],
+                                   ai->ai_addr, ai->ai_addrlen);
+                       nserv++;
+                       freeaddrinfo(ai);
+                   }
+#else /* INET6 */
                    if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
                        _res.nsaddr_list[nserv].sin_len = sizeof(struct sockaddr_in);
                        _res.nsaddr_list[nserv].sin_family = AF_INET;
@@ -266,10 +315,16 @@
                        _res.nsaddr_list[nserv].sin_addr = a;
                        nserv++;
                    }
+#endif /* INET6 */
                    continue;
                }
                if (MATCH(buf, "sortlist")) {
                    struct in_addr a;
+#ifdef INET6
+                   struct in6_addr a6;
+                   int m, i;
+                   u_char *u;
+#endif /* INET6 */
 
                    cp = buf + sizeof("sortlist") - 1;
                    while (nsort < MAXRESOLVSORT) {
@@ -303,8 +358,58 @@
                                _res.sort_list[nsort].mask = 
                                    net_mask(_res.sort_list[nsort].addr);
                            }
+#ifdef INET6
+                           _res_ext.sort_list[nsort].af = AF_INET;
+                           _res_ext.sort_list[nsort].addr.ina =
+                               _res.sort_list[nsort].addr;
+                           _res_ext.sort_list[nsort].mask.ina.s_addr =
+                               _res.sort_list[nsort].mask;
+#endif /* INET6 */
                            nsort++;
                        }
+#ifdef INET6
+                       else if (inet_pton(AF_INET6, net, &a6) == 1) {
+                           _res_ext.sort_list[nsort].af = AF_INET6;
+                           _res_ext.sort_list[nsort].addr.in6a = a6;
+                           u = (u_char *)&_res_ext.sort_list[nsort].mask.in6a;
+                           *cp++ = n;
+                           net = cp;
+                           while (*cp && *cp != ';' &&
+                                   isascii(*cp) && !isspace(*cp))
+                               cp++;
+                           m = n;
+                           n = *cp;
+                           *cp = 0;
+                           switch (m) {
+                           case '/':
+                               m = atoi(net);
+                               break;
+                           case '&':
+                               if (inet_pton(AF_INET6, net, u) == 1) {
+                                   m = -1;
+                                   break;
+                               }
+                               /*FALLTHRU*/
+                           default:
+                               m = sizeof(struct in6_addr) * NBBY;
+                               break;
+                           }
+                           if (m >= 0) {
+                               for (i = 0; i < sizeof(struct in6_addr); i++) {
+                                   if (m <= 0) {
+                                       *u = 0;
+                                   } else {
+                                       m -= NBBY;
+                                       *u = (u_char)~0;
+                                       if (m < 0)
+                                           *u <<= -m;
+                                   }
+                                   u++;
+                               }
+                           }
+                           nsort++;
+                       }
+#endif /* INET6 */
                        *cp = n;
                    }
                    continue;
diff -r 91d90dc71655 -r a82b9d9b91a9 lib/libc/net/res_send.c
--- a/lib/libc/net/res_send.c   Thu Jul 01 18:18:27 1999 +0000
+++ b/lib/libc/net/res_send.c   Thu Jul 01 18:19:35 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: res_send.c,v 1.17 1999/05/03 15:26:12 christos Exp $   */
+/*     $NetBSD: res_send.c,v 1.18 1999/07/01 18:19:35 itojun Exp $     */
 
 /*-
  * Copyright (c) 1985, 1989, 1993
@@ -59,7 +59,7 @@
 static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: res_send.c,v 1.17 1999/05/03 15:26:12 christos Exp $");
+__RCSID("$NetBSD: res_send.c,v 1.18 1999/07/01 18:19:35 itojun Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -106,6 +106,7 @@
 static int s = -1;     /* socket used for communications */
 static int connected = 0;      /* is the socket connected */
 static int vc = 0;     /* is the socket a virtual ciruit? */
+static int af = 0;     /* address family of socket */
 
 #define CAN_RECONNECT 1
 
@@ -120,7 +121,9 @@
                        fprintf args;\
                        __fp_nquery(query, size, stdout);\
                } else {}
-    static void Aerror __P((FILE *, char *, int, struct sockaddr_in));
+    static char abuf[INET6_ADDRSTRLEN];
+    static char pbuf[32];
+    static void Aerror __P((FILE *, char *, int, struct sockaddr *));
     static void Perror __P((FILE *, char *, int));
 
     static void
@@ -128,16 +131,15 @@
        FILE *file;
        char *string;
        int error;
-       struct sockaddr_in address;
+       struct sockaddr *address;
     {
        int save = errno;
 
        if (_res.options & RES_DEBUG) {
-               fprintf(file, "res_send: %s ([%s].%u): %s\n",
-                       string,
-                       inet_ntoa(address.sin_addr),
-                       ntohs(address.sin_port),
-                       strerror(error));
+               getnameinfo(address, address->sa_len, abuf, sizeof(abuf),
+                           pbuf, sizeof(pbuf), NI_NUMERICHOST|NI_NUMERICSERV);
+               fprintf(file, "res_send: %s ([%s].%s): %s\n",
+                       string, abuf, pbuf, strerror(error));
        }
        errno = save;
     }
@@ -192,9 +194,46 @@
 res_isourserver(inp)
        const struct sockaddr_in *inp;
 {
+#ifdef INET6
+       struct sockaddr_in6 *in6p = (struct sockaddr_in6 *)inp;
+       const struct sockaddr_in6 *srv6;
+       const struct sockaddr_in *srv;
+#else /* INET6 */
        struct sockaddr_in ina;
+#endif /* INET6 */
        register int ns, ret;
 
+#ifdef INET6
+       ret = 0;
+       switch (inp->sin_family) {
+       case AF_INET6:
+               for (ns = 0; ns < _res.nscount; ns++) {
+                       srv6 = (struct sockaddr_in6 *)&_res_ext.nsaddr_list[ns];
+                       if (srv6->sin6_family == in6p->sin6_family &&
+                           srv6->sin6_port == in6p->sin6_port &&
+                           (memcmp(&srv6->sin6_addr, &in6addr_any,
+                                   sizeof(struct in6_addr)) == 0 ||
+                            memcmp(&srv6->sin6_addr, &in6p->sin6_addr,
+                                   sizeof(struct in6_addr)) == 0)) {
+                               ret++;
+                               break;
+                       }
+               }
+               break;
+       case AF_INET:
+               for (ns = 0; ns < _res.nscount; ns++) {
+                       srv = (struct sockaddr_in *)&_res_ext.nsaddr_list[ns];
+                       if (srv->sin_family == inp->sin_family &&
+                           srv->sin_port == inp->sin_port &&
+                           (srv->sin_addr.s_addr == INADDR_ANY ||
+                            srv->sin_addr.s_addr == inp->sin_addr.s_addr)) {
+                               ret++;
+                               break;
+                       }
+               }
+               break;
+       }
+#else /* INET6 */
        ina = *inp;
        ret = 0;
        for (ns = 0;  ns < _res.nscount;  ns++) {
@@ -208,6 +247,7 @@
                        break;
                }
        }
+#endif /* INET6 */
        return (ret);
 }
 
@@ -315,7 +355,13 @@
         */
        for (try = 0; try < _res.retry; try++) {
            for (ns = 0; ns < _res.nscount; ns++) {
-               struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
+#ifdef INET6
+               struct sockaddr *nsap = (struct sockaddr *)



Home | Main Index | Thread Index | Old Index