1 | /* $Id: dnsproxy.h 53624 2014-12-31 14:59:44Z vboxsync $ */
|
---|
2 | /*
|
---|
3 | * Copyright (c) 2003,2004,2005 Armin Wolfermann
|
---|
4 | *
|
---|
5 | * Permission is hereby granted, free of charge, to any person obtaining a
|
---|
6 | * copy of this software and associated documentation files (the "Software"),
|
---|
7 | * to deal in the Software without restriction, including without limitation
|
---|
8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
---|
9 | * and/or sell copies of the Software, and to permit persons to whom the
|
---|
10 | * Software is furnished to do so, subject to the following conditions:
|
---|
11 | *
|
---|
12 | * The above copyright notice and this permission notice shall be included in
|
---|
13 | * all copies or substantial portions of the Software.
|
---|
14 | *
|
---|
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
---|
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
---|
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
---|
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
---|
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
---|
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
---|
21 | * DEALINGS IN THE SOFTWARE.
|
---|
22 | */
|
---|
23 |
|
---|
24 | #ifndef _DNSPROXY_H_
|
---|
25 | #define _DNSPROXY_H_
|
---|
26 |
|
---|
27 | /* LONGLONG */
|
---|
28 | #include <sys/types.h>
|
---|
29 |
|
---|
30 | #if TIME_WITH_SYS_TIME
|
---|
31 | # include <sys/time.h>
|
---|
32 | # include <time.h>
|
---|
33 | #else
|
---|
34 | # if HAVE_SYS_TIME_H
|
---|
35 | # include <sys/time.h>
|
---|
36 | # else
|
---|
37 | # include <time.h>
|
---|
38 | # endif
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #ifndef VBOX
|
---|
42 | #include <sys/socket.h>
|
---|
43 | #include <netinet/in.h>
|
---|
44 | #ifdef HAVE_ARPA_INET_H
|
---|
45 | # include <arpa/inet.h>
|
---|
46 | #endif
|
---|
47 | #include <stdarg.h>
|
---|
48 |
|
---|
49 | #include <event.h>
|
---|
50 |
|
---|
51 | #ifdef DEBUG
|
---|
52 | #define DPRINTF(x) do { printf x ; } while (0)
|
---|
53 | #else
|
---|
54 | #define DPRINTF(x)
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | #ifdef GLOBALS
|
---|
58 | #define GLOBAL(a) a
|
---|
59 | #define GLOBAL_INIT(a,b) a = b
|
---|
60 | #else
|
---|
61 | #define GLOBAL(a) extern a
|
---|
62 | #define GLOBAL_INIT(a,b) extern a
|
---|
63 | #endif
|
---|
64 | #endif
|
---|
65 |
|
---|
66 | struct request {
|
---|
67 | unsigned short id;
|
---|
68 |
|
---|
69 | struct sockaddr_in client;
|
---|
70 | unsigned short clientid;
|
---|
71 | unsigned char recursion;
|
---|
72 |
|
---|
73 | #ifndef VBOX
|
---|
74 | struct event timeout;
|
---|
75 | #endif
|
---|
76 |
|
---|
77 | struct request **prev;
|
---|
78 | struct request *next;
|
---|
79 | #ifdef VBOX
|
---|
80 | /* this field used for saving last attempt
|
---|
81 | * to connect server, timeout function should change
|
---|
82 | * it's value on next server. And dnsproxy_query should
|
---|
83 | * initializate with first server in the list
|
---|
84 | *
|
---|
85 | * dnsgen is a generation number - a copy of pData->dnsgen at the
|
---|
86 | * time of request creation (poor man's weak reference).
|
---|
87 | * dns_server must not be used if pData->dnsgen changed.
|
---|
88 | */
|
---|
89 | struct dns_entry *dns_server;
|
---|
90 | uint32_t dnsgen;
|
---|
91 | int nbyte; /* length of dns request */
|
---|
92 | char byte[1]; /* copy of original request */
|
---|
93 | #endif
|
---|
94 | };
|
---|
95 |
|
---|
96 | #ifndef VBOX
|
---|
97 | GLOBAL_INIT(unsigned int authoritative_port, 53);
|
---|
98 | GLOBAL_INIT(unsigned int authoritative_timeout, 10);
|
---|
99 | GLOBAL_INIT(unsigned int recursive_port, 53);
|
---|
100 | GLOBAL_INIT(unsigned int recursive_timeout, 90);
|
---|
101 | GLOBAL_INIT(unsigned int stats_timeout, 3600);
|
---|
102 | GLOBAL_INIT(unsigned int port, 53);
|
---|
103 |
|
---|
104 | GLOBAL(char *authoritative);
|
---|
105 | GLOBAL(char *chrootdir);
|
---|
106 | GLOBAL(char *listenat);
|
---|
107 | GLOBAL(char *recursive);
|
---|
108 | GLOBAL(char *user);
|
---|
109 |
|
---|
110 | GLOBAL(unsigned long active_queries);
|
---|
111 | GLOBAL(unsigned long all_queries);
|
---|
112 | GLOBAL(unsigned long authoritative_queries);
|
---|
113 | GLOBAL(unsigned long recursive_queries);
|
---|
114 | GLOBAL(unsigned long removed_queries);
|
---|
115 | GLOBAL(unsigned long dropped_queries);
|
---|
116 | GLOBAL(unsigned long answered_queries);
|
---|
117 | GLOBAL(unsigned long dropped_answers);
|
---|
118 | GLOBAL(unsigned long late_answers);
|
---|
119 | GLOBAL(unsigned long hash_collisions);
|
---|
120 |
|
---|
121 | /* dnsproxy.c */
|
---|
122 | RETSIGTYPE signal_handler(int);
|
---|
123 | int signal_event(void);
|
---|
124 |
|
---|
125 | /* daemon.c */
|
---|
126 | int daemon(int, int);
|
---|
127 | #endif
|
---|
128 |
|
---|
129 | /* hash.c */
|
---|
130 | void hash_add_request(PNATState, struct request *);
|
---|
131 | void hash_remove_request(PNATState, struct request *);
|
---|
132 | struct request *hash_find_request(PNATState, unsigned short);
|
---|
133 |
|
---|
134 | /* internal.c */
|
---|
135 | int add_internal(PNATState, char *);
|
---|
136 | int is_internal(PNATState, struct in_addr);
|
---|
137 |
|
---|
138 | #ifndef VBOX
|
---|
139 | /* log.c */
|
---|
140 | void log_syslog(const char *);
|
---|
141 | void info(const char *, ...);
|
---|
142 | void error(const char *, ...);
|
---|
143 | void fatal(const char *, ...);
|
---|
144 |
|
---|
145 | /* parse.c */
|
---|
146 | int parse(const char *);
|
---|
147 |
|
---|
148 | /* statistics.c */
|
---|
149 | void statistics_start(void);
|
---|
150 | #else
|
---|
151 | # define DPRINTF Log2
|
---|
152 | int dnsproxy_init(PNATState pData);
|
---|
153 | void dnsproxy_query(PNATState pData, struct socket *so, struct mbuf *m, int iphlen);
|
---|
154 | void dnsproxy_answer(PNATState pData, struct socket *so, struct mbuf *m);
|
---|
155 | #endif
|
---|
156 |
|
---|
157 | #endif /* _DNSPROXY_H_ */
|
---|