1 /* 2 * edns.h -- EDNS definitions (RFC 2671). 3 * 4 * Copyright (c) 2001-2006, NLnet Labs. All rights reserved. 5 * 6 * See LICENSE for the license. 7 * 8 */ 9 10 #ifndef _EDNS_H_ 11 #define _EDNS_H_ 12 13 #include "buffer.h" 14 struct nsd; 15 struct query; 16 17 #define OPT_LEN 9U /* Length of the NSD EDNS response record minus 2 */ 18 #define OPT_RDATA 2 /* holds the rdata length comes after OPT_LEN */ 19 #define OPT_HDR 4U /* NSID opt header length */ 20 #define NSID_CODE 3 /* nsid option code */ 21 #define EDE_CODE 15 /* Extended DNS Errors option code */ 22 #define DNSSEC_OK_MASK 0x8000U /* do bit mask */ 23 24 struct edns_data 25 { 26 char ok[OPT_LEN]; 27 char error[OPT_LEN]; 28 char rdata_none[OPT_RDATA]; 29 char rdata_nsid[OPT_RDATA]; 30 char nsid[OPT_HDR]; 31 }; 32 typedef struct edns_data edns_data_type; 33 34 enum edns_status 35 { 36 EDNS_NOT_PRESENT, 37 EDNS_OK, 38 /* EDNS states may be extended in the future */ 39 EDNS_ERROR 40 }; 41 typedef enum edns_status edns_status_type; 42 43 struct edns_record 44 { 45 edns_status_type status; 46 size_t position; 47 size_t maxlen; 48 size_t opt_reserved_space; 49 int dnssec_ok; 50 int nsid; 51 int ede; /* RFC 8914 - Extended DNS Errors */ 52 char* ede_text; /* RFC 8914 - Extended DNS Errors text*/ 53 uint16_t ede_text_len; 54 }; 55 typedef struct edns_record edns_record_type; 56 57 /* The Extended DNS Error codes (RFC8914) we use */ 58 #define EDE_OTHER 0 59 #define EDE_NOT_READY 14 60 #define EDE_PROHIBITED 18 61 #define EDE_NOT_AUTHORITATIVE 20 62 #define EDE_NOT_SUPPORTED 21 63 #define EDE_INVALID_DATA 24 64 65 /* ASSIGN_EDE_CODE_AND_STRING_LITERAL may only be used with string literals. 66 * This is guaranteed by concatenating and empty string to LITERAL, which 67 * will make compilation fail if this macro is used with variables. 68 */ 69 #define ASSIGN_EDE_CODE_AND_STRING_LITERAL(EDE, CODE, LITERAL) \ 70 do { \ 71 EDE = (CODE); \ 72 EDE ## _text = (LITERAL ""); \ 73 EDE ## _text_len = sizeof(LITERAL) - 1; \ 74 } while (0) 75 76 void edns_init_data(edns_data_type *data, uint16_t max_length); 77 void edns_init_record(edns_record_type *data); 78 int edns_parse_record(edns_record_type *data, buffer_type *packet, 79 struct query* q, struct nsd* nsd); 80 81 /* 82 * The amount of space to reserve in the response for the EDNS data 83 * (if required). 84 */ 85 size_t edns_reserved_space(edns_record_type *data); 86 87 void edns_init_nsid(edns_data_type *data, uint16_t nsid_len); 88 89 #endif /* _EDNS_H_ */ 90