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 15 #define OPT_LEN 9U /* Length of the NSD EDNS response record minus 2 */ 16 #define OPT_RDATA 2 /* holds the rdata length comes after OPT_LEN */ 17 #define OPT_HDR 4U /* NSID opt header length */ 18 #define NSID_CODE 3 /* nsid option code */ 19 #define DNSSEC_OK_MASK 0x8000U /* do bit mask */ 20 21 struct edns_data 22 { 23 char ok[OPT_LEN]; 24 char error[OPT_LEN]; 25 char rdata_none[OPT_RDATA]; 26 char rdata_nsid[OPT_RDATA]; 27 char nsid[OPT_HDR]; 28 }; 29 typedef struct edns_data edns_data_type; 30 31 enum edns_status 32 { 33 EDNS_NOT_PRESENT, 34 EDNS_OK, 35 /* EDNS states may be extended in the future */ 36 EDNS_ERROR 37 }; 38 typedef enum edns_status edns_status_type; 39 40 struct edns_record 41 { 42 edns_status_type status; 43 size_t position; 44 size_t maxlen; 45 int dnssec_ok; 46 int nsid; 47 }; 48 typedef struct edns_record edns_record_type; 49 50 void edns_init_data(edns_data_type *data, uint16_t max_length); 51 void edns_init_record(edns_record_type *data); 52 int edns_parse_record(edns_record_type *data, buffer_type *packet); 53 54 /* 55 * The amount of space to reserve in the response for the EDNS data 56 * (if required). 57 */ 58 size_t edns_reserved_space(edns_record_type *data); 59 60 void edns_init_nsid(edns_data_type *data, uint16_t nsid_len); 61 62 #endif /* _EDNS_H_ */ 63