nameser.h
001:
002:
003:
004:
005:
006:
007:
008:
009:
010:
011:
012:
013:
014:
015:
016:
017:
018:
019:
020:
021:
022:
023:
024:
025:
026:
027:
028:
029:
030:
031:
032:
033:
034:
035:
036:
037:
038:
039:
040:
041:
042:
043:
044:
045:
046:
047:
048:
049:
050:
051:
052: #ifndef _ARPA_NAMESER_H_
053: #define _ARPA_NAMESER_H_
054:
055:
056:
057: #define BIND_4_COMPAT
058:
059: #include <sys/param.h>
060: #if (!defined(BSD)) || (BSD < 199306)
061: # include <sys/bitypes.h>
062: #else
063: # include <sys/types.h>
064: #endif
065: #include <sys/cdefs.h>
066:
067:
068:
069:
070:
071:
072:
073:
074:
075: #define __NAMESER 19991006
076:
077:
078:
079: #define NS_PACKETSZ 512
080: #define NS_MAXDNAME 1025
081: #define NS_MAXMSG 65535
082: #define NS_MAXCDNAME 255
083: #define NS_MAXLABEL 63
084: #define NS_HFIXEDSZ 12
085: #define NS_QFIXEDSZ 4
086: #define NS_RRFIXEDSZ 10
087: #define NS_INT32SZ 4
088: #define NS_INT16SZ 2
089: #define NS_INT8SZ 1
090: #define NS_INADDRSZ 4
091: #define NS_IN6ADDRSZ 16
092: #define NS_CMPRSFLGS 0xc0
093: #define NS_DEFAULTPORT 53
094:
095:
096:
097:
098: typedef enum __ns_sect {
099: ns_s_qd = 0,
100: ns_s_zn = 0,
101: ns_s_an = 1,
102: ns_s_pr = 1,
103: ns_s_ns = 2,
104: ns_s_ud = 2,
105: ns_s_ar = 3,
106: ns_s_max = 4
107: } ns_sect;
108:
109:
110:
111:
112:
113:
114: typedef struct __ns_msg {
115: const u_char *_msg, *_eom;
116: u_int16_t _id, _flags, _counts[ns_s_max];
117: const u_char *_sections[ns_s_max];
118: ns_sect _sect;
119: int _rrnum;
120: const u_char *_msg_ptr;
121: } ns_msg;
122:
123:
124: struct _ns_flagdata { int mask, shift; };
125: extern const struct _ns_flagdata _ns_flagdata[];
126:
127:
128:
129: #define ns_msg_id(handle) ((handle)._id + 0)
130: #define ns_msg_base(handle) ((handle)._msg + 0)
131: #define ns_msg_end(handle) ((handle)._eom + 0)
132: #define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
133: #define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
134:
135:
136:
137:
138: typedef struct __ns_rr {
139: char name[NS_MAXDNAME];
140: u_int16_t type;
141: u_int16_t rr_class;
142: u_int32_t ttl;
143: u_int16_t rdlength;
144: const u_char * rdata;
145: } ns_rr;
146:
147:
148: #define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".")
149: #define ns_rr_type(rr) ((ns_type)((rr).type + 0))
150: #define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0))
151: #define ns_rr_ttl(rr) ((rr).ttl + 0)
152: #define ns_rr_rdlen(rr) ((rr).rdlength + 0)
153: #define ns_rr_rdata(rr) ((rr).rdata + 0)
154:
155:
156:
157:
158:
159:
160: typedef enum __ns_flag {
161: ns_f_qr,
162: ns_f_opcode,
163: ns_f_aa,
164: ns_f_tc,
165: ns_f_rd,
166: ns_f_ra,
167: ns_f_z,
168: ns_f_ad,
169: ns_f_cd,
170: ns_f_rcode,
171: ns_f_max
172: } ns_flag;
173:
174:
175:
176:
177: typedef enum __ns_opcode {
178: ns_o_query = 0,
179: ns_o_iquery = 1,
180: ns_o_status = 2,
181:
182: ns_o_notify = 4,
183: ns_o_update = 5,
184: ns_o_max = 6
185: } ns_opcode;
186:
187:
188:
189:
190: typedef enum __ns_rcode {
191: ns_r_noerror = 0,
192: ns_r_formerr = 1,
193: ns_r_servfail = 2,
194: ns_r_nxdomain = 3,
195: ns_r_notimpl = 4,
196: ns_r_refused = 5,
197:
198: ns_r_yxdomain = 6,
199: ns_r_yxrrset = 7,
200: ns_r_nxrrset = 8,
201: ns_r_notauth = 9,
202: ns_r_notzone = 10,
203: ns_r_max = 11,
204:
205: ns_r_badvers = 16,
206:
207: ns_r_badsig = 16,
208: ns_r_badkey = 17,
209: ns_r_badtime = 18
210: } ns_rcode;
211:
212:
213: typedef enum __ns_update_operation {
214: ns_uop_delete = 0,
215: ns_uop_add = 1,
216: ns_uop_max = 2
217: } ns_update_operation;
218:
219:
220:
221:
222: struct ns_tsig_key {
223: char name[NS_MAXDNAME], alg[NS_MAXDNAME];
224: unsigned char *data;
225: int len;
226: };
227: typedef struct ns_tsig_key ns_tsig_key;
228:
229:
230:
231:
232: struct ns_tcp_tsig_state {
233: int counter;
234: struct dst_key *key;
235: void *ctx;
236: unsigned char sig[NS_PACKETSZ];
237: int siglen;
238: };
239: typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;
240:
241: #define NS_TSIG_FUDGE 300
242: #define NS_TSIG_TCP_COUNT 100
243: #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"
244:
245: #define NS_TSIG_ERROR_NO_TSIG -10
246: #define NS_TSIG_ERROR_NO_SPACE -11
247: #define NS_TSIG_ERROR_FORMERR -12
248:
249:
250:
251:
252: typedef enum __ns_type {
253: ns_t_invalid = 0,
254: ns_t_a = 1,
255: ns_t_ns = 2,
256: ns_t_md = 3,
257: ns_t_mf = 4,
258: ns_t_cname = 5,
259: ns_t_soa = 6,
260: ns_t_mb = 7,
261: ns_t_mg = 8,
262: ns_t_mr = 9,
263: ns_t_null = 10,
264: ns_t_wks = 11,
265: ns_t_ptr = 12,
266: ns_t_hinfo = 13,
267: ns_t_minfo = 14,
268: ns_t_mx = 15,
269: ns_t_txt = 16,
270: ns_t_rp = 17,
271: ns_t_afsdb = 18,
272: ns_t_x25 = 19,
273: ns_t_isdn = 20,
274: ns_t_rt = 21,
275: ns_t_nsap = 22,
276: ns_t_nsap_ptr = 23,
277: ns_t_sig = 24,
278: ns_t_key = 25,
279: ns_t_px = 26,
280: ns_t_gpos = 27,
281: ns_t_aaaa = 28,
282: ns_t_loc = 29,
283: ns_t_nxt = 30,
284: ns_t_eid = 31,
285: ns_t_nimloc = 32,
286: ns_t_srv = 33,
287: ns_t_atma = 34,
288: ns_t_naptr = 35,
289: ns_t_kx = 36,
290: ns_t_cert = 37,
291: ns_t_a6 = 38,
292: ns_t_dname = 39,
293: ns_t_sink = 40,
294: ns_t_opt = 41,
295: ns_t_apl = 42,
296: ns_t_tkey = 249,
297: ns_t_tsig = 250,
298: ns_t_ixfr = 251,
299: ns_t_axfr = 252,
300: ns_t_mailb = 253,
301: ns_t_maila = 254,
302: ns_t_any = 255,
303: ns_t_zxfr = 256,
304: ns_t_max = 65536
305: } ns_type;
306:
307:
308: #define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
309: (t) == ns_t_mailb || (t) == ns_t_maila)
310:
311: #define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
312:
313: #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
314: #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
315: #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
316: (t) == ns_t_zxfr)
317:
318:
319:
320:
321: typedef enum __ns_class {
322: ns_c_invalid = 0,
323: ns_c_in = 1,
324: ns_c_2 = 2,
325: ns_c_chaos = 3,
326: ns_c_hs = 4,
327:
328: ns_c_none = 254,
329: ns_c_any = 255,
330: ns_c_max = 65536
331: } ns_class;
332:
333:
334:
335: typedef enum __ns_key_types {
336: ns_kt_rsa = 1,
337: ns_kt_dh = 2,
338: ns_kt_dsa = 3,
339: ns_kt_private = 254
340: } ns_key_types;
341:
342: typedef enum __ns_cert_types {
343: cert_t_pkix = 1,
344: cert_t_spki = 2,
345: cert_t_pgp = 3,
346: cert_t_url = 253,
347: cert_t_oid = 254
348: } ns_cert_types;
349:
350:
351: #define NS_KEY_TYPEMASK 0xC000
352: #define NS_KEY_TYPE_AUTH_CONF 0x0000
353: #define NS_KEY_TYPE_CONF_ONLY 0x8000
354: #define NS_KEY_TYPE_AUTH_ONLY 0x4000
355: #define NS_KEY_TYPE_NO_KEY 0xC000
356:
357: #define NS_KEY_NO_AUTH 0x8000
358: #define NS_KEY_NO_CONF 0x4000
359: #define NS_KEY_RESERVED2 0x2000
360: #define NS_KEY_EXTENDED_FLAGS 0x1000
361: #define NS_KEY_RESERVED4 0x0800
362: #define NS_KEY_RESERVED5 0x0400
363: #define NS_KEY_NAME_TYPE 0x0300
364: #define NS_KEY_NAME_USER 0x0000
365: #define NS_KEY_NAME_ENTITY 0x0200
366: #define NS_KEY_NAME_ZONE 0x0100
367: #define NS_KEY_NAME_RESERVED 0x0300
368: #define NS_KEY_RESERVED8 0x0080
369: #define NS_KEY_RESERVED9 0x0040
370: #define NS_KEY_RESERVED10 0x0020
371: #define NS_KEY_RESERVED11 0x0010
372: #define NS_KEY_SIGNATORYMASK 0x000F
373: #define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
374: NS_KEY_RESERVED4 | \
375: NS_KEY_RESERVED5 | \
376: NS_KEY_RESERVED8 | \
377: NS_KEY_RESERVED9 | \
378: NS_KEY_RESERVED10 | \
379: NS_KEY_RESERVED11 )
380: #define NS_KEY_RESERVED_BITMASK2 0xFFFF
381:
382: #define NS_ALG_MD5RSA 1
383: #define NS_ALG_DH 2
384: #define NS_ALG_DSA 3
385: #define NS_ALG_DSS NS_ALG_DSA
386: #define NS_ALG_EXPIRE_ONLY 253
387: #define NS_ALG_PRIVATE_OID 254
388:
389:
390: #define NS_KEY_PROT_TLS 1
391: #define NS_KEY_PROT_EMAIL 2
392: #define NS_KEY_PROT_DNSSEC 3
393: #define NS_KEY_PROT_IPSEC 4
394: #define NS_KEY_PROT_ANY 255
395:
396:
397: #define NS_MD5RSA_MIN_BITS 512
398: #define NS_MD5RSA_MAX_BITS 4096
399:
400: #define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3)
401:
402: #define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4)
403: #define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8)
404: #define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8)
405:
406: #define NS_DSA_SIG_SIZE 41
407: #define NS_DSA_MIN_SIZE 213
408: #define NS_DSA_MAX_BYTES 405
409:
410:
411: #define NS_SIG_TYPE 0
412: #define NS_SIG_ALG 2
413: #define NS_SIG_LABELS 3
414: #define NS_SIG_OTTL 4
415: #define NS_SIG_EXPIR 8
416: #define NS_SIG_SIGNED 12
417: #define NS_SIG_FOOT 16
418: #define NS_SIG_SIGNER 18
419:
420: #define NS_NXT_BITS 8
421: #define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS)))
422: #define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
423: #define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS)))
424: #define NS_NXT_MAX 127
425:
426:
427:
428:
429: #define NS_OPT_DNSSEC_OK 0x8000U
430: #define NS_OPT_NSID 3
431:
432:
433:
434:
435: #define NS_GET16(s, cp) do { \
436: register const u_char *t_cp = (const u_char *)(cp); \
437: (s) = ((u_int16_t)t_cp[0] << 8) \
438: | ((u_int16_t)t_cp[1]) \
439: ; \
440: (cp) += NS_INT16SZ; \
441: } while (0)
442:
443: #define NS_GET32(l, cp) do { \
444: register const u_char *t_cp = (const u_char *)(cp); \
445: (l) = ((u_int32_t)t_cp[0] << 24) \
446: | ((u_int32_t)t_cp[1] << 16) \
447: | ((u_int32_t)t_cp[2] << 8) \
448: | ((u_int32_t)t_cp[3]) \
449: ; \
450: (cp) += NS_INT32SZ; \
451: } while (0)
452:
453: #define NS_PUT16(s, cp) do { \
454: register u_int16_t t_s = (u_int16_t)(s); \
455: register u_char *t_cp = (u_char *)(cp); \
456: *t_cp++ = t_s >> 8; \
457: *t_cp = t_s; \
458: (cp) += NS_INT16SZ; \
459: } while (0)
460:
461: #define NS_PUT32(l, cp) do { \
462: register u_int32_t t_l = (u_int32_t)(l); \
463: register u_char *t_cp = (u_char *)(cp); \
464: *t_cp++ = t_l >> 24; \
465: *t_cp++ = t_l >> 16; \
466: *t_cp++ = t_l >> 8; \
467: *t_cp = t_l; \
468: (cp) += NS_INT32SZ; \
469: } while (0)
470:
471: __BEGIN_DECLS
472: int ns_msg_getflag (ns_msg, int) __THROW;
473: u_int ns_get16 (const u_char *) __THROW;
474: u_long ns_get32 (const u_char *) __THROW;
475: void ns_put16 (u_int, u_char *) __THROW;
476: void ns_put32 (u_long, u_char *) __THROW;
477: int ns_initparse (const u_char *, int, ns_msg *) __THROW;
478: int ns_skiprr (const u_char *, const u_char *, ns_sect, int)
479: __THROW;
480: int ns_parserr (ns_msg *, ns_sect, int, ns_rr *) __THROW;
481: int ns_sprintrr (const ns_msg *, const ns_rr *,
482: const char *, const char *, char *, size_t)
483: __THROW;
484: int ns_sprintrrf (const u_char *, size_t, const char *,
485: ns_class, ns_type, u_long, const u_char *,
486: size_t, const char *, const char *,
487: char *, size_t) __THROW;
488: int ns_format_ttl (u_long, char *, size_t) __THROW;
489: int ns_parse_ttl (const char *, u_long *) __THROW;
490: u_int32_t ns_datetosecs (const char *, int *) __THROW;
491: int ns_name_ntol (const u_char *, u_char *, size_t) __THROW;
492: int ns_name_ntop (const u_char *, char *, size_t) __THROW;
493: int ns_name_pton (const char *, u_char *, size_t) __THROW;
494: int ns_name_unpack (const u_char *, const u_char *,
495: const u_char *, u_char *, size_t) __THROW;
496: int ns_name_pack (const u_char *, u_char *, int,
497: const u_char **, const u_char **) __THROW;
498: int ns_name_uncompress (const u_char *, const u_char *,
499: const u_char *, char *, size_t) __THROW;
500: int ns_name_compress (const char *, u_char *, size_t,
501: const u_char **, const u_char **) __THROW;
502: int ns_name_skip (const u_char **, const u_char *) __THROW;
503: void ns_name_rollback (const u_char *, const u_char **,
504: const u_char **) __THROW;
505: int ns_sign (u_char *, int *, int, int, void *,
506: const u_char *, int, u_char *, int *, time_t) __THROW;
507: int ns_sign2 (u_char *, int *, int, int, void *,
508: const u_char *, int, u_char *, int *, time_t,
509: u_char **, u_char **) __THROW;
510: int ns_sign_tcp (u_char *, int *, int, int,
511: ns_tcp_tsig_state *, int) __THROW;
512: int ns_sign_tcp2 (u_char *, int *, int, int,
513: ns_tcp_tsig_state *, int,
514: u_char **, u_char **) __THROW;
515: int ns_sign_tcp_init (void *, const u_char *, int,
516: ns_tcp_tsig_state *) __THROW;
517: u_char *ns_find_tsig (u_char *, u_char *) __THROW;
518: int ns_verify (u_char *, int *, void *, const u_char *, int,
519: u_char *, int *, time_t *, int) __THROW;
520: int ns_verify_tcp (u_char *, int *, ns_tcp_tsig_state *, int)
521: __THROW;
522: int ns_verify_tcp_init (void *, const u_char *, int,
523: ns_tcp_tsig_state *) __THROW;
524: int ns_samedomain (const char *, const char *) __THROW;
525: int ns_subdomain (const char *, const char *) __THROW;
526: int ns_makecanon (const char *, char *, size_t) __THROW;
527: int ns_samename (const char *, const char *) __THROW;
528: __END_DECLS
529:
530: #ifdef BIND_4_COMPAT
531: #include <arpa/nameser_compat.h>
532: #endif
533:
534: #endif
535:
536:
© Andrew Scott 2006 -
2024,
All Rights Reserved