… | |
… | |
26 | #include <openssl/rsa.h> |
26 | #include <openssl/rsa.h> |
27 | |
27 | |
28 | #include "conf.h" |
28 | #include "conf.h" |
29 | #include "iom.h" |
29 | #include "iom.h" |
30 | #include "util.h" |
30 | #include "util.h" |
|
|
31 | #include "sockinfo.h" |
31 | #include "device.h" |
32 | #include "device.h" |
32 | |
33 | |
33 | /* Protocol version. Different major versions are incompatible, |
34 | /* Protocol version. Different major versions are incompatible, |
34 | * different minor versions probably are compatible ;) |
35 | * different minor versions probably are compatible ;) |
35 | */ |
36 | */ |
… | |
… | |
68 | struct connection |
69 | struct connection |
69 | { |
70 | { |
70 | conf_node *conf; |
71 | conf_node *conf; |
71 | struct vpn *vpn; |
72 | struct vpn *vpn; |
72 | |
73 | |
73 | SOCKADDR sa; // the current(!) destination ip to send packets to |
74 | sockinfo si; // the current(!) destination ip to send packets to |
74 | int retry_cnt; |
75 | int retry_cnt; |
75 | |
76 | |
76 | tstamp last_activity; // time of last packet received |
77 | tstamp last_activity; // time of last packet received |
77 | |
78 | |
78 | u32 oseqno; |
79 | u32 oseqno; |
79 | sliding_window iseqno; |
80 | sliding_window iseqno; |
|
|
81 | |
|
|
82 | u8 prot_send, prot_recv; |
80 | |
83 | |
81 | pkt_queue queue; |
84 | pkt_queue queue; |
82 | |
85 | |
83 | crypto_ctx *octx, *ictx; |
86 | crypto_ctx *octx, *ictx; |
84 | |
87 | |
… | |
… | |
91 | void reset_connection (); |
94 | void reset_connection (); |
92 | void establish_connection_cb (tstamp &ts); time_watcher establish_connection; |
95 | void establish_connection_cb (tstamp &ts); time_watcher establish_connection; |
93 | void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing) |
96 | void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing) |
94 | void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe |
97 | void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe |
95 | |
98 | |
96 | void send_auth_request (SOCKADDR *sa, bool initiate); |
99 | void send_auth_request (const sockinfo &si, bool initiate); |
97 | void send_auth_response (SOCKADDR *sa, const rsaid &id, const rsachallenge &chg); |
100 | void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg); |
98 | void send_reset (SOCKADDR *dsa); |
101 | void send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols); |
99 | void send_ping (SOCKADDR *dss, u8 pong = 0); |
102 | void send_reset (const sockinfo &dsi); |
|
|
103 | void send_ping (const sockinfo &dsi, u8 pong = 0); |
100 | void send_data_packet (tap_packet *pkt, bool broadcast = false); |
104 | void send_data_packet (tap_packet *pkt, bool broadcast = false); |
101 | void inject_data_packet (tap_packet *pkt, bool broadcast = false); |
105 | void inject_data_packet (tap_packet *pkt, bool broadcast = false); |
102 | void connect_request (int id); |
106 | void connect_request (int id); |
103 | |
107 | |
|
|
108 | void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY); |
104 | void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); |
109 | void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); |
105 | |
110 | |
106 | void script_node (); |
111 | void script_node (); |
107 | const char *script_node_up (int); |
112 | const char *script_node_up (int); |
108 | const char *script_node_down (int); |
113 | const char *script_node_down (int); |
|
|
114 | |
|
|
115 | void dump_status (); |
109 | |
116 | |
110 | connection(struct vpn *vpn_); |
117 | connection(struct vpn *vpn_); |
111 | ~connection (); |
118 | ~connection (); |
112 | }; |
119 | }; |
113 | |
120 | |
114 | struct vpn |
121 | struct vpn |
115 | { |
122 | { |
116 | int socket_fd; |
123 | int udpv4_fd; |
|
|
124 | int ipv4_fd; |
|
|
125 | |
117 | int events; |
126 | int events; |
118 | |
127 | |
119 | enum { |
128 | enum { |
120 | EVENT_RECONNECT = 1, |
129 | EVENT_RECONNECT = 1, |
121 | EVENT_SHUTDOWN = 2, |
130 | EVENT_SHUTDOWN = 2, |
… | |
… | |
128 | typedef vector<connection *> conns_vector; |
137 | typedef vector<connection *> conns_vector; |
129 | conns_vector conns; |
138 | conns_vector conns; |
130 | |
139 | |
131 | connection *find_router (); |
140 | connection *find_router (); |
132 | |
141 | |
133 | void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY); |
|
|
134 | void reconnect_all (); |
142 | void reconnect_all (); |
135 | void shutdown_all (); |
143 | void shutdown_all (); |
136 | void connect_request (int id); |
144 | void connect_request (int id); |
137 | |
145 | |
138 | void vpn_ev (short revents); io_watcher vpn_ev_watcher; |
146 | void tap_ev (short revents); io_watcher tap_ev_watcher; |
|
|
147 | void ipv4_ev (short revents); io_watcher ipv4_ev_watcher; |
139 | void udp_ev (short revents); io_watcher udp_ev_watcher; |
148 | void udpv4_ev (short revents); io_watcher udpv4_ev_watcher; |
|
|
149 | |
|
|
150 | void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); |
|
|
151 | |
|
|
152 | void send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY); |
|
|
153 | void send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY); |
140 | |
154 | |
141 | vpn (); |
155 | vpn (); |
142 | ~vpn (); |
156 | ~vpn (); |
143 | |
157 | |
144 | int setup (); |
158 | int setup (); |
145 | |
159 | |
|
|
160 | void dump_status (); |
|
|
161 | |
146 | const char *script_if_up (int); |
162 | const char *script_if_up (int); |
147 | }; |
163 | }; |
148 | |
164 | |
149 | #endif |
165 | #endif |
150 | |
166 | |