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 COOKIE_CODE 10 /* COOKIE option code */ 22 #define EDE_CODE 15 /* Extended DNS Errors option code */ 23 #define DNSSEC_OK_MASK 0x8000U /* do bit mask */ 24 25 struct edns_data 26 { 27 char ok[OPT_LEN]; 28 char error[OPT_LEN]; 29 char rdata_none[OPT_RDATA]; 30 char nsid[OPT_HDR]; 31 char cookie[OPT_HDR]; 32 }; 33 typedef struct edns_data edns_data_type; 34 35 enum edns_status 36 { 37 EDNS_NOT_PRESENT, 38 EDNS_OK, 39 /* EDNS states may be extended in the future */ 40 EDNS_ERROR 41 }; 42 typedef enum edns_status edns_status_type; 43 44 enum cookie_status 45 { 46 COOKIE_NOT_PRESENT, 47 COOKIE_UNVERIFIED, 48 COOKIE_VALID, 49 COOKIE_VALID_REUSE, 50 COOKIE_INVALID 51 }; 52 typedef enum cookie_status cookie_status_type; 53 54 struct edns_record 55 { 56 edns_status_type status; 57 size_t position; 58 size_t maxlen; 59 size_t opt_reserved_space; 60 int dnssec_ok; 61 int nsid; 62 cookie_status_type cookie_status; 63 size_t cookie_len; 64 uint8_t cookie[40]; 65 int ede; /* RFC 8914 - Extended DNS Errors */ 66 char* ede_text; /* RFC 8914 - Extended DNS Errors text*/ 67 uint16_t ede_text_len; 68 }; 69 typedef struct edns_record edns_record_type; 70 71 /* The Extended DNS Error codes (RFC8914) we use */ 72 #define EDE_OTHER 0 73 #define EDE_NOT_READY 14 74 #define EDE_PROHIBITED 18 75 #define EDE_NOT_AUTHORITATIVE 20 76 #define EDE_NOT_SUPPORTED 21 77 #define EDE_INVALID_DATA 24 78 79 /* ASSIGN_EDE_CODE_AND_STRING_LITERAL may only be used with string literals. 80 * This is guaranteed by concatenating and empty string to LITERAL, which 81 * will make compilation fail if this macro is used with variables. 82 */ 83 #define ASSIGN_EDE_CODE_AND_STRING_LITERAL(EDE, CODE, LITERAL) \ 84 do { \ 85 EDE = (CODE); \ 86 EDE ## _text = (LITERAL ""); \ 87 EDE ## _text_len = sizeof(LITERAL) - 1; \ 88 } while (0) 89 90 void edns_init_data(edns_data_type *data, uint16_t max_length); 91 void edns_init_record(edns_record_type *data); 92 int edns_parse_record(edns_record_type *data, buffer_type *packet, 93 struct query* q, struct nsd* nsd); 94 95 /* 96 * The amount of space to reserve in the response for the EDNS data 97 * (if required). 98 */ 99 size_t edns_reserved_space(edns_record_type *data); 100 101 void edns_init_nsid(edns_data_type *data, uint16_t nsid_len); 102 103 void cookie_verify(struct query *q, struct nsd* nsd, uint32_t *now_p); 104 void cookie_create(struct query *q, struct nsd* nsd, uint32_t *now_p); 105 106 #endif /* EDNS_H */ 107