gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r19294 - in gnunet/src: include tun


From: gnunet
Subject: [GNUnet-SVN] r19294 - in gnunet/src: include tun
Date: Sat, 21 Jan 2012 00:18:49 +0100

Author: grothoff
Date: 2012-01-21 00:18:49 +0100 (Sat, 21 Jan 2012)
New Revision: 19294

Modified:
   gnunet/src/include/gnunet_tun_lib.h
   gnunet/src/tun/tun.c
Log:
-adding ICMP support to TUN library

Modified: gnunet/src/include/gnunet_tun_lib.h
===================================================================
--- gnunet/src/include/gnunet_tun_lib.h 2012-01-20 22:16:29 UTC (rev 19293)
+++ gnunet/src/include/gnunet_tun_lib.h 2012-01-20 23:18:49 UTC (rev 19294)
@@ -145,6 +145,63 @@
   uint16_t arcount GNUNET_PACKED;
 };
 
+#define        GNUNET_TUN_ICMPTYPE_ECHO_REPLY 0
+#define        GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE 3
+#define        GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH 4
+#define        GNUNET_TUN_ICMPTYPE_REDIRECT_MESSAGE 5
+#define        GNUNET_TUN_ICMPTYPE_ECHO_REQUEST 8
+#define        GNUNET_TUN_ICMPTYPE_ROUTER_ADVERTISEMENT 9
+#define        GNUNET_TUN_ICMPTYPE_ROUTER_SOLICITATION 10
+#define        GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED 11
+
+#define        GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE 1
+#define        GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG 2
+#define        GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED 3
+#define        GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM 4
+#define        GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST 128
+#define        GNUNET_TUN_ICMPTYPE6_ECHO_REPLY 129
+
+/**
+ * ICMP header.
+ */
+struct GNUNET_TUN_IcmpHeader {
+  uint8_t type;                
+  uint8_t code;                 
+  uint16_t crc;
+
+  union {
+    /**
+     * ICMP Echo (request/reply) 
+     */
+    struct {
+      uint16_t identifier;
+      uint16_t sequence_number;
+    } echo;
+
+    /**
+     * ICMP Destination Unreachable (RFC 1191) 
+     */
+    struct ih_pmtu {
+      uint16_t empty;
+      uint16_t next_hop_mtu;
+      /* followed by original IP header + first 8 bytes of original IP 
datagram */
+    } destination_unreachable;
+
+    /**
+     * ICMP Redirect 
+     */        
+    struct in_addr redirect_gateway_address;   
+
+    /**
+     * Placeholder.
+     */
+    int32_t present;
+
+  } quench;
+
+};
+
+
 GNUNET_NETWORK_STRUCT_END
 
 
@@ -239,4 +296,17 @@
                                    uint16_t payload_length);
 
 
+/**
+ * Calculate ICMP checksum.
+ *
+ * @param icmp IMCP header (initialized except for CRC)
+ * @param payload the ICMP payload
+ * @param payload_length number of bytes of ICMP payload
+ */
+void
+GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
+                                   const void *payload,
+                                   uint16_t payload_length);
+
+
 #endif

Modified: gnunet/src/tun/tun.c
===================================================================
--- gnunet/src/tun/tun.c        2012-01-20 22:16:29 UTC (rev 19293)
+++ gnunet/src/tun/tun.c        2012-01-20 23:18:49 UTC (rev 19294)
@@ -242,4 +242,27 @@
 }
 
 
+/**
+ * Calculate ICMP checksum.
+ *
+ * @param icmp IMCP header (initialized except for CRC)
+ * @param payload the ICMP payload
+ * @param payload_length number of bytes of ICMP payload
+ */
+void
+GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
+                                   const void *payload,
+                                   uint16_t payload_length)
+{
+  uint32_t sum;
+
+  icmp->crc = 0;
+  sum = GNUNET_CRYPTO_crc16_step (0,
+                                 icmp,
+                                 sizeof (struct GNUNET_TUN_IcmpHeader));
+  sum = GNUNET_CRYPTO_crc16_step (sum, payload, payload_length);
+  icmp->crc = GNUNET_CRYPTO_crc16_finish (sum);
+}
+
+
 /* end of tun.c */




reply via email to

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