1 /* 2 * zonec.h -- zone compiler. 3 * 4 * Copyright (c) 2001-2006, 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 yylex_destroy(void); 75 /*int yyerror(const char *s);*/ 76 void yyrestart(FILE *); 77 78 void zc_warning(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 79 void zc_warning_prev_line(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 80 void zc_error(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 81 void zc_error_prev_line(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 82 83 void parser_push_stringbuf(char* str); 84 void parser_pop_stringbuf(void); 85 86 int process_rr(void); 87 uint16_t *zparser_conv_hex(region_type *region, const char *hex, size_t len); 88 uint16_t *zparser_conv_hex_length(region_type *region, const char *hex, size_t len); 89 uint16_t *zparser_conv_time(region_type *region, const char *time); 90 uint16_t *zparser_conv_services(region_type *region, const char *protostr, char *servicestr); 91 uint16_t *zparser_conv_serial(region_type *region, const char *periodstr); 92 uint16_t *zparser_conv_period(region_type *region, const char *periodstr); 93 uint16_t *zparser_conv_short(region_type *region, const char *text); 94 uint16_t *zparser_conv_long(region_type *region, const char *text); 95 uint16_t *zparser_conv_byte(region_type *region, const char *text); 96 uint16_t *zparser_conv_a(region_type *region, const char *text); 97 uint16_t *zparser_conv_aaaa(region_type *region, const char *text); 98 uint16_t *zparser_conv_ilnp64(region_type *region, const char *text); 99 uint16_t *zparser_conv_eui(region_type *region, const char *text, size_t len); 100 uint16_t *zparser_conv_text(region_type *region, const char *text, size_t len); 101 uint16_t *zparser_conv_long_text(region_type *region, const char *text, size_t len); 102 uint16_t *zparser_conv_tag(region_type *region, const char *text, size_t len); 103 uint16_t *zparser_conv_dns_name(region_type *region, const uint8_t* name, size_t len); 104 uint16_t *zparser_conv_b32(region_type *region, const char *b32); 105 uint16_t *zparser_conv_b64(region_type *region, const char *b64); 106 uint16_t *zparser_conv_rrtype(region_type *region, const char *rr); 107 uint16_t *zparser_conv_nxt(region_type *region, uint8_t nxtbits[]); 108 uint16_t *zparser_conv_nsec(region_type *region, uint8_t nsecbits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE]); 109 uint16_t *zparser_conv_loc(region_type *region, char *str); 110 uint16_t *zparser_conv_algorithm(region_type *region, const char *algstr); 111 uint16_t *zparser_conv_certificate_type(region_type *region, 112 const char *typestr); 113 uint16_t *zparser_conv_apl_rdata(region_type *region, char *str); 114 115 void parse_unknown_rdata(uint16_t type, uint16_t *wireformat); 116 117 uint32_t zparser_ttl2int(const char *ttlstr, int* error); 118 void zadd_rdata_wireformat(uint16_t *data); 119 void zadd_rdata_txt_wireformat(uint16_t *data, int first); 120 void zadd_rdata_txt_clean_wireformat(); 121 void zadd_rdata_domain(domain_type *domain); 122 123 void set_bitnsec(uint8_t bits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE], 124 uint16_t index); 125 uint16_t *alloc_rdata_init(region_type *region, const void *data, size_t size); 126 127 /* zparser.y */ 128 zparser_type *zparser_create(region_type *region, region_type *rr_region, 129 namedb_type *db); 130 void zparser_init(const char *filename, uint32_t ttl, uint16_t klass, 131 const dname_type *origin); 132 133 /* parser start and stop to parse a zone */ 134 void zonec_setup_parser(namedb_type* db); 135 void zonec_desetup_parser(void); 136 /* parse a zone into memory. name is origin. zonefile is file to read. 137 * returns number of errors; failure may have read a partial zone */ 138 unsigned int zonec_read(const char *name, const char *zonefile, zone_type* zone); 139 /* parse a string into the region. and with given domaintable. global parser 140 * is restored afterwards. zone needs apex set. returns last domain name 141 * parsed and the number rrs parse. return number of errors, 0 is success. 142 * The string must end with a newline after the RR. */ 143 int zonec_parse_string(region_type* region, domain_table_type* domains, 144 zone_type* zone, char* str, domain_type** parsed, int* num_rrs); 145 146 #endif /* _ZONEC_H_ */ 147