1 /* dnsmasq is Copyright (c) 2000-2022 Simon Kelley
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #define NAMESERVER_PORT 53
19 #define MIN_PORT 1024 /* first non-reserved port */
20 #define MAX_PORT 65535u
25 #define PACKETSZ 512 /* maximum packet size */
26 #define MAXDNAME 1025 /* maximum presentation domain name */
27 #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
28 #define MAXLABEL 63 /* maximum length of domain label */
30 #define NOERROR 0 /* no error */
31 #define FORMERR 1 /* format error */
32 #define SERVFAIL 2 /* server failure */
33 #define NXDOMAIN 3 /* non existent domain */
34 #define NOTIMP 4 /* not implemented */
35 #define REFUSED 5 /* query refused */
37 #define QUERY 0 /* opcode */
39 #define C_IN 1 /* the arpa internet */
40 #define C_CHAOS 3 /* for chaos net (MIT) */
41 #define C_HESIOD 4 /* hesiod */
42 #define C_ANY 255 /* wildcard match */
81 #define EDNS0_OPTION_MAC 65001 /* dyndns.org temporary assignment */
82 #define EDNS0_OPTION_CLIENT_SUBNET 8 /* IANA */
83 #define EDNS0_OPTION_EDE 15 /* IANA - RFC 8914 */
84 #define EDNS0_OPTION_NOMDEVICEID 65073 /* Nominum temporary assignment */
85 #define EDNS0_OPTION_NOMCPEID 65074 /* Nominum temporary assignment */
86 #define EDNS0_OPTION_UMBRELLA 20292 /* Cisco Umbrella temporary assignment */
88 /* RFC-8914 extended errors, negative values are our definitions */
89 #define EDE_UNSET -1 /* No extended DNS error available */
90 #define EDE_OTHER 0 /* Other */
91 #define EDE_USUPDNSKEY 1 /* Unsupported DNSKEY algo */
92 #define EDE_USUPDS 2 /* Unsupported DS Digest */
93 #define EDE_STALE 3 /* Stale answer */
94 #define EDE_FORGED 4 /* Forged answer */
95 #define EDE_DNSSEC_IND 5 /* DNSSEC Indeterminate */
96 #define EDE_DNSSEC_BOGUS 6 /* DNSSEC Bogus */
97 #define EDE_SIG_EXP 7 /* Signature Expired */
98 #define EDE_SIG_NYV 8 /* Signature Not Yet Valid */
99 #define EDE_NO_DNSKEY 9 /* DNSKEY missing */
100 #define EDE_NO_RRSIG 10 /* RRSIGs missing */
101 #define EDE_NO_ZONEKEY 11 /* No Zone Key Bit Set */
102 #define EDE_NO_NSEC 12 /* NSEC Missing */
103 #define EDE_CACHED_ERR 13 /* Cached Error */
104 #define EDE_NOT_READY 14 /* Not Ready */
105 #define EDE_BLOCKED 15 /* Blocked */
106 #define EDE_CENSORED 16 /* Censored */
107 #define EDE_FILTERED 17 /* Filtered */
108 #define EDE_PROHIBITED 18 /* Prohibited */
109 #define EDE_STALE_NXD 19 /* Stale NXDOMAIN */
110 #define EDE_NOT_AUTH 20 /* Not Authoritative */
111 #define EDE_NOT_SUP 21 /* Not Supported */
112 #define EDE_NO_AUTH 22 /* No Reachable Authority */
113 #define EDE_NETERR 23 /* Network error */
114 #define EDE_INVALID_DATA 24 /* Invalid Data */
122 u16 qdcount,ancount,nscount,arcount;
125 #define HB3_QR 0x80 /* Query */
126 #define HB3_OPCODE 0x78
127 #define HB3_AA 0x04 /* Authoritative Answer */
128 #define HB3_TC 0x02 /* TrunCated */
129 #define HB3_RD 0x01 /* Recursion Desired */
131 #define HB4_RA 0x80 /* Recursion Available */
132 #define HB4_AD 0x20 /* Authenticated Data */
133 #define HB4_CD 0x10 /* Checking Disabled */
134 #define HB4_RCODE 0x0f
136 #define OPCODE(x) (((x)->hb3 & HB3_OPCODE) >> 3)
137 #define SET_OPCODE(x, code) (x)->hb3 = ((x)->hb3 & ~HB3_OPCODE) | code
139 #define RCODE(x) ((x)->hb4 & HB4_RCODE)
140 #define SET_RCODE(x, code) (x)->hb4 = ((x)->hb4 & ~HB4_RCODE) | code
142 #define GETSHORT(s, cp) { \
143 unsigned char *t_cp = (unsigned char *)(cp); \
144 (s) = ((u16)t_cp[0] << 8) \
150 #define GETLONG(l, cp) { \
151 unsigned char *t_cp = (unsigned char *)(cp); \
152 (l) = ((u32)t_cp[0] << 24) \
153 | ((u32)t_cp[1] << 16) \
154 | ((u32)t_cp[2] << 8) \
160 #define PUTSHORT(s, cp) { \
161 u16 t_s = (u16)(s); \
162 unsigned char *t_cp = (unsigned char *)(cp); \
163 *t_cp++ = t_s >> 8; \
168 #define PUTLONG(l, cp) { \
169 u32 t_l = (u32)(l); \
170 unsigned char *t_cp = (unsigned char *)(cp); \
171 *t_cp++ = t_l >> 24; \
172 *t_cp++ = t_l >> 16; \
173 *t_cp++ = t_l >> 8; \
178 #define CHECK_LEN(header, pp, plen, len) \
179 ((size_t)((pp) - (unsigned char *)(header) + (len)) <= (plen))
181 #define ADD_RDLEN(header, pp, plen, len) \
182 (!CHECK_LEN(header, pp, plen, len) ? 0 : (((pp) += (len)), 1))
184 /* Escape character in our presentation format for names.
185 Cannot be '.' or /000 and must be !isprint().
186 Note that escaped chars are stored as
187 <NAME_ESCAPE> <orig-char+1>
188 to ensure that the escaped form of /000 doesn't include /000
190 #define NAME_ESCAPE 1