1 | /* $Id: dnsproxy.h 26495 2010-02-14 07:59:48Z 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 | struct dns_entry *dns_server;
|
---|
86 | int nbyte; /* length of dns request */
|
---|
87 | char byte[1]; /* copy of original request */
|
---|
88 | #endif
|
---|
89 | };
|
---|
90 |
|
---|
91 | #ifndef VBOX
|
---|
92 | GLOBAL_INIT(unsigned int authoritative_port, 53);
|
---|
93 | GLOBAL_INIT(unsigned int authoritative_timeout, 10);
|
---|
94 | GLOBAL_INIT(unsigned int recursive_port, 53);
|
---|
95 | GLOBAL_INIT(unsigned int recursive_timeout, 90);
|
---|
96 | GLOBAL_INIT(unsigned int stats_timeout, 3600);
|
---|
97 | GLOBAL_INIT(unsigned int port, 53);
|
---|
98 |
|
---|
99 | GLOBAL(char *authoritative);
|
---|
100 | GLOBAL(char *chrootdir);
|
---|
101 | GLOBAL(char *listenat);
|
---|
102 | GLOBAL(char *recursive);
|
---|
103 | GLOBAL(char *user);
|
---|
104 |
|
---|
105 | GLOBAL(unsigned long active_queries);
|
---|
106 | GLOBAL(unsigned long all_queries);
|
---|
107 | GLOBAL(unsigned long authoritative_queries);
|
---|
108 | GLOBAL(unsigned long recursive_queries);
|
---|
109 | GLOBAL(unsigned long removed_queries);
|
---|
110 | GLOBAL(unsigned long dropped_queries);
|
---|
111 | GLOBAL(unsigned long answered_queries);
|
---|
112 | GLOBAL(unsigned long dropped_answers);
|
---|
113 | GLOBAL(unsigned long late_answers);
|
---|
114 | GLOBAL(unsigned long hash_collisions);
|
---|
115 |
|
---|
116 | /* dnsproxy.c */
|
---|
117 | RETSIGTYPE signal_handler(int);
|
---|
118 | int signal_event(void);
|
---|
119 |
|
---|
120 | /* daemon.c */
|
---|
121 | int daemon(int, int);
|
---|
122 | #endif
|
---|
123 |
|
---|
124 | /* hash.c */
|
---|
125 | void hash_add_request(PNATState, struct request *);
|
---|
126 | void hash_remove_request(PNATState, struct request *);
|
---|
127 | struct request *hash_find_request(PNATState, unsigned short);
|
---|
128 |
|
---|
129 | /* internal.c */
|
---|
130 | int add_internal(PNATState, char *);
|
---|
131 | int is_internal(PNATState, struct in_addr);
|
---|
132 |
|
---|
133 | #ifndef VBOX
|
---|
134 | /* log.c */
|
---|
135 | void log_syslog(const char *);
|
---|
136 | void info(const char *, ...);
|
---|
137 | void error(const char *, ...);
|
---|
138 | void fatal(const char *, ...);
|
---|
139 |
|
---|
140 | /* parse.c */
|
---|
141 | int parse(const char *);
|
---|
142 |
|
---|
143 | /* statistics.c */
|
---|
144 | void statistics_start(void);
|
---|
145 | #else
|
---|
146 | # define DPRINTF Log2
|
---|
147 | int dnsproxy_init(PNATState pData);
|
---|
148 | void dnsproxy_query(PNATState pData, struct socket *so, struct mbuf *m, int iphlen);
|
---|
149 | void dnsproxy_answer(PNATState pData, struct socket *so, struct mbuf *m);
|
---|
150 | #endif
|
---|
151 |
|
---|
152 | #endif /* _DNSPROXY_H_ */
|
---|