ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.h
Revision: 1.20
Committed: Fri Mar 4 09:36:45 2005 UTC (19 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.19: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

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