Revision: 14771
Author: adrian.chadd
Date: Tue Aug 31 09:23:59 2010
Log: Do a quick conversion of the pconn code to be ipv6-ready.


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

Modified:
 /playpen/LUSCA_HEAD_ipv6/src/pconn.c
 /playpen/LUSCA_HEAD_ipv6/src/pconn.h

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/pconn.c        Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/pconn.c        Tue Aug 31 09:23:59 2010
@@ -47,8 +47,8 @@

 static PF pconnRead;
 static PF pconnTimeout;
-static hash_link *pconnLookup(const char *peer, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); -static int pconnKey(char *buf, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); +static hash_link * pconnLookup(const char *peer, u_short port, const char *domain, sqaddr_t *client_address); +static int pconnKey(char *buf, const char *host, u_short port, const char *domain, sqaddr_t *client_address);
 static hash_table *table = NULL;
 static struct _pconn *pconnNew(const char *key);
 static void pconnDelete(struct _pconn *p);
@@ -57,20 +57,28 @@
 static MemPool *pconn_data_pool = NULL;
 static MemPool *pconn_fds_pool = NULL;

-#define        PCONN_KEYLEN    (SQUIDHOSTNAMELEN + 30)
+#define        PCONN_KEYLEN    (MAX_IPSTRLEN + SQUIDHOSTNAMELEN + 30)

 static int
 pconnKey(char *buf, const char *host, u_short port, const char *domain,
-    struct in_addr *client_address, u_short client_port)
-{
+    sqaddr_t *client_address)
+{
+    char cbuf[MAX_IPSTRLEN];
+    int client_port = 0;
+
+    if (client_address) {
+        client_port = sqinet_get_port(client_address);
+ (void) sqinet_ntoa(client_address, cbuf, MAX_IPSTRLEN, SQADDR_NONE);
+    }
+
     if (domain && client_address)
        return snprintf(buf, PCONN_KEYLEN, "%s.%d:%s.%d/%s", host, (int) port,
-           inet_ntoa(*client_address), (int) client_port, domain);
+           cbuf, client_port, domain);
     else if (domain && (!client_address))
        return snprintf(buf, PCONN_KEYLEN, "%s.%d/%s", host, (int) port, 
domain);
     else if ((!domain) && client_address)
        return snprintf(buf, PCONN_KEYLEN, "%s.%d:%s.%d", host, (int) port,
-           inet_ntoa(*client_address), (int) client_port);
+           cbuf, client_port);
     else
        return snprintf(buf, PCONN_KEYLEN, "%s:%d", host, (int) port);
 }
@@ -193,7 +201,7 @@
 }

 void
-pconnPush(int fd, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port) +pconnPush6(int fd, const char *host, u_short port, const char *domain, sqaddr_t *client_address)
 {
     struct _pconn *p;
     int *old;
@@ -208,7 +216,7 @@
        return;
     }
     assert(table != NULL);
-    pconnKey(key, host, port, domain, client_address, client_port);
+    pconnKey(key, host, port, domain, client_address);
     p = (struct _pconn *) hash_lookup(table, key);
     if (p == NULL)
        p = pconnNew(key);
@@ -230,15 +238,27 @@
     fd_note(fd, desc);
     debug(48, 3) ("pconnPush: pushed FD %d for %s\n", fd, key);
 }
+
+void
+pconnPush(int fd, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port)
+{
+       sqaddr_t a;
+
+       sqinet_init(&a);
+       sqinet_set_v4_inaddr(&a, client_address);
+       sqinet_set_v4_port(&a, client_port, SQADDR_ASSERT_IS_V4);
+       pconnPush6(fd, host, port, domain, &a);
+       sqinet_done(&a);
+}

 int
-pconnPop(const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port, int *idle) +pconnPop6(const char *host, u_short port, const char *domain, sqaddr_t *client_address, int *idle)
 {
     struct _pconn *p;
     hash_link *hptr;
     int fd = -1;
     assert(table != NULL);
-    hptr = pconnLookup(host, port, domain, client_address, client_port);
+    hptr = pconnLookup(host, port, domain, client_address);
     if (hptr != NULL) {
        p = (struct _pconn *) hptr;
        assert(p->nfds > 0);
@@ -251,13 +271,26 @@
     }
     return fd;
 }
+
+int
+pconnPop(const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port, int *idle)
+{
+       sqaddr_t a;
+       int r;
+
+       sqinet_init(&a);
+       sqinet_set_v4_inaddr(&a, client_address);
+       sqinet_set_v4_port(&a, client_port, SQADDR_ASSERT_IS_V4);
+       r = pconnPop6(host, port, domain, &a, idle);
+       sqinet_done(&a);
+       return r;
+}

 static hash_link *
-pconnLookup(const char *peer, u_short port, const char *domain, struct in_addr *client_address, u_short client_port) +pconnLookup(const char *peer, u_short port, const char *domain, sqaddr_t *client_address)
 {
     LOCAL_ARRAY(char, key, PCONN_KEYLEN);
     assert(table != NULL);
-    pconnKey(key, peer, port, domain, client_address, client_port);
+    pconnKey(key, peer, port, domain, client_address);
     return hash_lookup(table, key);
 }
-
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/pconn.h        Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/pconn.h        Tue Aug 31 09:23:59 2010
@@ -3,6 +3,10 @@

extern void pconnPush(int, const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port); extern int pconnPop(const char *host, u_short port, const char *domain, struct in_addr *client_address, u_short client_port, int *idle);
+
+extern void pconnPush6(int, const char *host, u_short port, const char *domain, sqaddr_t *client_address); +extern int pconnPop6(const char *host, u_short port, const char *domain, sqaddr_t *client_address, int *idle);
+
 extern void pconnInit(void);

 #endif

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