1 /* 2 * This file is part of the Sofia-SIP package 3 * 4 * Copyright (C) 2005 Nokia Corporation. 5 * 6 * Contact: Pekka Pessi <pekka.pessi@nokia.com> 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public License 10 * as published by the Free Software Foundation; either version 2.1 of 11 * the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 21 * 02110-1301 USA 22 * 23 */ 24 25 #ifndef SOFIA_RESOLV_SRES_RECORD_H 26 /** Defined when <sofia-resolv/sres_record.h> has been included. */ 27 #define SOFIA_RESOLV_SRES_RECORD_H 28 /** 29 * @file sofia-resolv/sres_record.h Sofia DNS Resolver Records. 30 * 31 * @author Pekka Pessi <Pekka.Pessi@nokia.com>, 32 * 33 * @par Include Context 34 * @code 35 * #include <sys/types.h> 36 * #include <sys/socket.h> 37 * #include <netinet/in.h> 38 * #include <sofia-resolv/sres_record.h> 39 * @endcode 40 * 41 */ 42 43 #include "sofia-resolv/sres_config.h" 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 /** Common part of all DNS records. */ 50 typedef struct sres_common 51 { 52 int r_refcount; /**< Number of references to this record */ 53 char *r_name; /**< Domain name */ 54 uint16_t r_status; /**< Status of query (nonzero upon an error) */ 55 uint16_t r_size; /**< Size of this record */ 56 uint16_t r_type; /**< Record type (A, CNAME, A6, etc) */ 57 uint16_t r_class; /**< Record class (IN) */ 58 uint32_t r_ttl; /**< Time-to-live */ 59 uint16_t r_rdlen; /**< Length of record data */ 60 uint16_t r_parsed; /**< Nonzero if parsed */ 61 } sres_common_t; 62 63 /** Possible values for r_status (RCODE) in #sres_common */ 64 enum sres_status { 65 SRES_OK = 0, /**< No error condition. */ 66 SRES_FORMAT_ERR = 1, /**< Server could not interpret query. */ 67 SRES_SERVER_ERR = 2, /**< Server error. */ 68 SRES_NAME_ERR = 3, /**< No domain name. */ 69 SRES_UNIMPL_ERR = 4, /**< Not implemented. */ 70 SRES_AUTH_ERR = 5, /**< Refused */ 71 72 /* Errors generated by sresolv */ 73 SRES_TIMEOUT_ERR = 32, /**< Timeout occurred */ 74 SRES_RECORD_ERR = 33, /**< Name has no given record type */ 75 SRES_INTERNAL_ERR = 34, /**< Internal error */ 76 SRES_NETWORK_ERR = 35, /**< Network or DNS configuration error. */ 77 78 _SRES_LAST_ERR 79 }; 80 81 /** Start of a zone of authority record (@RFC1035). */ 82 typedef struct sres_soa_record 83 { 84 sres_common_t soa_record[1]; /**< Common part of DNS records. */ 85 char *soa_mname; /**< Primary name server */ 86 char *soa_rname; /**< Person responsible for domain */ 87 uint32_t soa_serial; /**< Version number */ 88 uint32_t soa_refresh; /**< Refresh intercal */ 89 uint32_t soa_retry; /**< Interval between refres retries */ 90 uint32_t soa_expire; /**< Upper limit on zone expiration time */ 91 uint32_t soa_minimum; /**< Minimum TTL for any record in zone */ 92 } sres_soa_record_t; 93 94 /** Generic DNS record. */ 95 typedef struct sres_generic 96 { 97 sres_common_t g_record[1]; /**< Common part of DNS records. */ 98 uint8_t g_data[128]; /**< Record data */ 99 } sres_generic_t; 100 101 /** Address record (@RFC1035). */ 102 typedef struct sres_a_record 103 { 104 sres_common_t a_record[1]; /**< Common part of DNS records. */ 105 struct in_addr a_addr; /**< IP4 address */ 106 } sres_a_record_t; 107 108 /** IPv6 address used by sresolv library. 109 * 110 * @sa #sres_aaaa_record, #sres_a6_record 111 */ 112 typedef struct 113 { 114 uint8_t u6_addr[16]; /**< Array of 16 octets. */ 115 } sres_in6_t; 116 117 /** Aggregated address record for IPv6 (@RFC2874, deprecated). */ 118 typedef struct sres_a6_record 119 { 120 sres_common_t a6_record[1]; /**< Common part of DNS records. */ 121 uint8_t a6_prelen; /**< Prefix length */ 122 uint8_t a6_pad[3]; /**< */ 123 sres_in6_t a6_suffix; /**< Address suffix */ 124 char *a6_prename; /**< Prefix name */ 125 } sres_a6_record_t; 126 127 /** Address record for IPv6 (@RFC1886). */ 128 typedef struct sres_aaaa_record 129 { 130 sres_common_t aaaa_record[1]; /**< Common part of DNS records. */ 131 sres_in6_t aaaa_addr; /**< IP6 address */ 132 } sres_aaaa_record_t; 133 134 /** Canonic name record (@RFC1035). */ 135 typedef struct sres_cname_record 136 { 137 sres_common_t cn_record[1]; /**< Common part of DNS records. */ 138 char *cn_cname; /**< */ 139 } sres_cname_record_t; 140 141 /** Pointer record (@RFC1035). */ 142 typedef struct sres_ptr_record 143 { 144 sres_common_t ptr_record[1]; /**< Common part of DNS records. */ 145 char *ptr_domain; /**< Domain */ 146 } sres_ptr_record_t; 147 148 /** Service location record (@RFC2782). */ 149 typedef struct sres_srv_record 150 { 151 sres_common_t srv_record[1]; /**< Common part of DNS records. */ 152 uint16_t srv_priority; /**< Priority */ 153 uint16_t srv_weight; /**< Weight */ 154 uint16_t srv_port; /**< Service port on the target host. */ 155 uint16_t srv_pad; 156 char *srv_target; /**< Domain name of the target host. */ 157 } sres_srv_record_t; 158 159 /** Naming authority pointer record (@RFC2915). */ 160 typedef struct sres_naptr_record 161 { 162 sres_common_t na_record[1]; /**< Common part of DNS records. */ 163 uint16_t na_order; /**< Processing order for NAPTR records. */ 164 uint16_t na_prefer; /**< Preference */ 165 char *na_flags; /**< Flags for interpretation and rewriting */ 166 char *na_services; /**< Services available. */ 167 char *na_regexp; /**< Substitution expression. */ 168 char *na_replace; /**< Replacement. */ 169 } sres_naptr_record_t; 170 171 172 #ifndef SRES_RECORD_T 173 #define SRES_RECORD_T 174 /** Type representing any DNS record. */ 175 typedef union sres_record sres_record_t; 176 #endif 177 178 /** Union of different DNS records */ 179 union sres_record 180 { 181 sres_common_t sr_record[1]; /**< Common part of all DNS records */ 182 sres_generic_t sr_generic[1]; /**< Generic (unparsed) DNS record */ 183 sres_soa_record_t sr_soa[1]; /**< SOA (start-of-authority) record */ 184 sres_a_record_t sr_a[1]; /**< A (address) record */ 185 sres_cname_record_t sr_cname[1]; /**< CNAME (canonic name) record */ 186 sres_ptr_record_t sr_ptr[1]; /**< PTR (pointer) record */ 187 sres_a6_record_t sr_a6[1]; /**< A6 (IP6 address) record */ 188 sres_aaaa_record_t sr_aaaa[1]; /**< AAAA (IP6 address) record */ 189 sres_srv_record_t sr_srv[1]; /**< SRV record */ 190 sres_naptr_record_t sr_naptr[1]; /**< NAPTR record */ 191 }; 192 193 /** Protocol family classes. */ 194 enum sres_class { 195 sres_class_in = 1, /**< Internet (@b IN) */ 196 sres_class_any = 255 /**< Any class */ 197 }; 198 199 /** Query types. */ 200 enum sres_qtypes { 201 sres_type_a = 1, /**< IPv4 address (#sres_a_record). */ 202 sres_type_ns = 2, /**< Authoritative server. */ 203 sres_type_mf = 4, /**< Mail forwarder. */ 204 sres_type_cname = 5, /**< Canonical name (#sres_cname_record). */ 205 sres_type_soa = 6, /**< Start of authority zone (#sres_soa_record). */ 206 sres_type_mb = 7, /**< Mailbox domain name. */ 207 sres_type_mg = 8, /**< Mail group member. */ 208 sres_type_mr = 9, /**< Mail rename name. */ 209 sres_type_null = 10, /**< Null resource record. */ 210 sres_type_wks = 11, /**< Well known service. */ 211 sres_type_ptr = 12, /**< Domain name pointer (#sres_ptr_record). */ 212 sres_type_hinfo = 13, /**< Host information. */ 213 sres_type_minfo = 14, /**< Mailbox information. */ 214 sres_type_mx = 15, /**< Mail routing information. */ 215 sres_type_txt = 16, /**< Text strings. */ 216 sres_type_rp = 17, /**< Responsible person. */ 217 sres_type_afsdb = 18, /**< AFS cell database. */ 218 sres_type_x25 = 19, /**< X_25 calling address. */ 219 sres_type_isdn = 20, /**< ISDN calling address. */ 220 sres_type_rt = 21, /**< Router. */ 221 sres_type_nsap = 22, /**< NSAP address. */ 222 sres_type_nsap_ptr = 23, /**< Reverse NSAP lookup. */ 223 sres_type_sig = 24, /**< Security signature. */ 224 sres_type_key = 25, /**< Security key. */ 225 sres_type_px = 26, /**< X.400 mail mapping. */ 226 sres_type_gpos = 27, /**< ICBM record. */ 227 sres_type_aaaa = 28, /**< IPv6 Address (#sres_aaaa_record). */ 228 sres_type_loc = 29, /**< Location Information. */ 229 sres_type_nxt = 30, /**< Next domain. */ 230 sres_type_eid = 31, /**< Endpoint identifier. */ 231 sres_type_nimloc = 32, /**< Nimrod Locator. */ 232 sres_type_srv = 33, /**< Server Selection (@RFC2782, 233 #sres_srv_record). */ 234 sres_type_atma = 34, /**< ATM Address */ 235 sres_type_naptr = 35, /**< Naming Authority PoinTeR (@RFC2915, 236 #sres_naptr_record) */ 237 sres_type_kx = 36, /**< Key Exchange */ 238 sres_type_cert = 37, /**< Certification record */ 239 sres_type_a6 = 38, /**< IPv6 address (deprecates AAAA) */ 240 sres_type_dname = 39, /**< Non-terminal DNAME (for IPv6) */ 241 sres_type_sink = 40, /**< Kitchen sink (experimental) */ 242 sres_type_opt = 41, /**< EDNS 0 option (@RFC2671) */ 243 244 sres_qtype_tsig = 250, /**< Transaction signature. */ 245 sres_qtype_ixfr = 251, /**< Incremental zone transfer. */ 246 sres_qtype_axfr = 252, /**< Transfer zone of authority. */ 247 sres_qtype_mailb = 253, /**< Transfer mailbox records. */ 248 sres_qtype_maila = 254, /**< Transfer mail agent records. */ 249 sres_qtype_any = 255 /**< Wildcard match. */ 250 }; 251 252 /** Convert type to its name. */ 253 SRESPUBFUN char const *sres_record_type(int type, char buffer[8]); 254 255 /** Convert status to its name. */ 256 SRESPUBFUN char const *sres_record_status(int status, char buffer[8]); 257 258 /** Compare two records. */ 259 SRESPUBFUN int sres_record_compare(sres_record_t const *, 260 sres_record_t const *); 261 262 #ifdef __cplusplus 263 } 264 #endif 265 266 #endif /* SOFIA_RESOLV_SRES_CACHE_H */ 267