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_ds = 43, 192 ns_t_sshfp = 44, 193 ns_t_ipseckey = 45, 194 ns_t_rrsig = 46, 195 ns_t_nsec = 47, 196 ns_t_dnskey = 48, 197 ns_t_dhcid = 49, 198 ns_t_nsec3 = 50, 199 ns_t_nsec3param = 51, 200 ns_t_tlsa = 52, 201 ns_t_smimea = 53, 202 ns_t_hip = 55, 203 ns_t_ninfo = 56, 204 ns_t_rkey = 57, 205 ns_t_talink = 58, 206 ns_t_cds = 59, 207 ns_t_cdnskey = 60, 208 ns_t_openpgpkey = 61, 209 ns_t_csync = 62, 210 ns_t_spf = 99, 211 ns_t_uinfo = 100, 212 ns_t_uid = 101, 213 ns_t_gid = 102, 214 ns_t_unspec = 103, 215 ns_t_nid = 104, 216 ns_t_l32 = 105, 217 ns_t_l64 = 106, 218 ns_t_lp = 107, 219 ns_t_eui48 = 108, 220 ns_t_eui64 = 109, 221 ns_t_tkey = 249, 222 ns_t_tsig = 250, 223 ns_t_ixfr = 251, 224 ns_t_axfr = 252, 225 ns_t_mailb = 253, 226 ns_t_maila = 254, 227 ns_t_any = 255, 228 ns_t_zxfr = 256, 229 ns_t_uri = 256, 230 ns_t_caa = 257, 231 ns_t_avc = 258, 232 ns_t_ta = 32768, 233 ns_t_dlv = 32769, 234 ns_t_max = 65536 235 } ns_type; 236 237 #define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ 238 (t) == ns_t_mailb || (t) == ns_t_maila) 239 #define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) 240 #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) 241 #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) 242 #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ 243 (t) == ns_t_zxfr) 244 245 typedef enum __ns_class { 246 ns_c_invalid = 0, 247 ns_c_in = 1, 248 ns_c_2 = 2, 249 ns_c_chaos = 3, 250 ns_c_hs = 4, 251 ns_c_none = 254, 252 ns_c_any = 255, 253 ns_c_max = 65536 254 } ns_class; 255 256 typedef enum __ns_key_types { 257 ns_kt_rsa = 1, 258 ns_kt_dh = 2, 259 ns_kt_dsa = 3, 260 ns_kt_private = 254 261 } ns_key_types; 262 263 typedef enum __ns_cert_types { 264 cert_t_pkix = 1, 265 cert_t_spki = 2, 266 cert_t_pgp = 3, 267 cert_t_url = 253, 268 cert_t_oid = 254 269 } ns_cert_types; 270 271 #define NS_KEY_TYPEMASK 0xC000 272 #define NS_KEY_TYPE_AUTH_CONF 0x0000 273 #define NS_KEY_TYPE_CONF_ONLY 0x8000 274 #define NS_KEY_TYPE_AUTH_ONLY 0x4000 275 #define NS_KEY_TYPE_NO_KEY 0xC000 276 #define NS_KEY_NO_AUTH 0x8000 277 #define NS_KEY_NO_CONF 0x4000 278 #define NS_KEY_RESERVED2 0x2000 279 #define NS_KEY_EXTENDED_FLAGS 0x1000 280 #define NS_KEY_RESERVED4 0x0800 281 #define NS_KEY_RESERVED5 0x0400 282 #define NS_KEY_NAME_TYPE 0x0300 283 #define NS_KEY_NAME_USER 0x0000 284 #define NS_KEY_NAME_ENTITY 0x0200 285 #define NS_KEY_NAME_ZONE 0x0100 286 #define NS_KEY_NAME_RESERVED 0x0300 287 #define NS_KEY_RESERVED8 0x0080 288 #define NS_KEY_RESERVED9 0x0040 289 #define NS_KEY_RESERVED10 0x0020 290 #define NS_KEY_RESERVED11 0x0010 291 #define NS_KEY_SIGNATORYMASK 0x000F 292 #define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ 293 NS_KEY_RESERVED4 | \ 294 NS_KEY_RESERVED5 | \ 295 NS_KEY_RESERVED8 | \ 296 NS_KEY_RESERVED9 | \ 297 NS_KEY_RESERVED10 | \ 298 NS_KEY_RESERVED11 ) 299 #define NS_KEY_RESERVED_BITMASK2 0xFFFF 300 #define NS_ALG_MD5RSA 1 301 #define NS_ALG_DH 2 302 #define NS_ALG_DSA 3 303 #define NS_ALG_DSS NS_ALG_DSA 304 #define NS_ALG_EXPIRE_ONLY 253 305 #define NS_ALG_PRIVATE_OID 254 306 307 #define NS_KEY_PROT_TLS 1 308 #define NS_KEY_PROT_EMAIL 2 309 #define NS_KEY_PROT_DNSSEC 3 310 #define NS_KEY_PROT_IPSEC 4 311 #define NS_KEY_PROT_ANY 255 312 313 #define NS_MD5RSA_MIN_BITS 512 314 #define NS_MD5RSA_MAX_BITS 4096 315 #define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) 316 #define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) 317 #define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) 318 #define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) 319 320 #define NS_DSA_SIG_SIZE 41 321 #define NS_DSA_MIN_SIZE 213 322 #define NS_DSA_MAX_BYTES 405 323 324 #define NS_SIG_TYPE 0 325 #define NS_SIG_ALG 2 326 #define NS_SIG_LABELS 3 327 #define NS_SIG_OTTL 4 328 #define NS_SIG_EXPIR 8 329 #define NS_SIG_SIGNED 12 330 #define NS_SIG_FOOT 16 331 #define NS_SIG_SIGNER 18 332 #define NS_NXT_BITS 8 333 #define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) 334 #define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) 335 #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) 336 #define NS_NXT_MAX 127 337 338 #define NS_OPT_DNSSEC_OK 0x8000U 339 #define NS_OPT_NSID 3 340 341 #define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) 342 #define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) 343 #define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2) 344 #define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4) 345 346 unsigned ns_get16(const unsigned char *); 347 unsigned long ns_get32(const unsigned char *); 348 void ns_put16(unsigned, unsigned char *); 349 void ns_put32(unsigned long, unsigned char *); 350 351 int ns_initparse(const unsigned char *, int, ns_msg *); 352 int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); 353 int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int); 354 int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t); 355 356 357 #define __BIND 19950621 358 359 typedef struct { 360 unsigned id :16; 361 #if __BYTE_ORDER == __BIG_ENDIAN 362 unsigned qr: 1; 363 unsigned opcode: 4; 364 unsigned aa: 1; 365 unsigned tc: 1; 366 unsigned rd: 1; 367 unsigned ra: 1; 368 unsigned unused :1; 369 unsigned ad: 1; 370 unsigned cd: 1; 371 unsigned rcode :4; 372 #else 373 unsigned rd :1; 374 unsigned tc :1; 375 unsigned aa :1; 376 unsigned opcode :4; 377 unsigned qr :1; 378 unsigned rcode :4; 379 unsigned cd: 1; 380 unsigned ad: 1; 381 unsigned unused :1; 382 unsigned ra :1; 383 #endif 384 unsigned qdcount :16; 385 unsigned ancount :16; 386 unsigned nscount :16; 387 unsigned arcount :16; 388 } HEADER; 389 390 #define PACKETSZ NS_PACKETSZ 391 #define MAXDNAME NS_MAXDNAME 392 #define MAXCDNAME NS_MAXCDNAME 393 #define MAXLABEL NS_MAXLABEL 394 #define HFIXEDSZ NS_HFIXEDSZ 395 #define QFIXEDSZ NS_QFIXEDSZ 396 #define RRFIXEDSZ NS_RRFIXEDSZ 397 #define INT32SZ NS_INT32SZ 398 #define INT16SZ NS_INT16SZ 399 #define INT8SZ NS_INT8SZ 400 #define INADDRSZ NS_INADDRSZ 401 #define IN6ADDRSZ NS_IN6ADDRSZ 402 #define INDIR_MASK NS_CMPRSFLGS 403 #define NAMESERVER_PORT NS_DEFAULTPORT 404 405 #define S_ZONE ns_s_zn 406 #define S_PREREQ ns_s_pr 407 #define S_UPDATE ns_s_ud 408 #define S_ADDT ns_s_ar 409 410 #define QUERY ns_o_query 411 #define IQUERY ns_o_iquery 412 #define STATUS ns_o_status 413 #define NS_NOTIFY_OP ns_o_notify 414 #define NS_UPDATE_OP ns_o_update 415 416 #define NOERROR ns_r_noerror 417 #define FORMERR ns_r_formerr 418 #define SERVFAIL ns_r_servfail 419 #define NXDOMAIN ns_r_nxdomain 420 #define NOTIMP ns_r_notimpl 421 #define REFUSED ns_r_refused 422 #define YXDOMAIN ns_r_yxdomain 423 #define YXRRSET ns_r_yxrrset 424 #define NXRRSET ns_r_nxrrset 425 #define NOTAUTH ns_r_notauth 426 #define NOTZONE ns_r_notzone 427 428 #define DELETE ns_uop_delete 429 #define ADD ns_uop_add 430 431 #define T_A ns_t_a 432 #define T_NS ns_t_ns 433 #define T_MD ns_t_md 434 #define T_MF ns_t_mf 435 #define T_CNAME ns_t_cname 436 #define T_SOA ns_t_soa 437 #define T_MB ns_t_mb 438 #define T_MG ns_t_mg 439 #define T_MR ns_t_mr 440 #define T_NULL ns_t_null 441 #define T_WKS ns_t_wks 442 #define T_PTR ns_t_ptr 443 #define T_HINFO ns_t_hinfo 444 #define T_MINFO ns_t_minfo 445 #define T_MX ns_t_mx 446 #define T_TXT ns_t_txt 447 #define T_RP ns_t_rp 448 #define T_AFSDB ns_t_afsdb 449 #define T_X25 ns_t_x25 450 #define T_ISDN ns_t_isdn 451 #define T_RT ns_t_rt 452 #define T_NSAP ns_t_nsap 453 #define T_NSAP_PTR ns_t_nsap_ptr 454 #define T_SIG ns_t_sig 455 #define T_KEY ns_t_key 456 #define T_PX ns_t_px 457 #define T_GPOS ns_t_gpos 458 #define T_AAAA ns_t_aaaa 459 #define T_LOC ns_t_loc 460 #define T_NXT ns_t_nxt 461 #define T_EID ns_t_eid 462 #define T_NIMLOC ns_t_nimloc 463 #define T_SRV ns_t_srv 464 #define T_ATMA ns_t_atma 465 #define T_NAPTR ns_t_naptr 466 #define T_A6 ns_t_a6 467 #define T_DNAME ns_t_dname 468 #define T_DS ns_t_ds 469 #define T_SSHFP ns_t_sshfp 470 #define T_IPSECKEY ns_t_ipseckey 471 #define T_RRSIG ns_t_rrsig 472 #define T_NSEC ns_t_nsec 473 #define T_DNSKEY ns_t_dnskey 474 #define T_DHCID ns_t_dhcid 475 #define T_NSEC3 ns_t_nsec3 476 #define T_NSEC3PARAM ns_t_nsec3param 477 #define T_TLSA ns_t_tlsa 478 #define T_SMIMEA ns_t_smimea 479 #define T_HIP ns_t_hip 480 #define T_NINFO ns_t_ninfo 481 #define T_RKEY ns_t_rkey 482 #define T_TALINK ns_t_talink 483 #define T_CDS ns_t_cds 484 #define T_CDNSKEY ns_t_cdnskey 485 #define T_OPENPGPKEY ns_t_openpgpkey 486 #define T_CSYNC ns_t_csync 487 #define T_SPF ns_t_spf 488 #define T_UINFO ns_t_uinfo 489 #define T_UID ns_t_uid 490 #define T_GID ns_t_gid 491 #define T_UNSPEC ns_t_unspec 492 #define T_NID ns_t_nid 493 #define T_L32 ns_t_l32 494 #define T_L64 ns_t_l64 495 #define T_LP ns_t_lp 496 #define T_EUI48 ns_t_eui48 497 #define T_EUI64 ns_t_eui64 498 #define T_TKEY ns_t_tkey 499 #define T_TSIG ns_t_tsig 500 #define T_IXFR ns_t_ixfr 501 #define T_AXFR ns_t_axfr 502 #define T_MAILB ns_t_mailb 503 #define T_MAILA ns_t_maila 504 #define T_ANY ns_t_any 505 #define T_URI ns_t_uri 506 #define T_CAA ns_t_caa 507 #define T_AVC ns_t_avc 508 #define T_TA ns_t_ta 509 #define T_DLV ns_t_dlv 510 511 #define C_IN ns_c_in 512 #define C_CHAOS ns_c_chaos 513 #define C_HS ns_c_hs 514 #define C_NONE ns_c_none 515 #define C_ANY ns_c_any 516 517 #define GETSHORT NS_GET16 518 #define GETLONG NS_GET32 519 #define PUTSHORT NS_PUT16 520 #define PUTLONG NS_PUT32 521 522 #ifdef __cplusplus 523 } 524 #endif 525 526 #endif 527