1 /*
2  * common.h
3  *
4  * This file contains definitions useful in all sorts of places.
5  *
6  * Copyright (C) 1998 Brad M. Garcia <garsh@home.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */
22 
23 #ifndef _DNRD_COMMON_H_
24 #define _DNRD_COMMON_H_
25 
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29 
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <netinet/in.h>
33 #include <syslog.h>
34 #include <semaphore.h>
35 #include "domnode.h"
36 
37 /* default chroot path. this might be redefined in compile time */
38 #ifndef DNRD_ROOT
39 #define DNRD_ROOT "/usr/local/etc/dnrd"
40 #endif
41 
42 #ifndef CONFIG_FILE
43 #define CONFIG_FILE "dnrd.conf"
44 #endif
45 
46 /* Set the default timeout value for select in seconds */
47 #ifndef SELECT_TIMEOUT
48 #define SELECT_TIMEOUT 1
49 #endif
50 
51 /* Set the default timeout value for forward DNS. If we get no
52  * response from a DNS server within forward_timeout, deactivate the
53  * server.  note that if select_timeout is greater than this, the
54  * forward timeout *might* increase to select_timeout. This value
55  * should be >= SELECT_TIMEOUT
56  */
57 /* 12 seems to be a good value under heavy load... */
58 #ifndef FORWARD_TIMEOUT
59 #define FORWARD_TIMEOUT 12
60 #endif
61 
62 /* not used yet */
63 #ifndef FORWARD_RETRIES
64 #define FORWARD_RETRIES 5
65 #endif
66 
67 /* only check if any server are to be reactivated every
68  * REACTIVATE_INTERVAL seconds
69  */
70 #define REACTIVATE_INTERVAL 10
71 
72 struct dnssrv_t {
73   int                    sock;      /* for communication with server */
74   struct sockaddr_in     addr;      /* IP address of server */
75   char*                  domain;    /* optional domain to match.  Set to
76 					 zero for a default server */
77 
78 };
79 
80 
81 extern const char*         version;   /* the version number for this program */
82 extern const char*         progname;  /* the name of this program */
83 extern unsigned char       opt_debug; /* debugging option */
84 extern const char*         pid_file; /* File containing current daemon's PID */
85 extern int                 isock;     /* for communication with clients */
86 extern int                 tcpsock;   /* same as isock, but for tcp requests */
87 extern int                 select_timeout; /* select timeout in seconds */
88 extern int                 forward_timeout; /* timeout for forward DNS */
89 extern struct sockaddr_in  recv_addr; /* address on which we receive queries */
90 #ifndef __CYGWIN__
91 extern uid_t               daemonuid; /* to switch to once daemonised */
92 extern gid_t               daemongid; /* to switch to once daemonised */
93 extern char                dnrd_user[256];
94 extern char                dnrd_group[256];
95 #endif
96 extern int                 gotterminal;
97 #ifndef EXCLUDE_MASTER
98 extern int		   master_onoff;
99 extern unsigned char       master_reload;
100 extern char                master_config[256];
101 extern char                blacklist[256];
102 #endif
103 extern sem_t               dnrd_sem;  /* Used for all thread synchronization */
104 
105 extern char                dnrd_root[512];
106 extern char                config_file[];
107 extern domnode_t           *domain_list;
108 
109 extern int                 reactivate_interval;
110 extern int                 stats_interval;
111 extern int                 stats_reset;
112 extern int                 ignore_inactive_cache_hits;
113 
114 extern int max_sockets;
115 extern int maxsock;
116 extern fd_set fdmaster;
117 
118 /* kill any currently running copies of dnrd */
119 int kill_current();
120 
121 /* print messages to stderr or syslog */
122 void log_msg(int type, const char *fmt, ...);
123 
124 /* same, but only if debugging is turned on */
125 void log_debug(int level, const char *fmt, ...);
126 
127 /* send to log_msg (LOG_ERR) and exit with exitcode */
128 void log_err_exit(int exitcode, const char *fmt, ...);
129 
130 /* cleanup everything and exit */
131 void cleanexit(int status);
132 
133 /* Reads in the domain name as a string, allocates space for the CNAME
134    version of it */
135 char* make_cname(const char *text, const int maxlen);
136 //void sprintf_cname(const char *cname, int namesize, char *buf, int bufsize);
137 
138 char *cname2asc(const char *cname);
139 
140 
141 /* Dumping DNS packets */
142 int dump_dnspacket(char *type, unsigned char *packet, int len);
143 
144 
145 #endif  /* _DNRD_COMMON_H_ */
146