summaryrefslogtreecommitdiffstats
path: root/src/VBox/Devices/Network/slirp/dnsproxy/dnsproxy.h
blob: 584f25ddf1e4372c30b28836278e449dd5e59e37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* $Id: dnsproxy.h $ */
/*
 * Copyright (c) 2003,2004,2005 Armin Wolfermann
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef _DNSPROXY_H_
#define _DNSPROXY_H_

/* LONGLONG */
#include <sys/types.h>

#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif

#ifndef VBOX
#include <sys/socket.h>
#include <netinet/in.h>
#ifdef HAVE_ARPA_INET_H
# include <arpa/inet.h>
#endif
#include <stdarg.h>

#include <event.h>

#ifdef DEBUG
#define DPRINTF(x) do { printf x ; } while (0)
#else
#define DPRINTF(x)
#endif

#ifdef GLOBALS
#define GLOBAL(a) a
#define GLOBAL_INIT(a,b) a = b
#else
#define GLOBAL(a) extern a
#define GLOBAL_INIT(a,b) extern a
#endif
#endif

struct request {
    unsigned short      id;

    struct sockaddr_in  client;
    unsigned short      clientid;
    unsigned char       recursion;

#ifndef VBOX
    struct event        timeout;
#endif

    struct request      **prev;
    struct request      *next;
#ifdef VBOX
    /* this field used for saving last attempt
     * to connect server, timeout function should change
     * it's value on next server. And dnsproxy_query should
     * initializate with first server in the list
     *
     * dnsgen is a generation number - a copy of pData->dnsgen at the
     * time of request creation (poor man's weak reference).
     * dns_server must not be used if pData->dnsgen changed.
     */
    struct dns_entry    *dns_server;
    uint32_t            dnsgen;
    int nbyte; /* length of dns request */
    char byte[1]; /* copy of original request */
#endif
};

#ifndef VBOX
GLOBAL_INIT(unsigned int authoritative_port, 53);
GLOBAL_INIT(unsigned int authoritative_timeout, 10);
GLOBAL_INIT(unsigned int recursive_port, 53);
GLOBAL_INIT(unsigned int recursive_timeout, 90);
GLOBAL_INIT(unsigned int stats_timeout, 3600);
GLOBAL_INIT(unsigned int port, 53);

GLOBAL(char *authoritative);
GLOBAL(char *chrootdir);
GLOBAL(char *listenat);
GLOBAL(char *recursive);
GLOBAL(char *user);

GLOBAL(unsigned long active_queries);
GLOBAL(unsigned long all_queries);
GLOBAL(unsigned long authoritative_queries);
GLOBAL(unsigned long recursive_queries);
GLOBAL(unsigned long removed_queries);
GLOBAL(unsigned long dropped_queries);
GLOBAL(unsigned long answered_queries);
GLOBAL(unsigned long dropped_answers);
GLOBAL(unsigned long late_answers);
GLOBAL(unsigned long hash_collisions);

/* dnsproxy.c */
RETSIGTYPE signal_handler(int);
int signal_event(void);

/* daemon.c */
int daemon(int, int);
#endif

/* hash.c */
void hash_add_request(PNATState, struct request *);
void hash_remove_request(PNATState, struct request *);
struct request *hash_find_request(PNATState, unsigned short);

/* internal.c */
int add_internal(PNATState, char *);
int is_internal(PNATState, struct in_addr);

#ifndef VBOX
/* log.c */
void log_syslog(const char *);
void info(const char *, ...);
void error(const char *, ...);
void fatal(const char *, ...);

/* parse.c */
int parse(const char *);

/* statistics.c */
void statistics_start(void);
#else
# define DPRINTF Log2
int dnsproxy_init(PNATState pData);
void dnsproxy_query(PNATState pData, struct socket *so, struct mbuf *m, int iphlen);
void dnsproxy_answer(PNATState pData, struct socket *so, struct mbuf *m);
#endif

#endif /* _DNSPROXY_H_ */