Simon Kelley | 6174435 | 2013-01-31 14:34:40 +0000 | [diff] [blame] | 1 | /* dnsmasq is Copyright (c) 2000-2013 Simon Kelley |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 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 as published by |
| 5 | the Free Software Foundation; version 2 dated June, 1991, or |
| 6 | (at your option) version 3 dated 29 June, 2007. |
| 7 | |
| 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. |
| 12 | |
| 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/>. |
| 15 | */ |
| 16 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 17 | #define NAMESERVER_PORT 53 |
| 18 | #define TFTP_PORT 69 |
| 19 | |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 20 | #define IN6ADDRSZ 16 |
| 21 | #define INADDRSZ 4 |
| 22 | |
| 23 | #define PACKETSZ 512 /* maximum packet size */ |
| 24 | #define MAXDNAME 1025 /* maximum presentation domain name */ |
| 25 | #define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ |
| 26 | #define MAXLABEL 63 /* maximum length of domain label */ |
| 27 | |
| 28 | #define NOERROR 0 /* no error */ |
| 29 | #define FORMERR 1 /* format error */ |
| 30 | #define SERVFAIL 2 /* server failure */ |
| 31 | #define NXDOMAIN 3 /* non existent domain */ |
| 32 | #define NOTIMP 4 /* not implemented */ |
| 33 | #define REFUSED 5 /* query refused */ |
| 34 | |
| 35 | #define QUERY 0 /* opcode */ |
| 36 | |
| 37 | #define C_IN 1 /* the arpa internet */ |
| 38 | #define C_CHAOS 3 /* for chaos net (MIT) */ |
| 39 | #define C_ANY 255 /* wildcard match */ |
| 40 | |
| 41 | #define T_A 1 |
| 42 | #define T_NS 2 |
| 43 | #define T_CNAME 5 |
| 44 | #define T_SOA 6 |
| 45 | #define T_PTR 12 |
| 46 | #define T_MX 15 |
| 47 | #define T_TXT 16 |
| 48 | #define T_SIG 24 |
| 49 | #define T_AAAA 28 |
| 50 | #define T_SRV 33 |
| 51 | #define T_NAPTR 35 |
| 52 | #define T_OPT 41 |
| 53 | #define T_TKEY 249 |
| 54 | #define T_TSIG 250 |
Simon Kelley | b75e936 | 2012-12-07 11:50:41 +0000 | [diff] [blame] | 55 | #define T_AXFR 252 |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 56 | #define T_MAILB 253 |
| 57 | #define T_ANY 255 |
| 58 | |
Simon Kelley | ed4c076 | 2013-10-08 20:46:34 +0100 | [diff] [blame^] | 59 | #define EDNS0_OPTION_MAC 65001 /* dyndns.org temporary assignment */ |
| 60 | #define EDNS0_OPTION_CLIENT_SUBNET 5 /* IANA */ |
| 61 | |
| 62 | |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 63 | struct dns_header { |
| 64 | u16 id; |
| 65 | u8 hb3,hb4; |
| 66 | u16 qdcount,ancount,nscount,arcount; |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 67 | }; |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 68 | |
| 69 | #define HB3_QR 0x80 |
| 70 | #define HB3_OPCODE 0x78 |
| 71 | #define HB3_AA 0x04 |
| 72 | #define HB3_TC 0x02 |
| 73 | #define HB3_RD 0x01 |
| 74 | |
| 75 | #define HB4_RA 0x80 |
| 76 | #define HB4_AD 0x20 |
| 77 | #define HB4_CD 0x10 |
| 78 | #define HB4_RCODE 0x0f |
| 79 | |
| 80 | #define OPCODE(x) (((x)->hb3 & HB3_OPCODE) >> 3) |
| 81 | #define RCODE(x) ((x)->hb4 & HB4_RCODE) |
| 82 | #define SET_RCODE(x, code) (x)->hb4 = ((x)->hb4 & ~HB4_RCODE) | code |
| 83 | |
| 84 | #define GETSHORT(s, cp) { \ |
| 85 | unsigned char *t_cp = (unsigned char *)(cp); \ |
| 86 | (s) = ((u16)t_cp[0] << 8) \ |
| 87 | | ((u16)t_cp[1]) \ |
| 88 | ; \ |
| 89 | (cp) += 2; \ |
| 90 | } |
| 91 | |
| 92 | #define GETLONG(l, cp) { \ |
| 93 | unsigned char *t_cp = (unsigned char *)(cp); \ |
| 94 | (l) = ((u32)t_cp[0] << 24) \ |
| 95 | | ((u32)t_cp[1] << 16) \ |
| 96 | | ((u32)t_cp[2] << 8) \ |
| 97 | | ((u32)t_cp[3]) \ |
| 98 | ; \ |
| 99 | (cp) += 4; \ |
| 100 | } |
| 101 | |
| 102 | #define PUTSHORT(s, cp) { \ |
| 103 | u16 t_s = (u16)(s); \ |
| 104 | unsigned char *t_cp = (unsigned char *)(cp); \ |
| 105 | *t_cp++ = t_s >> 8; \ |
| 106 | *t_cp = t_s; \ |
| 107 | (cp) += 2; \ |
| 108 | } |
| 109 | |
| 110 | #define PUTLONG(l, cp) { \ |
| 111 | u32 t_l = (u32)(l); \ |
| 112 | unsigned char *t_cp = (unsigned char *)(cp); \ |
| 113 | *t_cp++ = t_l >> 24; \ |
| 114 | *t_cp++ = t_l >> 16; \ |
| 115 | *t_cp++ = t_l >> 8; \ |
| 116 | *t_cp = t_l; \ |
| 117 | (cp) += 4; \ |
| 118 | } |
| 119 | |