ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.h
Revision: 1.9
Committed: Thu Oct 16 02:28:36 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.8: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.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 pcg 1.5 void set_hdr (ptype type_, unsigned int dst);
79 pcg 1.1
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 pcg 1.8 net_packet *queue[QUEUEDEPTH];
102 pcg 1.1 int i, j;
103    
104     public:
105    
106 pcg 1.8 void put (net_packet *p);
107     net_packet *get ();
108 pcg 1.1
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 pcg 1.8 pkt_queue data_queue, vpn_queue;
129 pcg 1.1
130     crypto_ctx *octx, *ictx;
131    
132     enum conf_node::connectmode connectmode;
133     u8 prot_minor; // minor number of other side
134    
135 pcg 1.6 void reset_si ();
136     const sockinfo &forward_si (const sockinfo &si) const;
137 pcg 1.1
138     void shutdown ();
139 pcg 1.7 void connection_established ();
140 pcg 1.1 void reset_connection ();
141 pcg 1.7
142 pcg 1.4 void establish_connection_cb (time_watcher &w); time_watcher establish_connection;
143     void rekey_cb (time_watcher &w); time_watcher rekey; // next rekying (actually current reset + reestablishing)
144     void keepalive_cb (time_watcher &w); time_watcher keepalive; // next keepalive probe
145 pcg 1.1
146 pcg 1.7 void send_connect_request (int id);
147 pcg 1.1 void send_auth_request (const sockinfo &si, bool initiate);
148     void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg);
149     void send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols);
150     void send_reset (const sockinfo &dsi);
151     void send_ping (const sockinfo &dsi, u8 pong = 0);
152 pcg 1.9 void send_data_packet (tap_packet *pkt);
153 pcg 1.7
154 pcg 1.1 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
155 pcg 1.6 void inject_vpn_packet (vpn_packet *pkt, int tos = 0); // for forwarding
156 pcg 1.1
157 pcg 1.7 void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = 0);
158 pcg 1.1 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
159    
160     void script_node ();
161 pcg 1.3 const char *script_node_up ();
162     const char *script_node_down ();
163 pcg 1.1
164     void dump_status ();
165    
166     connection(struct vpn *vpn_);
167     ~connection ();
168     };
169    
170     #endif
171