Revision: 14784
Author: adrian.chadd
Date: Mon Sep  6 09:06:16 2010
Log: Migrate request_t->my_addr / my_port to IPv6 aware types.

Squid/Lusca sets my_addr to "NoAddr" when request_t is created.
This new code leaves it unassigned so any access to it will error.
It must be set somewhere (eg by parsing a client request.)

The forward.c transparent code path uses request_t->my_addr
as a destination address for outbound connections if a DNS lookup
on the client-provided URL fails. This codepath is currently
IPv4-only. Which is fine; the forward code is not going to be made
IPv6-aware in this pass.


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

Modified:
 /playpen/LUSCA_HEAD_ipv6/src/HttpRequest.c
 /playpen/LUSCA_HEAD_ipv6/src/access_log.c
 /playpen/LUSCA_HEAD_ipv6/src/acl.c
 /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c
 /playpen/LUSCA_HEAD_ipv6/src/client_side_rewrite.c
 /playpen/LUSCA_HEAD_ipv6/src/external_acl.c
 /playpen/LUSCA_HEAD_ipv6/src/forward.c
 /playpen/LUSCA_HEAD_ipv6/src/redirect.c
 /playpen/LUSCA_HEAD_ipv6/src/store_rewrite.c
 /playpen/LUSCA_HEAD_ipv6/src/structs.h

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/HttpRequest.c  Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/HttpRequest.c  Mon Sep  6 09:06:16 2010
@@ -59,7 +59,8 @@
     req->lastmod = -1;
     SetAnyAddr(&req->out_ip);
     SetNoAddr(&req->client_addr);
-    SetNoAddr(&req->my_addr);
+    sqinet_init(&req->my_address);
+//    SetNoAddr(&req->my_addr);
     httpHeaderInit(&req->header, hoRequest);
     return req;
 }
@@ -80,6 +81,7 @@
     safe_free(req->urlgroup);
     safe_free(req->extacl_user);
     safe_free(req->extacl_passwd);
+    sqinet_done(&req->my_address);
     stringClean(&req->urlpath);
     httpHeaderClean(&req->header);
     if (req->cache_control)
@@ -141,10 +143,13 @@
 void
 httpRequestPackDebug(request_t * req, Packer * p)
 {
+    LOCAL_ARRAY(char, cbuf, MAX_IPSTRLEN);
+
     assert(req && p);
     /* Client info */
+    (void) sqinet_ntoa(&req->my_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
     packerPrintf(p, "Client: %s ", inet_ntoa(req->client_addr));
- packerPrintf(p, "http_port: %s:%d", inet_ntoa(req->my_addr), req->my_port); + packerPrintf(p, "http_port: %s:%d", cbuf, sqinet_get_port(&req->my_address)); if (req->auth_user_request && authenticateUserRequestUsername(req->auth_user_request)) packerPrintf(p, "user: %s", authenticateUserRequestUsername(req->auth_user_request));
     packerPrintf(p, "\n");
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/access_log.c   Sat Sep  4 06:11:36 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/access_log.c   Mon Sep  6 09:06:16 2010
@@ -506,13 +506,15 @@
            /* case LFT_SERVER_PORT: */

        case LFT_LOCAL_IP:
-           if (al->request)
-               out = inet_ntoa(al->request->my_addr);
+           if (al->request) {
+ (void) sqinet_ntoa(&al->request->my_address, cbuf, sizeof(cbuf), SQADDR_NONE);
+               out = cbuf;
+           }
            break;

        case LFT_LOCAL_PORT:
            if (al->request) {
-               outint = al->request->my_port;
+               outint = sqinet_get_port(&al->request->my_address);
                doint = 1;
            }
            break;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/acl.c  Sat Sep  4 07:04:25 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/acl.c  Mon Sep  6 09:06:16 2010
@@ -2676,7 +2676,7 @@
        } else
 #endif /* FOLLOW_X_FORWARDED_FOR */
            checklist->src_addr = request->client_addr;
-        sqinet_set_v4_inaddr(&checklist->my_address, &request->my_addr);
+        sqinet_copy(&checklist->my_address, &request->my_address);
sqinet_set_port(&checklist->my_address, request->my_port, SQADDR_ASSERT_IS_V4);
 #if 0 && USE_IDENT
        /*
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c Mon Jul 12 01:10:06 2010 +++ /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c Mon Sep 6 09:06:16 2010
@@ -563,8 +563,7 @@
 #if FOLLOW_X_FORWARDED_FOR
        request->indirect_client_addr = request->client_addr;
 #endif /* FOLLOW_X_FORWARDED_FOR */
-       request->my_addr = sqinet_get_v4_inaddr(&conn->me2, 
SQADDR_ASSERT_IS_V4);
-       request->my_port = sqinet_get_port(&conn->me2);
+        sqinet_copy(&request->my_address, &conn->me2);
        request->http_ver = http->http_ver;
        if (!urlCheckRequest(request)) {
            err = errorCon(ERR_UNSUP_REQ, HTTP_NOT_IMPLEMENTED, request);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side_rewrite.c Sat Jan 10 13:14:07 2009 +++ /playpen/LUSCA_HEAD_ipv6/src/client_side_rewrite.c Mon Sep 6 09:06:16 2010
@@ -141,8 +141,7 @@
 #if FOLLOW_X_FORWARDED_FOR
        new_request->indirect_client_addr = old_request->indirect_client_addr;
 #endif /* FOLLOW_X_FORWARDED_FOR */
-       new_request->my_addr = old_request->my_addr;
-       new_request->my_port = old_request->my_port;
+        sqinet_copy(&new_request->my_address, &old_request->my_address);
        new_request->flags = old_request->flags;
        new_request->flags.redirected = 1;
        if (old_request->auth_user_request) {
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/external_acl.c Mon Feb  8 01:08:16 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/external_acl.c Mon Sep  6 09:06:16 2010
@@ -652,10 +652,11 @@
            str = buf;
            break;
        case EXT_ACL_MYADDR:
-           str = inet_ntoa(request->my_addr);
+ (void) sqinet_ntoa(&request->my_address, buf, sizeof(buf), SQADDR_NONE);
+           str = buf;
            break;
        case EXT_ACL_MYPORT:
-           snprintf(buf, sizeof(buf), "%d", request->my_port);
+ snprintf(buf, sizeof(buf), "%d", sqinet_get_port(&request->my_address));
            str = buf;
            break;
        case EXT_ACL_URI:
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/forward.c      Tue Aug 31 18:24:09 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/forward.c      Mon Sep  6 09:06:16 2010
@@ -716,8 +716,11 @@
      * returned
      */
if (fwdState->request->flags.transparent && (fwdState->n_tries > 1) && (NULL == fs->peer)) {
+#warning This needs to be made ipv6-aware
+       struct in_addr addr;
+ addr = sqinet_get_v4_inaddr(&fwdState->request->my_address, SQADDR_ASSERT_IS_V4);
        storeRelease(fwdState->entry);
- commConnectStart(fd, host, port, fwdConnectDone, fwdState, &fwdState->request->my_addr);
+       commConnectStart(fd, host, port, fwdConnectDone, fwdState, &addr);
     } else {
        commConnectStart(fd, host, port, fwdConnectDone, fwdState, NULL);
     }
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/redirect.c     Sun Jul 11 22:42:23 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/redirect.c     Mon Sep  6 09:06:16 2010
@@ -100,7 +100,7 @@
     char *urlgroup = conn->port->urlgroup;
     char buf[8192];
     char claddr[MAX_IPSTRLEN];
-    char myaddr[20];
+    LOCAL_ARRAY(char, myaddr, MAX_IPSTRLEN);
     assert(http);
     assert(handler);
     debug(61, 5) ("redirectStart: '%s'\n", http->uri);
@@ -135,7 +135,7 @@
     if ((fqdn = fqdncache_gethostbyaddr6(&r->client_addr2, 0)) == NULL)
        fqdn = dash_str;
(void) sqinet_ntoa(&r->client_addr2, claddr, sizeof(claddr), SQADDR_NONE);
-    xstrncpy(myaddr, inet_ntoa(http->request->my_addr), 20);
+ (void) sqinet_ntoa(&http->request->my_address, myaddr, MAX_IPSTRLEN, SQADDR_NONE);
     snprintf(buf, 8191, "%s %s/%s %s %s %s myip=%s myport=%d",
        r->orig_url,
        claddr,
@@ -144,7 +144,7 @@
        r->method_s,
        urlgroup ? urlgroup : "-",
        myaddr,
-       http->request->my_port);
+        sqinet_get_port(&http->request->my_address));
     debug(61, 6) ("redirectStart: sending '%s' to the helper\n", buf);
     strcat(buf, "\n");
     helperSubmit(redirectors, buf, redirectHandleReply, r);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/store_rewrite.c        Sun Jul 11 22:42:23 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/store_rewrite.c        Mon Sep  6 09:06:16 2010
@@ -100,7 +100,7 @@
     char *urlgroup = conn->port->urlgroup;
     char buf[8192];
     char claddr[MAX_IPSTRLEN];
-    char myaddr[20];
+    char myaddr[MAX_IPSTRLEN];
     assert(http);
     assert(handler);
     debug(61, 5) ("storeurlStart: '%s'\n", http->uri);
@@ -135,7 +135,7 @@
     if ((fqdn = fqdncache_gethostbyaddr6(&r->client_addr2, 0)) == NULL)
        fqdn = dash_str;
     sqinet_ntoa(&r->client_addr2, claddr, sizeof(claddr), SQADDR_NONE);
-    xstrncpy(myaddr, inet_ntoa(http->request->my_addr), 20);
+ (void) sqinet_ntoa(&http->request->my_address, myaddr, sizeof(myaddr), SQADDR_NONE);
     snprintf(buf, 8191, "%s %s/%s %s %s %s myip=%s myport=%d",
        r->orig_url,
        claddr,
@@ -144,7 +144,7 @@
        r->method_s,
        urlgroup ? urlgroup : "-",
        myaddr,
-       http->request->my_port);
+       sqinet_get_port(&http->request->my_address));
     debug(61, 6) ("storeurlStart: sending '%s' to the helper\n", buf);
     strcat(buf, "\n");
     helperSubmit(storeurlors, buf, storeurlHandleReply, r);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/structs.h      Sat Sep  4 07:04:25 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/structs.h      Mon Sep  6 09:06:16 2010
@@ -1654,7 +1654,7 @@
 #if FOLLOW_X_FORWARDED_FOR
struct in_addr indirect_client_addr; /* after following X-Forwarded-For */
 #endif                         /* FOLLOW_X_FORWARDED_FOR */
-    struct in_addr my_addr;
+    sqaddr_t my_address;
     unsigned short my_port;
     HttpHeader header;
     squid_off_t content_length;

--
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