1 |
/* |
2 |
connection.h -- header for connection.C |
3 |
|
4 |
This program is free software; you can redistribute it and/or modify |
5 |
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 |
7 |
(at your option) any later version. |
8 |
|
9 |
This program is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
13 |
|
14 |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software |
16 |
Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 |
*/ |
18 |
|
19 |
#ifndef VPE_CONNECTION_H__ |
20 |
#define VPE_CONNECTION_H__ |
21 |
|
22 |
#include <openssl/hmac.h> |
23 |
|
24 |
#include "global.h" |
25 |
#include "conf.h" |
26 |
#include "sockinfo.h" |
27 |
#include "util.h" |
28 |
#include "device.h" |
29 |
|
30 |
struct vpn; |
31 |
|
32 |
// called after HUP etc. to (re-)initialize global data structures |
33 |
void connection_init (); |
34 |
|
35 |
struct rsaid { |
36 |
u8 id[RSA_IDLEN]; // the challenge id |
37 |
}; |
38 |
|
39 |
typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data; |
40 |
typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge |
41 |
typedef u8 rsaresponse[RSA_RESLEN]; // the encrypted ripemd160 hash |
42 |
|
43 |
//////////////////////////////////////////////////////////////////////////////////////// |
44 |
|
45 |
struct crypto_ctx; |
46 |
|
47 |
struct hmac_packet:net_packet |
48 |
{ |
49 |
u8 hmac[HMACLENGTH]; // each and every packet has a hmac field, but that is not (yet) checked everywhere |
50 |
|
51 |
void hmac_set (crypto_ctx * ctx); |
52 |
bool hmac_chk (crypto_ctx * ctx); |
53 |
|
54 |
private: |
55 |
static unsigned char hmac_digest[EVP_MAX_MD_SIZE]; |
56 |
|
57 |
void hmac_gen (crypto_ctx * ctx); |
58 |
}; |
59 |
|
60 |
struct vpn_packet : hmac_packet |
61 |
{ |
62 |
enum ptype |
63 |
{ |
64 |
PT_RESET = 0, |
65 |
PT_DATA_UNCOMPRESSED, |
66 |
PT_DATA_COMPRESSED, |
67 |
PT_PING, PT_PONG, // wasting namespace space? ;) |
68 |
PT_AUTH_REQ, // authentification request |
69 |
PT_AUTH_RES, // authentification response |
70 |
PT_CONNECT_REQ, // want other host to contact me |
71 |
PT_CONNECT_INFO, // request connection to some node |
72 |
PT_MAX |
73 |
}; |
74 |
|
75 |
u8 type; |
76 |
u8 srcdst, src1, dst1; |
77 |
|
78 |
void set_hdr (ptype type_, unsigned int dst); |
79 |
|
80 |
unsigned int src () const |
81 |
{ |
82 |
return src1 | ((srcdst >> 4) << 8); |
83 |
} |
84 |
|
85 |
unsigned int dst () const |
86 |
{ |
87 |
return dst1 | ((srcdst & 0xf) << 8); |
88 |
} |
89 |
|
90 |
ptype typ () const |
91 |
{ |
92 |
return (ptype) type; |
93 |
} |
94 |
}; |
95 |
|
96 |
//////////////////////////////////////////////////////////////////////////////////////// |
97 |
|
98 |
// a very simple fifo pkt-queue |
99 |
class pkt_queue |
100 |
{ |
101 |
tap_packet *queue[QUEUEDEPTH]; |
102 |
int i, j; |
103 |
|
104 |
public: |
105 |
|
106 |
void put (tap_packet *p); |
107 |
tap_packet *get (); |
108 |
|
109 |
pkt_queue (); |
110 |
~pkt_queue (); |
111 |
}; |
112 |
|
113 |
struct connection |
114 |
{ |
115 |
conf_node *conf; |
116 |
struct vpn *vpn; |
117 |
|
118 |
sockinfo si; // the current(!) destination ip to send packets to |
119 |
int retry_cnt; |
120 |
|
121 |
tstamp last_activity; // time of last packet received |
122 |
|
123 |
u32 oseqno; |
124 |
sliding_window iseqno; |
125 |
|
126 |
u8 protocol; |
127 |
|
128 |
pkt_queue queue; |
129 |
|
130 |
crypto_ctx *octx, *ictx; |
131 |
|
132 |
enum conf_node::connectmode connectmode; |
133 |
u8 prot_minor; // minor number of other side |
134 |
|
135 |
void reset_dstaddr (); |
136 |
|
137 |
void shutdown (); |
138 |
void reset_connection (); |
139 |
void establish_connection_cb (time_watcher &w); time_watcher establish_connection; |
140 |
void rekey_cb (time_watcher &w); time_watcher rekey; // next rekying (actually current reset + reestablishing) |
141 |
void keepalive_cb (time_watcher &w); time_watcher keepalive; // next keepalive probe |
142 |
|
143 |
void send_auth_request (const sockinfo &si, bool initiate); |
144 |
void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg); |
145 |
void send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols); |
146 |
void send_reset (const sockinfo &dsi); |
147 |
void send_ping (const sockinfo &dsi, u8 pong = 0); |
148 |
void send_data_packet (tap_packet *pkt, bool broadcast = false); |
149 |
void inject_data_packet (tap_packet *pkt, bool broadcast = false); |
150 |
void connect_request (int id); |
151 |
|
152 |
void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); |
153 |
|
154 |
void script_node (); |
155 |
const char *script_node_up (); |
156 |
const char *script_node_down (); |
157 |
|
158 |
void dump_status (); |
159 |
|
160 |
connection(struct vpn *vpn_); |
161 |
~connection (); |
162 |
}; |
163 |
|
164 |
#endif |
165 |
|