Electroneum
msgparse.h
Go to the documentation of this file.
1 /*
2  * util/data/msgparse.h - parse wireformat DNS messages.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
63 #ifndef UTIL_DATA_MSGPARSE_H
64 #define UTIL_DATA_MSGPARSE_H
65 #include "util/storage/lruhash.h"
66 #include "sldns/pkthdr.h"
67 #include "sldns/rrdef.h"
68 struct sldns_buffer;
69 struct rrset_parse;
70 struct rr_parse;
71 struct regional;
72 struct edns_option;
73 
75 #define PARSE_TABLE_SIZE 32
76 
77 extern time_t MAX_TTL;
79 extern time_t MIN_TTL;
81 extern time_t MAX_NEG_TTL;
83 #define NORR_TTL 5 /* seconds */
84 
89 struct msg_parse {
103  size_t an_rrsets;
105  size_t ns_rrsets;
107  size_t ar_rrsets;
109  size_t rrset_count;
110 
114  size_t qname_len;
119 
125 
130 };
131 
135 struct rrset_parse {
149  size_t dname_len;
157  size_t rr_count;
159  size_t size;
163  struct rr_parse* rr_last;
165  size_t rrsig_count;
170 };
171 
175 struct rr_parse {
186  size_t size;
188  struct rr_parse* next;
189 };
190 
192 #define LABEL_IS_PTR(x) ( ((x)&0xc0) == 0xc0 )
193 
195 #define PTR_OFFSET(x, y) ( ((x)&0x3f)<<8 | (y) )
196 
197 #define PTR_CREATE(offset) ((uint16_t)(0xc000 | (offset)))
198 
200 #define EDNS_RCODE_BADVERS 16
202 #define PTR_MAX_OFFSET 0x3fff
203 
209 struct edns_data {
222 };
223 
227 struct edns_option {
229  struct edns_option* next;
233  size_t opt_len;
236 };
237 
244 size_t get_rdf_size(sldns_rdf_type rdf);
245 
254 int parse_packet(struct sldns_buffer* pkt, struct msg_parse* msg,
255  struct regional* region);
256 
274 int parse_extract_edns(struct msg_parse* msg, struct edns_data* edns,
275  struct regional* region);
276 
287 int parse_edns_from_pkt(struct sldns_buffer* pkt, struct edns_data* edns,
288  struct regional* region);
289 
300  uint16_t type, uint16_t dclass, uint32_t rrset_flags);
301 
314 struct rrset_parse* msgparse_hashtable_lookup(struct msg_parse* msg,
315  struct sldns_buffer* pkt, hashvalue_type h, uint32_t rrset_flags,
316  uint8_t* dname, size_t dnamelen, uint16_t type, uint16_t dclass);
317 
323 void msgparse_bucket_remove(struct msg_parse* msg, struct rrset_parse* rrset);
324 
331 void log_edns_opt_list(enum verbosity_value level, const char* info_str,
332  struct edns_option* list);
333 
334 #endif /* UTIL_DATA_MSGPARSE_H */
time_t MAX_NEG_TTL
size_t get_rdf_size(sldns_rdf_type rdf)
uint8_t ext_rcode
Definition: msgparse.h:213
size_t rrset_count
Definition: msgparse.h:109
struct rrset_parse * msgparse_hashtable_lookup(struct msg_parse *msg, struct sldns_buffer *pkt, hashvalue_type h, uint32_t rrset_flags, uint8_t *dname, size_t dnamelen, uint16_t type, uint16_t dclass)
#define PARSE_TABLE_SIZE
Definition: msgparse.h:75
struct rrset_parse * rrset_last
Definition: msgparse.h:129
uint8_t * dname
Definition: msgparse.h:147
struct rrset_parse * rrset_all_next
Definition: msgparse.h:139
uint16_t opt_code
Definition: msgparse.h:231
size_t ar_rrsets
Definition: msgparse.h:107
unsigned short uint16_t
Definition: stdint.h:125
uint16_t type
Definition: msgparse.h:151
size_t an_rrsets
Definition: msgparse.h:103
struct rrset_parse * hashtable[PARSE_TABLE_SIZE]
Definition: msgparse.h:124
unsigned char uint8_t
Definition: stdint.h:124
uint16_t udp_size
Definition: msgparse.h:219
uint8_t * opt_data
Definition: msgparse.h:235
uint8_t * ttl_data
Definition: msgparse.h:181
uint16_t nscount
Definition: msgparse.h:99
uint16_t qtype
Definition: msgparse.h:116
struct rr_parse * rrsig_last
Definition: msgparse.h:169
uint16_t bits
Definition: msgparse.h:217
unsigned int uint32_t
Definition: stdint.h:126
uint16_t id
Definition: msgparse.h:91
uint16_t rrset_class
Definition: msgparse.h:153
uint32_t hashvalue_type
Definition: lruhash.h:119
struct rrset_parse * rrset_first
Definition: msgparse.h:127
int parse_extract_edns(struct msg_parse *msg, struct edns_data *edns, struct regional *region)
verbosity_value
Definition: log.h:49
struct rr_parse * rr_first
Definition: msgparse.h:161
int parse_edns_from_pkt(struct sldns_buffer *pkt, struct edns_data *edns, struct regional *region)
size_t opt_len
Definition: msgparse.h:233
time_t MAX_TTL
size_t qname_len
Definition: msgparse.h:114
size_t dname_len
Definition: msgparse.h:149
sldns_pkt_section section
Definition: msgparse.h:145
uint16_t qdcount
Definition: msgparse.h:95
struct rr_parse * next
Definition: msgparse.h:188
size_t size
Definition: msgparse.h:186
size_t size
Definition: msgparse.h:159
void log_edns_opt_list(enum verbosity_value level, const char *info_str, struct edns_option *list)
int edns_present
Definition: msgparse.h:211
uint32_t flags
Definition: msgparse.h:155
struct rrset_parse * rrset_bucket_next
Definition: msgparse.h:137
struct edns_option * opt_list
Definition: msgparse.h:221
uint8_t edns_version
Definition: msgparse.h:215
int outside_packet
Definition: msgparse.h:184
size_t ns_rrsets
Definition: msgparse.h:105
struct edns_option * next
Definition: msgparse.h:229
size_t rr_count
Definition: msgparse.h:157
int parse_packet(struct sldns_buffer *pkt, struct msg_parse *msg, struct regional *region)
time_t MIN_TTL
hashvalue_type hash
Definition: msgparse.h:141
hashvalue_type pkt_hash_rrset(struct sldns_buffer *pkt, uint8_t *dname, uint16_t type, uint16_t dclass, uint32_t rrset_flags)
uint8_t * qname
Definition: msgparse.h:112
struct rr_parse * rrsig_first
Definition: msgparse.h:167
uint16_t ancount
Definition: msgparse.h:97
size_t rrsig_count
Definition: msgparse.h:165
uint16_t arcount
Definition: msgparse.h:101
void msgparse_bucket_remove(struct msg_parse *msg, struct rrset_parse *rrset)
enum sldns_enum_rdf_type sldns_rdf_type
Definition: rrdef.h:360
struct rr_parse * rr_last
Definition: msgparse.h:163
enum sldns_enum_pkt_section sldns_pkt_section
Definition: pkthdr.h:126
uint16_t flags
Definition: msgparse.h:93
uint16_t qclass
Definition: msgparse.h:118