Blame


1 c45084ea 2005-11-29 pbug /*
2 324df6f2 2014-04-13 pjp * Copyright (c) 2005-2014 Peter J. Philipp
3 c45084ea 2005-11-29 pbug * All rights reserved.
4 c45084ea 2005-11-29 pbug *
5 c45084ea 2005-11-29 pbug * Redistribution and use in source and binary forms, with or without
6 c45084ea 2005-11-29 pbug * modification, are permitted provided that the following conditions
7 c45084ea 2005-11-29 pbug * are met:
8 c45084ea 2005-11-29 pbug * 1. Redistributions of source code must retain the above copyright
9 c45084ea 2005-11-29 pbug * notice, this list of conditions and the following disclaimer.
10 c45084ea 2005-11-29 pbug * 2. Redistributions in binary form must reproduce the above copyright
11 c45084ea 2005-11-29 pbug * notice, this list of conditions and the following disclaimer in the
12 c45084ea 2005-11-29 pbug * documentation and/or other materials provided with the distribution.
13 c45084ea 2005-11-29 pbug * 3. The name of the author may not be used to endorse or promote products
14 c45084ea 2005-11-29 pbug * derived from this software without specific prior written permission
15 c45084ea 2005-11-29 pbug *
16 c45084ea 2005-11-29 pbug * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 c45084ea 2005-11-29 pbug * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 c45084ea 2005-11-29 pbug * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 c45084ea 2005-11-29 pbug * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 c45084ea 2005-11-29 pbug * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 c45084ea 2005-11-29 pbug * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 c45084ea 2005-11-29 pbug * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 c45084ea 2005-11-29 pbug * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 c45084ea 2005-11-29 pbug * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 c45084ea 2005-11-29 pbug * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 c45084ea 2005-11-29 pbug *
27 c45084ea 2005-11-29 pbug */
28 c45084ea 2005-11-29 pbug #ifndef _DB_H
29 c45084ea 2005-11-29 pbug #define _DB_H
30 c45084ea 2005-11-29 pbug
31 c45084ea 2005-11-29 pbug #define CONFFILE "/etc/wildcarddns.conf"
32 c25e4088 2011-06-28 pbug #define DEFAULT_SOCKET 64
33 c45084ea 2005-11-29 pbug
34 c45084ea 2005-11-29 pbug #define ERR_DROP 0x1
35 c45084ea 2005-11-29 pbug #define ERR_NXDOMAIN 0x2
36 8c7bdc7c 2009-03-07 pbug #define ERR_NOERROR 0x4
37 c45084ea 2005-11-29 pbug
38 b0a72376 2010-04-01 pbug #define RECORD_COUNT 20
39 604e0a34 2010-09-15 pbug #define NEGATIVE_CACHE_TIME 600 /* DNS & Bind 3rd edition page 35 */
40 b0a72376 2010-04-01 pbug
41 c45084ea 2005-11-29 pbug /* db stuff */
42 c45084ea 2005-11-29 pbug
43 c45084ea 2005-11-29 pbug struct soa {
44 c45084ea 2005-11-29 pbug char nsserver[DNS_MAXNAME];
45 c45084ea 2005-11-29 pbug u_int8_t nsserver_len;
46 c45084ea 2005-11-29 pbug char responsible_person[DNS_MAXNAME];
47 c45084ea 2005-11-29 pbug u_int8_t rp_len;
48 c45084ea 2005-11-29 pbug u_int32_t serial;
49 c45084ea 2005-11-29 pbug u_int32_t refresh;
50 c45084ea 2005-11-29 pbug u_int32_t retry;
51 c45084ea 2005-11-29 pbug u_int32_t expire;
52 c45084ea 2005-11-29 pbug u_int32_t minttl;
53 c45084ea 2005-11-29 pbug } __attribute__((packed));
54 c45084ea 2005-11-29 pbug
55 c45084ea 2005-11-29 pbug struct smx {
56 7202f80f 2008-07-12 pbug u_int16_t preference; /* MX preference */
57 7202f80f 2008-07-12 pbug char exchange[DNS_MAXNAME]; /* name of exchange server */
58 1a591502 2010-03-28 pbug int exchangelen; /* length of exchange server name */
59 c45084ea 2005-11-29 pbug } __attribute__((packed));
60 c45084ea 2005-11-29 pbug
61 c45084ea 2005-11-29 pbug struct ns {
62 7202f80f 2008-07-12 pbug char nsserver[DNS_MAXNAME]; /* NS name */
63 1a591502 2010-03-28 pbug int nslen; /* length of NS */
64 c45084ea 2005-11-29 pbug } __attribute__((packed));
65 c45084ea 2005-11-29 pbug
66 6f8190d3 2012-04-30 pbug struct srv {
67 6f8190d3 2012-04-30 pbug u_int16_t priority; /* SRV 16 bit priority */
68 6f8190d3 2012-04-30 pbug u_int16_t weight; /* 16 bit weight */
69 6f8190d3 2012-04-30 pbug u_int16_t port; /* 16 bit port */
70 6f8190d3 2012-04-30 pbug char target[DNS_MAXNAME]; /* SRV target name */
71 6f8190d3 2012-04-30 pbug int targetlen; /* SRV target name length */
72 6f8190d3 2012-04-30 pbug } __attribute__((packed));
73 6f8190d3 2012-04-30 pbug
74 df34d218 2014-04-21 pjp struct sshfp {
75 df34d218 2014-04-21 pjp u_int8_t algorithm; /* SSHFP algorithm */
76 df34d218 2014-04-21 pjp u_int8_t fptype; /* SSHFP fingerprint type */
77 df34d218 2014-04-21 pjp char fingerprint[DNS_MAXNAME]; /* fingerprint */
78 df34d218 2014-04-21 pjp int fplen; /* fingerprint length */
79 df34d218 2014-04-21 pjp } __attribute__((packed));
80 df34d218 2014-04-21 pjp
81 1f1faf13 2014-05-11 pjp struct naptr {
82 1f1faf13 2014-05-11 pjp u_int16_t order; /* NAPTR 16 bit order */
83 1f1faf13 2014-05-11 pjp u_int16_t preference; /* 16 bit preference */
84 1f1faf13 2014-05-11 pjp char flags[DNS_MAXNAME]; /* flags 255 bytes */
85 1f1faf13 2014-05-11 pjp int flagslen; /* flags length */
86 1f1faf13 2014-05-11 pjp char services[DNS_MAXNAME]; /* services */
87 1f1faf13 2014-05-11 pjp int serviceslen; /* services length */
88 1f1faf13 2014-05-11 pjp char regexp[DNS_MAXNAME]; /* regexp */
89 1f1faf13 2014-05-11 pjp int regexplen; /* regexp len */
90 1f1faf13 2014-05-11 pjp char replacement[DNS_MAXNAME]; /* replacement this is a domain */
91 1f1faf13 2014-05-11 pjp int replacementlen;
92 1f1faf13 2014-05-11 pjp } __attribute__((packed));
93 1f1faf13 2014-05-11 pjp
94 c45084ea 2005-11-29 pbug struct domain {
95 f98bb34d 2011-09-19 pbug char zone[DNS_MAXNAME]; /* name of zone in dns name format */
96 33a0a60d 2009-11-03 pbug int zonelen; /* length of zone, above */
97 f98bb34d 2011-09-19 pbug char zonename[DNS_MAXNAME + 1]; /* name of zone in human readable */
98 df34d218 2014-04-21 pjp u_int32_t flags; /* flags of zone */
99 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_A 0x1
100 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_SOA 0x2
101 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_CNAME 0x4
102 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_PTR 0x8
103 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_MX 0x10
104 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_AAAA 0x20
105 c45084ea 2005-11-29 pbug #define DOMAIN_HAVE_NS 0x40
106 fe42904f 2010-03-27 pbug #define DOMAIN_HAVE_TXT 0x80
107 b6dc64dc 2010-04-15 pbug #define DOMAIN_STATIC_ZONE 0x100
108 604e0a34 2010-09-15 pbug #define DOMAIN_NEGATIVE_CACHE 0x200
109 6f8190d3 2012-04-30 pbug #define DOMAIN_HAVE_SRV 0x400
110 f5989689 2014-04-21 pjp #define DOMAIN_HAVE_SPF 0x800
111 df34d218 2014-04-21 pjp #define DOMAIN_HAVE_SSHFP 0x1000
112 1f1faf13 2014-05-11 pjp #define DOMAIN_HAVE_NAPTR 0x2000
113 f98bb34d 2011-09-19 pbug struct soa soa; /* start of authority */
114 7202f80f 2008-07-12 pbug u_int32_t ttl; /* time to live */
115 b6dc64dc 2010-04-15 pbug time_t created; /* time created, for dynamic zones */
116 b0a72376 2010-04-01 pbug in_addr_t a[RECORD_COUNT]; /* IP addresses */
117 b0a72376 2010-04-01 pbug u_int8_t region[RECORD_COUNT]; /* region of IP address */
118 7202f80f 2008-07-12 pbug int a_count; /* IP address count (max 10) */
119 7202f80f 2008-07-12 pbug int a_ptr; /* pointer to last used address */
120 f98bb34d 2011-09-19 pbug struct in6_addr aaaa[RECORD_COUNT]; /* IPv6 addresses */
121 7202f80f 2008-07-12 pbug int aaaa_count; /* IPv6 address count (max 10) */
122 7202f80f 2008-07-12 pbug int aaaa_ptr; /* pointer to last used IPv6 address */
123 f98bb34d 2011-09-19 pbug struct smx mx[RECORD_COUNT]; /* MX addresses */
124 7202f80f 2008-07-12 pbug int mx_count; /* MX address count, max 10 */
125 7202f80f 2008-07-12 pbug int mx_ptr; /* pointer to last used MX adddress */
126 f98bb34d 2011-09-19 pbug struct ns ns[RECORD_COUNT]; /* NS resource records (max 10) */
127 7202f80f 2008-07-12 pbug int ns_count; /* count of NS records, (max 10) */
128 7202f80f 2008-07-12 pbug int ns_ptr; /* pointer to last used NS address */
129 b0a72376 2010-04-01 pbug int ns_type; /* set if it's a delegation */
130 b0a72376 2010-04-01 pbug #define NS_TYPE_DELEGATE 0x1
131 b0a72376 2010-04-01 pbug #define NS_TYPE_HINT 0x2
132 df34d218 2014-04-21 pjp char cname[DNS_MAXNAME]; /* CNAME RR */
133 df34d218 2014-04-21 pjp int cnamelen; /* len of CNAME */
134 df34d218 2014-04-21 pjp char ptr[DNS_MAXNAME]; /* PTR RR */
135 df34d218 2014-04-21 pjp int ptrlen; /* len of PTR */
136 df34d218 2014-04-21 pjp char txt[DNS_MAXNAME]; /* TXT string */
137 df34d218 2014-04-21 pjp int txtlen; /* len of TXT */
138 df34d218 2014-04-21 pjp char spf[DNS_MAXNAME]; /* SPF string */
139 df34d218 2014-04-21 pjp int spflen; /* len of SPF */
140 df34d218 2014-04-21 pjp struct srv srv[RECORD_COUNT]; /* SRV resource record */
141 df34d218 2014-04-21 pjp int srv_count; /* count of SRV RR */
142 df34d218 2014-04-21 pjp struct sshfp sshfp[RECORD_COUNT]; /* SSHFP resource record */
143 df34d218 2014-04-21 pjp int sshfp_count; /* SSHFP RR count */
144 1f1faf13 2014-05-11 pjp struct naptr naptr[RECORD_COUNT]; /* NAPTR RR, eek 20K! */
145 1f1faf13 2014-05-11 pjp int naptr_count;
146 c45084ea 2005-11-29 pbug } __attribute__((packed));
147 c45084ea 2005-11-29 pbug
148 c45084ea 2005-11-29 pbug struct sreply {
149 c45084ea 2005-11-29 pbug int so; /* socket */
150 c45084ea 2005-11-29 pbug char *buf; /* question packet */
151 c45084ea 2005-11-29 pbug int len; /* question packet length */
152 c45084ea 2005-11-29 pbug struct question *q; /* struct question */
153 c45084ea 2005-11-29 pbug struct sockaddr *sa; /* struct sockaddr of question */
154 c45084ea 2005-11-29 pbug int salen; /* length of struct sockaddr */
155 c45084ea 2005-11-29 pbug struct domain *sd1; /* first resolved domain */
156 c45084ea 2005-11-29 pbug struct domain *sd2; /* CNAME to second resolved domain */
157 ed247332 2010-03-09 pbug u_int8_t region; /* region of question */
158 f1e3cfca 2010-03-12 pbug int istcp; /* when set it's tcp */
159 959d1769 2010-04-05 pbug int wildcard; /* wildcarding boolean */
160 22893736 2010-09-19 pbug struct recurses *sr; /* recurses struct for raw sockets */
161 df34d218 2014-04-21 pjp char *replybuf; /* reply buffer */
162 c45084ea 2005-11-29 pbug };
163 b6dc64dc 2010-04-15 pbug
164 b6dc64dc 2010-04-15 pbug struct srecurseheader {
165 b6dc64dc 2010-04-15 pbug int af; /* address family */
166 b6dc64dc 2010-04-15 pbug int proto; /* protocol UDP/TCP */
167 b6dc64dc 2010-04-15 pbug struct sockaddr_storage source; /* source + port */
168 b6dc64dc 2010-04-15 pbug struct sockaddr_storage dest; /* dest + port */
169 b6dc64dc 2010-04-15 pbug int len; /* length of question */
170 b6dc64dc 2010-04-15 pbug char buf[512]; /* question buffer */
171 b6dc64dc 2010-04-15 pbug };
172 22893736 2010-09-19 pbug
173 22893736 2010-09-19 pbug
174 22893736 2010-09-19 pbug SLIST_HEAD(listhead2, recurses) recurseshead;
175 22893736 2010-09-19 pbug
176 22893736 2010-09-19 pbug struct recurses {
177 22893736 2010-09-19 pbug char query[512]; /* the query we received */
178 22893736 2010-09-19 pbug int len; /* length of query */
179 22893736 2010-09-19 pbug
180 22893736 2010-09-19 pbug int isfake; /* received or faked */
181 5528a18e 2010-09-21 pbug int launched; /* is launched */
182 22893736 2010-09-19 pbug int replied; /* we replied to this question */
183 437140e3 2010-09-25 pbug int packetcount; /* packet count of requests */
184 22893736 2010-09-19 pbug int af; /* address family */
185 22893736 2010-09-19 pbug int proto; /* protocol UDP/TCP */
186 22893736 2010-09-19 pbug struct sockaddr_storage source; /* source + port */
187 22893736 2010-09-19 pbug struct sockaddr_storage dest; /* dest + port */
188 22893736 2010-09-19 pbug
189 22893736 2010-09-19 pbug time_t received; /* received request time */
190 22893736 2010-09-19 pbug time_t sent_last_query; /* the last time we did a lookup */
191 c45084ea 2005-11-29 pbug
192 22893736 2010-09-19 pbug char upperlower[32]; /* uppercase / lowercase bitmap */
193 22893736 2010-09-19 pbug int so; /* the socket we did a lookup with */
194 22893736 2010-09-19 pbug u_short port; /* port used on outgoing */
195 22893736 2010-09-19 pbug u_int16_t id; /* last id used */
196 22893736 2010-09-19 pbug
197 22893736 2010-09-19 pbug /* the below get loaded from the database upon each lookup */
198 22893736 2010-09-19 pbug in_addr_t a[RECORD_COUNT]; /* IPv4 addresses of nameservers */
199 22893736 2010-09-19 pbug int a_count; /* IPv4 address count */
200 22893736 2010-09-19 pbug int a_ptr; /* pointer to last used address */
201 22893736 2010-09-19 pbug struct in6_addr aaaa[RECORD_COUNT]; /* IPv6 addresses of nameservers */
202 22893736 2010-09-19 pbug int aaaa_count; /* IPv6 address count */
203 22893736 2010-09-19 pbug int aaaa_ptr; /* pointer to last used IPv6 address */
204 22893736 2010-09-19 pbug
205 22893736 2010-09-19 pbug /* the below is our indicator which part of the lookup we're at */
206 22893736 2010-09-19 pbug
207 f1e825ef 2010-09-28 pbug u_char *lookrecord; /* what zone lookup is it from */
208 22893736 2010-09-19 pbug int indicator; /* indicator of ns lookup */
209 b36746d8 2010-09-25 pbug int authoritative; /* last reply was authoritative, type */
210 22893736 2010-09-19 pbug int hascallback; /* some request has callback don't remove */
211 22893736 2010-09-19 pbug
212 22893736 2010-09-19 pbug struct question *question; /* question struct */
213 c0963faf 2014-05-01 pjp SLIST_ENTRY(recurses) recurses_entry;
214 22893736 2010-09-19 pbug struct recurses *callback; /* callback */
215 5528a18e 2010-09-21 pbug } *sr, *sr1, *sr2;
216 b6dc64dc 2010-04-15 pbug
217 c25e4088 2011-06-28 pbug struct logging {
218 c25e4088 2011-06-28 pbug int active;
219 c25e4088 2011-06-28 pbug char *hostname;
220 c25e4088 2011-06-28 pbug int bind;
221 c25e4088 2011-06-28 pbug char *loghost;
222 c25e4088 2011-06-28 pbug struct sockaddr_storage loghost2;
223 c25e4088 2011-06-28 pbug char *logport;
224 c25e4088 2011-06-28 pbug u_int16_t logport2;
225 c25e4088 2011-06-28 pbug char *logpasswd;
226 c25e4088 2011-06-28 pbug };
227 c25e4088 2011-06-28 pbug
228 c25e4088 2011-06-28 pbug struct cfg {
229 c25e4088 2011-06-28 pbug int udp[DEFAULT_SOCKET]; /* udp sockets */
230 c25e4088 2011-06-28 pbug int tcp[DEFAULT_SOCKET]; /* tcp socket */
231 f98bb34d 2011-09-19 pbug int axfr[DEFAULT_SOCKET]; /* axfr udp socket */
232 c25e4088 2011-06-28 pbug char *ident[DEFAULT_SOCKET]; /* identification of interface */
233 c25e4088 2011-06-28 pbug int recurse; /* recurse socket */
234 c25e4088 2011-06-28 pbug int log; /* logging socket */
235 c25e4088 2011-06-28 pbug int sockcount; /* set sockets */
236 c25e4088 2011-06-28 pbug DB *db; /* database */
237 c25e4088 2011-06-28 pbug };
238 22893736 2010-09-19 pbug
239 c25e4088 2011-06-28 pbug
240 c45084ea 2005-11-29 pbug int parse_file(DB *db, char *);
241 c45084ea 2005-11-29 pbug DB * opendatabase(DB *);
242 c45084ea 2005-11-29 pbug
243 c45084ea 2005-11-29 pbug
244 c45084ea 2005-11-29 pbug #endif /* _DB_H */