Revision: 14794
Author: adrian.chadd
Date: Mon Sep  6 22:29:42 2010
Log: Migrate request_t->client_addr/client_port to be the IPv6 "client_address".

There's likely a lot of fallout from this - check #warning entries for more
information.


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

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/authenticate.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/delay_pools.c
 /playpen/LUSCA_HEAD_ipv6/src/errorpage.c
 /playpen/LUSCA_HEAD_ipv6/src/external_acl.c
 /playpen/LUSCA_HEAD_ipv6/src/forward.c
 /playpen/LUSCA_HEAD_ipv6/src/http.c
 /playpen/LUSCA_HEAD_ipv6/src/internal.c
 /playpen/LUSCA_HEAD_ipv6/src/peer_sourcehash.c
 /playpen/LUSCA_HEAD_ipv6/src/ssl.c
 /playpen/LUSCA_HEAD_ipv6/src/structs.h

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/HttpRequest.c  Mon Sep  6 09:06:16 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/HttpRequest.c  Mon Sep  6 22:29:42 2010
@@ -58,8 +58,12 @@
     req->max_forwards = -1;
     req->lastmod = -1;
     SetAnyAddr(&req->out_ip);
-    SetNoAddr(&req->client_addr);
+//    SetNoAddr(&req->client_addr);
     sqinet_init(&req->my_address);
+    sqinet_init(&req->client_address);
+#if FOLLOW_X_FORWARDED_FOR
+    sqinet_init(&req->indirect_client_address);
+#endif
 //    SetNoAddr(&req->my_addr);
     httpHeaderInit(&req->header, hoRequest);
     return req;
@@ -82,6 +86,10 @@
     safe_free(req->extacl_user);
     safe_free(req->extacl_passwd);
     sqinet_done(&req->my_address);
+    sqinet_done(&req->client_address);
+#if FOLLOW_X_FORWARDED_FOR
+    sqinet_done(&req->indirect_client_address);
+#endif
     stringClean(&req->urlpath);
     httpHeaderClean(&req->header);
     if (req->cache_control)
@@ -147,8 +155,9 @@

     assert(req && p);
     /* Client info */
+ (void) sqinet_ntoa(&req->client_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
+    packerPrintf(p, "Client: %s ", cbuf);
     (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", 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));
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/access_log.c   Mon Sep  6 09:06:16 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/access_log.c   Mon Sep  6 22:29:42 2010
@@ -488,7 +488,7 @@

        case LFT_CLIENT_PORT:
            if (al->request) {
-               outint = al->request->client_port;
+               outint = sqinet_get_port(&al->request->client_address);
                doint = 1;
            }
            break;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/acl.c  Mon Sep  6 21:43:44 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/acl.c  Mon Sep  6 22:29:42 2010
@@ -2684,7 +2684,7 @@
            checklist->src_addr = request->indirect_client_addr;
        } else
 #endif /* FOLLOW_X_FORWARDED_FOR */
-       sqinet_set_v4_inaddr(&checklist->src_address, &request->client_addr);
+       sqinet_copy(&checklist->src_address, &request->client_address);
         sqinet_copy(&checklist->my_address, &request->my_address);
 #if 0 && USE_IDENT
        /*
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/authenticate.c Thu Sep  2 18:24:55 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/authenticate.c Mon Sep  6 22:29:42 2010
@@ -494,11 +494,7 @@
     else if (conn && conn->auth_user_request)
        return conn->auth_user_request;
     else {
-        sqaddr_t a;
-        sqinet_init(&a);
-       sqinet_set_v4_inaddr(&a, &request->client_addr);
-       request->auth_user_request = authenticateAuthUserRequestFindByIp(&a);
-       sqinet_done(&a);
+ request->auth_user_request = authenticateAuthUserRequestFindByIp(&request->client_address);
        if (request->auth_user_request)
            authenticateAuthUserRequestLock(request->auth_user_request);
        return request->auth_user_request;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c Mon Sep 6 09:06:16 2010 +++ /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c Mon Sep 6 22:29:42 2010
@@ -558,10 +558,9 @@
        request->content_length = httpHeaderGetSize(&request->header,
            HDR_CONTENT_LENGTH);
        request->flags.internal = http->flags.internal;
- request->client_addr = sqinet_get_v4_inaddr(&conn->peer2, SQADDR_ASSERT_IS_V4);
-       request->client_port = sqinet_get_port(&conn->peer2);
+        sqinet_copy(&request->client_address, &conn->peer2);
 #if FOLLOW_X_FORWARDED_FOR
-       request->indirect_client_addr = request->client_addr;
+        sqinet_copy(&request->indirect_client_address, &conn->peer2);
 #endif /* FOLLOW_X_FORWARDED_FOR */
         sqinet_copy(&request->my_address, &conn->me2);
        request->http_ver = http->http_ver;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side_rewrite.c Mon Sep 6 09:06:16 2010 +++ /playpen/LUSCA_HEAD_ipv6/src/client_side_rewrite.c Mon Sep 6 22:29:42 2010
@@ -136,10 +136,9 @@
        http->log_uri = xstrdup(urlCanonicalClean(old_request));
        new_request->http_ver = old_request->http_ver;
        httpHeaderAppend(&new_request->header, &old_request->header);
-       new_request->client_addr = old_request->client_addr;
-       new_request->client_port = old_request->client_port;
+       sqinet_copy(&new_request->client_address, &old_request->client_address);
 #if FOLLOW_X_FORWARDED_FOR
-       new_request->indirect_client_addr = old_request->indirect_client_addr;
+ sqinet_copy(&new_request->indirect_client_address, &old_request->indirect_client_address);
 #endif /* FOLLOW_X_FORWARDED_FOR */
         sqinet_copy(&new_request->my_address, &old_request->my_address);
        new_request->flags = old_request->flags;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/delay_pools.c  Mon Sep  6 21:39:50 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/delay_pools.c  Mon Sep  6 22:29:42 2010
@@ -333,8 +333,8 @@
     aclCheckSetup(&ch);
     ch.conn = http->conn;
     ch.request = r;
-    if (r->client_addr.s_addr == INADDR_BROADCAST) {
- debug(77, 2) ("delayClient: WARNING: Called with 'allones' address, ignoring\n");
+    if (sqinet_is_noaddr(&r->client_address)) {
+ debug(77, 2) ("delayClient: WARNING: Called with 'allones'/none address, ignoring\n");
         aclCheckFinish(&ch);
        return delayId(0, 0);
     }
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/errorpage.c    Tue Aug 31 09:02:21 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/errorpage.c    Mon Sep  6 22:29:42 2010
@@ -273,7 +273,7 @@
     sqinet_init(&err->src_addr2);
     if (request != NULL) {
        err->request = requestLink(request);
-        errorSetAddr4(err, request->client_addr);
+        errorSetAddr(err, &request->client_address);
     }
     return err;
 }
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/external_acl.c Mon Sep  6 21:39:50 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/external_acl.c Mon Sep  6 22:29:42 2010
@@ -649,7 +649,7 @@
            str = buf;
            break;
        case EXT_ACL_SRCPORT:
-           snprintf(buf, sizeof(buf), "%d", request->client_port);
+ snprintf(buf, sizeof(buf), "%d", sqinet_get_port(&request->client_address));
            str = buf;
            break;
        case EXT_ACL_MYADDR:
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/forward.c      Mon Sep  6 21:39:50 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/forward.c      Mon Sep  6 22:29:42 2010
@@ -634,7 +634,7 @@
        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); + fd = pconnPop6(name, port, domain, &fwdState->request->client_address, NULL);
     if (fd == -1) {
        fd = pconnPop(name, port, domain, NULL, 0, &idle);
     }
@@ -938,7 +938,7 @@
      * from peer_digest.c, asn.c, netdb.c, etc and should always
      * be allowed.  yuck, I know.
      */
- if (! IsNoAddr(&r->client_addr) && r->protocol != PROTO_INTERNAL && r->protocol != PROTO_CACHEOBJ) { + if (! sqinet_is_noaddr(&r->client_address) && r->protocol != PROTO_INTERNAL && r->protocol != PROTO_CACHEOBJ) {
        /*
         * Check if this host is allowed to fetch MISSES from us (miss_access)
         */
@@ -993,9 +993,7 @@
     /* If we need to transparently proxy the request
      * then we need the client source address and port */
/* XXX should we only do this if the request has the tproxy flag set?! */
-    fwdState->src.sin_family = AF_INET;
-    fwdState->src.sin_addr = r->client_addr;
-    fwdState->src.sin_port = r->client_port;
+ fwdState->src = sqinet_get_v4_sockaddr(&r->client_address, SQADDR_ASSERT_IS_V4);

     storeLockObject(e);
     if (!fwdState->request->flags.pinned)
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/http.c Mon Sep  6 21:39:50 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/http.c Mon Sep  6 22:29:42 2010
@@ -788,6 +788,7 @@
     const request_t *request = httpState->request;
     const request_t *orig_request = httpState->orig_request;
     struct in_addr *client_addr = NULL;
+    struct in_addr ca;
     u_short client_port = 0;
     int fd = httpState->fd;
     int complete = httpState->eof;
@@ -968,7 +969,9 @@
     if (keep_alive) {
        int pinned = 0;
        if (orig_request->flags.tproxy) {
-           client_addr = &httpState->request->client_addr;
+#warning TPROXY, IPv6, AIEE!
+ ca = sqinet_get_v4_inaddr(&httpState->request->client_address, SQADDR_ASSERT_IS_V4);
+           client_addr = &ca;
        }
        /* yes we have to clear all these! */
        commSetDefer(fd, NULL, NULL);
@@ -1325,6 +1328,7 @@
     /* building buffer for complex strings */
 #define BBUF_SZ (MAX_URL+32)
     LOCAL_ARRAY(char, bbuf, BBUF_SZ);
+    LOCAL_ARRAY(char, cbuf, MAX_IPSTRLEN);
     String strConnection = StringNull;
     const HttpHeader *hdr_in = &orig_request->header;
     int we_do_ranges;
@@ -1512,8 +1516,9 @@
     case FORWARDED_FOR_OFF:
        strFwd = httpHeaderGetList(hdr_in, HDR_X_FORWARDED_FOR);
     case FORWARDED_FOR_TRUNCATE:
- strListAdd(&strFwd, (((! IsNoAddr(&orig_request->client_addr)) && opt_forwarded_for != FORWARDED_FOR_OFF) ?
-               inet_ntoa(orig_request->client_addr) : "unknown"), ',');
+ (void) sqinet_ntoa(&orig_request->client_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE); + strListAdd(&strFwd, (((! sqinet_is_noaddr(&orig_request->client_address)) && opt_forwarded_for != FORWARDED_FOR_OFF) ?
+               cbuf : "unknown"), ',');
        break;
     case FORWARDED_FOR_TRANSPARENT:
        /* Handled above */
@@ -1852,9 +1857,11 @@
     httpState->body_buf = NULL;
     if (size > 0) {
        if (httpState->reply_hdr_state >= 2 && 
!httpState->flags.abuse_detected) {
+           LOCAL_ARRAY(char, cbuf, MAX_IPSTRLEN);
            httpState->flags.abuse_detected = 1;
+ (void) sqinet_ntoa(&httpState->orig_request->client_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE); debug(11, 1) ("httpRequestBodyHandler: Likely proxy abuse detected '%s' -> '%s'\n",
-               inet_ntoa(httpState->orig_request->client_addr),
+               cbuf,
                storeUrl(httpState->entry));
if (httpState->entry->mem_obj->reply->sline.status == HTTP_INVALID_HEADER) {
                memFree8K(buf);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/internal.c     Mon Feb  2 10:59:28 2009
+++ /playpen/LUSCA_HEAD_ipv6/src/internal.c     Mon Sep  6 22:29:42 2010
@@ -43,9 +43,13 @@
 internalStart(request_t * request, StoreEntry * entry)
 {
     ErrorState *err;
-
-    debug(76, 3) ("internalStart: %s requesting '%.*s'\n",
- inet_ntoa(request->client_addr), strLen2(request->urlpath), strBuf2(request->urlpath));
+    LOCAL_ARRAY(char, cbuf, MAX_IPSTRLEN);
+
+    if (debugLevels[76] >= 3) {
+ (void) sqinet_ntoa(&request->client_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
+        debug(76, 3) ("internalStart: %s requesting '%.*s'\n",
+          cbuf, strLen2(request->urlpath), strBuf2(request->urlpath));
+    }
     if (strCmp(request->urlpath, "/squid-internal-dynamic/netdb") == 0) {
        netdbBinaryExchange(entry);
} else if (strCmp(request->urlpath, "/squid-internal-periodic/store_digest") == 0) {
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/peer_sourcehash.c      Fri Jan  9 16:13:08 2009
+++ /playpen/LUSCA_HEAD_ipv6/src/peer_sourcehash.c      Mon Sep  6 22:29:42 2010
@@ -137,11 +137,13 @@
     double score;
     double high_score = 0;
     const char *key = NULL;
+    LOCAL_ARRAY(char, cbuf, MAX_IPSTRLEN);

     if (n_sourcehash_peers == 0)
        return NULL;

-    key = inet_ntoa(request->client_addr);
+ (void) sqinet_ntoa(&request->client_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
+    key = cbuf;

     /* calculate hash key */
debug(39, 2) ("peerSourceHashSelectParent: Calculating hash for %s\n", key);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/ssl.c  Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/ssl.c  Mon Sep  6 22:29:42 2010
@@ -505,7 +505,8 @@
      * from peer_digest.c, asn.c, netdb.c, etc and should always
      * be allowed.  yuck, I know.
      */
-    if (! IsNoAddr(&request->client_addr)) {
+#warning IS THIS EVEN VALID? Ew.
+    if (! sqinet_is_noaddr(&request->client_address)) {
        /*
         * Check if this host is allowed to fetch MISSES from us (miss_access)
         */
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/structs.h      Mon Sep  6 21:39:50 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/structs.h      Mon Sep  6 22:29:42 2010
@@ -1647,11 +1647,9 @@
     time_t ims;
     int imslen;
     int max_forwards;
-    /* these in_addr's could probably be sockaddr_in's */
-    unsigned short client_port;
-    struct in_addr client_addr;
+    sqaddr_t client_address;
 #if FOLLOW_X_FORWARDED_FOR
- struct in_addr indirect_client_addr; /* after following X-Forwarded-For */
+    sqaddr_t indirect_client_address;
 #endif                         /* FOLLOW_X_FORWARDED_FOR */
     sqaddr_t my_address;
     HttpHeader header;

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