xref: /openbsd-src/usr.sbin/nsd/edns.h (revision d13be5d47e4149db2549a9828e244d59dbc43f15)
1 /*
2  * edns.h -- EDNS definitions (RFC 2671).
3  *
4  * Copyright (c) 2001-2011, 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_ERROR
36 };
37 typedef enum edns_status edns_status_type;
38 
39 struct edns_record
40 {
41 	edns_status_type status;
42 	size_t           position;
43 	size_t           maxlen;
44 	int              dnssec_ok;
45 	int              nsid;
46 };
47 typedef struct edns_record edns_record_type;
48 
49 void edns_init_data(edns_data_type *data, uint16_t max_length);
50 void edns_init_record(edns_record_type *data);
51 int edns_parse_record(edns_record_type *data, buffer_type *packet);
52 
53 /*
54  * The amount of space to reserve in the response for the EDNS data
55  * (if required).
56  */
57 size_t edns_reserved_space(edns_record_type *data);
58 
59 void edns_init_nsid(edns_data_type *data, uint16_t nsid_len);
60 
61 #endif /* _EDNS_H_ */
62