1 |
/* |
2 |
vpn.h -- header for vpn.C |
3 |
Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de> |
4 |
|
5 |
This file is part of GVPE. |
6 |
|
7 |
GVPE is free software; you can redistribute it and/or modify it |
8 |
under the terms of the GNU General Public License as published by the |
9 |
Free Software Foundation; either version 3 of the License, or (at your |
10 |
option) any later version. |
11 |
|
12 |
This program is distributed in the hope that it will be useful, but |
13 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
15 |
Public License for more details. |
16 |
|
17 |
You should have received a copy of the GNU General Public License along |
18 |
with this program; if not, see <http://www.gnu.org/licenses/>. |
19 |
|
20 |
Additional permission under GNU GPL version 3 section 7 |
21 |
|
22 |
If you modify this Program, or any covered work, by linking or |
23 |
combining it with the OpenSSL project's OpenSSL library (or a modified |
24 |
version of that library), containing parts covered by the terms of the |
25 |
OpenSSL or SSLeay licenses, the licensors of this Program grant you |
26 |
additional permission to convey the resulting work. Corresponding |
27 |
Source for a non-source form of such a combination shall include the |
28 |
source code for the parts of OpenSSL used as well as that of the |
29 |
covered work. |
30 |
*/ |
31 |
|
32 |
#ifndef GVPE_VPN_H__ |
33 |
#define GVPE_VPN_H__ |
34 |
|
35 |
#include "global.h" |
36 |
#include "conf.h" |
37 |
#include "device.h" |
38 |
#include "connection.h" |
39 |
|
40 |
struct vpn |
41 |
{ |
42 |
int udpv4_fd , tcpv4_fd, ipv4_fd , icmpv4_fd , dnsv4_fd; |
43 |
int udpv4_tos, ipv4_tos, icmpv4_tos, dnsv4_tos; |
44 |
|
45 |
int events; |
46 |
|
47 |
enum { |
48 |
EVENT_RECONNECT = 1, |
49 |
EVENT_SHUTDOWN = 2, |
50 |
}; |
51 |
|
52 |
void event_cb (ev::timer &w, int revents); ev::timer event; |
53 |
|
54 |
tap_device *tap; |
55 |
|
56 |
typedef vector<connection *> conns_vector; |
57 |
conns_vector conns; |
58 |
|
59 |
// called when any conenction has been established |
60 |
void connection_established (connection *c); |
61 |
|
62 |
// return true if src can connect directly to dst |
63 |
bool can_direct (conf_node *src, conf_node *dst) const; |
64 |
connection *find_router_for (const connection *dst); |
65 |
|
66 |
void reconnect_all (); |
67 |
void shutdown_all (); |
68 |
|
69 |
void tap_ev (ev::io &w, int revents); ev::io tap_ev_watcher; |
70 |
void inject_data_packet (tap_packet *pkt, int dst); |
71 |
|
72 |
void send_connect_request (connection *c); |
73 |
|
74 |
void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); |
75 |
bool send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = 0); |
76 |
|
77 |
#if ENABLE_TCP |
78 |
void tcpv4_ev (ev::io &w, int revents); ev::io tcpv4_ev_watcher; |
79 |
bool send_tcpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
80 |
#endif |
81 |
|
82 |
#if ENABLE_ICMP |
83 |
void icmpv4_ev (ev::io &w, int revents); ev::io icmpv4_ev_watcher; |
84 |
bool send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
85 |
#endif |
86 |
|
87 |
#if ENABLE_DNS |
88 |
vector<struct dns_snd *> dns_sndpq; |
89 |
sockinfo dns_forwarder; |
90 |
|
91 |
void dnsv4_ev (ev::io &w, int revents); ev::io dnsv4_ev_watcher; |
92 |
void dnsv4_server (struct dns_packet &pkt); |
93 |
void dnsv4_client (struct dns_packet &pkt); |
94 |
|
95 |
bool send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
96 |
#endif |
97 |
|
98 |
void udpv4_ev (ev::io &w, int revents); ev::io udpv4_ev_watcher; |
99 |
bool send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
100 |
|
101 |
void ipv4_ev (ev::io &w, int revents); ev::io ipv4_ev_watcher; |
102 |
bool send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
103 |
|
104 |
vpn (); |
105 |
~vpn (); |
106 |
|
107 |
int setup_socket (u8 prot, int family, int type, int proto); |
108 |
int setup (); |
109 |
bool drop_privileges (); |
110 |
|
111 |
void dump_status (); |
112 |
|
113 |
void script_init_env (); |
114 |
const char *script_if_init (); |
115 |
const char *script_if_up (); |
116 |
}; |
117 |
|
118 |
extern vpn network; // THE vpn |
119 |
|
120 |
#endif |
121 |
|