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