Revision: 14916
Author:   adrian.chadd
Date:     Wed Jul 13 02:00:28 2011
Log:      Begin converting the ICMP/Pinger code to be IPv6 aware.

This just modifies the underlying type to be a struct sockaddr_storage.
What needs to happen:

* IPv6-ify the icmp code
* add an IPv6 ICMP echo/reponse handling module (from Squid-3, most likely)
* correctly set the sockaddr_in / sockaddr_in6 length entries to ensure
  completeness
* robustly test all of this stuff!

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

Modified:
 /playpen/LUSCA_HEAD_ipv6/src/icmp.c
 /playpen/LUSCA_HEAD_ipv6/src/pinger.c
 /playpen/LUSCA_HEAD_ipv6/src/pinger.h

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/icmp.c Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/icmp.c Wed Jul 13 02:00:28 2011
@@ -60,10 +60,18 @@
 icmpSendEcho(struct in_addr to, int opcode, const char *payload, int len)
 {
     static pingerEchoData pecho;
+    struct sockaddr_in *v4;
+
     if (payload && len == 0)
        len = strlen(payload);
     assert(len <= PINGER_PAYLOAD_SZ);
-    pecho.to = to;
+
+    /* Set ipv4 address */
+#warning IPv6-ify this!
+    v4 = (struct sockaddr_in *) &pecho.to;
+    v4->sin_family = AF_INET;
+    v4->sin_port = 0;
+    v4->sin_addr = to;
     pecho.opcode = (unsigned char) opcode;
     pecho.psize = len;
     xmemcpy(pecho.payload, payload, len);
@@ -77,6 +85,7 @@
     static int fail_count = 0;
     pingerReplyData preply;
     static struct sockaddr_in F;
+    struct sockaddr_in *v4;
     commSetSelect(icmp_sock, COMM_SELECT_READ, icmpRecv, NULL, 0);
     memset(&preply, '\0', sizeof(pingerReplyData));
 #if NOTYET
@@ -95,9 +104,14 @@
     fail_count = 0;
     if (n == 0)                        /* test probe from pinger */
        return;
+
+    /* Only handle a IPv4 reply for now */
+#warning IPv6-ify this!
+    v4 = (struct sockaddr_in *) &preply.from;
     F.sin_family = AF_INET;
-    F.sin_addr = preply.from;
+    F.sin_addr = v4->sin_addr;
     F.sin_port = 0;
+
     switch (preply.opcode) {
     case S_ICMP_ECHO:
        break;
@@ -119,10 +133,14 @@
 icmpSend(pingerEchoData * pkt, int len)
 {
     int x;
+    struct sockaddr_in *v4;
+
     if (icmp_sock < 0)
        return;
+#warning IPv6-ify this!
+    v4 = (struct sockaddr_in *) &pkt->to;
     debug(37, 2) ("icmpSend: to %s, opcode %d, len %d\n",
-       inet_ntoa(pkt->to), (int) pkt->opcode, pkt->psize);
+       inet_ntoa(v4->sin_addr), (int) pkt->opcode, pkt->psize);
     x = send(icmp_sock, (char *) pkt, len, 0);
     if (x < 0) {
        debug(37, 1) ("icmpSend: send: %s\n", xstrerror());
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/pinger.c       Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/pinger.c       Wed Jul 13 02:00:28 2011
@@ -360,6 +360,7 @@
     icmpEchoData *echo;
     static pingerReplyData preply;
     struct timeval tv;
+    struct sockaddr_in *v4;

     if (pkt == NULL)
        pkt = xmalloc(MAX_PKT_SZ);
@@ -392,7 +393,16 @@
     if (icmp->icmp_id != icmp_ident)
        return;
     echo = (icmpEchoData *) (void *) (icmp + 1);
-    preply.from = from.sin_addr;
+
+    /* Assign IPv4 address */
+#warning IPv6-ify this!
+
+    v4 = (struct sockaddr_in *) &preply.from;
+    /* This should also match ss_family */
+    v4->sin_family = AF_INET;
+    v4->sin_port = 0;
+    v4->sin_addr = from.sin_addr;
+
     preply.opcode = echo->opcode;
     preply.hops = ipHops(ip->ip_ttl);
     memcpy(&tv, &echo->tv, sizeof(tv));
@@ -460,6 +470,8 @@
     static pingerEchoData pecho;
     int n;
     int guess_size;
+    struct sockaddr_in *v4;
+
     memset(&pecho, '\0', sizeof(pecho));
     n = read(socket_from_squid, (char *) &pecho, sizeof(pecho));
     if (n < 0) {
@@ -479,7 +491,10 @@
        /* don't process this message, but keep running */
        return 0;
     }
-    pingerSendEcho(pecho.to,
+
+#warning IPv6-ify this!
+    v4 = (struct sockaddr_in *) &pecho.to;
+    pingerSendEcho(v4->sin_addr,
        pecho.opcode,
        pecho.payload,
        pecho.psize);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/pinger.h       Sun Jul  4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/pinger.h       Wed Jul 13 02:00:28 2011
@@ -3,15 +3,20 @@

 #define PINGER_PAYLOAD_SZ 8192

+/*
+ * Use sockaddr_storage; it's big enough to
+ * store IPv4 and IPv6 addresses.
+ */
+
 struct _pingerEchoData {
-    struct in_addr to;
+    struct sockaddr_storage to;
     unsigned char opcode;
     int psize;
     char payload[PINGER_PAYLOAD_SZ];
 };

 struct _pingerReplyData {
-    struct in_addr from;
+    struct sockaddr_storage from;
     unsigned char opcode;
     int rtt;
     int hops;

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