ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
Revision: 1.9
Committed: Wed Mar 26 14:39:52 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
Changes since 1.8: +5 -4 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     #include "device.h"
32    
33 pcg 1.9 /* Protocol version. Different major versions are incompatible,
34     * different minor versions probably are compatible ;)
35 pcg 1.1 */
36    
37 pcg 1.9 #define PROTOCOL_MAJOR 0
38 pcg 1.1 #define PROTOCOL_MINOR 0
39    
40     struct vpn;
41     struct vpn_packet;
42    
43 pcg 1.8 struct rsaid {
44     u8 id[RSA_IDLEN]; // the challenge id
45     };
46    
47     typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data;
48 pcg 1.1 typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
49 pcg 1.9 typedef u8 rsaresponse[RSA_RESLEN]; // the encrypted ripemd160 hash
50 pcg 1.1
51     struct crypto_ctx;
52    
53 pcg 1.5 // a very simple fifo pkt-queue
54     class pkt_queue
55     {
56     tap_packet *queue[QUEUEDEPTH];
57     int i, j;
58    
59     public:
60    
61     void put (tap_packet *p);
62     tap_packet *get ();
63    
64     pkt_queue ();
65     ~pkt_queue ();
66     };
67    
68 pcg 1.1 struct connection
69     {
70     conf_node *conf;
71     struct vpn *vpn;
72    
73 pcg 1.8 SOCKADDR sa; // the current(!) destination ip to send packets to
74 pcg 1.1 int retry_cnt;
75    
76 pcg 1.5 tstamp last_activity; // time of last packet received
77 pcg 1.1
78     u32 oseqno;
79 pcg 1.4 sliding_window iseqno;
80 pcg 1.1
81     pkt_queue queue;
82    
83     crypto_ctx *octx, *ictx;
84    
85 pcg 1.2 enum conf_node::connectmode connectmode;
86 pcg 1.9 u8 prot_minor; // minor number of other side
87 pcg 1.2
88 pcg 1.1 void reset_dstaddr ();
89    
90     void shutdown ();
91     void reset_connection ();
92 pcg 1.5 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)
94     void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
95 pcg 1.1
96 pcg 1.8 void send_auth_request (SOCKADDR *sa, bool initiate);
97     void send_auth_response (SOCKADDR *sa, const rsaid &id, const rsachallenge &chg);
98 pcg 1.1 void send_reset (SOCKADDR *dsa);
99     void send_ping (SOCKADDR *dss, u8 pong = 0);
100     void send_data_packet (tap_packet *pkt, bool broadcast = false);
101     void inject_data_packet (tap_packet *pkt, bool broadcast = false);
102     void connect_request (int id);
103    
104     void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
105    
106     void script_node ();
107 pcg 1.8 const char *script_node_up (int);
108     const char *script_node_down (int);
109 pcg 1.5
110     connection(struct vpn *vpn_);
111     ~connection ();
112 pcg 1.1 };
113    
114     struct vpn
115     {
116     int socket_fd;
117     int events;
118    
119     enum {
120     EVENT_RECONNECT = 1,
121     EVENT_SHUTDOWN = 2,
122     };
123    
124 pcg 1.5 void event_cb (tstamp &ts); time_watcher event;
125    
126     tap_device *tap;
127    
128 pcg 1.1 typedef vector<connection *> conns_vector;
129     conns_vector conns;
130    
131     connection *find_router ();
132    
133 pcg 1.3 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
134 pcg 1.1 void reconnect_all ();
135     void shutdown_all ();
136     void connect_request (int id);
137    
138 pcg 1.5 void vpn_ev (short revents); io_watcher vpn_ev_watcher;
139     void udp_ev (short revents); io_watcher udp_ev_watcher;
140    
141 pcg 1.1 vpn ();
142     ~vpn ();
143    
144     int setup ();
145    
146 pcg 1.8 const char *script_if_up (int);
147 pcg 1.1 };
148    
149     #endif
150