… | |
… | |
26 | #include "conf.h" |
26 | #include "conf.h" |
27 | #include "device.h" |
27 | #include "device.h" |
28 | #include "connection.h" |
28 | #include "connection.h" |
29 | |
29 | |
30 | struct vpn |
30 | struct vpn |
31 | { |
31 | { |
32 | int udpv4_fd, tcpv4_fd, ipv4_fd, icmpv4_fd, dnsv4_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; |
33 | |
34 | |
34 | int events; |
35 | int events; |
35 | |
36 | |
36 | enum { |
37 | enum { |
37 | EVENT_RECONNECT = 1, |
38 | EVENT_RECONNECT = 1, |
38 | EVENT_SHUTDOWN = 2, |
39 | EVENT_SHUTDOWN = 2, |
39 | }; |
40 | }; |
40 | |
41 | |
41 | void event_cb (ev::timer &w, int revents); ev::timer event; |
42 | void event_cb (ev::timer &w, int revents); ev::timer event; |
42 | |
43 | |
43 | tap_device *tap; |
44 | tap_device *tap; |
44 | |
45 | |
45 | typedef vector<connection *> conns_vector; |
46 | typedef vector<connection *> conns_vector; |
46 | conns_vector conns; |
47 | conns_vector conns; |
47 | |
48 | |
48 | connection *find_router (); |
49 | connection *find_router (); |
49 | connection *find_forwarder (); |
50 | connection *find_forwarder (); |
50 | |
51 | |
51 | void reconnect_all (); |
52 | void reconnect_all (); |
52 | void shutdown_all (); |
53 | void shutdown_all (); |
53 | |
54 | |
54 | void tap_ev (ev::io &w, int revents); ev::io tap_ev_watcher; |
55 | void tap_ev (ev::io &w, int revents); ev::io tap_ev_watcher; |
55 | void inject_data_packet (tap_packet *pkt, int dst); |
56 | void inject_data_packet (tap_packet *pkt, int dst); |
56 | |
57 | |
57 | void send_connect_request (int id); |
58 | void send_connect_request (int id); |
58 | |
59 | |
59 | void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); |
60 | void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); |
60 | bool 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); |
61 | |
62 | |
62 | #if ENABLE_TCP |
63 | #if ENABLE_TCP |
63 | void tcpv4_ev (ev::io &w, int revents); ev::io tcpv4_ev_watcher; |
64 | 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); |
65 | bool send_tcpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
65 | #endif |
66 | #endif |
66 | |
67 | |
67 | #if ENABLE_ICMP |
68 | #if ENABLE_ICMP |
68 | void icmpv4_ev (ev::io &w, int revents); ev::io icmpv4_ev_watcher; |
69 | 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); |
70 | bool send_icmpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
70 | #endif |
71 | #endif |
71 | |
72 | |
72 | #if ENABLE_DNS |
73 | #if ENABLE_DNS |
73 | vector<struct dns_snd *> dns_sndpq; |
74 | vector<struct dns_snd *> dns_sndpq; |
74 | sockinfo dns_forwarder; |
75 | sockinfo dns_forwarder; |
75 | |
76 | |
76 | void dnsv4_ev (ev::io &w, int revents); ev::io dnsv4_ev_watcher; |
77 | void dnsv4_ev (ev::io &w, int revents); ev::io dnsv4_ev_watcher; |
77 | void dnsv4_server (struct dns_packet &pkt); |
78 | void dnsv4_server (struct dns_packet &pkt); |
78 | void dnsv4_client (struct dns_packet &pkt); |
79 | void dnsv4_client (struct dns_packet &pkt); |
79 | |
80 | |
80 | bool send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
81 | bool send_dnsv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
81 | #endif |
82 | #endif |
82 | |
83 | |
83 | void udpv4_ev (ev::io &w, int revents); ev::io udpv4_ev_watcher; |
84 | 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); |
85 | bool send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
85 | |
86 | |
86 | void ipv4_ev (ev::io &w, int revents); ev::io ipv4_ev_watcher; |
87 | 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); |
88 | bool send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos); |
88 | |
89 | |
89 | vpn (); |
90 | vpn (); |
90 | ~vpn (); |
91 | ~vpn (); |
91 | |
92 | |
92 | int setup (); |
93 | int setup (); |
93 | |
94 | |
94 | void dump_status (); |
95 | void dump_status (); |
95 | |
96 | |
96 | void script_init_env (); |
97 | void script_init_env (); |
97 | const char *script_if_init (); |
98 | const char *script_if_init (); |
98 | const char *script_if_up (); |
99 | const char *script_if_up (); |
99 | }; |
100 | }; |
100 | |
101 | |
101 | extern vpn network; // THE vpn |
102 | extern vpn network; // THE vpn |
102 | |
103 | |
103 | #endif |
104 | #endif |
104 | |
105 | |