ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
Revision: 1.11
Committed: Fri Mar 28 16:14:40 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.10: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*
2     protocol.h -- header for protocol.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_PROTOCOL_H__
20     #define VPE_PROTOCOL_H__
21    
22     #include <netinet/in.h>
23 pcg 1.3 #include <netinet/ip.h> // for tos etc.
24 pcg 1.1
25     #include <openssl/evp.h>
26     #include <openssl/rsa.h>
27    
28     #include "conf.h"
29 pcg 1.5 #include "iom.h"
30 pcg 1.1 #include "util.h"
31 pcg 1.10 #include "sockinfo.h"
32 pcg 1.1 #include "device.h"
33    
34 pcg 1.9 /* Protocol version. Different major versions are incompatible,
35     * different minor versions probably are compatible ;)
36 pcg 1.1 */
37    
38 pcg 1.9 #define PROTOCOL_MAJOR 0
39 pcg 1.1 #define PROTOCOL_MINOR 0
40    
41     struct vpn;
42     struct vpn_packet;
43    
44 pcg 1.8 struct rsaid {
45     u8 id[RSA_IDLEN]; // the challenge id
46     };
47    
48     typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data;
49 pcg 1.1 typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
50 pcg 1.9 typedef u8 rsaresponse[RSA_RESLEN]; // the encrypted ripemd160 hash
51 pcg 1.1
52     struct crypto_ctx;
53    
54 pcg 1.5 // a very simple fifo pkt-queue
55     class pkt_queue
56     {
57     tap_packet *queue[QUEUEDEPTH];
58     int i, j;
59    
60     public:
61    
62     void put (tap_packet *p);
63     tap_packet *get ();
64    
65     pkt_queue ();
66     ~pkt_queue ();
67     };
68    
69 pcg 1.1 struct connection
70     {
71     conf_node *conf;
72     struct vpn *vpn;
73    
74 pcg 1.10 sockinfo si; // the current(!) destination ip to send packets to
75 pcg 1.1 int retry_cnt;
76    
77 pcg 1.5 tstamp last_activity; // time of last packet received
78 pcg 1.1
79     u32 oseqno;
80 pcg 1.4 sliding_window iseqno;
81 pcg 1.1
82 pcg 1.10 u8 prot_send, prot_recv;
83    
84 pcg 1.1 pkt_queue queue;
85    
86     crypto_ctx *octx, *ictx;
87    
88 pcg 1.2 enum conf_node::connectmode connectmode;
89 pcg 1.9 u8 prot_minor; // minor number of other side
90 pcg 1.2
91 pcg 1.1 void reset_dstaddr ();
92    
93     void shutdown ();
94     void reset_connection ();
95 pcg 1.5 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
96     void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing)
97     void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
98 pcg 1.1
99 pcg 1.10 void send_auth_request (const sockinfo &si, bool initiate);
100     void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg);
101 pcg 1.11 void send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols);
102 pcg 1.10 void send_reset (const sockinfo &dsi);
103     void send_ping (const sockinfo &dsi, u8 pong = 0);
104 pcg 1.1 void send_data_packet (tap_packet *pkt, bool broadcast = false);
105     void inject_data_packet (tap_packet *pkt, bool broadcast = false);
106     void connect_request (int id);
107    
108 pcg 1.10 void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
109     void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
110 pcg 1.1
111     void script_node ();
112 pcg 1.8 const char *script_node_up (int);
113     const char *script_node_down (int);
114 pcg 1.5
115 pcg 1.10 void dump_status ();
116    
117 pcg 1.5 connection(struct vpn *vpn_);
118     ~connection ();
119 pcg 1.1 };
120    
121     struct vpn
122     {
123 pcg 1.10 int udpv4_fd;
124     int ipv4_fd;
125    
126 pcg 1.1 int events;
127    
128     enum {
129     EVENT_RECONNECT = 1,
130     EVENT_SHUTDOWN = 2,
131     };
132    
133 pcg 1.5 void event_cb (tstamp &ts); time_watcher event;
134    
135     tap_device *tap;
136    
137 pcg 1.1 typedef vector<connection *> conns_vector;
138     conns_vector conns;
139    
140     connection *find_router ();
141    
142     void reconnect_all ();
143     void shutdown_all ();
144     void connect_request (int id);
145    
146 pcg 1.10 void tap_ev (short revents); io_watcher tap_ev_watcher;
147     void ipv4_ev (short revents); io_watcher ipv4_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);
154 pcg 1.5
155 pcg 1.1 vpn ();
156     ~vpn ();
157    
158     int setup ();
159 pcg 1.10
160     void dump_status ();
161 pcg 1.1
162 pcg 1.8 const char *script_if_up (int);
163 pcg 1.1 };
164    
165     #endif
166