1 #ifndef _ARPA_NAMESER_H 2 #define _ARPA_NAMESER_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <stddef.h> 9 #include <stdint.h> 10 11 #define __NAMESER 19991006 12 #define NS_PACKETSZ 512 13 #define NS_MAXDNAME 1025 14 #define NS_MAXMSG 65535 15 #define NS_MAXCDNAME 255 16 #define NS_MAXLABEL 63 17 #define NS_HFIXEDSZ 12 18 #define NS_QFIXEDSZ 4 19 #define NS_RRFIXEDSZ 10 20 #define NS_INT32SZ 4 21 #define NS_INT16SZ 2 22 #define NS_INT8SZ 1 23 #define NS_INADDRSZ 4 24 #define NS_IN6ADDRSZ 16 25 #define NS_CMPRSFLGS 0xc0 26 #define NS_DEFAULTPORT 53 27 28 typedef enum __ns_sect { 29 ns_s_qd = 0, 30 ns_s_zn = 0, 31 ns_s_an = 1, 32 ns_s_pr = 1, 33 ns_s_ns = 2, 34 ns_s_ud = 2, 35 ns_s_ar = 3, 36 ns_s_max = 4 37 } ns_sect; 38 39 typedef struct __ns_msg { 40 const unsigned char *_msg, *_eom; 41 uint16_t _id, _flags, _counts[ns_s_max]; 42 const unsigned char *_sections[ns_s_max]; 43 ns_sect _sect; 44 int _rrnum; 45 const unsigned char *_msg_ptr; 46 } ns_msg; 47 48 struct _ns_flagdata { int mask, shift; }; 49 extern const struct _ns_flagdata _ns_flagdata[]; 50 51 #define ns_msg_id(handle) ((handle)._id + 0) 52 #define ns_msg_base(handle) ((handle)._msg + 0) 53 #define ns_msg_end(handle) ((handle)._eom + 0) 54 #define ns_msg_size(handle) ((handle)._eom - (handle)._msg) 55 #define ns_msg_count(handle, section) ((handle)._counts[section] + 0) 56 #define ns_msg_getflag(handle, flag) \ 57 (((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) 58 59 typedef struct __ns_rr { 60 char name[NS_MAXDNAME]; 61 uint16_t type; 62 uint16_t rr_class; 63 uint32_t ttl; 64 uint16_t rdlength; 65 const unsigned char *rdata; 66 } ns_rr; 67 68 #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") 69 #define ns_rr_type(rr) ((ns_type)((rr).type + 0)) 70 #define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) 71 #define ns_rr_ttl(rr) ((rr).ttl + 0) 72 #define ns_rr_rdlen(rr) ((rr).rdlength + 0) 73 #define ns_rr_rdata(rr) ((rr).rdata + 0) 74 75 typedef enum __ns_flag { 76 ns_f_qr, 77 ns_f_opcode, 78 ns_f_aa, 79 ns_f_tc, 80 ns_f_rd, 81 ns_f_ra, 82 ns_f_z, 83 ns_f_ad, 84 ns_f_cd, 85 ns_f_rcode, 86 ns_f_max 87 } ns_flag; 88 89 typedef enum __ns_opcode { 90 ns_o_query = 0, 91 ns_o_iquery = 1, 92 ns_o_status = 2, 93 ns_o_notify = 4, 94 ns_o_update = 5, 95 ns_o_max = 6 96 } ns_opcode; 97 98 typedef enum __ns_rcode { 99 ns_r_noerror = 0, 100 ns_r_formerr = 1, 101 ns_r_servfail = 2, 102 ns_r_nxdomain = 3, 103 ns_r_notimpl = 4, 104 ns_r_refused = 5, 105 ns_r_yxdomain = 6, 106 ns_r_yxrrset = 7, 107 ns_r_nxrrset = 8, 108 ns_r_notauth = 9, 109 ns_r_notzone = 10, 110 ns_r_max = 11, 111 ns_r_badvers = 16, 112 ns_r_badsig = 16, 113 ns_r_badkey = 17, 114 ns_r_badtime = 18 115 } ns_rcode; 116 117 typedef enum __ns_update_operation { 118 ns_uop_delete = 0, 119 ns_uop_add = 1, 120 ns_uop_max = 2 121 } ns_update_operation; 122 123 struct ns_tsig_key { 124 char name[NS_MAXDNAME], alg[NS_MAXDNAME]; 125 unsigned char *data; 126 int len; 127 }; 128 typedef struct ns_tsig_key ns_tsig_key; 129 130 struct ns_tcp_tsig_state { 131 int counter; 132 struct dst_key *key; 133 void *ctx; 134 unsigned char sig[NS_PACKETSZ]; 135 int siglen; 136 }; 137 typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; 138 139 #define NS_TSIG_FUDGE 300 140 #define NS_TSIG_TCP_COUNT 100 141 #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" 142 143 #define NS_TSIG_ERROR_NO_TSIG -10 144 #define NS_TSIG_ERROR_NO_SPACE -11 145 #define NS_TSIG_ERROR_FORMERR -12 146 147 typedef enum __ns_type { 148 ns_t_invalid = 0, 149 ns_t_a = 1, 150 ns_t_ns = 2, 151 ns_t_md = 3, 152 ns_t_mf = 4, 153 ns_t_cname = 5, 154 ns_t_soa = 6, 155 ns_t_mb = 7, 156 ns_t_mg = 8, 157 ns_t_mr = 9, 158 ns_t_null = 10, 159 ns_t_wks = 11, 160 ns_t_ptr = 12, 161 ns_t_hinfo = 13, 162 ns_t_minfo = 14, 163 ns_t_mx = 15, 164 ns_t_txt = 16, 165 ns_t_rp = 17, 166 ns_t_afsdb = 18, 167 ns_t_x25 = 19, 168 ns_t_isdn = 20, 169 ns_t_rt = 21, 170 ns_t_nsap = 22, 171 ns_t_nsap_ptr = 23, 172 ns_t_sig = 24, 173 ns_t_key = 25, 174 ns_t_px = 26, 175 ns_t_gpos = 27, 176 ns_t_aaaa = 28, 177 ns_t_loc = 29, 178 ns_t_nxt = 30, 179 ns_t_eid = 31, 180 ns_t_nimloc = 32, 181 ns_t_srv = 33, 182 ns_t_atma = 34, 183 ns_t_naptr = 35, 184 ns_t_kx = 36, 185 ns_t_cert = 37, 186 ns_t_a6 = 38, 187 ns_t_dname = 39, 188 ns_t_sink = 40, 189 ns_t_opt = 41, 190 ns_t_apl = 42, 191 ns_t_tkey = 249, 192 ns_t_tsig = 250, 193 ns_t_ixfr = 251, 194 ns_t_axfr = 252, 195 ns_t_mailb = 253, 196 ns_t_maila = 254, 197 ns_t_any = 255, 198 ns_t_zxfr = 256, 199 ns_t_max = 65536 200 } ns_type; 201 202 #define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ 203 (t) == ns_t_mailb || (t) == ns_t_maila) 204 #define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) 205 #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) 206 #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) 207 #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ 208 (t) == ns_t_zxfr) 209 210 typedef enum __ns_class { 211 ns_c_invalid = 0, 212 ns_c_in = 1, 213 ns_c_2 = 2, 214 ns_c_chaos = 3, 215 ns_c_hs = 4, 216 ns_c_none = 254, 217 ns_c_any = 255, 218 ns_c_max = 65536 219 } ns_class; 220 221 typedef enum __ns_key_types { 222 ns_kt_rsa = 1, 223 ns_kt_dh = 2, 224 ns_kt_dsa = 3, 225 ns_kt_private = 254 226 } ns_key_types; 227 228 typedef enum __ns_cert_types { 229 cert_t_pkix = 1, 230 cert_t_spki = 2, 231 cert_t_pgp = 3, 232 cert_t_url = 253, 233 cert_t_oid = 254 234 } ns_cert_types; 235 236 #define NS_KEY_TYPEMASK 0xC000 237 #define NS_KEY_TYPE_AUTH_CONF 0x0000 238 #define NS_KEY_TYPE_CONF_ONLY 0x8000 239 #define NS_KEY_TYPE_AUTH_ONLY 0x4000 240 #define NS_KEY_TYPE_NO_KEY 0xC000 241 #define NS_KEY_NO_AUTH 0x8000 242 #define NS_KEY_NO_CONF 0x4000 243 #define NS_KEY_RESERVED2 0x2000 244 #define NS_KEY_EXTENDED_FLAGS 0x1000 245 #define NS_KEY_RESERVED4 0x0800 246 #define NS_KEY_RESERVED5 0x0400 247 #define NS_KEY_NAME_TYPE 0x0300 248 #define NS_KEY_NAME_USER 0x0000 249 #define NS_KEY_NAME_ENTITY 0x0200 250 #define NS_KEY_NAME_ZONE 0x0100 251 #define NS_KEY_NAME_RESERVED 0x0300 252 #define NS_KEY_RESERVED8 0x0080 253 #define NS_KEY_RESERVED9 0x0040 254 #define NS_KEY_RESERVED10 0x0020 255 #define NS_KEY_RESERVED11 0x0010 256 #define NS_KEY_SIGNATORYMASK 0x000F 257 #define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ 258 NS_KEY_RESERVED4 | \ 259 NS_KEY_RESERVED5 | \ 260 NS_KEY_RESERVED8 | \ 261 NS_KEY_RESERVED9 | \ 262 NS_KEY_RESERVED10 | \ 263 NS_KEY_RESERVED11 ) 264 #define NS_KEY_RESERVED_BITMASK2 0xFFFF 265 #define NS_ALG_MD5RSA 1 266 #define NS_ALG_DH 2 267 #define NS_ALG_DSA 3 268 #define NS_ALG_DSS NS_ALG_DSA 269 #define NS_ALG_EXPIRE_ONLY 253 270 #define NS_ALG_PRIVATE_OID 254 271 272 #define NS_KEY_PROT_TLS 1 273 #define NS_KEY_PROT_EMAIL 2 274 #define NS_KEY_PROT_DNSSEC 3 275 #define NS_KEY_PROT_IPSEC 4 276 #define NS_KEY_PROT_ANY 255 277 278 #define NS_MD5RSA_MIN_BITS 512 279 #define NS_MD5RSA_MAX_BITS 4096 280 #define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) 281 #define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) 282 #define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) 283 #define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) 284 285 #define NS_DSA_SIG_SIZE 41 286 #define NS_DSA_MIN_SIZE 213 287 #define NS_DSA_MAX_BYTES 405 288 289 #define NS_SIG_TYPE 0 290 #define NS_SIG_ALG 2 291 #define NS_SIG_LABELS 3 292 #define NS_SIG_OTTL 4 293 #define NS_SIG_EXPIR 8 294 #define NS_SIG_SIGNED 12 295 #define NS_SIG_FOOT 16 296 #define NS_SIG_SIGNER 18 297 #define NS_NXT_BITS 8 298 #define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) 299 #define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) 300 #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) 301 #define NS_NXT_MAX 127 302 303 #define NS_OPT_DNSSEC_OK 0x8000U 304 #define NS_OPT_NSID 3 305 306 #define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) 307 #define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) 308 #define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2) 309 #define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4) 310 311 unsigned ns_get16(const unsigned char *); 312 unsigned long ns_get32(const unsigned char *); 313 void ns_put16(unsigned, unsigned char *); 314 void ns_put32(unsigned long, unsigned char *); 315 316 int ns_initparse(const unsigned char *, int, ns_msg *); 317 int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); 318 int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int); 319 int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t); 320 321 322 #define __BIND 19950621 323 324 typedef struct { 325 unsigned id :16; 326 #if __BYTE_ORDER == __BIG_ENDIAN 327 unsigned qr: 1; 328 unsigned opcode: 4; 329 unsigned aa: 1; 330 unsigned tc: 1; 331 unsigned rd: 1; 332 unsigned ra: 1; 333 unsigned unused :1; 334 unsigned ad: 1; 335 unsigned cd: 1; 336 unsigned rcode :4; 337 #else 338 unsigned rd :1; 339 unsigned tc :1; 340 unsigned aa :1; 341 unsigned opcode :4; 342 unsigned qr :1; 343 unsigned rcode :4; 344 unsigned cd: 1; 345 unsigned ad: 1; 346 unsigned unused :1; 347 unsigned ra :1; 348 #endif 349 unsigned qdcount :16; 350 unsigned ancount :16; 351 unsigned nscount :16; 352 unsigned arcount :16; 353 } HEADER; 354 355 #define PACKETSZ NS_PACKETSZ 356 #define MAXDNAME NS_MAXDNAME 357 #define MAXCDNAME NS_MAXCDNAME 358 #define MAXLABEL NS_MAXLABEL 359 #define HFIXEDSZ NS_HFIXEDSZ 360 #define QFIXEDSZ NS_QFIXEDSZ 361 #define RRFIXEDSZ NS_RRFIXEDSZ 362 #define INT32SZ NS_INT32SZ 363 #define INT16SZ NS_INT16SZ 364 #define INT8SZ NS_INT8SZ 365 #define INADDRSZ NS_INADDRSZ 366 #define IN6ADDRSZ NS_IN6ADDRSZ 367 #define INDIR_MASK NS_CMPRSFLGS 368 #define NAMESERVER_PORT NS_DEFAULTPORT 369 370 #define S_ZONE ns_s_zn 371 #define S_PREREQ ns_s_pr 372 #define S_UPDATE ns_s_ud 373 #define S_ADDT ns_s_ar 374 375 #define QUERY ns_o_query 376 #define IQUERY ns_o_iquery 377 #define STATUS ns_o_status 378 #define NS_NOTIFY_OP ns_o_notify 379 #define NS_UPDATE_OP ns_o_update 380 381 #define NOERROR ns_r_noerror 382 #define FORMERR ns_r_formerr 383 #define SERVFAIL ns_r_servfail 384 #define NXDOMAIN ns_r_nxdomain 385 #define NOTIMP ns_r_notimpl 386 #define REFUSED ns_r_refused 387 #define YXDOMAIN ns_r_yxdomain 388 #define YXRRSET ns_r_yxrrset 389 #define NXRRSET ns_r_nxrrset 390 #define NOTAUTH ns_r_notauth 391 #define NOTZONE ns_r_notzone 392 393 #define DELETE ns_uop_delete 394 #define ADD ns_uop_add 395 396 #define T_A ns_t_a 397 #define T_NS ns_t_ns 398 #define T_MD ns_t_md 399 #define T_MF ns_t_mf 400 #define T_CNAME ns_t_cname 401 #define T_SOA ns_t_soa 402 #define T_MB ns_t_mb 403 #define T_MG ns_t_mg 404 #define T_MR ns_t_mr 405 #define T_NULL ns_t_null 406 #define T_WKS ns_t_wks 407 #define T_PTR ns_t_ptr 408 #define T_HINFO ns_t_hinfo 409 #define T_MINFO ns_t_minfo 410 #define T_MX ns_t_mx 411 #define T_TXT ns_t_txt 412 #define T_RP ns_t_rp 413 #define T_AFSDB ns_t_afsdb 414 #define T_X25 ns_t_x25 415 #define T_ISDN ns_t_isdn 416 #define T_RT ns_t_rt 417 #define T_NSAP ns_t_nsap 418 #define T_NSAP_PTR ns_t_nsap_ptr 419 #define T_SIG ns_t_sig 420 #define T_KEY ns_t_key 421 #define T_PX ns_t_px 422 #define T_GPOS ns_t_gpos 423 #define T_AAAA ns_t_aaaa 424 #define T_LOC ns_t_loc 425 #define T_NXT ns_t_nxt 426 #define T_EID ns_t_eid 427 #define T_NIMLOC ns_t_nimloc 428 #define T_SRV ns_t_srv 429 #define T_ATMA ns_t_atma 430 #define T_NAPTR ns_t_naptr 431 #define T_A6 ns_t_a6 432 #define T_DNAME ns_t_dname 433 #define T_TSIG ns_t_tsig 434 #define T_IXFR ns_t_ixfr 435 #define T_AXFR ns_t_axfr 436 #define T_MAILB ns_t_mailb 437 #define T_MAILA ns_t_maila 438 #define T_ANY ns_t_any 439 440 #define C_IN ns_c_in 441 #define C_CHAOS ns_c_chaos 442 #define C_HS ns_c_hs 443 #define C_NONE ns_c_none 444 #define C_ANY ns_c_any 445 446 #define GETSHORT NS_GET16 447 #define GETLONG NS_GET32 448 #define PUTSHORT NS_PUT16 449 #define PUTLONG NS_PUT32 450 451 #ifdef __cplusplus 452 } 453 #endif 454 455 #endif 456