From: Christian Grothoff Date: Thu, 21 Jun 2012 07:32:50 +0000 (+0000) Subject: -improving comments, towards implementing #2268 X-Git-Tag: initial-import-from-subversion-38251~12906 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e2931e9e5cffd9f3dc37b71b2a01ed151c0dd4e5;p=oweals%2Fgnunet.git -improving comments, towards implementing #2268 --- diff --git a/src/dns/dnsparser.c b/src/dns/dnsparser.c index 0e658bdda..c11ec25d6 100644 --- a/src/dns/dnsparser.c +++ b/src/dns/dnsparser.c @@ -29,42 +29,153 @@ #include "gnunet_dnsparser_lib.h" -// DNS-Stuff GNUNET_NETWORK_STRUCT_BEGIN -/* FIXME: replace this one with the one from tcpip_tun.h! */ + +/* FIXME: replace this one with the one from tcpip_tun.h!? */ +/** + * Head of a any DNS message. + */ struct GNUNET_TUN_DnsHeader { + /** + * Request/response ID. (NBO) + */ uint16_t id GNUNET_PACKED; + + /** + * Flags for the operation. + */ struct GNUNET_DNSPARSER_Flags flags; - uint16_t query_count GNUNET_PACKED; // number of questions - uint16_t answer_rcount GNUNET_PACKED; // number of answers - uint16_t authority_rcount GNUNET_PACKED; // number of authority-records - uint16_t additional_rcount GNUNET_PACKED; // number of additional records + + /** + * number of questions (NBO) + */ + uint16_t query_count GNUNET_PACKED; + + /** + * number of answers (NBO) + */ + uint16_t answer_rcount GNUNET_PACKED; + + /** + * number of authority-records (NBO) + */ + uint16_t authority_rcount GNUNET_PACKED; + + /** + * number of additional records (NBO) + */ + uint16_t additional_rcount GNUNET_PACKED; }; + +/** + * DNS query prefix. + */ struct query_line { + /** + * Desired type (GNUNET_DNSPARSER_TYPE_XXX). (NBO) + */ uint16_t type GNUNET_PACKED; + + /** + * Desired class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO) + */ uint16_t class GNUNET_PACKED; }; + +/** + * General DNS record prefix. + */ struct record_line { + /** + * Record type (GNUNET_DNSPARSER_TYPE_XXX). (NBO) + */ uint16_t type GNUNET_PACKED; + + /** + * Record class (usually GNUNET_DNSPARSER_CLASS_INTERNET). (NBO) + */ uint16_t class GNUNET_PACKED; + + /** + * Expiration for the record (in seconds). (NBO) + */ uint32_t ttl GNUNET_PACKED; + + /** + * Number of bytes of data that follow. (NBO) + */ uint16_t data_len GNUNET_PACKED; }; + +/** + * Payload of DNS SOA record (header). + */ struct soa_data { + /** + * The version number of the original copy of the zone. (NBO) + */ uint32_t serial GNUNET_PACKED; + + /** + * Time interval before the zone should be refreshed. (NBO) + */ uint32_t refresh GNUNET_PACKED; + + /** + * Time interval that should elapse before a failed refresh should + * be retried. (NBO) + */ uint32_t retry GNUNET_PACKED; + + /** + * Time value that specifies the upper limit on the time interval + * that can elapse before the zone is no longer authoritative. (NBO) + */ uint32_t expire GNUNET_PACKED; + + /** + * The bit minimum TTL field that should be exported with any RR + * from this zone. (NBO) + */ uint32_t minimum GNUNET_PACKED; }; + +/** + * Payload of DNS SRV record (header). + */ +struct srv_data +{ + + /** + * 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. (NBO) + */ + uint16_t prio GNUNET_PACKED; + + /** + * 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. (NBO) + */ + uint16_t weight GNUNET_PACKED; + + /** + * TCP or UDP port of the service. (NBO) + */ + uint16_t port GNUNET_PACKED; + + /* followed by 'target' name */ +}; + GNUNET_NETWORK_STRUCT_END diff --git a/src/include/gnunet_dnsparser_lib.h b/src/include/gnunet_dnsparser_lib.h index 28cc4c048..5a42baea6 100644 --- a/src/include/gnunet_dnsparser_lib.h +++ b/src/include/gnunet_dnsparser_lib.h @@ -41,6 +41,7 @@ #define GNUNET_DNSPARSER_TYPE_MX 15 #define GNUNET_DNSPARSER_TYPE_TXT 16 #define GNUNET_DNSPARSER_TYPE_AAAA 28 +#define GNUNET_DNSPARSER_TYPE_SRV 33 /** * A few common DNS classes (ok, only one is common, but I list a @@ -173,6 +174,65 @@ 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 +{ + + /** + * Preference for this entry (lower value is higher preference). + * 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 +312,9 @@ struct GNUNET_DNSPARSER_Record */ char *name; + /** + * Payload of the record (which one of these is valid depends on the 'type'). + */ union { @@ -270,6 +333,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. */