1
0

nameser.h 12 KB

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