gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19212 - in gnunet/src: . dns exit include vpn


From: gnunet
Subject: [GNUnet-SVN] r19212 - in gnunet/src: . dns exit include vpn
Date: Tue, 17 Jan 2012 20:22:23 +0100

Author: grothoff
Date: 2012-01-17 20:22:23 +0100 (Tue, 17 Jan 2012)
New Revision: 19212

Modified:
   gnunet/src/Makefile.am
   gnunet/src/dns/Makefile.am
   gnunet/src/dns/gnunet-service-dns.c
   gnunet/src/exit/Makefile.am
   gnunet/src/exit/gnunet-daemon-exit.c
   gnunet/src/include/gnunet_tun_lib.h
   gnunet/src/vpn/Makefile.am
   gnunet/src/vpn/gnunet-service-vpn.c
Log:
-move IPv4 header initialization to tun library

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/Makefile.am      2012-01-17 19:22:23 UTC (rev 19212)
@@ -10,6 +10,7 @@
   include $(INTLEMU_SUBDIRS) \
   util \
   hello \
+  tun \
   block \
   statistics \
   arm \

Modified: gnunet/src/dns/Makefile.am
===================================================================
--- gnunet/src/dns/Makefile.am  2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/dns/Makefile.am  2012-01-17 19:22:23 UTC (rev 19212)
@@ -70,6 +70,7 @@
 gnunet_service_dns_SOURCES = \
  gnunet-service-dns.c 
 gnunet_service_dns_LDADD = \
+  $(top_builddir)/src/tun/libgnunettun.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)

Modified: gnunet/src/dns/gnunet-service-dns.c
===================================================================
--- gnunet/src/dns/gnunet-service-dns.c 2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/dns/gnunet-service-dns.c 2012-01-17 19:22:23 UTC (rev 19212)
@@ -32,9 +32,6 @@
 #include "gnunet_statistics_service.h"
 #include "gnunet_tun_lib.h"
 
-#ifndef IPVERSION
-#define IPVERSION 4
-#endif
 
 /**
  * Phases each request goes through.
@@ -387,21 +384,14 @@
        
        spt = dst->sin_port;
        dpt = src->sin_port;
-       ip.header_length =  sizeof (struct GNUNET_TUN_IPv4Header) / 4;
-       ip.version = IPVERSION; /* aka 4 */
-       ip.diff_serv = 0;
-       ip.total_length = htons ((uint16_t) reply_len - off);
-       ip.identification = (uint16_t) GNUNET_CRYPTO_random_u32 
(GNUNET_CRYPTO_QUALITY_WEAK, 
-                                                       65536);
-       ip.flags = 0;
-       ip.fragmentation_offset = 0;
-       ip.ttl = 255; /* or lower? */
-       ip.protocol = IPPROTO_UDP;
-       ip.checksum = 0; /* checksum is optional */
-       ip.source_address = dst->sin_addr;
-       ip.destination_address = src->sin_addr;
-       ip.checksum = GNUNET_CRYPTO_crc16_n (&ip, sizeof (ip));
+       GNUNET_TUN_initialize_ipv4_header (&ip,
+                                          IPPROTO_UDP,
+                                          reply_len - off - sizeof (struct 
GNUNET_TUN_IPv4Header),
+                                          &dst->sin_addr,
+                                          &src->sin_addr);
 
+
+
        udp_crc_sum = GNUNET_CRYPTO_crc16_step (udp_crc_sum, 
                                                &ip.source_address,
                                                sizeof (struct in_addr) * 2);
@@ -1062,7 +1052,7 @@
   case ETH_P_IPV4:
     ip4 = (const struct GNUNET_TUN_IPv4Header *) &tun[1];
     if ( (msize < sizeof (struct GNUNET_TUN_IPv4Header)) ||
-        (ip4->version != IPVERSION) ||
+        (ip4->version != 4) ||
         (ip4->header_length != sizeof (struct GNUNET_TUN_IPv4Header) / 4) ||
         (ntohs(ip4->total_length) != msize) ||
         (ip4->protocol != IPPROTO_UDP) )
@@ -1119,7 +1109,7 @@
 
   /* setup new request */
   rr->phase = RP_INIT;
-  if (ip4->version == IPVERSION)
+  if (ip4->version == 4)
   {
     srca4 = (struct sockaddr_in*) &rr->src_addr;
     dsta4 = (struct sockaddr_in*) &rr->dst_addr;

Modified: gnunet/src/exit/Makefile.am
===================================================================
--- gnunet/src/exit/Makefile.am 2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/exit/Makefile.am 2012-01-17 19:22:23 UTC (rev 19212)
@@ -37,6 +37,7 @@
 gnunet_daemon_exit_LDADD = \
   $(top_builddir)/src/core/libgnunetcore.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(top_builddir)/src/tun/libgnunettun.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/mesh/libgnunetmesh.la \
   $(GN_LIBINTL)

Modified: gnunet/src/exit/gnunet-daemon-exit.c
===================================================================
--- gnunet/src/exit/gnunet-daemon-exit.c        2012-01-17 19:06:15 UTC (rev 
19211)
+++ gnunet/src/exit/gnunet-daemon-exit.c        2012-01-17 19:22:23 UTC (rev 
19212)
@@ -1065,21 +1065,11 @@
     return;
   }
 
-  pkt4->version = 4;
-  pkt4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
-  pkt4->diff_serv = 0;
-  pkt4->total_length = htons ((uint16_t) (sizeof (struct 
GNUNET_TUN_IPv4Header) + len));
-  pkt4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 
(GNUNET_CRYPTO_QUALITY_WEAK, 
-                                                             UINT16_MAX + 1);
-  pkt4->flags = 0;
-  pkt4->fragmentation_offset = 0;
-  pkt4->ttl = 255;
-  pkt4->protocol = protocol;
-  pkt4->checksum = 0;
-  pkt4->destination_address = dst_address->address.ipv4;
-  pkt4->source_address = src_address->address.ipv4;
-  pkt4->checksum = GNUNET_CRYPTO_crc16_n (pkt4, sizeof (struct 
GNUNET_TUN_IPv4Header));
-
+  GNUNET_TUN_initialize_ipv4_header (pkt4,
+                                    protocol,
+                                    len,
+                                    &src_address->address.ipv4,
+                                    &dst_address->address.ipv4);
   switch (protocol)
   {
   case IPPROTO_UDP:

Modified: gnunet/src/include/gnunet_tun_lib.h
===================================================================
--- gnunet/src/include/gnunet_tun_lib.h 2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/include/gnunet_tun_lib.h 2012-01-17 19:22:23 UTC (rev 19212)
@@ -148,4 +148,21 @@
 GNUNET_NETWORK_STRUCT_END
 
 
+/**
+ * Initialize an IPv4 header.
+ *
+ * @param ip header to initialize
+ * @param protocol protocol to use (i.e. IPPROTO_UDP)
+ * @param payload_length number of bytes of payload that follow (excluding 
IPv4 header)
+ * @param src source IP address to use
+ * @param dst destination IP address to use
+ */
+void
+GNUNET_TUN_initialize_ipv4_header (struct GNUNET_TUN_IPv4Header *ip,
+                                  uint8_t protocol,
+                                  uint16_t payload_length,
+                                  const struct in_addr *src,
+                                  const struct in_addr *dst);
+
+
 #endif

Modified: gnunet/src/vpn/Makefile.am
===================================================================
--- gnunet/src/vpn/Makefile.am  2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/vpn/Makefile.am  2012-01-17 19:22:23 UTC (rev 19212)
@@ -40,6 +40,7 @@
  gnunet-service-vpn.c 
 gnunet_service_vpn_LDADD = \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
+  $(top_builddir)/src/tun/libgnunettun.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(top_builddir)/src/mesh/libgnunetmesh.la \
   $(GN_LIBINTL)

Modified: gnunet/src/vpn/gnunet-service-vpn.c
===================================================================
--- gnunet/src/vpn/gnunet-service-vpn.c 2012-01-17 19:06:15 UTC (rev 19211)
+++ gnunet/src/vpn/gnunet-service-vpn.c 2012-01-17 19:22:23 UTC (rev 19212)
@@ -1422,23 +1422,11 @@
        msg->size = htons (size);
        tun->flags = htons (0);
        tun->proto = htons (ETH_P_IPV4);
-       ipv4->version = 4;
-       ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
-       ipv4->diff_serv = 0;
-       ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) +
-                                   sizeof (struct GNUNET_TUN_UdpHeader) +
-                                   mlen);
-       ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 
(GNUNET_CRYPTO_QUALITY_WEAK, 
-                                                                   UINT16_MAX 
+ 1);
-       ipv4->flags = 0;
-       ipv4->fragmentation_offset = 0;
-       ipv4->ttl = 255;
-       ipv4->protocol = IPPROTO_UDP;
-       ipv4->checksum = 0; 
-       ipv4->source_address = ts->destination_ip.v4;
-       ipv4->destination_address = ts->source_ip.v4;
-       ipv4->checksum =
-         GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header));
+       GNUNET_TUN_initialize_ipv4_header (ipv4,
+                                          IPPROTO_UDP,
+                                          sizeof (struct GNUNET_TUN_UdpHeader) 
+ mlen,
+                                          &ts->destination_ip.v4,
+                                          &ts->source_ip.v4);
        if (0 == ntohs (reply->source_port))
          udp->spt = htons (ts->destination_port);
        else
@@ -1600,23 +1588,11 @@
        msg->size = htons (size);
        tun->flags = htons (0);
        tun->proto = htons (ETH_P_IPV4);
-       ipv4->version = 4;
-       ipv4->header_length = sizeof (struct GNUNET_TUN_IPv4Header) / 4;
-       ipv4->diff_serv = 0;
-       ipv4->total_length = htons (sizeof (struct GNUNET_TUN_IPv4Header) +
-                                   sizeof (struct GNUNET_TUN_TcpHeader) +
-                                   mlen);
-       ipv4->identification = (uint16_t) GNUNET_CRYPTO_random_u32 
(GNUNET_CRYPTO_QUALITY_WEAK, 
-                                                                   UINT16_MAX 
+ 1);
-       ipv4->flags = 0;
-       ipv4->fragmentation_offset = 0;
-       ipv4->ttl = 255;
-       ipv4->protocol = IPPROTO_TCP;
-       ipv4->checksum = 0; 
-       ipv4->source_address = ts->destination_ip.v4;
-       ipv4->destination_address = ts->source_ip.v4;
-       ipv4->checksum =
-         GNUNET_CRYPTO_crc16_n (ipv4, sizeof (struct GNUNET_TUN_IPv4Header));
+       GNUNET_TUN_initialize_ipv4_header (ipv4,
+                                          IPPROTO_TCP,
+                                          sizeof (struct GNUNET_TUN_TcpHeader) 
+ mlen,
+                                          &ts->destination_ip.v4,
+                                          &ts->source_ip.v4);
        *tcp = data->tcp_header;
        tcp->spt = htons (ts->destination_port);
        tcp->dpt = htons (ts->source_port);




reply via email to

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