xref: /openbsd/usr.sbin/nsd/zonec.h (revision 891d7ab6)
1 /*
2  * zonec.h -- zone compiler.
3  *
4  * Copyright (c) 2001-2011, NLnet Labs. All rights reserved.
5  *
6  * See LICENSE for the license.
7  *
8  */
9 
10 #ifndef _ZONEC_H_
11 #define _ZONEC_H_
12 
13 #include "namedb.h"
14 
15 #define	MAXTOKENSLEN	512		/* Maximum number of tokens per entry */
16 #define	B64BUFSIZE	65535		/* Buffer size for b64 conversion */
17 #define	ROOT		(const uint8_t *)"\001"
18 
19 #define NSEC_WINDOW_COUNT     256
20 #define NSEC_WINDOW_BITS_COUNT 256
21 #define NSEC_WINDOW_BITS_SIZE  (NSEC_WINDOW_BITS_COUNT / 8)
22 
23 #define IPSECKEY_NOGATEWAY      0       /* RFC 4025 */
24 #define IPSECKEY_IP4            1
25 #define IPSECKEY_IP6            2
26 #define IPSECKEY_DNAME          3
27 
28 #define LINEBUFSZ 1024
29 
30 struct lex_data {
31     size_t   len;		/* holds the label length */
32     char    *str;		/* holds the data */
33 };
34 
35 #define DEFAULT_TTL 3600
36 
37 /* administration struct */
38 typedef struct zparser zparser_type;
39 struct zparser {
40 	region_type *region;	/* Allocate for parser lifetime data.  */
41 	region_type *rr_region;	/* Allocate RR lifetime data.  */
42 	namedb_type *db;
43 
44 	const char *filename;
45 	uint32_t default_ttl;
46 	uint16_t default_class;
47 	zone_type *current_zone;
48 	domain_type *origin;
49 	domain_type *prev_dname;
50 	domain_type *default_apex;
51 
52 	int error_occurred;
53 	unsigned int errors;
54 	unsigned int line;
55 
56 	rr_type current_rr;
57 	rdata_atom_type *temporary_rdatas;
58 };
59 
60 extern zparser_type *parser;
61 
62 /* used in zonec.lex */
63 extern FILE *yyin;
64 
65 /*
66  * Used to mark bad domains and domain names.  Do not dereference
67  * these pointers!
68  */
69 extern const dname_type *error_dname;
70 extern domain_type *error_domain;
71 
72 int yyparse(void);
73 int yylex(void);
74 /*int yyerror(const char *s);*/
75 void yyrestart(FILE *);
76 
77 void zc_warning(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2);
78 void zc_warning_prev_line(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2);
79 void zc_error(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2);
80 void zc_error_prev_line(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2);
81 
82 int process_rr(void);
83 uint16_t *zparser_conv_hex(region_type *region, const char *hex, size_t len);
84 uint16_t *zparser_conv_hex_length(region_type *region, const char *hex, size_t len);
85 uint16_t *zparser_conv_time(region_type *region, const char *time);
86 uint16_t *zparser_conv_services(region_type *region, const char *protostr, char *servicestr);
87 uint16_t *zparser_conv_serial(region_type *region, const char *periodstr);
88 uint16_t *zparser_conv_period(region_type *region, const char *periodstr);
89 uint16_t *zparser_conv_short(region_type *region, const char *text);
90 uint16_t *zparser_conv_long(region_type *region, const char *text);
91 uint16_t *zparser_conv_byte(region_type *region, const char *text);
92 uint16_t *zparser_conv_a(region_type *region, const char *text);
93 uint16_t *zparser_conv_aaaa(region_type *region, const char *text);
94 uint16_t *zparser_conv_text(region_type *region, const char *text, size_t len);
95 uint16_t *zparser_conv_dns_name(region_type *region, const uint8_t* name, size_t len);
96 uint16_t *zparser_conv_b32(region_type *region, const char *b32);
97 uint16_t *zparser_conv_b64(region_type *region, const char *b64);
98 uint16_t *zparser_conv_rrtype(region_type *region, const char *rr);
99 uint16_t *zparser_conv_nxt(region_type *region, uint8_t nxtbits[]);
100 uint16_t *zparser_conv_nsec(region_type *region, uint8_t nsecbits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE]);
101 uint16_t *zparser_conv_loc(region_type *region, char *str);
102 uint16_t *zparser_conv_algorithm(region_type *region, const char *algstr);
103 uint16_t *zparser_conv_certificate_type(region_type *region,
104 					const char *typestr);
105 uint16_t *zparser_conv_apl_rdata(region_type *region, char *str);
106 
107 void parse_unknown_rdata(uint16_t type, uint16_t *wireformat);
108 
109 uint32_t zparser_ttl2int(const char *ttlstr, int* error);
110 void zadd_rdata_wireformat(uint16_t *data);
111 void zadd_rdata_txt_wireformat(uint16_t *data, int first);
112 void zadd_rdata_txt_clean_wireformat();
113 void zadd_rdata_domain(domain_type *domain);
114 
115 void set_bitnsec(uint8_t  bits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE],
116 		 uint16_t index);
117 uint16_t *alloc_rdata_init(region_type *region, const void *data, size_t size);
118 
119 /* zparser.y */
120 zparser_type *zparser_create(region_type *region, region_type *rr_region,
121 			     namedb_type *db);
122 void zparser_init(const char *filename, uint32_t ttl, uint16_t klass,
123 		  const dname_type *origin);
124 
125 #endif /* _ZONEC_H_ */
126