djbdnscurve6  38
djbdnscurve6
edns0.c
Go to the documentation of this file.
1 /* (C) 2012 Peter Conrad <conrad@quisquis.de>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 3 as
5  * published by the Free Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 // #include "ip.h"
17 #include "dns.h"
18 #include "edns0.h"
19 #include "response.h"
20 #include "uint_t.h"
21 
22 unsigned int dns_packet_edns0(const char header[12], const char *buf, const int len, unsigned int pos)
23 {
24  char opt_class[2];
25  char opt_ttl[4];
26  uint16 size;
27  uint16 min_len;
28 // int max_response_len;
29  char nametype[3];
30 
31  do_dnssec = 0;
32  if (!header[6] && !header[7] && !header[8] &&
33  !header[9] && !header[10] && header[11] == 1) {
34  pos = dns_packet_copy(buf,len,pos,nametype,3); if (!pos) return pos;
35  if (nametype[0] || nametype[1] || nametype[2] != DNS_T_OPT[1]) return pos;
36  pos = dns_packet_copy(buf,len,pos,opt_class,2); if (!pos) return pos;
37  pos = dns_packet_copy(buf,len,pos,opt_ttl,4); if (!pos) return pos;
38  if (opt_ttl[0]) return pos; // unsupported RCODE in query
39  if (opt_ttl[1]) return pos; // unsupported version
40  do_dnssec = opt_ttl[2] & 0x80;
41  uint16_unpack_big(opt_class,&size);
42  min_len = do_dnssec ? 1220 : 512;
43  max_response_len = size > 4000 ? 4000 : size;
44  if (max_response_len < min_len) { max_response_len = min_len; }
45  }
46  return pos;
47 }
uint16 len
Definition: axfrdns.c:302
char buf[MSGSIZE]
Definition: axfrdns.c:301
unsigned int dns_packet_copy(const char *, unsigned int, unsigned int, char *, unsigned int)
Definition: dns_packet.c:8
#define DNS_T_OPT
Definition: dns.h:52
unsigned int dns_packet_edns0(const char header[12], const char *buf, const int len, unsigned int pos)
Definition: edns0.c:22
unsigned int max_response_len
Definition: response.c:8
unsigned int do_dnssec
Definition: response.c:9