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 51 int error_occurred; 52 unsigned int errors; 53 unsigned int line; 54 55 rr_type current_rr; 56 rdata_atom_type *temporary_rdatas; 57 }; 58 59 extern zparser_type *parser; 60 61 /* used in zonec.lex */ 62 extern FILE *yyin; 63 64 /* 65 * Used to mark bad domains and domain names. Do not dereference 66 * these pointers! 67 */ 68 extern const dname_type *error_dname; 69 extern domain_type *error_domain; 70 71 int yyparse(void); 72 int yylex(void); 73 int yylex_destroy(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 void parser_push_stringbuf(char* str); 83 void parser_pop_stringbuf(void); 84 void parser_flush(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 uint16_t *zparser_conv_svcbparam(region_type *region, 115 const char *key, size_t key_len, const char *value, size_t value_len); 116 117 void parse_unknown_rdata(uint16_t type, uint16_t *wireformat); 118 119 uint32_t zparser_ttl2int(const char *ttlstr, int* error); 120 void zadd_rdata_wireformat(uint16_t *data); 121 void zadd_rdata_txt_wireformat(uint16_t *data, int first); 122 void zadd_rdata_txt_clean_wireformat(void); 123 void zadd_rdata_svcb_check_wireformat(void); 124 void zadd_rdata_domain(domain_type *domain); 125 126 void set_bitnsec(uint8_t bits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE], 127 uint16_t index); 128 uint16_t *alloc_rdata_init(region_type *region, const void *data, size_t size); 129 130 /* zparser.y */ 131 zparser_type *zparser_create(region_type *region, region_type *rr_region, 132 namedb_type *db); 133 void zparser_init(const char *filename, uint32_t ttl, uint16_t klass, 134 const dname_type *origin); 135 136 /* parser start and stop to parse a zone */ 137 void zonec_setup_parser(namedb_type* db); 138 void zonec_desetup_parser(void); 139 /* parse a zone into memory. name is origin. zonefile is file to read. 140 * returns number of errors; failure may have read a partial zone */ 141 unsigned int zonec_read(const char *name, const char *zonefile, zone_type* zone); 142 /* parse a string into the region. and with given domaintable. global parser 143 * is restored afterwards. zone needs apex set. returns last domain name 144 * parsed and the number rrs parse. return number of errors, 0 is success. 145 * The string must end with a newline after the RR. */ 146 int zonec_parse_string(region_type* region, domain_table_type* domains, 147 zone_type* zone, char* str, domain_type** parsed, int* num_rrs); 148 /** check SSHFP type for failures and emit warnings */ 149 void check_sshfp(void); 150 void apex_rrset_checks(struct namedb* db, rrset_type* rrset, 151 domain_type* domain); 152 153 #endif /* ZONEC_H */ 154