extend API to enalbe exclusive port ranges to be specified for testing-system objects
[oweals/gnunet.git] / src / include / gnunet_dnsparser_lib.h
index 6654394be1ff75bfc8fd70f08b7ea4316972e69a..328a2286a605d907321907a994268e91cb5b2b87 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 /**
- * @file include/gnunet_dnsparse_lib.h
+ * @file include/gnunet_dnsparser_lib.h
  * @brief API for helper library to parse DNS packets. 
  * @author Philipp Toelke
  * @author Christian Grothoff
@@ -41,6 +41,8 @@
 #define GNUNET_DNSPARSER_TYPE_MX 15
 #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
@@ -78,6 +80,7 @@
  */
 struct GNUNET_DNSPARSER_Flags
 {
+#if __BYTE_ORDER == __LITTLE_ENDIAN
   /**
    * Set to 1 if recursion is desired (client -> server)
    */
@@ -127,8 +130,63 @@ 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;
 
 
 /**
@@ -173,6 +231,64 @@ struct GNUNET_DNSPARSER_MxRecord
 
 };
 
+
+/**
+ * Information from SRV records (RFC 2782).  The 'service', 'proto'
+ * and 'domain_name' fields together give the DNS-name which for SRV
+ * records is of the form "_$SERVICE._$PROTO.$DOMAIN_NAME".  The DNS
+ * parser provides the full name in 'struct DNSPARSER_Record' and the
+ * individual components in the respective fields of this struct.
+ * When serializing, you CAN set the 'name' field of 'struct
+ * GNUNET_DNSPARSER_Record' to NULL, in which case the DNSPARSER code
+ * will populate 'name' from the 'service', 'proto' and 'domain_name'
+ * fields in this struct.
+ */
+struct GNUNET_DNSPARSER_SrvRecord
+{
+  
+  /**
+   * Service name without the underscore (!).  Note that RFC 6335 clarifies the
+   * set of legal characters for service names.
+   */
+  char *service;
+
+  /**
+   * Transport protocol (typcially "tcp" or "udp", but others might be allowed).
+   * Without the underscore (!).
+   */
+  char *proto;
+
+  /**
+   * Domain name for which the record is valid
+   */
+  char *domain_name;
+
+  /**
+   * Hostname offering the service.
+   */
+  char *target;
+
+  /**
+   * Preference for this entry (lower value is higher preference).  Clients
+   * will contact hosts from the lowest-priority group first and fall back
+   * to higher priorities if the low-priority entries are unavailable.
+   */
+  uint16_t priority;
+
+  /**
+   * Relative weight for records with the same priority.  Clients will use
+   * the hosts of the same (lowest) priority with a probability proportional
+   * to the weight given.
+   */
+  uint16_t weight;
+
+  /**
+   * TCP or UDP port of the service.
+   */
+  uint16_t port;
+
+};
+
   
 /**
  * Information from SOA records (RFC 1035).
@@ -252,6 +368,9 @@ struct GNUNET_DNSPARSER_Record
    */
   char *name;
 
+  /**
+   * Payload of the record (which one of these is valid depends on the 'type').
+   */
   union 
   {
 
@@ -270,6 +389,11 @@ struct GNUNET_DNSPARSER_Record
      */
     struct GNUNET_DNSPARSER_MxRecord *mx;
 
+    /**
+     * SRV data for SRV records.
+     */
+    struct GNUNET_DNSPARSER_SrvRecord *srv;
+
     /**
      * Raw data for all other types.
      */
@@ -394,97 +518,4 @@ GNUNET_DNSPARSER_pack (const struct GNUNET_DNSPARSER_Packet *p,
                       size_t *buf_length);
 
 
-
-
-/* legacy API below */
-
-// DNS-Stuff
-GNUNET_NETWORK_STRUCT_BEGIN
-
-struct dns_static
-{
-  uint16_t id GNUNET_PACKED;
-
-  unsigned rd:1 GNUNET_PACKED;  // recursion desired (client -> server)
-  unsigned tc:1 GNUNET_PACKED;  // message is truncated
-  unsigned aa:1 GNUNET_PACKED;  // authoritative answer
-  unsigned op:4 GNUNET_PACKED;  // query:0, inverse q.:1, status: 2
-  unsigned qr:1 GNUNET_PACKED;  // query:0, response:1
-
-  unsigned rcode:4 GNUNET_PACKED;       // 0 No error
-  // 1 Format error
-  // 2 Server failure
-  // 3 Name Error
-  // 4 Not Implemented
-  // 5 Refused
-  unsigned z:3 GNUNET_PACKED;   // reserved
-  unsigned ra:1 GNUNET_PACKED;  // recursion available (server -> client)
-
-  uint16_t qdcount GNUNET_PACKED;       // number of questions
-  uint16_t ancount GNUNET_PACKED;       // number of answers
-  uint16_t nscount GNUNET_PACKED;       // number of authority-records
-  uint16_t arcount GNUNET_PACKED;       // number of additional records
-};
-GNUNET_NETWORK_STRUCT_END
-
-
-struct dns_pkt
-{
-  struct dns_static s;
-  unsigned char data[1];
-};
-
-struct dns_pkt_parsed
-{
-  struct dns_static s;
-  struct dns_query **queries;
-  struct dns_record **answers;
-  struct dns_record **nameservers;
-  struct dns_record **additional;
-};
-
-struct dns_query_line
-{
-  uint16_t type;
-  uint16_t class;
-};
-
-struct dns_query
-{
-  char *name;
-  unsigned char namelen;
-  uint16_t qtype;
-  uint16_t qclass;
-};
-
-struct dns_record_line
-{
-  uint16_t type;
-  uint16_t class;
-  uint32_t ttl;
-  uint16_t data_len;
-  unsigned char data;
-};
-
-struct dns_record
-{
-  char *name;
-  unsigned char namelen;
-  uint16_t type;
-  uint16_t class;
-  uint32_t ttl;
-  uint16_t data_len;
-  unsigned char *data;
-};
-
-
-struct dns_pkt_parsed *
-parse_dns_packet (struct dns_pkt *pkt);
-
-struct dns_pkt *
-unparse_dns_packet (struct dns_pkt_parsed *pkt);
-
-void
-free_parsed_dns_packet (struct dns_pkt_parsed *ppkt);
-
 #endif