162ac0c33Sjakob /* 262ac0c33Sjakob * zonec.h -- zone compiler. 362ac0c33Sjakob * 4dd5b221eSsthen * Copyright (c) 2001-2006, NLnet Labs. All rights reserved. 562ac0c33Sjakob * 662ac0c33Sjakob * See LICENSE for the license. 762ac0c33Sjakob * 862ac0c33Sjakob */ 962ac0c33Sjakob 10*3efee2e1Sflorian #ifndef ZONEC_H 11*3efee2e1Sflorian #define ZONEC_H 1262ac0c33Sjakob 1362ac0c33Sjakob #include "namedb.h" 1462ac0c33Sjakob 1562ac0c33Sjakob #define MAXTOKENSLEN 512 /* Maximum number of tokens per entry */ 1662ac0c33Sjakob #define B64BUFSIZE 65535 /* Buffer size for b64 conversion */ 1762ac0c33Sjakob #define ROOT (const uint8_t *)"\001" 1862ac0c33Sjakob 1962ac0c33Sjakob #define NSEC_WINDOW_COUNT 256 2062ac0c33Sjakob #define NSEC_WINDOW_BITS_COUNT 256 2162ac0c33Sjakob #define NSEC_WINDOW_BITS_SIZE (NSEC_WINDOW_BITS_COUNT / 8) 2262ac0c33Sjakob 2362ac0c33Sjakob #define IPSECKEY_NOGATEWAY 0 /* RFC 4025 */ 2462ac0c33Sjakob #define IPSECKEY_IP4 1 2562ac0c33Sjakob #define IPSECKEY_IP6 2 2662ac0c33Sjakob #define IPSECKEY_DNAME 3 2762ac0c33Sjakob 2862ac0c33Sjakob #define LINEBUFSZ 1024 2962ac0c33Sjakob 3062ac0c33Sjakob struct lex_data { 3162ac0c33Sjakob size_t len; /* holds the label length */ 3262ac0c33Sjakob char *str; /* holds the data */ 3362ac0c33Sjakob }; 3462ac0c33Sjakob 3562ac0c33Sjakob #define DEFAULT_TTL 3600 3662ac0c33Sjakob 3762ac0c33Sjakob /* administration struct */ 3862ac0c33Sjakob typedef struct zparser zparser_type; 3962ac0c33Sjakob struct zparser { 4062ac0c33Sjakob region_type *region; /* Allocate for parser lifetime data. */ 4162ac0c33Sjakob region_type *rr_region; /* Allocate RR lifetime data. */ 4262ac0c33Sjakob namedb_type *db; 4362ac0c33Sjakob 4462ac0c33Sjakob const char *filename; 4562ac0c33Sjakob uint32_t default_ttl; 4662ac0c33Sjakob uint16_t default_class; 4762ac0c33Sjakob zone_type *current_zone; 4862ac0c33Sjakob domain_type *origin; 4962ac0c33Sjakob domain_type *prev_dname; 5062ac0c33Sjakob 5162ac0c33Sjakob int error_occurred; 5262ac0c33Sjakob unsigned int errors; 5362ac0c33Sjakob unsigned int line; 5462ac0c33Sjakob 5562ac0c33Sjakob rr_type current_rr; 5662ac0c33Sjakob rdata_atom_type *temporary_rdatas; 5762ac0c33Sjakob }; 5862ac0c33Sjakob 5962ac0c33Sjakob extern zparser_type *parser; 6062ac0c33Sjakob 6162ac0c33Sjakob /* used in zonec.lex */ 6262ac0c33Sjakob extern FILE *yyin; 6362ac0c33Sjakob 6462ac0c33Sjakob /* 6562ac0c33Sjakob * Used to mark bad domains and domain names. Do not dereference 6662ac0c33Sjakob * these pointers! 6762ac0c33Sjakob */ 6862ac0c33Sjakob extern const dname_type *error_dname; 6962ac0c33Sjakob extern domain_type *error_domain; 7062ac0c33Sjakob 7162ac0c33Sjakob int yyparse(void); 7262ac0c33Sjakob int yylex(void); 73dd5b221eSsthen int yylex_destroy(void); 7462ac0c33Sjakob /*int yyerror(const char *s);*/ 7562ac0c33Sjakob void yyrestart(FILE *); 7662ac0c33Sjakob 7762ac0c33Sjakob void zc_warning(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 7862ac0c33Sjakob void zc_warning_prev_line(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 7962ac0c33Sjakob void zc_error(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 8062ac0c33Sjakob void zc_error_prev_line(const char *fmt, ...) ATTR_FORMAT(printf, 1, 2); 8162ac0c33Sjakob 82dd5b221eSsthen void parser_push_stringbuf(char* str); 83dd5b221eSsthen void parser_pop_stringbuf(void); 84ee5153b7Sflorian void parser_flush(void); 85dd5b221eSsthen 8662ac0c33Sjakob int process_rr(void); 8762ac0c33Sjakob uint16_t *zparser_conv_hex(region_type *region, const char *hex, size_t len); 8862ac0c33Sjakob uint16_t *zparser_conv_hex_length(region_type *region, const char *hex, size_t len); 8962ac0c33Sjakob uint16_t *zparser_conv_time(region_type *region, const char *time); 9062ac0c33Sjakob uint16_t *zparser_conv_services(region_type *region, const char *protostr, char *servicestr); 9162ac0c33Sjakob uint16_t *zparser_conv_serial(region_type *region, const char *periodstr); 9262ac0c33Sjakob uint16_t *zparser_conv_period(region_type *region, const char *periodstr); 9362ac0c33Sjakob uint16_t *zparser_conv_short(region_type *region, const char *text); 9462ac0c33Sjakob uint16_t *zparser_conv_long(region_type *region, const char *text); 9562ac0c33Sjakob uint16_t *zparser_conv_byte(region_type *region, const char *text); 9662ac0c33Sjakob uint16_t *zparser_conv_a(region_type *region, const char *text); 9762ac0c33Sjakob uint16_t *zparser_conv_aaaa(region_type *region, const char *text); 9875343be4Ssthen uint16_t *zparser_conv_ilnp64(region_type *region, const char *text); 999c620270Ssthen uint16_t *zparser_conv_eui(region_type *region, const char *text, size_t len); 10062ac0c33Sjakob uint16_t *zparser_conv_text(region_type *region, const char *text, size_t len); 101a302926fSbrad uint16_t *zparser_conv_long_text(region_type *region, const char *text, size_t len); 102a302926fSbrad uint16_t *zparser_conv_tag(region_type *region, const char *text, size_t len); 10362ac0c33Sjakob uint16_t *zparser_conv_dns_name(region_type *region, const uint8_t* name, size_t len); 10462ac0c33Sjakob uint16_t *zparser_conv_b32(region_type *region, const char *b32); 10562ac0c33Sjakob uint16_t *zparser_conv_b64(region_type *region, const char *b64); 10662ac0c33Sjakob uint16_t *zparser_conv_rrtype(region_type *region, const char *rr); 10762ac0c33Sjakob uint16_t *zparser_conv_nxt(region_type *region, uint8_t nxtbits[]); 10862ac0c33Sjakob uint16_t *zparser_conv_nsec(region_type *region, uint8_t nsecbits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE]); 10962ac0c33Sjakob uint16_t *zparser_conv_loc(region_type *region, char *str); 11062ac0c33Sjakob uint16_t *zparser_conv_algorithm(region_type *region, const char *algstr); 11162ac0c33Sjakob uint16_t *zparser_conv_certificate_type(region_type *region, 11262ac0c33Sjakob const char *typestr); 11362ac0c33Sjakob uint16_t *zparser_conv_apl_rdata(region_type *region, char *str); 114063644e9Sflorian uint16_t *zparser_conv_svcbparam(region_type *region, 115063644e9Sflorian const char *key, size_t key_len, const char *value, size_t value_len); 11662ac0c33Sjakob 11762ac0c33Sjakob void parse_unknown_rdata(uint16_t type, uint16_t *wireformat); 11862ac0c33Sjakob 11962ac0c33Sjakob uint32_t zparser_ttl2int(const char *ttlstr, int* error); 12062ac0c33Sjakob void zadd_rdata_wireformat(uint16_t *data); 121f72b2965Sjakob void zadd_rdata_txt_wireformat(uint16_t *data, int first); 1223b24e79eSsthen void zadd_rdata_txt_clean_wireformat(void); 123063644e9Sflorian void zadd_rdata_svcb_check_wireformat(void); 12462ac0c33Sjakob void zadd_rdata_domain(domain_type *domain); 12562ac0c33Sjakob 12662ac0c33Sjakob void set_bitnsec(uint8_t bits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE], 12762ac0c33Sjakob uint16_t index); 12862ac0c33Sjakob uint16_t *alloc_rdata_init(region_type *region, const void *data, size_t size); 12962ac0c33Sjakob 13062ac0c33Sjakob /* zparser.y */ 13162ac0c33Sjakob zparser_type *zparser_create(region_type *region, region_type *rr_region, 13262ac0c33Sjakob namedb_type *db); 13362ac0c33Sjakob void zparser_init(const char *filename, uint32_t ttl, uint16_t klass, 13462ac0c33Sjakob const dname_type *origin); 13562ac0c33Sjakob 136dd5b221eSsthen /* parser start and stop to parse a zone */ 137dd5b221eSsthen void zonec_setup_parser(namedb_type* db); 138dd5b221eSsthen void zonec_desetup_parser(void); 139dd5b221eSsthen /* parse a zone into memory. name is origin. zonefile is file to read. 140dd5b221eSsthen * returns number of errors; failure may have read a partial zone */ 141dd5b221eSsthen unsigned int zonec_read(const char *name, const char *zonefile, zone_type* zone); 142dd5b221eSsthen /* parse a string into the region. and with given domaintable. global parser 143dd5b221eSsthen * is restored afterwards. zone needs apex set. returns last domain name 144dd5b221eSsthen * parsed and the number rrs parse. return number of errors, 0 is success. 145dd5b221eSsthen * The string must end with a newline after the RR. */ 146dd5b221eSsthen int zonec_parse_string(region_type* region, domain_table_type* domains, 147dd5b221eSsthen zone_type* zone, char* str, domain_type** parsed, int* num_rrs); 148eab1363eSsthen /** check SSHFP type for failures and emit warnings */ 149eab1363eSsthen void check_sshfp(void); 1504564029fSflorian void apex_rrset_checks(struct namedb* db, rrset_type* rrset, 1514564029fSflorian domain_type* domain); 152dd5b221eSsthen 153*3efee2e1Sflorian #endif /* ZONEC_H */ 154