nameser.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  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_tkey = 249,
  174. ns_t_tsig = 250,
  175. ns_t_ixfr = 251,
  176. ns_t_axfr = 252,
  177. ns_t_mailb = 253,
  178. ns_t_maila = 254,
  179. ns_t_any = 255,
  180. ns_t_zxfr = 256,
  181. ns_t_max = 65536
  182. } ns_type;
  183. #define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
  184. (t) == ns_t_mailb || (t) == ns_t_maila)
  185. #define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
  186. #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
  187. #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
  188. #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
  189. (t) == ns_t_zxfr)
  190. typedef enum __ns_class {
  191. ns_c_invalid = 0,
  192. ns_c_in = 1,
  193. ns_c_2 = 2,
  194. ns_c_chaos = 3,
  195. ns_c_hs = 4,
  196. ns_c_none = 254,
  197. ns_c_any = 255,
  198. ns_c_max = 65536
  199. } ns_class;
  200. typedef enum __ns_key_types {
  201. ns_kt_rsa = 1,
  202. ns_kt_dh = 2,
  203. ns_kt_dsa = 3,
  204. ns_kt_private = 254
  205. } ns_key_types;
  206. typedef enum __ns_cert_types {
  207. cert_t_pkix = 1,
  208. cert_t_spki = 2,
  209. cert_t_pgp = 3,
  210. cert_t_url = 253,
  211. cert_t_oid = 254
  212. } ns_cert_types;
  213. #define NS_KEY_TYPEMASK 0xC000
  214. #define NS_KEY_TYPE_AUTH_CONF 0x0000
  215. #define NS_KEY_TYPE_CONF_ONLY 0x8000
  216. #define NS_KEY_TYPE_AUTH_ONLY 0x4000
  217. #define NS_KEY_TYPE_NO_KEY 0xC000
  218. #define NS_KEY_NO_AUTH 0x8000
  219. #define NS_KEY_NO_CONF 0x4000
  220. #define NS_KEY_RESERVED2 0x2000
  221. #define NS_KEY_EXTENDED_FLAGS 0x1000
  222. #define NS_KEY_RESERVED4 0x0800
  223. #define NS_KEY_RESERVED5 0x0400
  224. #define NS_KEY_NAME_TYPE 0x0300
  225. #define NS_KEY_NAME_USER 0x0000
  226. #define NS_KEY_NAME_ENTITY 0x0200
  227. #define NS_KEY_NAME_ZONE 0x0100
  228. #define NS_KEY_NAME_RESERVED 0x0300
  229. #define NS_KEY_RESERVED8 0x0080
  230. #define NS_KEY_RESERVED9 0x0040
  231. #define NS_KEY_RESERVED10 0x0020
  232. #define NS_KEY_RESERVED11 0x0010
  233. #define NS_KEY_SIGNATORYMASK 0x000F
  234. #define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
  235. NS_KEY_RESERVED4 | \
  236. NS_KEY_RESERVED5 | \
  237. NS_KEY_RESERVED8 | \
  238. NS_KEY_RESERVED9 | \
  239. NS_KEY_RESERVED10 | \
  240. NS_KEY_RESERVED11 )
  241. #define NS_KEY_RESERVED_BITMASK2 0xFFFF
  242. #define NS_ALG_MD5RSA 1
  243. #define NS_ALG_DH 2
  244. #define NS_ALG_DSA 3
  245. #define NS_ALG_DSS NS_ALG_DSA
  246. #define NS_ALG_EXPIRE_ONLY 253
  247. #define NS_ALG_PRIVATE_OID 254
  248. #define NS_KEY_PROT_TLS 1
  249. #define NS_KEY_PROT_EMAIL 2
  250. #define NS_KEY_PROT_DNSSEC 3
  251. #define NS_KEY_PROT_IPSEC 4
  252. #define NS_KEY_PROT_ANY 255
  253. #define NS_MD5RSA_MIN_BITS 512
  254. #define NS_MD5RSA_MAX_BITS 4096
  255. #define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)
  256. #define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4)
  257. #define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8)
  258. #define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8)
  259. #define NS_DSA_SIG_SIZE 41
  260. #define NS_DSA_MIN_SIZE 213
  261. #define NS_DSA_MAX_BYTES 405
  262. #define NS_SIG_TYPE 0
  263. #define NS_SIG_ALG 2
  264. #define NS_SIG_LABELS 3
  265. #define NS_SIG_OTTL 4
  266. #define NS_SIG_EXPIR 8
  267. #define NS_SIG_SIGNED 12
  268. #define NS_SIG_FOOT 16
  269. #define NS_SIG_SIGNER 18
  270. #define NS_NXT_BITS 8
  271. #define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS)))
  272. #define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
  273. #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS)))
  274. #define NS_NXT_MAX 127
  275. #define NS_OPT_DNSSEC_OK 0x8000U
  276. #define NS_OPT_NSID 3
  277. #define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
  278. #define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
  279. #define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
  280. #define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)
  281. unsigned ns_get16(const unsigned char *);
  282. unsigned long ns_get32(const unsigned char *);
  283. void ns_put16(unsigned, unsigned char *);
  284. void ns_put32(unsigned long, unsigned char *);
  285. int ns_initparse(const unsigned char *, int, ns_msg *);
  286. int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
  287. int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
  288. int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);
  289. #define __BIND 19950621
  290. typedef struct {
  291. unsigned id :16;
  292. #if __BYTE_ORDER == __BIG_ENDIAN
  293. unsigned qr: 1;
  294. unsigned opcode: 4;
  295. unsigned aa: 1;
  296. unsigned tc: 1;
  297. unsigned rd: 1;
  298. unsigned ra: 1;
  299. unsigned unused :1;
  300. unsigned ad: 1;
  301. unsigned cd: 1;
  302. unsigned rcode :4;
  303. #else
  304. unsigned rd :1;
  305. unsigned tc :1;
  306. unsigned aa :1;
  307. unsigned opcode :4;
  308. unsigned qr :1;
  309. unsigned rcode :4;
  310. unsigned cd: 1;
  311. unsigned ad: 1;
  312. unsigned unused :1;
  313. unsigned ra :1;
  314. #endif
  315. unsigned qdcount :16;
  316. unsigned ancount :16;
  317. unsigned nscount :16;
  318. unsigned arcount :16;
  319. } HEADER;
  320. #define PACKETSZ NS_PACKETSZ
  321. #define MAXDNAME NS_MAXDNAME
  322. #define MAXCDNAME NS_MAXCDNAME
  323. #define MAXLABEL NS_MAXLABEL
  324. #define HFIXEDSZ NS_HFIXEDSZ
  325. #define QFIXEDSZ NS_QFIXEDSZ
  326. #define RRFIXEDSZ NS_RRFIXEDSZ
  327. #define INT32SZ NS_INT32SZ
  328. #define INT16SZ NS_INT16SZ
  329. #define INT8SZ NS_INT8SZ
  330. #define INADDRSZ NS_INADDRSZ
  331. #define IN6ADDRSZ NS_IN6ADDRSZ
  332. #define INDIR_MASK NS_CMPRSFLGS
  333. #define NAMESERVER_PORT NS_DEFAULTPORT
  334. #define S_ZONE ns_s_zn
  335. #define S_PREREQ ns_s_pr
  336. #define S_UPDATE ns_s_ud
  337. #define S_ADDT ns_s_ar
  338. #define QUERY ns_o_query
  339. #define IQUERY ns_o_iquery
  340. #define STATUS ns_o_status
  341. #define NS_NOTIFY_OP ns_o_notify
  342. #define NS_UPDATE_OP ns_o_update
  343. #define NOERROR ns_r_noerror
  344. #define FORMERR ns_r_formerr
  345. #define SERVFAIL ns_r_servfail
  346. #define NXDOMAIN ns_r_nxdomain
  347. #define NOTIMP ns_r_notimpl
  348. #define REFUSED ns_r_refused
  349. #define YXDOMAIN ns_r_yxdomain
  350. #define YXRRSET ns_r_yxrrset
  351. #define NXRRSET ns_r_nxrrset
  352. #define NOTAUTH ns_r_notauth
  353. #define NOTZONE ns_r_notzone
  354. #define DELETE ns_uop_delete
  355. #define ADD ns_uop_add
  356. #define T_A ns_t_a
  357. #define T_NS ns_t_ns
  358. #define T_MD ns_t_md
  359. #define T_MF ns_t_mf
  360. #define T_CNAME ns_t_cname
  361. #define T_SOA ns_t_soa
  362. #define T_MB ns_t_mb
  363. #define T_MG ns_t_mg
  364. #define T_MR ns_t_mr
  365. #define T_NULL ns_t_null
  366. #define T_WKS ns_t_wks
  367. #define T_PTR ns_t_ptr
  368. #define T_HINFO ns_t_hinfo
  369. #define T_MINFO ns_t_minfo
  370. #define T_MX ns_t_mx
  371. #define T_TXT ns_t_txt
  372. #define T_RP ns_t_rp
  373. #define T_AFSDB ns_t_afsdb
  374. #define T_X25 ns_t_x25
  375. #define T_ISDN ns_t_isdn
  376. #define T_RT ns_t_rt
  377. #define T_NSAP ns_t_nsap
  378. #define T_NSAP_PTR ns_t_nsap_ptr
  379. #define T_SIG ns_t_sig
  380. #define T_KEY ns_t_key
  381. #define T_PX ns_t_px
  382. #define T_GPOS ns_t_gpos
  383. #define T_AAAA ns_t_aaaa
  384. #define T_LOC ns_t_loc
  385. #define T_NXT ns_t_nxt
  386. #define T_EID ns_t_eid
  387. #define T_NIMLOC ns_t_nimloc
  388. #define T_SRV ns_t_srv
  389. #define T_ATMA ns_t_atma
  390. #define T_NAPTR ns_t_naptr
  391. #define T_A6 ns_t_a6
  392. #define T_DNAME ns_t_dname
  393. #define T_TSIG ns_t_tsig
  394. #define T_IXFR ns_t_ixfr
  395. #define T_AXFR ns_t_axfr
  396. #define T_MAILB ns_t_mailb
  397. #define T_MAILA ns_t_maila
  398. #define T_ANY ns_t_any
  399. #define C_IN ns_c_in
  400. #define C_CHAOS ns_c_chaos
  401. #define C_HS ns_c_hs
  402. #define C_NONE ns_c_none
  403. #define C_ANY ns_c_any
  404. #define GETSHORT NS_GET16
  405. #define GETLONG NS_GET32
  406. #define PUTSHORT NS_PUT16
  407. #define PUTLONG NS_PUT32
  408. #ifdef __cplusplus
  409. }
  410. #endif
  411. #endif