1 /* 2 * dns.h -- DNS definitions. 3 * 4 * Copyright (c) 2001-2011, NLnet Labs. All rights reserved. 5 * 6 * See LICENSE for the license. 7 * 8 */ 9 10 #ifndef _DNS_H_ 11 #define _DNS_H_ 12 13 enum rr_section { 14 QUESTION_SECTION, 15 ANSWER_SECTION, 16 AUTHORITY_SECTION, 17 ADDITIONAL_SECTION, 18 /* 19 * Use a split additional section to ensure A records appear 20 * before any AAAA records (this is recommended practice to 21 * avoid truncating the additional section for IPv4 clients 22 * that do not specify EDNS0), and AAAA records before other 23 * types of additional records (such as X25 and ISDN). 24 * Encode_answer sets the ARCOUNT field of the response packet 25 * correctly. 26 */ 27 ADDITIONAL_A_SECTION = ADDITIONAL_SECTION, 28 ADDITIONAL_AAAA_SECTION, 29 ADDITIONAL_OTHER_SECTION, 30 31 RR_SECTION_COUNT 32 }; 33 typedef enum rr_section rr_section_type; 34 35 /* Possible OPCODE values */ 36 #define OPCODE_QUERY 0 /* a standard query (QUERY) */ 37 #define OPCODE_IQUERY 1 /* an inverse query (IQUERY) */ 38 #define OPCODE_STATUS 2 /* a server status request (STATUS) */ 39 #define OPCODE_NOTIFY 4 /* NOTIFY */ 40 #define OPCODE_UPDATE 5 /* Dynamic update */ 41 42 /* Possible RCODE values */ 43 #define RCODE_OK 0 /* No error condition */ 44 #define RCODE_FORMAT 1 /* Format error */ 45 #define RCODE_SERVFAIL 2 /* Server failure */ 46 #define RCODE_NXDOMAIN 3 /* Name Error */ 47 #define RCODE_IMPL 4 /* Not implemented */ 48 #define RCODE_REFUSE 5 /* Refused */ 49 #define RCODE_YXDOMAIN 6 /* name should not exist */ 50 #define RCODE_YXRRSET 7 /* rrset should not exist */ 51 #define RCODE_NXRRSET 8 /* rrset does not exist */ 52 #define RCODE_NOTAUTH 9 /* server not authoritative */ 53 #define RCODE_NOTZONE 10 /* name not inside zone */ 54 55 /* Standardized NSD return code. Partially maps to DNS RCODE values. */ 56 enum nsd_rc 57 { 58 /* Discard the client request. */ 59 NSD_RC_DISCARD = -1, 60 /* OK, continue normal processing. */ 61 NSD_RC_OK = RCODE_OK, 62 /* Return the appropriate error code to the client. */ 63 NSD_RC_FORMAT = RCODE_FORMAT, 64 NSD_RC_SERVFAIL = RCODE_SERVFAIL, 65 NSD_RC_NXDOMAIN = RCODE_NXDOMAIN, 66 NSD_RC_IMPL = RCODE_IMPL, 67 NSD_RC_REFUSE = RCODE_REFUSE, 68 NSD_RC_NOTAUTH = RCODE_NOTAUTH 69 }; 70 typedef enum nsd_rc nsd_rc_type; 71 72 /* RFC1035 */ 73 #define CLASS_IN 1 /* Class IN */ 74 #define CLASS_CS 2 /* Class CS */ 75 #define CLASS_CH 3 /* Class CHAOS */ 76 #define CLASS_HS 4 /* Class HS */ 77 #define CLASS_NONE 254 /* Class NONE rfc2136 */ 78 #define CLASS_ANY 255 /* Class ANY */ 79 80 #define TYPE_A 1 /* a host address */ 81 #define TYPE_NS 2 /* an authoritative name server */ 82 #define TYPE_MD 3 /* a mail destination (Obsolete - use MX) */ 83 #define TYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */ 84 #define TYPE_CNAME 5 /* the canonical name for an alias */ 85 #define TYPE_SOA 6 /* marks the start of a zone of authority */ 86 #define TYPE_MB 7 /* a mailbox domain name (EXPERIMENTAL) */ 87 #define TYPE_MG 8 /* a mail group member (EXPERIMENTAL) */ 88 #define TYPE_MR 9 /* a mail rename domain name (EXPERIMENTAL) */ 89 #define TYPE_NULL 10 /* a null RR (EXPERIMENTAL) */ 90 #define TYPE_WKS 11 /* a well known service description */ 91 #define TYPE_PTR 12 /* a domain name pointer */ 92 #define TYPE_HINFO 13 /* host information */ 93 #define TYPE_MINFO 14 /* mailbox or mail list information */ 94 #define TYPE_MX 15 /* mail exchange */ 95 #define TYPE_TXT 16 /* text strings */ 96 #define TYPE_RP 17 /* RFC1183 */ 97 #define TYPE_AFSDB 18 /* RFC1183 */ 98 #define TYPE_X25 19 /* RFC1183 */ 99 #define TYPE_ISDN 20 /* RFC1183 */ 100 #define TYPE_RT 21 /* RFC1183 */ 101 #define TYPE_NSAP 22 /* RFC1706 */ 102 103 #define TYPE_SIG 24 /* 2535typecode */ 104 #define TYPE_KEY 25 /* 2535typecode */ 105 #define TYPE_PX 26 /* RFC2163 */ 106 107 #define TYPE_AAAA 28 /* ipv6 address */ 108 #define TYPE_LOC 29 /* LOC record RFC1876 */ 109 #define TYPE_NXT 30 /* 2535typecode */ 110 111 #define TYPE_SRV 33 /* SRV record RFC2782 */ 112 113 #define TYPE_NAPTR 35 /* RFC2915 */ 114 #define TYPE_KX 36 /* RFC2230 Key Exchange Delegation Record */ 115 #define TYPE_CERT 37 /* RFC2538 */ 116 117 #define TYPE_A6 38 /* RFC2874 */ 118 119 #define TYPE_DNAME 39 /* RFC2672 */ 120 121 #define TYPE_OPT 41 /* Pseudo OPT record... */ 122 #define TYPE_APL 42 /* RFC3123 */ 123 #define TYPE_DS 43 /* RFC 4033, 4034, and 4035 */ 124 #define TYPE_SSHFP 44 /* SSH Key Fingerprint */ 125 #define TYPE_IPSECKEY 45 /* public key for ipsec use. RFC 4025 */ 126 127 #define TYPE_RRSIG 46 /* RFC 4033, 4034, and 4035 */ 128 #define TYPE_NSEC 47 /* RFC 4033, 4034, and 4035 */ 129 #define TYPE_DNSKEY 48 /* RFC 4033, 4034, and 4035 */ 130 #define TYPE_DHCID 49 /* RFC4701 DHCP information */ 131 #define TYPE_NSEC3 50 /* NSEC3, secure denial, prevents zonewalking */ 132 #define TYPE_NSEC3PARAM 51 /* NSEC3PARAM at zone apex nsec3 parameters */ 133 134 #define TYPE_SPF 99 /* RFC 4408 */ 135 136 #define TYPE_TSIG 250 137 #define TYPE_IXFR 251 138 #define TYPE_AXFR 252 139 #define TYPE_MAILB 253 /* A request for mailbox-related records (MB, MG or MR) */ 140 #define TYPE_MAILA 254 /* A request for mail agent RRs (Obsolete - see MX) */ 141 #define TYPE_ANY 255 /* any type (wildcard) */ 142 143 #define TYPE_DLV 32769 /* RFC 4431 */ 144 #define PSEUDO_TYPE_DLV RRTYPE_DESCRIPTORS_LENGTH 145 146 #define MAXLABELLEN 63 147 #define MAXDOMAINLEN 255 148 149 #define MAXRDATALEN 64 /* This is more than enough, think multiple TXT. */ 150 #define MAX_RDLENGTH 65535 151 152 /* Maximum size of a single RR. */ 153 #define MAX_RR_SIZE \ 154 (MAXDOMAINLEN + sizeof(uint32_t) + 4*sizeof(uint16_t) + MAX_RDLENGTH) 155 156 #define IP4ADDRLEN (32/8) 157 #define IP6ADDRLEN (128/8) 158 159 /* 160 * The different types of RDATA wireformat data. 161 */ 162 enum rdata_wireformat 163 { 164 RDATA_WF_COMPRESSED_DNAME, /* Possibly compressed domain name. */ 165 RDATA_WF_UNCOMPRESSED_DNAME, /* Uncompressed domain name. */ 166 RDATA_WF_LITERAL_DNAME, /* Literal (not downcased) dname. */ 167 RDATA_WF_BYTE, /* 8-bit integer. */ 168 RDATA_WF_SHORT, /* 16-bit integer. */ 169 RDATA_WF_LONG, /* 32-bit integer. */ 170 RDATA_WF_TEXT, /* Text string. */ 171 RDATA_WF_TEXTS, /* Text string sequence. */ 172 RDATA_WF_A, /* 32-bit IPv4 address. */ 173 RDATA_WF_AAAA, /* 128-bit IPv6 address. */ 174 RDATA_WF_BINARY, /* Binary data (unknown length). */ 175 RDATA_WF_BINARYWITHLENGTH, /* Binary data preceded by 1 byte length */ 176 RDATA_WF_APL, /* APL data. */ 177 RDATA_WF_IPSECGATEWAY /* IPSECKEY gateway ip4, ip6 or dname. */ 178 }; 179 typedef enum rdata_wireformat rdata_wireformat_type; 180 181 /* 182 * The different types of RDATA that can appear in the zone file. 183 */ 184 enum rdata_zoneformat 185 { 186 RDATA_ZF_DNAME, /* Domain name. */ 187 RDATA_ZF_LITERAL_DNAME, /* DNS name (not lowercased domain name). */ 188 RDATA_ZF_TEXT, /* Text string. */ 189 RDATA_ZF_TEXTS, /* Text string sequence. */ 190 RDATA_ZF_BYTE, /* 8-bit integer. */ 191 RDATA_ZF_SHORT, /* 16-bit integer. */ 192 RDATA_ZF_LONG, /* 32-bit integer. */ 193 RDATA_ZF_A, /* 32-bit IPv4 address. */ 194 RDATA_ZF_AAAA, /* 128-bit IPv6 address. */ 195 RDATA_ZF_RRTYPE, /* RR type. */ 196 RDATA_ZF_ALGORITHM, /* Cryptographic algorithm. */ 197 RDATA_ZF_CERTIFICATE_TYPE, 198 RDATA_ZF_PERIOD, /* Time period. */ 199 RDATA_ZF_TIME, 200 RDATA_ZF_BASE64, /* Base-64 binary data. */ 201 RDATA_ZF_BASE32, /* Base-32 binary data. */ 202 RDATA_ZF_HEX, /* Hexadecimal binary data. */ 203 RDATA_ZF_HEX_LEN, /* Hexadecimal binary data. Skip initial length byte. */ 204 RDATA_ZF_NSAP, /* NSAP. */ 205 RDATA_ZF_APL, /* APL. */ 206 RDATA_ZF_IPSECGATEWAY, /* IPSECKEY gateway ip4, ip6 or dname. */ 207 RDATA_ZF_SERVICES, /* Protocol and port number bitmap. */ 208 RDATA_ZF_NXT, /* NXT type bitmap. */ 209 RDATA_ZF_NSEC, /* NSEC type bitmap. */ 210 RDATA_ZF_LOC, /* Location data. */ 211 RDATA_ZF_UNKNOWN /* Unknown data. */ 212 }; 213 typedef enum rdata_zoneformat rdata_zoneformat_type; 214 215 struct rrtype_descriptor 216 { 217 uint16_t type; /* RR type */ 218 const char *name; /* Textual name. */ 219 int token; /* Parser token. */ 220 uint32_t minimum; /* Minimum number of RDATAs. */ 221 uint32_t maximum; /* Maximum number of RDATAs. */ 222 uint8_t wireformat[MAXRDATALEN]; /* rdata_wireformat_type */ 223 uint8_t zoneformat[MAXRDATALEN]; /* rdata_zoneformat_type */ 224 }; 225 typedef struct rrtype_descriptor rrtype_descriptor_type; 226 227 /* 228 * Indexed by type. The special type "0" can be used to get a 229 * descriptor for unknown types (with one binary rdata). 230 * 231 * spf + 1 232 */ 233 #define RRTYPE_DESCRIPTORS_LENGTH (TYPE_SPF + 1) 234 rrtype_descriptor_type *rrtype_descriptor_by_name(const char *name); 235 rrtype_descriptor_type *rrtype_descriptor_by_type(uint16_t type); 236 237 const char *rrtype_to_string(uint16_t rrtype); 238 239 /* 240 * Lookup the type in the ztypes lookup table. If not found, check if 241 * the type uses the "TYPExxx" notation for unknown types. 242 * 243 * Return 0 if no type matches. 244 */ 245 uint16_t rrtype_from_string(const char *name); 246 247 const char *rrclass_to_string(uint16_t rrclass); 248 uint16_t rrclass_from_string(const char *name); 249 250 #ifdef __cplusplus 251 inline rr_section_type 252 operator++(rr_section_type &lhs) 253 { 254 lhs = (rr_section_type) ((int) lhs + 1); 255 return lhs; 256 } 257 #endif /* __cplusplus */ 258 259 #endif /* _DNS_H_ */ 260