Revision: 14772
Author: adrian.chadd
Date: Tue Aug 31 18:24:09 2010
Log: A very, very dirty conversion of the http_port address type to be ipv6-ready;
even if the rest of the codebase won't be.

This hasn't even yet been tested!


http://code.google.com/p/lusca-cache/source/detail?r=14772

Modified:
 /playpen/LUSCA_HEAD_ipv6/src/cache_cf.c
 /playpen/LUSCA_HEAD_ipv6/src/client_side.c
 /playpen/LUSCA_HEAD_ipv6/src/forward.c
 /playpen/LUSCA_HEAD_ipv6/src/neighbors.c
 /playpen/LUSCA_HEAD_ipv6/src/structs.h
 /playpen/LUSCA_HEAD_ipv6/src/tools.c

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/cache_cf.c     Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/cache_cf.c     Tue Aug 31 18:24:09 2010
@@ -2964,9 +2964,13 @@
 parse_http_port_specification(http_port_list * s, char *token)
 {
     char *host = NULL;
+#if NOTYET
     const struct hostent *hp;
+#endif
     unsigned short port = 0;
     char *t;
+
+    sqinet_init(&s->ss);
     s->name = xstrdup(token);
     if ((t = strchr(token, ':'))) {
        /* host:port */
@@ -2979,17 +2983,22 @@
     }
     if (port == 0)
        self_destruct();
-    s->s.sin_port = htons(port);
-    if (NULL == host)
-       SetAnyAddr(&s->s.sin_addr);
-    else if (1 == safe_inet_addr(host, &s->s.sin_addr))
+ if (NULL == host) { /* Default this to v4 for now, preserves behaviour */
+       sqinet_set_family(&s->ss, AF_INET);
+       sqinet_set_anyaddr(&s->ss);
+    } else if (1 == sqinet_aton(&s->ss, host, SQATON_PASSIVE)) {
        (void) 0;
-    else if ((hp = gethostbyname(host))) {
+#warning This needs to be ipv6-ified
+#if NOTYET             /* This should be eventually added back -adrian */
+    } else if ((hp = gethostbyname(host))) {
        /* dont use ipcache */
        s->s.sin_addr = inaddrFromHostent(hp);
        s->defaultsite = xstrdup(host);
+#endif
     } else
        self_destruct();
+
+    sqinet_set_port(&s->ss, port, SQADDR_NONE);
 }

 static void
@@ -3103,10 +3112,13 @@
 static void
dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s)
 {
+    char cbuf[MAX_IPSTRLEN];
+
+    (void) sqinet_ntoa(&s->ss, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
     storeAppendPrintf(e, "%s %s:%d",
        n,
-       inet_ntoa(s->s.sin_addr),
-       ntohs(s->s.sin_port));
+        cbuf,
+       sqinet_get_port(&s->ss));
     if (s->transparent)
        storeAppendPrintf(e, " transparent");
     if (s->accel)
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side.c  Tue Aug 31 09:02:21 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/client_side.c  Tue Aug 31 18:24:09 2010
@@ -2908,6 +2908,8 @@
     http_port_list *s;
     int fd;
     int comm_flags;
+    char cbuf[MAX_IPSTRLEN];
+
     for (s = Config.Sockaddr.http; s; s = s->next) {
        comm_flags = COMM_NONBLOCKING;
        if (s->tproxy)
@@ -2927,19 +2929,13 @@
            comm_fdopen(fd,
                SOCK_STREAM,
                no_addr,
-               ntohs(s->s.sin_port),
+               sqinet_get_port(&s->ss),
                comm_flags,
                COMM_TOS_DEFAULT,
                "HTTP Socket");
        } else {
            enter_suid();
-           fd = comm_open(SOCK_STREAM,
-               IPPROTO_TCP,
-               s->s.sin_addr,
-               ntohs(s->s.sin_port),
-               comm_flags,
-               COMM_TOS_DEFAULT,
-               "HTTP Socket");
+ fd = comm_open6(SOCK_STREAM, IPPROTO_TCP, &s->ss, comm_flags, COMM_TOS_DEFAULT, "HTTP Socket");
            leave_suid();
        }
        if (fd < 0)
@@ -2951,13 +2947,14 @@
         * peg the CPU with select() when we hit the FD limit.
         */
        commSetDefer(fd, httpAcceptDefer, NULL);
+       (void) sqinet_ntoa(&s->ss, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
        debug(1, 1) ("Accepting %s %sHTTP connections at %s, port %d, FD %d.\n",
            s->transparent ? "transparently proxied" :
            s->accel ? "accelerated" :
            "proxy",
            s->tproxy ? "and tproxy'ied " : "",
-           inet_ntoa(s->s.sin_addr),
-           (int) ntohs(s->s.sin_port),
+           cbuf,
+           sqinet_get_port(&s->ss),
            fd);
        HttpSockets[NHttpSockets++] = fd;
     }
@@ -2969,6 +2966,7 @@
 {
     https_port_list *s;
     int fd;
+    char cbuf[MAX_IPSTRLEN];
for (s = Config.Sockaddr.https; s; s = (https_port_list *) s->http.next) {
        if (MAXHTTPPORTS == NHttpSockets) {
            debug(1, 1) ("WARNING: You have too many 'https_port' lines.\n");
@@ -2978,22 +2976,17 @@
        if (!s->sslContext)
            continue;
        enter_suid();
-       fd = comm_open(SOCK_STREAM,
-           IPPROTO_TCP,
-           s->http.s.sin_addr,
-           ntohs(s->http.s.sin_port),
-           COMM_NONBLOCKING,
-           COMM_TOS_DEFAULT,
-           "HTTPS Socket");
+ fd = comm_open6(SOCK_STREAM, IPPROTO_TCP, &s->http.ss, comm_flags, COMM_TOS_DEFAULT, "HTTPS Socket");
        leave_suid();
        if (fd < 0)
            continue;
        comm_listen(fd);
        commSetSelect(fd, COMM_SELECT_READ, httpsAccept, s, 0);
        commSetDefer(fd, httpAcceptDefer, NULL);
+       (void) sqinet_ntoa(&s->ss, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
        debug(1, 1) ("Accepting HTTPS connections at %s, port %d, FD %d.\n",
-           inet_ntoa(s->http.s.sin_addr),
-           (int) ntohs(s->http.s.sin_port),
+           cbuf,
+           sqinet_get_port(&s->http.ss),
            fd);
        HttpSockets[NHttpSockets++] = fd;
     }
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/forward.c      Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/forward.c      Tue Aug 31 18:24:09 2010
@@ -625,6 +625,7 @@
     if (fs->peer && fs->peer->options.no_tproxy)
        do_tproxy = 0;
     if (fd == -1 && fwdState->request->flags.tproxy && do_tproxy)
+ /* Why is the client_port 0? Make sure you maintain this when you convert it to ipv6 -adrian */ fd = pconnPop(name, port, domain, &fwdState->request->client_addr, 0, NULL);
     if (fd == -1) {
        fd = pconnPop(name, port, domain, NULL, 0, &idle);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/neighbors.c    Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/neighbors.c    Tue Aug 31 18:24:09 2010
@@ -394,7 +394,7 @@
            if (0 != strcmp(this->host, me))
                continue;
            for (s = Config.Sockaddr.http; s; s = s->next) {
-               if (this->http_port != ntohs(s->s.sin_port))
+               if (this->http_port != sqinet_get_port(&s->ss))
                    continue;
                debug(15, 1) ("WARNING: Peer looks like this host\n");
                debug(15, 1) ("         Ignoring %s %s/%d/%d\n",
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/structs.h      Tue Aug 31 09:02:21 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/structs.h      Tue Aug 31 18:24:09 2010
@@ -336,7 +336,7 @@

 struct _http_port_list {
     http_port_list *next;
-    struct sockaddr_in s;
+    sqaddr_t ss;
     char *protocol;            /* protocol name */
     char *name;                        /* visible name */
     char *defaultsite;         /* default web site */
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/tools.c        Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/tools.c        Tue Aug 31 18:24:09 2010
@@ -491,13 +491,19 @@
 {
     LOCAL_ARRAY(char, host, SQUIDHOSTNAMELEN + 1);
     static int present = 0;
+#if NOTYET
     const struct hostent *h = NULL;
     struct in_addr sa;
+#endif
     if (Config.visibleHostname != NULL)
        return Config.visibleHostname;
     if (present)
        return host;
     host[0] = '\0';
+
+ /* This all needs to be rewritten for IPv6-ness once the dust settles -adrian */
+#warning This needs to be IPv6-ified
+#if NOTYET
     SetAnyAddr(&sa);
     if (Config.Sockaddr.http && IsAnyAddr(&sa))
        memcpy(&sa, &Config.Sockaddr.http->s.sin_addr, sizeof(sa));
@@ -544,6 +550,7 @@
        if (strchr(host, '.'))
            return host;
     }
+#endif
     if (opt_send_signal == -1)
debug(50, 1) ("Could not determine fully qualified hostname. Please set 'visible_hostname'\n");
     if (host[0])
@@ -1079,10 +1086,10 @@
 getMyPort(void)
 {
     if (Config.Sockaddr.http)
-       return ntohs(Config.Sockaddr.http->s.sin_port);
+       return sqinet_get_port(&Config.Sockaddr.http->ss);
 #if USE_SSL
     if (Config.Sockaddr.https)
-       return ntohs(Config.Sockaddr.https->http.s.sin_port);
+       return sqinet_get_port(&Config.Sockaddr.https->http.ss);
 #endif
     fatal("No port defined");
     return 0;                  /* NOT REACHED */

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to