Revision: 14728
Author: adrian.chadd
Date: Sun Jul 11 02:47:00 2010
Log:
IPv6: Migrate the ConnStateData internals over from sockaddr_in to sqaddr_t.
http://code.google.com/p/lusca-cache/source/detail?r=14728
Modified:
/playpen/LUSCA_HEAD_ipv6/libsqinet/sqinet.c
/playpen/LUSCA_HEAD_ipv6/libsqinet/sqinet.h
/playpen/LUSCA_HEAD_ipv6/src/acl.c
/playpen/LUSCA_HEAD_ipv6/src/client_side.c
/playpen/LUSCA_HEAD_ipv6/src/client_side_conn.c
/playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c
/playpen/LUSCA_HEAD_ipv6/src/redirect.c
/playpen/LUSCA_HEAD_ipv6/src/stat.c
/playpen/LUSCA_HEAD_ipv6/src/store_rewrite.c
/playpen/LUSCA_HEAD_ipv6/src/structs.h
=======================================
--- /playpen/LUSCA_HEAD_ipv6/libsqinet/sqinet.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/libsqinet/sqinet.c Sun Jul 11 02:47:00 2010
@@ -289,6 +289,24 @@
v4 = (struct sockaddr_in *) &s->st;
return v4->sin_addr;
}
+
+struct in6_addr
+sqinet_get_v6_inaddr(const sqaddr_t *s, sqaddr_flags flags)
+{
+ struct sockaddr_in6 *v6;
+ struct in6_addr no6addr = {{{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }}};
+
+ assert(s->init);
+ if (flags & SQADDR_ASSERT_IS_V6) {
+ assert(s->st.ss_family == AF_INET6);
+ }
+ if (s->st.ss_family != AF_INET6)
+ return no6addr;
+
+ v6 = (struct sockaddr_in6 *) &s->st;
+ return v6->sin6_addr;
+}
+
/*!
* @function
=======================================
--- /playpen/LUSCA_HEAD_ipv6/libsqinet/sqinet.h Thu Jan 15 20:21:06 2009
+++ /playpen/LUSCA_HEAD_ipv6/libsqinet/sqinet.h Sun Jul 11 02:47:00 2010
@@ -37,6 +37,7 @@
extern int sqinet_get_port(const sqaddr_t *s);
extern void sqinet_set_port(const sqaddr_t *s, short port, sqaddr_flags
flags);
extern struct in_addr sqinet_get_v4_inaddr(const sqaddr_t *s, sqaddr_flags
flags);
+extern struct in6_addr sqinet_get_v6_inaddr(const sqaddr_t *s,
sqaddr_flags flags);
extern int sqinet_get_v4_sockaddr_ptr(const sqaddr_t *s, struct
sockaddr_in *v4, sqaddr_flags flags);
extern struct sockaddr_in sqinet_get_v4_sockaddr(const sqaddr_t *s,
sqaddr_flags flags);
extern void sqinet_set_anyaddr(sqaddr_t *s);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/acl.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/acl.c Sun Jul 11 02:47:00 2010
@@ -2280,7 +2280,7 @@
else if (checklist->state[ACL_IDENT] == ACL_LOOKUP_NEEDED) {
debug(28, 3) ("aclCheck: Doing ident lookup\n");
if (cbdataValid(checklist->conn)) {
- identStart4(&checklist->conn->me, &checklist->conn->peer,
+ identStart(&checklist->conn->me2, &checklist->conn->peer2,
aclLookupIdentDone, checklist);
checklist->state[ACL_IDENT] = ACL_LOOKUP_PENDING;
return;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/client_side.c Sun Jul 11 02:47:00 2010
@@ -280,7 +280,7 @@
http->al.http.code = mem->reply->sline.status;
http->al.http.content_type = strBuf(mem->reply->content_type);
}
- http->al.cache.caddr = conn->log_addr;
+ http->al.cache.caddr = sqinet_get_v4_inaddr(&conn->log_addr2,
SQADDR_ASSERT_IS_V4);
http->al.cache.size = http->out.size;
http->al.cache.code = http->log_type;
http->al.cache.msec = tvSubMsec(http->start, current_time);
@@ -322,7 +322,7 @@
http->al.reply = http->reply;
accessLogLog(&http->al, http->acl_checklist);
clientUpdateCounters(http);
- clientdbUpdate(conn->peer.sin_addr, http->log_type, PROTO_HTTP,
http->out.size);
+ clientdbUpdate6(&conn->peer2, http->log_type, PROTO_HTTP,
http->out.size);
}
}
safe_free(http->al.headers.request);
@@ -1930,11 +1930,15 @@
#if DELAY_POOLS
debug(33, 5) ("clientWriteComplete : Normal\n");
if (clientDelayBodyTooLarge(http, http->out.offset - 4096)) {
+ struct in_addr a;
+
debug(33, 5) ("clientWriteComplete: we should put this into the pool:
DelayId=%i\n",
http->sc->delay_id);
delayUnregisterDelayIdPtr(&http->sc->delay_id);
+ a = sqinet_get_v4_inaddr(&http->conn->peer2, SQADDR_ASSERT_IS_V4);
+#warning delay pools should obviously be mapped to be ipv6 aware at some
point
delaySetStoreClient(http->sc,
delayPoolClient(http->delayAssignedPool,
- (in_addr_t) http->conn->peer.sin_addr.s_addr));
+ (in_addr_t) a.s_addr));
}
#endif
/* More data will be coming from primary server; register with
@@ -2518,8 +2522,10 @@
{
clientHttpRequest *http = data;
ConnStateData *conn = http->conn;
- debug(33, 1) ("WARNING: Closing client %s connection due to lifetime
timeout\n",
- inet_ntoa(conn->peer.sin_addr));
+ LOCAL_ARRAY(char, sb, MAX_IPSTRLEN);
+
+ (void) sqinet_ntoa(&conn->peer2, sb, sizeof(sb), SQADDR_NO_BRACKET_V6);
+ debug(33, 1) ("WARNING: Closing client %s connection due to lifetime
timeout\n", sb);
debug(33, 1) ("\t%s\n", http->uri);
comm_close(fd);
}
@@ -2586,7 +2592,7 @@
identChecklist.my_addr = sqinet_get_v4_inaddr(&me, SQADDR_ASSERT_IS_V4);
identChecklist.my_port = sqinet_get_port(&me);
if (aclCheckFast(Config.accessList.identLookup, &identChecklist))
- identStart4(&connState->me, &connState->peer, clientIdentDone,
connState);
+ identStart(&connState->me2, &connState->peer2, clientIdentDone,
connState);
#endif
commSetSelect(fd, COMM_SELECT_READ, clientReadRequest, connState, 0);
commSetDefer(fd, clientReadDefer, connState);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side_conn.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/client_side_conn.c Sun Jul 11 02:47:00 2010
@@ -16,7 +16,7 @@
clientHttpRequest *http;
debug(33, 3) ("connStateFree: FD %d\n", fd);
assert(connState != NULL);
- clientdbEstablished(connState->peer.sin_addr, -1); /* decrement */
+ clientdbEstablished6(&connState->peer2, -1); /* decrement */
n = connState->reqs.head;
while (n != NULL) {
http = n->data;
@@ -32,6 +32,9 @@
pconnHistCount(0, connState->nrequests);
if (connState->pinning.fd >= 0)
comm_close(connState->pinning.fd);
+ sqinet_done(&connState->me2);
+ sqinet_done(&connState->peer2);
+ sqinet_done(&connState->log_addr2);
cbdataFree(connState);
clientside_num_conns--;
#ifdef _SQUID_LINUX_
@@ -51,10 +54,19 @@
CBDATA_INIT_TYPE(ConnStateData);
connState = cbdataAlloc(ConnStateData);
clientside_num_conns++;
- sqinet_get_v4_sockaddr_ptr(peer, &connState->peer,
SQADDR_ASSERT_IS_V4);
- connState->log_addr = connState->peer.sin_addr;
+ sqinet_init(&connState->me2);
+ sqinet_init(&connState->peer2);
+ sqinet_init(&connState->log_addr2);
+
+ sqinet_copy(&connState->peer2, peer);
+ sqinet_copy(&connState->log_addr2, peer);
+
+#warning XXX still need to add back client_netmask! And/or add a v6
client_netmask config option!
+#if 0
connState->log_addr.s_addr &= Config.Addrs.client_netmask.s_addr;
- sqinet_get_v4_sockaddr_ptr(me, &connState->me,
SQADDR_ASSERT_IS_V4);
+#endif
+ sqinet_copy(&connState->me2, me);
+
connState->fd = fd;
connState->pinning.fd = -1;
connState->in.buf = memAllocBuf(CLIENT_REQ_BUF_SZ,
&connState->in.size);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c Sun Jul 4
06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/client_side_request_parse.c Sun Jul 11
02:47:00 2010
@@ -194,6 +194,7 @@
int port = 0;
const char *host = mime_get_header(req_hdr, "Host");
char *portstr;
+ char hostbuf[MAX_IPSTRLEN];
if (host && (portstr = strchr(host, ':')) != NULL) {
*portstr++ = '\0';
@@ -207,9 +208,11 @@
if (conn->port->transparent && clientNatLookup(conn) == 0)
conn->transparent = 1;
if (!host && conn->transparent) {
- port = ntohs(conn->me.sin_port);
- if (!host)
- host = inet_ntoa(conn->me.sin_addr);
+ port = sqinet_get_port(&conn->me2);
+ if (!host) {
+ (void) sqinet_ntoa(&conn->me2, hostbuf, sizeof(hostbuf),
SQADDR_NONE);
+ host = hostbuf;
+ }
}
if (host) {
size_t url_sz = 10 + strlen(host) + 6 + strlen(url) + 32 +
Config.appendDomainLen;
@@ -235,6 +238,7 @@
int vhost = conn->port->vhost;
int vport = conn->port->vport;
const char *t = NULL;
+ char hostbuf[MAX_IPSTRLEN];
http->flags.accel = 1;
if (*url != '/' && !vhost && strncasecmp(url, "cache_object://", 15) !=
0) {
@@ -254,14 +258,15 @@
if (vport > 0)
port = vport;
else
- port = htons(http->conn->me.sin_port);
+ port = sqinet_get_port(&http->conn->me2);
if (vhost && (t = mime_get_header(req_hdr, "Host")))
host = t;
else if (conn->port->defaultsite)
host = conn->port->defaultsite;
- else if (vport == -1)
- host = inet_ntoa(http->conn->me.sin_addr);
- else
+ else if (vport == -1) {
+ (void) sqinet_ntoa(&conn->me2, hostbuf, sizeof(hostbuf),
SQADDR_NONE);
+ host = hostbuf;
+ } else
host = getMyHostname();
url_sz = strlen(url) + 32 + Config.appendDomainLen + strlen(host);
http->uri = xcalloc(url_sz, 1);
@@ -482,7 +487,7 @@
if (parser_return_code < 0) {
debug(33, 1) ("clientTryParseRequest: FD %d (%s:%d) Invalid
Request\n", fd, fd_table[fd].ipaddrstr, fd_table[fd].remote_port);
err = errorCon(ERR_INVALID_REQ, HTTP_BAD_REQUEST, NULL);
- err->src_addr = conn->peer.sin_addr;
+ errorSetAddr(err, &conn->peer2);
err->request_hdrs = xstrdup(conn->in.buf);
http->log_type = LOG_TCP_DENIED;
http->entry = clientCreateStoreEntry(http, method,
null_request_flags);
@@ -493,7 +498,7 @@
if ((request = urlParse(method, http->uri)) == NULL) {
debug(33, 5) ("Invalid URL: %s\n", http->uri);
err = errorCon(ERR_INVALID_URL, HTTP_BAD_REQUEST, NULL);
- err->src_addr = conn->peer.sin_addr;
+ errorSetAddr(err, &conn->peer2);
err->url = xstrdup(http->uri);
http->al.http.code = err->http_status;
http->log_type = LOG_TCP_DENIED;
@@ -550,13 +555,13 @@
request->content_length = httpHeaderGetSize(&request->header,
HDR_CONTENT_LENGTH);
request->flags.internal = http->flags.internal;
- request->client_addr = conn->peer.sin_addr;
- request->client_port = ntohs(conn->peer.sin_port);
+ request->client_addr = sqinet_get_v4_inaddr(&conn->peer2,
SQADDR_ASSERT_IS_V4);
+ request->client_port = sqinet_get_port(&conn->peer2);
#if FOLLOW_X_FORWARDED_FOR
request->indirect_client_addr = request->client_addr;
#endif /* FOLLOW_X_FORWARDED_FOR */
- request->my_addr = conn->me.sin_addr;
- request->my_port = ntohs(conn->me.sin_port);
+ request->my_addr = sqinet_get_v4_inaddr(&conn->me2,
SQADDR_ASSERT_IS_V4);
+ request->my_port = sqinet_get_port(&conn->me2);
request->http_ver = http->http_ver;
if (!urlCheckRequest(request)) {
err = errorCon(ERR_UNSUP_REQ, HTTP_NOT_IMPLEMENTED, request);
@@ -603,7 +608,9 @@
if (!DLINK_ISEMPTY(conn->reqs) && DLINK_HEAD(conn->reqs) == http)
clientCheckFollowXForwardedFor(http);
else {
- debug(33, 1) ("WARNING: pipelined CONNECT request seen from %s\n",
inet_ntoa(http->conn->peer.sin_addr));
+ char buf[MAX_IPSTRLEN];
+ (void) sqinet_ntoa(&http->conn->peer2, buf, sizeof(buf),
SQADDR_NONE);
+ debug(33, 1) ("WARNING: pipelined CONNECT request seen from
%s\n", buf);
debugObj(33, 1, "Previous request:\n", ((clientHttpRequest *)
DLINK_HEAD(conn->reqs))->request,
(ObjPackMethod) & httpRequestPackDebug);
debugObj(33, 1, "This request:\n", request, (ObjPackMethod) &
httpRequestPackDebug);
@@ -625,7 +632,7 @@
debug(33, 1) ("Config 'request_header_max_size'= %ld bytes.\n",
(long int) Config.maxRequestHeaderSize);
err = errorCon(ERR_TOO_BIG, HTTP_REQUEST_URI_TOO_LONG, NULL);
- err->src_addr = conn->peer.sin_addr;
+ errorSetAddr(err, &conn->peer2);
http = parseHttpRequestAbort(conn,
&method, "error:request-too-large");
/* add to the client request queue */
dlinkAddTail(http, &http->node, &conn->reqs);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/redirect.c Mon Feb 8 01:08:16 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/redirect.c Sun Jul 11 02:47:00 2010
@@ -111,7 +111,7 @@
}
r = cbdataAlloc(redirectStateData);
r->orig_url = xstrdup(http->uri);
- r->client_addr = conn->log_addr;
+ r->client_addr = sqinet_get_v4_inaddr(&conn->log_addr2,
SQADDR_ASSERT_IS_V4);
r->client_ident = NULL;
if (http->request->auth_user_request)
r->client_ident =
authenticateUserRequestUsername(http->request->auth_user_request);
@@ -365,6 +365,7 @@
int do_free = 0;
unsigned long ulong = 0;
const char *ulong_fmt = "%lu";
+ char buf[MAX_IPSTRLEN];
debug(85, 5) ("internalRedirectProcessURL: token=%s str=%s
urlEncode=%s\n",
tokenNames[head->type], head->str,
head->urlEncode ? "true" : "false");
switch (head->type) {
@@ -373,13 +374,15 @@
str_len = head->str_len;
break;
case RFT_CLIENT_IPADDRESS:
- str = inet_ntoa(req->conn->peer.sin_addr);
+ (void) sqinet_ntoa(&req->conn->peer2, buf, sizeof(buf),
SQADDR_NONE);
+ str = buf;
break;
case RFT_LOCAL_IPADDRESS:
- str = inet_ntoa(req->conn->me.sin_addr);
+ (void) sqinet_ntoa(&req->conn->me2, buf, sizeof(buf), SQADDR_NONE);
+ str = buf;
break;
case RFT_LOCAL_PORT:
- ulong = ntohs(req->conn->me.sin_port);
+ ulong = sqinet_get_port(&req->conn->me2);
do_ulong = 1;
break;
case RFT_EPOCH_SECONDS:
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/stat.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/stat.c Sun Jul 11 02:47:00 2010
@@ -1504,6 +1504,7 @@
static void
statClientRequests(StoreEntry * s)
{
+ LOCAL_ARRAY(char, buf, MAX_IPSTRLEN);
dlink_node *i;
clientHttpRequest *http;
ConnStateData *conn;
@@ -1522,12 +1523,13 @@
storeAppendPrintf(s, "\tFD desc: %s\n", fd_table[fd].desc);
storeAppendPrintf(s, "\tin: buf %p, offset %ld, size %ld\n",
conn->in.buf, (long int) conn->in.offset, (long int)
conn->in.size);
- storeAppendPrintf(s, "\tpeer: %s:%d\n",
- inet_ntoa(conn->peer.sin_addr),
- ntohs(conn->peer.sin_port));
- storeAppendPrintf(s, "\tme: %s:%d\n",
- inet_ntoa(conn->me.sin_addr),
- ntohs(conn->me.sin_port));
+
+ (void) sqinet_ntoa(&conn->peer2, buf, sizeof(buf), SQADDR_NONE);
+ storeAppendPrintf(s, "\tpeer: %s:%d\n", buf,
sqinet_get_port(&conn->peer2));
+
+ (void) sqinet_ntoa(&conn->me2, buf, sizeof(buf), SQADDR_NONE);
+ storeAppendPrintf(s, "\tme: %s:%d\n", buf,
sqinet_get_port(&conn->me2));
+
storeAppendPrintf(s, "\tnrequests: %d\n",
conn->nrequests);
storeAppendPrintf(s, "\tdefer: n %d, until %ld\n",
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/store_rewrite.c Mon Feb 8 01:08:16 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/store_rewrite.c Sun Jul 11 02:47:00 2010
@@ -111,7 +111,7 @@
}
r = cbdataAlloc(storeurlStateData);
r->orig_url = xstrdup(http->uri);
- r->client_addr = conn->log_addr;
+ r->client_addr = sqinet_get_v4_inaddr(&conn->log_addr2,
SQADDR_ASSERT_IS_V4);
r->client_ident = NULL;
if (http->request->auth_user_request)
r->client_ident =
authenticateUserRequestUsername(http->request->auth_user_request);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/structs.h Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/structs.h Sun Jul 11 02:47:00 2010
@@ -1041,9 +1041,9 @@
/* the user details for connection based authentication */
auth_user_request_t *auth_user_request;
dlink_list reqs;
- struct sockaddr_in peer;
- struct sockaddr_in me;
- struct in_addr log_addr;
+ sqaddr_t peer2;
+ sqaddr_t me2;
+ sqaddr_t log_addr2;
char rfc931[USER_IDENT_SZ];
int nrequests;
struct {
--
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.