multicast, psyc, psycstore, client_manager fixes
[oweals/gnunet.git] / src / include / gnunet_tun_lib.h
index 17cec8d124ed7c5224e85a7452232dea2c124ab3..5c5627ee55b221194525329468c8961d6233dbcf 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010-2013 Christian Grothoff
+     Copyright (C) 2010-2013 Christian Grothoff
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      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.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
 
 
 /**
- * Maximum regex string length for use with GNUNET_TUN_ipv4toregexsearch
+ * Maximum regex string length for use with #GNUNET_TUN_ipv4toregexsearch.
+ *
+ * 8 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-",
+ * one byte for 0-termination.
  */
-#define GNUNET_TUN_IPV4_REGEXLEN 32 + 6
+#define GNUNET_TUN_IPV4_REGEXLEN 16
 
 
 /**
- * Maximum regex string length for use with GNUNET_TUN_ipv6toregexsearch
+ * Maximum regex string length for use with #GNUNET_TUN_ipv6toregexsearch
+ *
+ * 32 bytes for IPv4, 4 bytes for port, 1 byte for "4", 2 bytes for "-",
+ * one byte for 0-termination.
  */
-#define GNUNET_TUN_IPV6_REGEXLEN 128 + 6
+#define GNUNET_TUN_IPV6_REGEXLEN 40
 
 
 GNUNET_NETWORK_STRUCT_BEGIN
@@ -178,6 +184,18 @@ struct GNUNET_TUN_IPv6Header
 } GNUNET_GCC_STRUCT_LAYOUT;
 
 
+/**
+ * TCP flags.
+ */
+#define GNUNET_TUN_TCP_FLAGS_FIN 1
+#define GNUNET_TUN_TCP_FLAGS_SYN 2
+#define GNUNET_TUN_TCP_FLAGS_RST 4
+#define GNUNET_TUN_TCP_FLAGS_PSH 8
+#define GNUNET_TUN_TCP_FLAGS_ACK 16
+#define GNUNET_TUN_TCP_FLAGS_URG 32
+#define GNUNET_TUN_TCP_FLAGS_ECE 64
+#define GNUNET_TUN_TCP_FLAGS_CWR 128
+
 /**
  * TCP packet header.
  */
@@ -523,6 +541,31 @@ struct GNUNET_TUN_DnsSrvRecord
 };
 
 
+/**
+ * Payload of DNS CERT record.
+ */
+struct GNUNET_TUN_DnsCertRecord
+{
+
+  /**
+   * Certificate type
+   */
+  uint16_t cert_type;
+
+  /**
+   * Certificate KeyTag
+   */
+  uint16_t cert_tag;
+
+  /**
+   * Algorithm
+   */
+  uint8_t algorithm;
+
+  /* Followed by the certificate */
+};
+
+
 /**
  * Payload of DNSSEC TLSA record.
  * http://datatracker.ietf.org/doc/draft-ietf-dane-protocol/
@@ -588,6 +631,7 @@ struct GNUNET_TUN_GnsVpnRecord
   /* followed by the servicename */
 };
 
+
 /**
  * DNS query prefix.
  */
@@ -652,16 +696,19 @@ struct GNUNET_TUN_DnsRecordLine
 /**
  * ICMP header.
  */
-struct GNUNET_TUN_IcmpHeader {
-  uint8_t type;                
-  uint8_t code;                
+struct GNUNET_TUN_IcmpHeader
+{
+  uint8_t type;
+  uint8_t code;
   uint16_t crc GNUNET_PACKED;
 
-  union {
+  union
+  {
     /**
      * ICMP Echo (request/reply)
      */
-    struct {
+    struct
+    {
       uint16_t identifier GNUNET_PACKED;
       uint16_t sequence_number GNUNET_PACKED;
     } echo;
@@ -669,7 +716,8 @@ struct GNUNET_TUN_IcmpHeader {
     /**
      * ICMP Destination Unreachable (RFC 1191)
      */
-    struct ih_pmtu {
+    struct ih_pmtu
+    {
       uint16_t empty GNUNET_PACKED;
       uint16_t next_hop_mtu GNUNET_PACKED;
       /* followed by original IP header + first 8 bytes of original IP datagram */
@@ -677,8 +725,8 @@ struct GNUNET_TUN_IcmpHeader {
 
     /**
      * ICMP Redirect
-     */        
-    struct in_addr redirect_gateway_address GNUNET_PACKED;     
+     */
+    struct in_addr redirect_gateway_address GNUNET_PACKED;
 
     /**
      * MTU for packets that are too big (IPv6).
@@ -775,7 +823,7 @@ GNUNET_TUN_calculate_udp4_checksum (const struct GNUNET_TUN_IPv4Header *ip,
  * @param ip ipv6 header fully initialized
  * @param udp UDP header (initialized except for CRC)
  * @param payload the UDP payload
- * @param payload_length number of bytes of UDP payload
+ * @param payload_length number of bytes of @a payload
  */
 void
 GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
@@ -789,7 +837,7 @@ GNUNET_TUN_calculate_udp6_checksum (const struct GNUNET_TUN_IPv6Header *ip,
  *
  * @param icmp IMCP header (initialized except for CRC)
  * @param payload the ICMP payload
- * @param payload_length number of bytes of ICMP payload
+ * @param payload_length number of bytes of @a payload
  */
 void
 GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
@@ -798,29 +846,31 @@ GNUNET_TUN_calculate_icmp_checksum (struct GNUNET_TUN_IcmpHeader *icmp,
 
 
 /**
- * Create a regex in @a rxstr from the given @a ip and @a netmask.
+ * Create a regex in @a rxstr from the given @a ip and @a port.
  *
  * @param ip IPv4 representation.
- * @param netmask netmask for the ip.
+ * @param port destination port
  * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV4_REGEXLEN
  *              bytes long.
  */
 void
-GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip, const char *netmask,
-                       char *rxstr);
+GNUNET_TUN_ipv4toregexsearch (const struct in_addr *ip,
+                              uint16_t port,
+                              char *rxstr);
 
 
 /**
- * Create a regex in @a rxstr from the given @a ipv6 and @a prefixlen.
+ * Create a regex in @a rxstr from the given @a ipv6 and @a port.
  *
  * @param ipv6 IPv6 representation.
- * @param prefixlen length of the ipv6 prefix.
+ * @param port destination port
  * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV6_REGEXLEN
  *              bytes long.
  */
 void
 GNUNET_TUN_ipv6toregexsearch (const struct in6_addr *ipv6,
-                       unsigned int prefixlen, char *rxstr);
+                              uint16_t port,
+                              char *rxstr);
 
 
 /**
@@ -849,4 +899,16 @@ char *
 GNUNET_TUN_ipv4policy2regex (const char *policy);
 
 
+/**
+ * Hash the service name of a hosted service to the
+ * hash code that is used to identify the service on
+ * the network.
+ *
+ * @param service_name a string
+ * @param hc corresponding hash
+ */
+void
+GNUNET_TUN_service_name_to_hash (const char *service_name,
+                                 struct GNUNET_HashCode *hc);
+
 #endif