-more cleanup and input validation fixes
[oweals/gnunet.git] / src / include / gnunet_dnsparser_lib.h
index a369964323505f1e763324b7c80c2fd16f769a8e..526c40ab2ed7ad4a67864e6976e67315db1cb31b 100644 (file)
 #include "platform.h"
 #include "gnunet_common.h"
 
+/**
+ * Maximum length of a label in DNS.
+ */
+#define GNUNET_DNSPARSER_MAX_LABEL_LENGTH 63
+
+/**
+ * Maximum length of a name in DNS.
+ */
+#define GNUNET_DNSPARSER_MAX_NAME_LENGTH 253
+
+
 /**
  * A few common DNS types.
  */
@@ -42,6 +53,7 @@
 #define GNUNET_DNSPARSER_TYPE_TXT 16
 #define GNUNET_DNSPARSER_TYPE_AAAA 28
 #define GNUNET_DNSPARSER_TYPE_SRV 33
+#define GNUNET_DNSPARSER_TYPE_TLSA 52
 
 /**
  * A few common DNS classes (ok, only one is common, but I list a
@@ -79,6 +91,7 @@
  */
 struct GNUNET_DNSPARSER_Flags
 {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
   /**
    * Set to 1 if recursion is desired (client -> server)
    */
@@ -128,6 +141,61 @@ struct GNUNET_DNSPARSER_Flags
    * Set to 1 if recursion is available (server -> client)
    */
   unsigned int recursion_available  : 1 GNUNET_PACKED; 
+#elif __BYTE_ORDER == __BIG_ENDIAN
+  
+  /**
+   * query:0, response:1
+   */
+  unsigned int query_or_response    : 1 GNUNET_PACKED;  
+  
+  /**
+   * See GNUNET_DNSPARSER_OPCODE_ defines.
+   */
+  unsigned int opcode               : 4 GNUNET_PACKED;  
+  
+  /**
+   * Set to 1 if this is an authoritative answer
+   */
+  unsigned int authoritative_answer : 1 GNUNET_PACKED;
+  
+  /**
+   * Set to 1 if message is truncated
+   */
+  unsigned int message_truncated    : 1 GNUNET_PACKED; 
+  
+  /**
+   * Set to 1 if recursion is desired (client -> server)
+   */
+  unsigned int recursion_desired    : 1 GNUNET_PACKED;  
+
+  /**
+   * Set to 1 if recursion is available (server -> client)
+   */
+  unsigned int recursion_available  : 1 GNUNET_PACKED;
+  
+  /**
+   * Always zero.
+   */
+  unsigned int zero                 : 1 GNUNET_PACKED;
+  
+  /**
+   * Response has been cryptographically verified, RFC 4035.
+   */
+  unsigned int authenticated_data   : 1 GNUNET_PACKED;
+  
+  /**
+   * See RFC 4035.
+   */
+  unsigned int checking_disabled    : 1 GNUNET_PACKED; 
+  
+  /**
+   * See GNUNET_DNSPARSER_RETURN_CODE_ defines.
+   */  
+  unsigned int return_code          : 4 GNUNET_PACKED; 
+#else
+  #error byteorder undefined
+#endif
   
 } GNUNET_GCC_STRUCT_LAYOUT;
 
@@ -140,6 +208,10 @@ struct GNUNET_DNSPARSER_Query
 
   /**
    * Name of the record that the query is for (0-terminated).
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *name;
 
@@ -169,6 +241,10 @@ struct GNUNET_DNSPARSER_MxRecord
 
   /**
    * Name of the mail server.
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *mxhost;
 
@@ -192,6 +268,10 @@ struct GNUNET_DNSPARSER_SrvRecord
   /**
    * Service name without the underscore (!).  Note that RFC 6335 clarifies the
    * set of legal characters for service names.
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *service;
 
@@ -203,11 +283,19 @@ struct GNUNET_DNSPARSER_SrvRecord
 
   /**
    * Domain name for which the record is valid
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *domain_name;
 
   /**
    * Hostname offering the service.
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *target;
 
@@ -242,12 +330,20 @@ struct GNUNET_DNSPARSER_SoaRecord
   /**
    *The domainname of the name server that was the
    * original or primary source of data for this zone.
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *mname;
 
   /**
    * A domainname which specifies the mailbox of the
    * person responsible for this zone.
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *rname;
 
@@ -308,6 +404,10 @@ struct GNUNET_DNSPARSER_Record
 
   /**
    * Name of the record that the query is for (0-terminated).
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
    */
   char *name;
 
@@ -319,6 +419,10 @@ struct GNUNET_DNSPARSER_Record
 
     /**
      * For NS, CNAME and PTR records, this is the uncompressed 0-terminated hostname.
+   * In UTF-8 format.  The library will convert from and to DNS-IDNA 
+   * as necessary.  Use 'GNUNET_DNSPARSER_check_label' to test if an
+   * individual label is well-formed.  If a given name is not well-formed,
+   * creating the DNS packet will fail.
      */
     char *hostname;
     
@@ -421,6 +525,18 @@ struct GNUNET_DNSPARSER_Packet
 };
 
 
+/**
+ * Check if a label in UTF-8 format can be coded into valid IDNA.
+ * This can fail if the ASCII-conversion becomes longer than 63 characters.
+ *
+ * @param label label to check (UTF-8 string)
+ * @return GNUNET_OK if the label can be converted to IDNA,
+ *         GNUNET_SYSERR if the label is not valid for DNS names
+ */
+int
+GNUNET_DNSPARSER_check_label (const char *label);
+
+
 /**
  * Parse a UDP payload of a DNS packet in to a nice struct for further
  * processing and manipulation.