gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18915 - in gnunet/src: dns include vpn


From: gnunet
Subject: [GNUnet-SVN] r18915 - in gnunet/src: dns include vpn
Date: Mon, 2 Jan 2012 05:37:59 +0100

Author: grothoff
Date: 2012-01-02 05:37:59 +0100 (Mon, 02 Jan 2012)
New Revision: 18915

Added:
   gnunet/src/dns/dns.conf
   gnunet/src/dns/dns.h
Modified:
   gnunet/src/dns/Makefile.am
   gnunet/src/dns/dns_api.c
   gnunet/src/dns/gnunet-service-dns.c
   gnunet/src/include/gnunet_dns_service.h
   gnunet/src/vpn/gnunet-daemon-exit.c
   gnunet/src/vpn/gnunet-daemon-vpn-helper.c
   gnunet/src/vpn/gnunet-daemon-vpn.c
   gnunet/src/vpn/gnunet-daemon-vpn.h
   gnunet/src/vpn/gnunet-vpn-packet.h
Log:
-small steps towards saner DNS API

Modified: gnunet/src/dns/Makefile.am
===================================================================
--- gnunet/src/dns/Makefile.am  2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/dns/Makefile.am  2012-01-02 04:37:59 UTC (rev 18915)
@@ -12,6 +12,9 @@
 
 plugindir = $(libdir)/gnunet
 
+dist_pkgcfg_DATA = \
+  dns.conf
+
 if LINUX
 HIJACKBIN = gnunet-helper-hijack-dns
 install-exec-hook:
@@ -52,7 +55,7 @@
 
 
 libgnunetdns_la_SOURCES = \
- dns_api.c 
+ dns_api.c dns.h
 libgnunetdns_la_LIBADD = \
  $(top_builddir)/src/util/libgnunetutil.la $(XLIB)
 libgnunetdns_la_LDFLAGS = \

Added: gnunet/src/dns/dns.conf
===================================================================
--- gnunet/src/dns/dns.conf                             (rev 0)
+++ gnunet/src/dns/dns.conf     2012-01-02 04:37:59 UTC (rev 18915)
@@ -0,0 +1,11 @@
+[dns]
+AUTOSTART = YES
+PORT = 0
+HOSTNAME = localhost
+HOME = $SERVICEHOME
+CONFIG = $DEFAULTCONFIG
+BINARY = gnunet-service-dns
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/gnunet-service-dns.sock
+PROVIDE_EXIT = NO

Added: gnunet/src/dns/dns.h
===================================================================
--- gnunet/src/dns/dns.h                                (rev 0)
+++ gnunet/src/dns/dns.h        2012-01-02 04:37:59 UTC (rev 18915)
@@ -0,0 +1,54 @@
+/*
+      This file is part of GNUnet
+      (C) 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
+
+      GNUnet is free software; you can redistribute it and/or modify
+      it under the terms of the GNU General Public License as published
+      by the Free Software Foundation; either version 2, or (at your
+      option) any later version.
+
+      GNUnet is distributed in the hope that it will be useful, but
+      WITHOUT ANY WARRANTY; without even the implied warranty of
+      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+      General Public License for more details.
+
+      You should have received a copy of the GNU General Public License
+      along with GNUnet; see the file COPYING.  If not, write to the
+      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+      Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * @file dns/dns.h
+ * @brief IPC messages between DNS API and DNS service
+ * @author Philipp Toelke
+ * @author Christian Grothoff
+ */
+#ifndef DNS_H
+#define DNS_H
+
+GNUNET_NETWORK_STRUCT_BEGIN
+
+struct query_packet
+{
+  struct GNUNET_MessageHeader hdr;
+
+        /**
+        * The IP-Address this query was originally sent to
+        */
+  char orig_to[16];
+        /**
+        * The IP-Address this query was originally sent from
+        */
+  char orig_from[16];
+  char addrlen;
+        /**
+        * The UDP-Port this query was originally sent from
+        */
+  uint16_t src_port GNUNET_PACKED;
+
+  unsigned char data[1];        /* The DNS-Packet */
+};
+GNUNET_NETWORK_STRUCT_END
+
+#endif

Modified: gnunet/src/dns/dns_api.c
===================================================================
--- gnunet/src/dns/dns_api.c    2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/dns/dns_api.c    2012-01-02 04:37:59 UTC (rev 18915)
@@ -34,8 +34,17 @@
 #include <block_dns.h>
 
 #include "gnunet_dns_service.h"
+#include "dns.h"
 
+struct query_packet_list
+{
+  struct query_packet_list *next GNUNET_PACKED;
+  struct query_packet_list *prev GNUNET_PACKED;
+  struct query_packet pkt;
+};
 
+
+
 struct GNUNET_DNS_Handle
 {
   struct query_packet_list *head;
@@ -237,9 +246,9 @@
  * FIXME: we should not expost our internal structures like this.
  * Just a quick initial hack.
  */
-void
-GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h,
-                         struct query_packet_list *q)
+static void
+queue_request (struct GNUNET_DNS_Handle *h,
+              struct query_packet_list *q)
 {
   GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, q);
   if (h->dns_connection != NULL && h->dns_transmit_handle == NULL)
@@ -251,7 +260,79 @@
 }
 
 
+
+/**
+ * Process a DNS request sent to an IPv4 resolver.  Pass it
+ * to the DNS service for resolution.
+ *
+ * @param h DNS handle
+ * @param dst_ip destination IPv4 address
+ * @param src_ip source IPv4 address (usually local machine)
+ * @param src_port source port (to be used for reply)
+ * @param udp_packet_len length of the UDP payload in bytes
+ * @param udp_packet UDP payload
+ */
 void
+GNUNET_DNS_queue_request_v4 (struct GNUNET_DNS_Handle *h,
+                            const struct in_addr *dst_ip,
+                            const struct in_addr *src_ip,
+                            uint16_t src_port,
+                            size_t udp_packet_len,
+                            const char *udp_packet)
+{
+  size_t len = sizeof (struct query_packet) + udp_packet_len - 1;
+  struct query_packet_list *query =
+    GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+                  sizeof (struct answer_packet));
+  query->pkt.hdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
+  query->pkt.hdr.size = htons (len);
+  memcpy (query->pkt.orig_to, dst_ip, 4);
+  memcpy (query->pkt.orig_from, src_ip, 4);
+  query->pkt.addrlen = 4;
+  query->pkt.src_port = htons (src_port);
+  memcpy (query->pkt.data, udp_packet, udp_packet_len);  
+  queue_request (h, query);
+}
+
+
+/**
+ * Process a DNS request sent to an IPv6 resolver.  Pass it
+ * to the DNS service for resolution.
+ *
+ * @param h DNS handle
+ * @param dst_ip destination IPv6 address
+ * @param src_ip source IPv6 address (usually local machine)
+ * @param src_port source port (to be used for reply)
+ * @param udp_packet_len length of the UDP payload in bytes
+ * @param udp_packet UDP payload
+ */
+void
+GNUNET_DNS_queue_request_v6 (struct GNUNET_DNS_Handle *h,
+                            const struct in6_addr *dst_ip,
+                            const struct in6_addr *src_ip,
+                            uint16_t src_port,
+                            size_t udp_packet_len,
+                            const char *udp_packet)
+{
+  size_t len =
+    sizeof (struct query_packet) + udp_packet_len - 1;
+  struct query_packet_list *query =
+    GNUNET_malloc (len + sizeof (struct answer_packet_list) -
+                  sizeof (struct answer_packet));
+  query->pkt.hdr.type =
+    htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
+  query->pkt.hdr.size = htons (len);
+  memcpy (query->pkt.orig_to, dst_ip, 16);
+  memcpy (query->pkt.orig_from, src_ip, 16);
+  query->pkt.addrlen = 16;
+  query->pkt.src_port = htons (src_port);
+  memcpy (query->pkt.data, udp_packet,
+         udp_packet_len);
+  queue_request (h, query);
+}
+
+
+void
 GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h)
 {
   if (h->dns_connection != NULL)
@@ -261,3 +342,5 @@
   }
   GNUNET_free (h);
 }
+
+/* end of dns_api.c */

Modified: gnunet/src/dns/gnunet-service-dns.c
===================================================================
--- gnunet/src/dns/gnunet-service-dns.c 2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/dns/gnunet-service-dns.c 2012-01-02 04:37:59 UTC (rev 18915)
@@ -41,10 +41,10 @@
 #include "gnunet_mesh_service.h"
 #include "gnunet_signatures.h"
 
+#include "dns.h"
 
 
 
-
 static struct GNUNET_MESH_Handle *mesh_handle;
 
 static struct GNUNET_CONNECTION_TransmitHandle *server_notify;

Modified: gnunet/src/include/gnunet_dns_service.h
===================================================================
--- gnunet/src/include/gnunet_dns_service.h     2012-01-02 03:57:34 UTC (rev 
18914)
+++ gnunet/src/include/gnunet_dns_service.h     2012-01-02 04:37:59 UTC (rev 
18915)
@@ -36,36 +36,7 @@
 #include "gnunet_common.h"
 #include "gnunet_util_lib.h"
 
-GNUNET_NETWORK_STRUCT_BEGIN
 
-struct query_packet
-{
-  struct GNUNET_MessageHeader hdr;
-
-        /**
-        * The IP-Address this query was originally sent to
-        */
-  char orig_to[16];
-        /**
-        * The IP-Address this query was originally sent from
-        */
-  char orig_from[16];
-        /**
-        * The UDP-Portthis query was originally sent from
-        */
-  char addrlen;
-  uint16_t src_port GNUNET_PACKED;
-
-  unsigned char data[1];        /* The DNS-Packet */
-};
-
-struct query_packet_list
-{
-  struct query_packet_list *next GNUNET_PACKED;
-  struct query_packet_list *prev GNUNET_PACKED;
-  struct query_packet pkt;
-};
-
 enum GNUNET_DNS_ANSWER_Subtype
 {
     /**
@@ -106,6 +77,7 @@
   uint32_t service_type GNUNET_PACKED;
 };
 
+GNUNET_NETWORK_STRUCT_BEGIN
 struct answer_packet
 {
   /* General data */
@@ -161,14 +133,45 @@
 
 
 /**
- * FIXME: we should not expost our internal structures like this.
- * Just a quick initial hack.
+ * Process a DNS request sent to an IPv4 resolver.  Pass it
+ * to the DNS service for resolution.
+ *
+ * @param h DNS handle
+ * @param dst_ip destination IPv4 address
+ * @param src_ip source IPv4 address (usually local machine)
+ * @param src_port source port (to be used for reply)
+ * @param udp_packet_len length of the UDP payload in bytes
+ * @param udp_packet UDP payload
  */
 void
-GNUNET_DNS_queue_request (struct GNUNET_DNS_Handle *h,
-                         struct query_packet_list *q);
+GNUNET_DNS_queue_request_v4 (struct GNUNET_DNS_Handle *h,
+                            const struct in_addr *dst_ip,
+                            const struct in_addr *src_ip,
+                            uint16_t src_port,
+                            size_t udp_packet_len,
+                            const char *udp_packet);
 
+/**
+ * Process a DNS request sent to an IPv6 resolver.  Pass it
+ * to the DNS service for resolution.
+ *
+ * @param h DNS handle
+ * @param dst_ip destination IPv6 address
+ * @param src_ip source IPv6 address (usually local machine)
+ * @param src_port source port (to be used for reply)
+ * @param udp_packet_len length of the UDP payload in bytes
+ * @param udp_packet UDP payload
+ */
 void
+GNUNET_DNS_queue_request_v6 (struct GNUNET_DNS_Handle *h,
+                            const struct in6_addr *dst_ip,
+                            const struct in6_addr *src_ip,
+                            uint16_t src_port,
+                            size_t udp_packet_len,
+                            const char *udp_packet);
+
+
+void
 GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *h);
 
 #endif

Modified: gnunet/src/vpn/gnunet-daemon-exit.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-exit.c 2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/vpn/gnunet-daemon-exit.c 2012-01-02 04:37:59 UTC (rev 18915)
@@ -550,11 +550,10 @@
   else if (ntohs (pkt_tun->tun.type) == 0x0800)
   {
     struct ip_pkt *pkt4 = (struct ip_pkt *) pkt_tun;
-    uint32_t tmp = pkt4->ip_hdr.dadr;
 
     if (IPPROTO_UDP == pkt4->ip_hdr.proto)
       udp_from_helper (&((struct ip_udp *) pkt4)->udp_hdr,
-                       (unsigned char *) &tmp, 4);
+                       (unsigned char *) &pkt4->ip_hdr.dadr, 4);
     else if (IPPROTO_TCP == pkt4->ip_hdr.proto)
     {
       size_t pktlen = ntohs (pkt4->ip_hdr.tot_lngth);
@@ -563,7 +562,7 @@
       pktlen -= 4 * pkt4->ip_hdr.hdr_lngth;
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "-hdr: %d\n", pktlen);
       tcp_from_helper (&((struct ip_tcp *) pkt4)->tcp_hdr,
-                       (unsigned char *) &tmp, 4, pktlen);
+                       (unsigned char *) &pkt4->ip_hdr.dadr, 4, pktlen);
     }
   }
   else
@@ -860,8 +859,7 @@
   pkt4->ip_hdr.proto = protocol;
   pkt4->ip_hdr.chks = 0;        /* Will be calculated later */
 
-  memcpy (&tmp, ipaddress, 4);
-  pkt4->ip_hdr.dadr = tmp;
+  memcpy (&pkt4->ip_hdr.dadr, ipaddress, sizeof (struct in_addr));
 
   /* Generate a new src-address */
   char *ipv4addr;
@@ -883,7 +881,7 @@
 
   tmp |= ntohl (*((uint32_t *) tunnel)) & (~tmp2);
 
-  pkt4->ip_hdr.sadr = tmp;
+  pkt4->ip_hdr.sadr.s_addr = tmp;
 
   memcpy (&state->redirect_info.addr, &tmp, 4);
   if (IPPROTO_UDP == protocol)
@@ -903,10 +901,8 @@
     pkt4_tcp->tcp_hdr.crc = 0;
     uint32_t sum = 0;
 
-    tmp = pkt4->ip_hdr.sadr;
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
-    tmp = pkt4->ip_hdr.dadr;
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 
sizeof (struct in_addr));
+    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 
sizeof (struct in_addr));
 
     tmp = (protocol << 16) | (0xffff & pktlen);
 
@@ -947,7 +943,7 @@
   pkt6->ip6_hdr.paylgth = htons (pktlen);
   pkt6->ip6_hdr.hoplmt = 64;
 
-  memcpy (pkt6->ip6_hdr.dadr, ipaddress, 16);
+  memcpy (&pkt6->ip6_hdr.dadr, ipaddress, sizeof (struct in6_addr));
 
   /* Generate a new src-address
    * This takes as much from the address of the tunnel as fits into

Modified: gnunet/src/vpn/gnunet-daemon-vpn-helper.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn-helper.c   2012-01-02 03:57:34 UTC (rev 
18914)
+++ gnunet/src/vpn/gnunet-daemon-vpn-helper.c   2012-01-02 04:37:59 UTC (rev 
18915)
@@ -338,29 +338,20 @@
       if (ntohs (pkt6_udp->udp_hdr.dpt) == 53)
       {
         /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
-        size_t len =
-            sizeof (struct query_packet) + ntohs (pkt6_udp->udp_hdr.len) - 9;
+       GNUNET_DNS_queue_request_v6 (dns_handle,
+                                    &pkt6->ip6_hdr.dadr,
+                                    &pkt6->ip6_hdr.sadr,
+                                    ntohs (pkt6_udp->udp_hdr.spt),
+                                    ntohs (pkt6_udp->udp_hdr.len) - 8,
+                                    (const void*) pkt6_udp->data);
 
-        struct query_packet_list *query =
-            GNUNET_malloc (len + sizeof (struct answer_packet_list) -
-                           sizeof (struct answer_packet));
-        query->pkt.hdr.type =
-            htons (GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
-        query->pkt.hdr.size = htons (len);
-        memcpy (query->pkt.orig_to, &pkt6->ip6_hdr.dadr, 16);
-        memcpy (query->pkt.orig_from, &pkt6->ip6_hdr.sadr, 16);
-        query->pkt.addrlen = 16;
-        query->pkt.src_port = pkt6_udp->udp_hdr.spt;
-        memcpy (query->pkt.data, pkt6_udp->data,
-                ntohs (pkt6_udp->udp_hdr.len) - 8);
-       GNUNET_DNS_queue_request (dns_handle, query);
         break;
       }
       /* fall through */
     case IPPROTO_TCP:
       pkt6_tcp = (struct ip6_tcp *) pkt6;
 
-      if ((key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
+      if ((key = address6_mapping_exists (&pkt6->ip6_hdr.dadr)) != NULL)
       {
         struct map_entry *me = GNUNET_CONTAINER_multihashmap_get (hashmap, 
key);
 
@@ -487,16 +478,13 @@
       }
       else
       {
+       char pbuf[INET6_ADDRSTRLEN];
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                    "Packet to 
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x, which 
has no mapping\n",
-                    pkt6->ip6_hdr.dadr[0], pkt6->ip6_hdr.dadr[1],
-                    pkt6->ip6_hdr.dadr[2], pkt6->ip6_hdr.dadr[3],
-                    pkt6->ip6_hdr.dadr[4], pkt6->ip6_hdr.dadr[5],
-                    pkt6->ip6_hdr.dadr[6], pkt6->ip6_hdr.dadr[7],
-                    pkt6->ip6_hdr.dadr[8], pkt6->ip6_hdr.dadr[9],
-                    pkt6->ip6_hdr.dadr[10], pkt6->ip6_hdr.dadr[11],
-                    pkt6->ip6_hdr.dadr[12], pkt6->ip6_hdr.dadr[13],
-                    pkt6->ip6_hdr.dadr[14], pkt6->ip6_hdr.dadr[15]);
+                    "Packet to %s, which has no mapping\n",
+                   inet_ntop (AF_INET6,
+                              &pkt6->ip6_hdr.dadr,
+                              pbuf,
+                              sizeof (pbuf)));
       }
       break;
     case 0x3a:
@@ -504,7 +492,7 @@
       pkt6_icmp = (struct ip6_icmp *) pkt6;
       /* If this packet is an icmp-echo-request and a mapping exists, answer */
       if (pkt6_icmp->icmp_hdr.type == 0x80 &&
-          (key = address6_mapping_exists (pkt6->ip6_hdr.dadr)) != NULL)
+          (key = address6_mapping_exists (&pkt6->ip6_hdr.dadr)) != NULL)
       {
         GNUNET_free (key);
         pkt6_icmp = GNUNET_malloc (ntohs (pkt6->shdr.size));
@@ -528,25 +516,16 @@
     /* Send dns-packets to the service-dns */
     if (pkt->ip_hdr.proto == IPPROTO_UDP && ntohs (udp->udp_hdr.dpt) == 53)
     {
-      /* 9 = 8 for the udp-header + 1 for the unsigned char data[1]; */
-      size_t len = sizeof (struct query_packet) + ntohs (udp->udp_hdr.len) - 9;
-
-      struct query_packet_list *query =
-          GNUNET_malloc (len + sizeof (struct answer_packet_list) -
-                         sizeof (struct answer_packet));
-      query->pkt.hdr.type = htons 
(GNUNET_MESSAGE_TYPE_VPN_DNS_LOCAL_QUERY_DNS);
-      query->pkt.hdr.size = htons (len);
-      memcpy (query->pkt.orig_to, &pkt->ip_hdr.dadr, 4);
-      memcpy (query->pkt.orig_from, &pkt->ip_hdr.sadr, 4);
-      query->pkt.addrlen = 4;
-      query->pkt.src_port = udp->udp_hdr.spt;
-      memcpy (query->pkt.data, udp->data, ntohs (udp->udp_hdr.len) - 8);
-      
-      GNUNET_DNS_queue_request (dns_handle, query);
+      GNUNET_DNS_queue_request_v4 (dns_handle,
+                                  &pkt->ip_hdr.dadr,
+                                  &pkt->ip_hdr.sadr,
+                                  ntohs (udp->udp_hdr.spt),
+                                  ntohs (udp->udp_hdr.len) - 8,
+                                  (const void*) udp->data);
     }
     else
     {
-      uint32_t dadr = pkt->ip_hdr.dadr;
+      uint32_t dadr = pkt->ip_hdr.dadr.s_addr;
       unsigned char *c = (unsigned char *) &dadr;
 
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Packet to %d.%d.%d.%d, proto %x\n",

Modified: gnunet/src/vpn/gnunet-daemon-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.c  2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/vpn/gnunet-daemon-vpn.c  2012-01-02 04:37:59 UTC (rev 18915)
@@ -118,8 +118,9 @@
  * @return the hash of the IP-Address if a mapping exists, NULL otherwise
  */
 GNUNET_HashCode *
-address6_mapping_exists (unsigned char addr[])
+address6_mapping_exists (struct in6_addr *v6addr)
 {
+  unsigned char *addr = (unsigned char*) v6addr;
   GNUNET_HashCode *key = GNUNET_malloc (sizeof (GNUNET_HashCode));
   unsigned char *k = (unsigned char *) key;
 
@@ -375,9 +376,11 @@
  * Create a new Address from an answer-packet
  */
 void
-new_ip6addr (unsigned char *buf, const GNUNET_HashCode * peer,
+new_ip6addr (struct in6_addr *v6addr,
+            const GNUNET_HashCode * peer,
              const GNUNET_HashCode * service_desc)
 {                               /* {{{ */
+  unsigned char *buf = (unsigned char*) v6addr;
   char *ipv6addr;
   unsigned long long ipv6prefix;
 
@@ -415,8 +418,10 @@
  * Create a new Address from an answer-packet
  */
 void
-new_ip6addr_remote (unsigned char *buf, unsigned char *addr, char addrlen)
+new_ip6addr_remote (struct in6_addr *v6addr,
+                   unsigned char *addr, char addrlen)
 {                               /* {{{ */
+  unsigned char *buf = (unsigned char*) v6addr;
   char *ipv6addr;
   unsigned long long ipv6prefix;
 
@@ -529,7 +534,8 @@
     unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
     unsigned char *k = (unsigned char *) &key;
 
-    new_ip6addr (c, &pkt->service_descr.peer,
+    new_ip6addr ((struct in6_addr*) c, 
+                &pkt->service_descr.peer,
                  &pkt->service_descr.service_descriptor);
     /*
      * Copy the newly generated ip-address to the key backwarts (as only the 
first part is hashed)
@@ -655,7 +661,8 @@
 
     unsigned char *c = ((unsigned char *) pkt) + ntohs (pkt->addroffset);
 
-    new_ip6addr_remote (c, pkt->addr, pkt->addrsize);
+    new_ip6addr_remote ((struct in6_addr*) c,
+                       pkt->addr, pkt->addrsize);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "New mapping to 
%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\n",
                 c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7], c[8], c[9],
@@ -877,9 +884,9 @@
     GNUNET_assert (pkt6 != NULL);
 
     if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK)
-      new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
+      new_ip6addr (&pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
     else
-      new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
+      new_ip6addr_remote (&pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
@@ -906,12 +913,12 @@
                      GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
                                                             "IPV6ADDR",
                                                             &ipv6addr));
-      inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
+      inet_pton (AF_INET6, ipv6addr, &pkt6->ip6_hdr.dadr);
       GNUNET_free (ipv6addr);
     }
     memcpy (&pkt6->udp_hdr, pkt, ntohs (pkt->len));
 
-    GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
+    GNUNET_HashCode *key = address6_mapping_exists (&pkt6->ip6_hdr.sadr);
 
     GNUNET_assert (key != NULL);
 
@@ -968,7 +975,7 @@
     uint32_t sadr;
 
     new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen);
-    pkt4->ip_hdr.sadr = sadr;
+    pkt4->ip_hdr.sadr.s_addr = sadr;
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Relaying calc:%d gnu:%d udp:%d bytes!\n", size,
@@ -1001,11 +1008,11 @@
                                                             &ipv4addr));
       inet_pton (AF_INET, ipv4addr, &dadr);
       GNUNET_free (ipv4addr);
-      pkt4->ip_hdr.dadr = dadr;
+      pkt4->ip_hdr.dadr.s_addr = dadr;
     }
     memcpy (&pkt4->udp_hdr, pkt, ntohs (pkt->len));
 
-    GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr);
+    GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr.s_addr);
 
     GNUNET_assert (key != NULL);
 
@@ -1061,9 +1068,9 @@
     GNUNET_assert (pkt6 != NULL);
 
     if (ntohs (message->type) == GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK)
-      new_ip6addr (pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
+      new_ip6addr (&pkt6->ip6_hdr.sadr, &other->hashPubKey, desc);
     else
-      new_ip6addr_remote (pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
+      new_ip6addr_remote (&pkt6->ip6_hdr.sadr, s->addr, s->addrlen);
 
     pkt6->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
     pkt6->shdr.size = htons (size);
@@ -1086,12 +1093,12 @@
                      GNUNET_CONFIGURATION_get_value_string (cfg, "vpn",
                                                             "IPV6ADDR",
                                                             &ipv6addr));
-      inet_pton (AF_INET6, ipv6addr, pkt6->ip6_hdr.dadr);
+      inet_pton (AF_INET6, ipv6addr, &pkt6->ip6_hdr.dadr);
       GNUNET_free (ipv6addr);
     }
     memcpy (&pkt6->tcp_hdr, pkt, pktlen);
 
-    GNUNET_HashCode *key = address6_mapping_exists (pkt6->ip6_hdr.sadr);
+    GNUNET_HashCode *key = address6_mapping_exists (&pkt6->ip6_hdr.sadr);
 
     GNUNET_assert (key != NULL);
 
@@ -1141,7 +1148,7 @@
     uint32_t sadr;
 
     new_ip4addr_remote ((unsigned char *) &sadr, s->addr, s->addrlen);
-    pkt4->ip_hdr.sadr = sadr;
+    pkt4->ip_hdr.sadr.s_addr = sadr;
 
     pkt4->shdr.type = htons (GNUNET_MESSAGE_TYPE_VPN_HELPER);
     pkt4->shdr.size = htons (size);
@@ -1170,12 +1177,12 @@
                                                             &ipv4addr));
       inet_pton (AF_INET, ipv4addr, &dadr);
       GNUNET_free (ipv4addr);
-      pkt4->ip_hdr.dadr = dadr;
+      pkt4->ip_hdr.dadr.s_addr = dadr;
     }
 
     memcpy (&pkt4->tcp_hdr, pkt, pktlen);
 
-    GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr);
+    GNUNET_HashCode *key = address4_mapping_exists (pkt4->ip_hdr.sadr.s_addr);
 
     GNUNET_assert (key != NULL);
 
@@ -1191,10 +1198,8 @@
     uint32_t sum = 0;
     uint32_t tmp;
 
-    tmp = pkt4->ip_hdr.sadr;
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
-    tmp = pkt4->ip_hdr.dadr;
-    sum = calculate_checksum_update (sum, (uint16_t *) & tmp, 4);
+    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.sadr, 4);
+    sum = calculate_checksum_update (sum, (uint16_t *) &pkt4->ip_hdr.dadr, 4);
 
     tmp = (0x06 << 16) | (0xffff & pktlen);     // 0x06 for TCP?
 

Modified: gnunet/src/vpn/gnunet-daemon-vpn.h
===================================================================
--- gnunet/src/vpn/gnunet-daemon-vpn.h  2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/vpn/gnunet-daemon-vpn.h  2012-01-02 04:37:59 UTC (rev 18915)
@@ -53,7 +53,7 @@
 send_udp_service (void *cls, size_t size, void *buf);
 
 GNUNET_HashCode *
-address6_mapping_exists (unsigned char addr[]);
+address6_mapping_exists (struct in6_addr *v6addr);
 GNUNET_HashCode *
 address4_mapping_exists (uint32_t addr);
 

Modified: gnunet/src/vpn/gnunet-vpn-packet.h
===================================================================
--- gnunet/src/vpn/gnunet-vpn-packet.h  2012-01-02 03:57:34 UTC (rev 18914)
+++ gnunet/src/vpn/gnunet-vpn-packet.h  2012-01-02 04:37:59 UTC (rev 18915)
@@ -23,8 +23,8 @@
   unsigned paylgth:16 GNUNET_PACKED;
   unsigned nxthdr:8 GNUNET_PACKED;
   unsigned hoplmt:8 GNUNET_PACKED;
-  unsigned char sadr[16];
-  unsigned char dadr[16];
+  struct in6_addr sadr;
+  struct in6_addr dadr;
 };
 
 struct ip_hdr
@@ -43,8 +43,8 @@
   unsigned proto:8 GNUNET_PACKED;
   unsigned chks:16 GNUNET_PACKED;
 
-  uint32_t sadr GNUNET_PACKED;
-  uint32_t dadr GNUNET_PACKED;
+  struct in_addr sadr GNUNET_PACKED;
+  struct in_addr dadr GNUNET_PACKED;
 };
 
 #define TCP_FLAG_SYN 2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]