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