xref: /openbsd/usr.sbin/nsd/edns.h (revision 09467b48)
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 DNSSEC_OK_MASK  0x8000U         /* do bit mask */
22 
23 struct edns_data
24 {
25 	char ok[OPT_LEN];
26 	char error[OPT_LEN];
27 	char rdata_none[OPT_RDATA];
28 	char rdata_nsid[OPT_RDATA];
29 	char nsid[OPT_HDR];
30 };
31 typedef struct edns_data edns_data_type;
32 
33 enum edns_status
34 {
35 	EDNS_NOT_PRESENT,
36 	EDNS_OK,
37 	/* EDNS states may be extended in the future */
38 	EDNS_ERROR
39 };
40 typedef enum edns_status edns_status_type;
41 
42 struct edns_record
43 {
44 	edns_status_type status;
45 	size_t           position;
46 	size_t           maxlen;
47 	size_t		 opt_reserved_space;
48 	int              dnssec_ok;
49 	int              nsid;
50 };
51 typedef struct edns_record edns_record_type;
52 
53 void edns_init_data(edns_data_type *data, uint16_t max_length);
54 void edns_init_record(edns_record_type *data);
55 int edns_parse_record(edns_record_type *data, buffer_type *packet,
56 	struct query* q, struct nsd* nsd);
57 
58 /*
59  * The amount of space to reserve in the response for the EDNS data
60  * (if required).
61  */
62 size_t edns_reserved_space(edns_record_type *data);
63 
64 void edns_init_nsid(edns_data_type *data, uint16_t nsid_len);
65 
66 #endif /* _EDNS_H_ */
67