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