Revision: 14889
Author: adrian.chadd
Date: Sun Jul 10 02:54:48 2011
Log: Convert the bulk of the ICP UDP stuff to use v4/v6 sockets.
It's a bit ugly, because I'm now opening two sockets - one for v4,
one for v6 - and again it hasn't even been tested.
I've never even used the multicast stuff before, so this likely
heavily breaks it. In any case, it's only currently supported
for IPv4. I'll worry about IPv6'ing it later.
Send-announce is only ipv4 aware now. I'll worry about this
at a later date.
http://code.google.com/p/lusca-cache/source/detail?r=14889
Modified:
/playpen/LUSCA_HEAD_ipv6/src/icp_v2.c
/playpen/LUSCA_HEAD_ipv6/src/multicast.c
/playpen/LUSCA_HEAD_ipv6/src/neighbors.c
/playpen/LUSCA_HEAD_ipv6/src/protos.h
/playpen/LUSCA_HEAD_ipv6/src/send-announce.c
/playpen/LUSCA_HEAD_ipv6/src/tools.c
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/icp_v2.c Sun Jul 10 02:19:03 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/icp_v2.c Sun Jul 10 02:54:48 2011
@@ -46,6 +46,18 @@
* to call icpUdpSendQueue.
*/
static icpUdpData *IcpQueueTail = NULL;
+
+int
+icpGetOutSock(sqaddr_t *a)
+{
+ if (sqinet_get_family(a) == AF_INET)
+ return theOutIcpConnection4;
+ else if (sqinet_get_family(a) == AF_INET6)
+ return theOutIcpConnection4;
+ else
+ fatal("unknown address family!");
+ return -1;
+}
static void
icpLogIcp(const sqaddr_t *caddr, log_type logcode, int len, const char
*url,
@@ -446,33 +458,55 @@
int x;
socklen_t len;
wordlist *s;
+ char sbuf[MAX_IPSTRLEN];
+
if ((port = Config.Port.icp) <= 0)
return;
enter_suid();
- theInIcpConnection = comm_open(SOCK_DGRAM,
+
+ /* ipv4 */
+ theInIcpConnection4 = comm_open(SOCK_DGRAM,
IPPROTO_UDP,
Config.Addrs.udp_incoming,
port,
COMM_NONBLOCKING,
COMM_TOS_DEFAULT,
- "ICP Socket");
+ "ICP IPv4 Socket");
+
+ /* ipv6 */
+ theInIcpConnection6 = comm_open6(SOCK_DGRAM,
+ IPPROTO_UDP,
+ &Config.Addrs.udp_incoming6,
+ COMM_NONBLOCKING,
+ COMM_TOS_DEFAULT,
+ "ICP IPv6 Socket");
+
leave_suid();
- if (theInIcpConnection < 0)
- fatal("Cannot open ICP Port");
- commSetSelect(theInIcpConnection,
- COMM_SELECT_READ,
- icpHandleUdp,
- NULL,
- 0);
+
+ if (theInIcpConnection4 < 0)
+ fatal("Cannot open ICPv4 Port");
+ if (theInIcpConnection6 < 0)
+ fatal("Cannot open ICPv6 Port");
+
+ commSetSelect(theInIcpConnection4, COMM_SELECT_READ, icpHandleUdp,
NULL, 0);
+ commSetSelect(theInIcpConnection6, COMM_SELECT_READ, icpHandleUdp,
NULL, 0);
+
for (s = Config.mcast_group_list; s; s = s->next)
- ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
- debug(12, 1) ("Accepting ICP messages at %s, port %d, FD %d.\n",
- inet_ntoa(Config.Addrs.udp_incoming),
- (int) port, theInIcpConnection);
+ ipcache_nbgethostbyname(s->key, mcastJoinGroups, NULL);
+
+ debug(12, 1) ("Accepting IPv4 ICP messages at %s, port %d, FD %d.\n",
+ inet_ntoa(Config.Addrs.udp_incoming), (int) port,
theInIcpConnection4);
+
+ (void) sqinet_ntoa(&Config.Addrs.udp_incoming6, sbuf, MAX_IPSTRLEN,
+ SQADDR_NONE);
+ debug(12, 1) ("Accepting IPv6 ICP messages at %s, port %d, FD %d.\n",
+ sbuf, (int) port, theInIcpConnection6);
+
+ /* IPv4 outgoing */
addr = Config.Addrs.udp_outgoing;
if (! IsNoAddr(&addr)) {
enter_suid();
- theOutIcpConnection = comm_open(SOCK_DGRAM,
+ theOutIcpConnection4 = comm_open(SOCK_DGRAM,
IPPROTO_UDP,
addr,
port,
@@ -480,28 +514,54 @@
COMM_TOS_DEFAULT,
"ICP Port");
leave_suid();
- if (theOutIcpConnection < 0)
- fatal("Cannot open Outgoing ICP Port");
- commSetSelect(theOutIcpConnection,
+ if (theOutIcpConnection4 < 0)
+ fatal("Cannot open Outgoing IPv4 ICP Port");
+ commSetSelect(theOutIcpConnection4,
COMM_SELECT_READ,
icpHandleUdp,
NULL,
0);
- debug(12, 1) ("Outgoing ICP messages on port %d, FD %d.\n",
- (int) port, theOutIcpConnection);
- fd_note(theOutIcpConnection, "Outgoing ICP socket");
- fd_note(theInIcpConnection, "Incoming ICP socket");
+ debug(12, 1) ("Outgoing IPv4 ICP messages on port %d, FD %d.\n",
+ (int) port, theOutIcpConnection4);
+ fd_note(theOutIcpConnection4, "Outgoing ICP socket");
+ fd_note(theInIcpConnection4, "Incoming ICP socket");
} else {
- theOutIcpConnection = theInIcpConnection;
- }
+ theOutIcpConnection4 = theInIcpConnection4;
+ }
+
+ /* IPv6 outgoing */
+ if (! sqinet_is_noaddr(&Config.Addrs.udp_outgoing6)) {
+ enter_suid();
+ theOutIcpConnection6 = comm_open6(SOCK_DGRAM,
+ IPPROTO_UDP,
+ &Config.Addrs.udp_outgoing6,
+ COMM_NONBLOCKING,
+ COMM_TOS_DEFAULT,
+ "IPv6 outgoing ICP Port");
+ leave_suid();
+ if (theOutIcpConnection6 < 0)
+ fatal("Cannot open Outgoing IPv6 ICP Port");
+ commSetSelect(theOutIcpConnection6,
+ COMM_SELECT_READ,
+ icpHandleUdp,
+ NULL,
+ 0);
+ debug(12, 1) ("Outgoing IPv6 ICP messages on port %d, FD %d.\n",
+ (int) port, theOutIcpConnection6);
+ fd_note(theOutIcpConnection4, "Outgoing IPv6 ICP socket");
+ fd_note(theInIcpConnection4, "Incoming IPv6 ICP socket");
+ } else {
+ theOutIcpConnection6 = theInIcpConnection6;
+ }
+
memset(&theOutICPAddr, '\0', sizeof(struct in_addr));
len = sizeof(struct sockaddr_in);
memset(&xaddr, '\0', len);
- x = getsockname(theOutIcpConnection,
+ x = getsockname(theOutIcpConnection4,
(struct sockaddr *) &xaddr, &len);
if (x < 0)
debug(12, 1) ("theOutIcpConnection FD %d: getsockname: %s\n",
- theOutIcpConnection, xstrerror());
+ theOutIcpConnection4, xstrerror());
else
theOutICPAddr = xaddr.sin_addr;
}
@@ -513,37 +573,59 @@
void
icpConnectionShutdown(void)
{
- if (theInIcpConnection < 0)
- return;
- if (theInIcpConnection != theOutIcpConnection) {
- debug(12, 1) ("FD %d Closing ICP connection\n", theInIcpConnection);
- comm_close(theInIcpConnection);
- }
- /*
- * Here we set 'theInIcpConnection' to -1 even though the ICP 'in'
- * and 'out' sockets might be just one FD. This prevents this
- * function from executing repeatedly. When we are really ready to
- * exit or restart, main will comm_close the 'out' descriptor.
- */
- theInIcpConnection = -1;
- /*
- * Normally we only write to the outgoing ICP socket, but
- * we also have a read handler there to catch messages sent
- * to that specific interface. During shutdown, we must
- * disable reading on the outgoing socket.
- */
- assert(theOutIcpConnection > -1);
- commSetSelect(theOutIcpConnection, COMM_SELECT_READ, NULL, NULL, 0);
+ /* ipv4 */
+ if (theInIcpConnection4 > -1) {
+ if (theInIcpConnection4 != theOutIcpConnection4) {
+ debug(12, 1) ("FD %d Closing IPv4 ICP connection\n",
+ theInIcpConnection4);
+ comm_close(theInIcpConnection4);
+ }
+ /*
+ * Here we set 'theInIcpConnection' to -1 even though the ICP 'in'
+ * and 'out' sockets might be just one FD. This prevents this
+ * function from executing repeatedly. When we are really ready to
+ * exit or restart, main will comm_close the 'out' descriptor.
+ */
+ theInIcpConnection4 = -1;
+ /*
+ * Normally we only write to the outgoing ICP socket, but
+ * we also have a read handler there to catch messages sent
+ * to that specific interface. During shutdown, we must
+ * disable reading on the outgoing socket.
+ */
+ assert(theOutIcpConnection4 > -1);
+ commSetSelect(theOutIcpConnection4, COMM_SELECT_READ, NULL, NULL,
0);
+ }
+
+ /* ipv6 */
+ if (theInIcpConnection6 > -1) {
+ if (theInIcpConnection6 != theOutIcpConnection6) {
+ debug(12, 1) ("FD %d Closing IPv6 ICP connection\n",
+ theInIcpConnection6);
+ comm_close(theInIcpConnection6);
+ }
+ theInIcpConnection6 = -1;
+ assert(theOutIcpConnection6 > -1);
+ commSetSelect(theOutIcpConnection6, COMM_SELECT_READ, NULL, NULL,
0);
+ }
+
}
void
icpConnectionClose(void)
{
icpConnectionShutdown();
- if (theOutIcpConnection > -1) {
- debug(12, 1) ("FD %d Closing ICP connection\n", theOutIcpConnection);
- comm_close(theOutIcpConnection);
- theOutIcpConnection = -1;
+ if (theOutIcpConnection4 > -1) {
+ debug(12, 1) ("FD %d Closing IPv4 ICP connection\n",
+ theOutIcpConnection4);
+ comm_close(theOutIcpConnection4);
+ theOutIcpConnection4 = -1;
+ }
+ if (theOutIcpConnection6 > -1) {
+ debug(12, 1) ("FD %d Closing IPv6 ICP connection\n",
+ theOutIcpConnection6);
+ comm_close(theOutIcpConnection6);
+ theOutIcpConnection6 = -1;
}
}
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/multicast.c Tue Jan 11 21:34:35 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/multicast.c Sun Jul 10 02:54:48 2011
@@ -47,11 +47,14 @@
return 0;
}
+/*
+ * This is all ipv4 specific at the moment, unfortunately.
+ */
void
mcastJoinGroups(const ipcache_addrs * ia, void *datanotused)
{
#ifdef IP_MULTICAST_TTL
- int fd = theInIcpConnection;
+ int fd = theInIcpConnection4;
struct ip_mreq mr;
int i;
int x;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/neighbors.c Sun Jul 10 02:23:22 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/neighbors.c Sun Jul 10 02:54:48 2011
@@ -387,7 +387,8 @@
const char *me = getMyHostname();
peer *this;
peer *next;
- int fd = theInIcpConnection;
+ int fd = theInIcpConnection4;
+#warning This needs to check both ipv4 and ipv6!!
if (fd >= 0) {
memset(&name, '\0', sizeof(struct sockaddr_in));
if (getsockname(fd, (struct sockaddr *) &name, &len) < 0)
@@ -424,7 +425,7 @@
cachemgrRegister("server_list",
"Peer Cache Statistics",
neighborDumpPeers, 0, 1);
- if (theInIcpConnection >= 0) {
+ if (theInIcpConnection4 >= 0) {
cachemgrRegister("non_peers",
"List of Unknown sites sending ICP messages",
neighborDumpNonPeers, 0, 1);
@@ -454,8 +455,10 @@
if (Config.peers == NULL)
return 0;
+#if 0
if (theOutIcpConnection < 0)
fatal("neighborsUdpPing: There is no ICP socket!");
+#endif
assert(entry->swap_status == SWAPOUT_NONE);
mem->start_ping = current_time;
mem->ping_reply_callback = callback;
@@ -471,7 +474,7 @@
debug(15, 4) ("neighborsUdpPing: pinging peer %s for '%s'\n",
p->name, url);
if (p->type == PEER_MULTICAST)
- mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
+ mcastSetTtl(icpGetOutSock(&p->addr), p->mcast.ttl);
debug(15, 3) ("neighborsUdpPing: key = '%s'\n",
storeKeyText(entry->hash.key));
debug(15, 3) ("neighborsUdpPing: reqnum = %d\n", reqnum);
@@ -485,7 +488,7 @@
debug(15, 4) ("neighborsUdpPing: Looks like a dumb cache, send DECHO
ping\n");
echo_hdr.reqnum = reqnum;
query = icpCreateMessage(ICP_DECHO, 0, url, reqnum, 0);
- icpUdpSend(theOutIcpConnection,
+ icpUdpSend(icpGetOutSock(&p->addr),
&p->addr,
query,
LOG_ICP_QUERY,
@@ -496,7 +499,7 @@
if (p->icp.version == ICP_VERSION_2)
flags |= ICP_FLAG_SRC_RTT;
query = icpCreateMessage(ICP_QUERY, flags, url, reqnum, 0);
- icpUdpSend(theOutIcpConnection,
+ icpUdpSend(icpGetOutSock(&p->addr),
&p->addr,
query,
LOG_ICP_QUERY,
@@ -1240,11 +1243,11 @@
mem->start_ping = current_time;
mem->ping_reply_callback = peerCountHandleIcpReply;
mem->ircb_data = psstate;
- mcastSetTtl(theOutIcpConnection, p->mcast.ttl);
+ mcastSetTtl(icpGetOutSock(&p->addr), p->mcast.ttl);
p->mcast.id = mem->id;
reqnum = icpSetCacheKey(fake->hash.key);
query = icpCreateMessage(ICP_QUERY, 0, url, reqnum, 0);
- icpUdpSend(theOutIcpConnection,
+ icpUdpSend(icpGetOutSock(&p->addr),
&p->addr,
query,
LOG_ICP_QUERY,
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/protos.h Sun Jul 10 02:19:03 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/protos.h Sun Jul 10 02:54:48 2011
@@ -269,6 +269,7 @@
extern void requestReadBody(request_t * request, char *buf, size_t size,
CBCB * callback, void *cbdata);
extern void requestAbortBody(request_t * request);
+extern int icpGetOutSock(sqaddr_t *a);
extern void *icpCreateMessage(icp_opcode opcode,
int flags,
const char *url,
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/send-announce.c Tue Jan 11 21:34:35 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/send-announce.c Sun Jul 10 02:54:48 2011
@@ -41,11 +41,12 @@
start_announce(void *datanotused)
{
if (0 == Config.onoff.announce)
- return;
- if (theOutIcpConnection < 0)
- return;
+ return;
+ if (theOutIcpConnection4 < 0 || theOutIcpConnection6 < 0)
+ return;
ipcache_nbgethostbyname(Config.Announce.host, send_announce, NULL);
- eventAdd("send_announce", start_announce, NULL, (double)
Config.Announce.period, 1);
+ eventAdd("send_announce", start_announce, NULL,
+ (double) Config.Announce.period, 1);
}
static void
@@ -95,15 +96,16 @@
debug(50, 1) ("send_announce: %s: %s\n", file, xstrerror());
}
}
+ /* XXX this is ipv4 specific, but noone likely uses it anymore -adrian
*/
memset(&S, '\0', sizeof(S));
S.sin_family = AF_INET;
S.sin_port = htons(port);
S.sin_addr = ipcacheGetAddrV4(ia, 0);
- assert(theOutIcpConnection > 0);
- x = comm_udp_sendto(theOutIcpConnection,
+ assert(theOutIcpConnection4 > 0);
+ x = comm_udp_sendto(theOutIcpConnection4,
&S, sizeof(S),
sndbuf, strlen(sndbuf) + 1);
if (x < 0)
- debug(27, 1) ("send_announce: FD %d: %s\n", theOutIcpConnection,
+ debug(27, 1) ("send_announce: FD %d: %s\n", theOutIcpConnection4,
xstrerror());
}
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/tools.c Tue Aug 31 18:24:09 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/tools.c Sun Jul 10 02:54:48 2011
@@ -85,13 +85,20 @@
int i;
/* Release the main ports as early as possible */
for (i = 0; i < NHttpSockets; i++) {
- if (HttpSockets[i] >= 0)
- close(HttpSockets[i]);
- }
- if (theInIcpConnection >= 0)
- close(theInIcpConnection);
- if (theOutIcpConnection >= 0 && theOutIcpConnection !=
theInIcpConnection)
- close(theOutIcpConnection);
+ if (HttpSockets[i] >= 0)
+ close(HttpSockets[i]);
+ }
+ if (theInIcpConnection4 >= 0)
+ close(theInIcpConnection4);
+ if (theOutIcpConnection4 >= 0 &&
+ theOutIcpConnection4 != theInIcpConnection4)
+ close(theOutIcpConnection4);
+
+ if (theInIcpConnection6 >= 0)
+ close(theInIcpConnection6);
+ if (theOutIcpConnection6 >= 0 &&
+ theOutIcpConnection6 != theInIcpConnection6)
+ close(theOutIcpConnection6);
}
static char *
--
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.