1 /************************************************************************************************** 2 $Id: named.h,v 1.65 2005/04/20 16:49:12 bboy Exp $ 3 4 Copyright (C) 2002-2005 Don Moore <bboy@bboy.net> 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at Your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 **************************************************************************************************/ 20 21 #ifndef _MYDNS_NAMED_H 22 #define _MYDNS_NAMED_H 23 24 #include "mydnsutil.h" 25 #include "header.h" 26 #include "mydns.h" 27 #include "task.h" 28 #include "cache.h" 29 30 #if HAVE_SYS_RESOURCE_H 31 # include <sys/resource.h> 32 #endif 33 34 #if HAVE_SYS_WAIT_H 35 # include <sys/wait.h> 36 #endif 37 38 #if HAVE_NETDB_H 39 # include <netdb.h> 40 #endif 41 42 43 /* The alarm function runs every ALARM_INTERVAL seconds */ 44 #define ALARM_INTERVAL 15 45 #define DNS_MAXPACKETLEN DNS_MAXPACKETLEN_UDP 46 #if ALIAS_ENABLED 47 # define MAX_ALIAS_LEVEL 6 48 #endif 49 50 /* Maximum CNAME recursion depth */ 51 #define DNS_MAX_CNAME_RECURSION 25 52 53 /* Size of reply header data; that's id + DNS_HEADER + qdcount + ancount + nscount + arcount */ 54 #define DNS_HEADERSIZE (SIZE16 * 6) 55 56 57 #define SQLESC(s,d) { \ 58 char *rv = alloca(strlen((s))*2+1); \ 59 if (!rv) Err("alloca"); \ 60 sql_escstr(sql, rv, s, strlen((s))); \ 61 d = rv; \ 62 } 63 64 /* This is the header offset at the start of most reply functions. 65 The extra SIZE16 at the end is the RDLENGTH field in the RR's header. */ 66 #define CUROFFSET(t) (DNS_HEADERSIZE + (t)->qdlen + (t)->rdlen + SIZE16) 67 68 69 #if DEBUG_ENABLED 70 extern char *datasection_str[]; /* Strings describing data section types */ 71 #endif 72 73 74 /* Queue structure for TASK records (really not a queue, but a list) */ 75 typedef struct _named_queue 76 { 77 size_t size; /* Number of elements in queue */ 78 TASK *head; /* Pointer to first element in list */ 79 TASK *tail; /* Pointer to last element in list */ 80 } QUEUE; 81 82 83 #define MAX_RESULTS 20 84 typedef struct _serverstatus /* Server status information */ 85 { 86 time_t start_time; /* Time server started */ 87 uint32_t udp_requests, tcp_requests; /* Total # of requests handled */ 88 uint32_t timedout; /* Number of requests that timed out */ 89 uint32_t results[MAX_RESULTS]; /* Result codes */ 90 } SERVERSTATUS; 91 92 extern SERVERSTATUS Status; 93 94 95 96 /* Global variables */ 97 extern CONF *Conf; /* Config file data */ 98 extern QUEUE *Tasks; /* Task queue */ 99 extern CACHE *Cache; /* Zone cache */ 100 extern time_t current_time; /* Current time */ 101 extern time_t task_timeout; /* Task timeout */ 102 extern int axfr_enabled; /* Allow AXFR? */ 103 extern int tcp_enabled; /* Enable TCP? */ 104 extern int dns_update_enabled; /* Enable DNS UPDATE? */ 105 extern int ignore_minimum; /* Ignore minimum TTL? */ 106 extern char hostname[256]; /* This machine's hostname */ 107 108 extern uint32_t answer_then_quit; /* Answer this many queries then quit */ 109 extern int show_data_errors; /* Output data errors? */ 110 111 extern int forward_recursive; /* Forward recursive queries? */ 112 extern char *recursive_fwd_server; /* Name of server for recursive forwarding */ 113 extern int recursive_family; /* Protocol family for recursion */ 114 115 #if HAVE_IPV6 116 extern struct sockaddr_in6 recursive_sa6; /* Recursive server (IPv6) */ 117 #endif 118 extern struct sockaddr_in recursive_sa; /* Recursive server (IPv4) */ 119 120 121 #if ALIAS_ENABLED 122 /* alias.c */ 123 extern MYDNS_RR *find_alias(TASK *, char *); 124 extern int alias_recurse(TASK *t, datasection_t section, char *fqdn, MYDNS_SOA *soa, char *label, MYDNS_RR *alias); 125 #endif 126 127 128 /* axfr.c */ 129 extern void axfr(TASK *); 130 131 132 /* conf.c */ 133 extern void load_config(void); 134 extern void dump_config(void); 135 extern void conf_set_logging(void); 136 extern void check_config_file_perms(void); 137 138 139 /* data.c */ 140 extern MYDNS_SOA *find_soa(TASK *, char *, char *); 141 extern MYDNS_RR *find_rr(TASK *, MYDNS_SOA *, dns_qtype_t, char *); 142 143 144 /* db.c */ 145 extern void db_connect(void); 146 extern void db_output_create_tables(void); 147 extern void db_verify_tables(void); 148 149 150 /* encode.c */ 151 extern int name_remember(TASK *, char *, unsigned int); 152 extern void name_forget(TASK *); 153 extern unsigned int name_find(TASK *, char *); 154 extern char *name_unencode(char *, size_t, char *, char *, size_t); 155 extern int name_encode(TASK *, char *, char *, unsigned int, int); 156 157 158 /* error.c */ 159 extern int _formerr_internal(TASK *, dns_rcode_t, task_error_t, char *, const char *, unsigned int); 160 extern int _dnserror_internal(TASK *, dns_rcode_t, task_error_t, const char *, unsigned int); 161 extern char *err_reason_str(TASK *, task_error_t); 162 extern int rr_error_repeat(uint32_t); 163 extern int rr_error(uint32_t, const char *, ...) __printflike(2,3); 164 165 #define formerr(task,rcode,reason,xtra) _formerr_internal((task),(rcode),(reason),(xtra),__FILE__,__LINE__) 166 #define dnserror(task,rcode,reason) _dnserror_internal((task),(rcode),(reason),__FILE__,__LINE__) 167 168 169 /* queue.c */ 170 extern QUEUE *queue_init(void); 171 extern int _enqueue(QUEUE *, TASK *, const char *, unsigned int); 172 extern void _dequeue(QUEUE *, TASK *, const char *, unsigned int); 173 174 #define enqueue(Q,T) _enqueue((Q), (T), __FILE__, __LINE__) 175 #define dequeue(Q,T) _dequeue((Q), (T), __FILE__, __LINE__) 176 177 178 /* recursive.c */ 179 extern int recursive_fwd(TASK *); 180 extern int recursive_fwd_connect(TASK *); 181 extern int recursive_fwd_write(TASK *); 182 extern int recursive_fwd_read(TASK *); 183 184 185 /* reply.c */ 186 extern int reply_init(TASK *); 187 extern void build_cache_reply(TASK *); 188 extern void build_reply(TASK *, int); 189 190 191 /* resolve.c */ 192 extern int resolve(TASK *, datasection_t, dns_qtype_t, char *, int); 193 194 195 /* rr.c */ 196 extern void rrlist_add(TASK *, datasection_t, dns_rrtype_t, void *, char *); 197 extern void rrlist_free(RRLIST *); 198 199 200 /* sort.c */ 201 extern void sort_a_recs(TASK *, RRLIST *, datasection_t); 202 extern void sort_mx_recs(TASK *, RRLIST *, datasection_t); 203 extern void sort_srv_recs(TASK *, RRLIST *, datasection_t); 204 205 206 /* task.c */ 207 extern int new_task(TASK *, unsigned char *, size_t); 208 extern void task_init_header(TASK *); 209 extern char *clientaddr(TASK *); 210 extern char *desctask(TASK *); 211 extern TASK *_task_init(taskstat_t, int, int, int, void *, const char *, int); 212 #define task_init(S,fd,p,f,a) _task_init((S), (fd), (p), (f), (a), __FILE__, __LINE__) 213 extern void _task_free(TASK *, const char *, int); 214 #define task_free(T) if ((T)) _task_free((T), __FILE__, __LINE__), (T) = NULL 215 216 217 extern void task_build_reply(TASK *); 218 extern void task_output_info(TASK *, char *); 219 extern void task_process(register TASK *); 220 221 222 /* tcp.c */ 223 extern int accept_tcp_query(int, int); 224 extern int read_tcp_query(TASK *); 225 extern int write_tcp_reply(TASK *); 226 227 228 /* udp.c */ 229 extern int read_udp_query(int, int); 230 extern void write_udp_reply(TASK *); 231 232 233 /* update.c */ 234 extern int dns_update(TASK *); 235 236 #endif /* _MYDNS_NAMED_H */ 237 238 /* vi:set ts=3: */ 239