ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/protocol.h
(Generate patch)

Comparing gvpe/src/protocol.h (file contents):
Revision 1.2 by pcg, Sat Mar 8 10:48:41 2003 UTC vs.
Revision 1.7 by pcg, Sat Mar 22 22:36:25 2003 UTC

18 18
19#ifndef VPE_PROTOCOL_H__ 19#ifndef VPE_PROTOCOL_H__
20#define VPE_PROTOCOL_H__ 20#define VPE_PROTOCOL_H__
21 21
22#include <netinet/in.h> 22#include <netinet/in.h>
23#include <netinet/ip.h> // for tos etc.
23 24
24#include <openssl/evp.h> 25#include <openssl/evp.h>
25#include <openssl/rsa.h> 26#include <openssl/rsa.h>
26 27
27#include "conf.h" 28#include "conf.h"
29#include "iom.h"
28#include "util.h" 30#include "util.h"
29#include "device.h" 31#include "device.h"
30 32
31/* Protocol version. Different versions are incompatible, 33/* Protocol version. Different versions are incompatible,
32 incompatible version have different protocols. 34 incompatible version have different protocols.
33 */ 35 */
34 36
35#define PROTOCOL_MAJOR 2 37#define PROTOCOL_MAJOR 3
36#define PROTOCOL_MINOR 0 38#define PROTOCOL_MINOR 0
37 39
38struct vpn; 40struct vpn;
39struct vpn_packet; 41struct vpn_packet;
40 42
41typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data 43typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data
42typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge 44typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
43 45
44struct crypto_ctx; 46struct crypto_ctx;
45 47
48// a very simple fifo pkt-queue
49class pkt_queue
50 {
51 tap_packet *queue[QUEUEDEPTH];
52 int i, j;
53
54 public:
55
56 void put (tap_packet *p);
57 tap_packet *get ();
58
59 pkt_queue ();
60 ~pkt_queue ();
61 };
62
46enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY }; 63enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY };
64
65struct auth_packet;
47 66
48struct connection 67struct connection
49 { 68 {
50 conf_node *conf; 69 conf_node *conf;
51 struct vpn *vpn; 70 struct vpn *vpn;
71 u32 seqrand;
52 72
53 SOCKADDR sa; 73 SOCKADDR sa;
54 int retry_cnt; 74 int retry_cnt;
55 75
56 time_t next_retry; // next connection retry
57 time_t next_rekey; // next rekying (actually current reset + reestablishing)
58 time_t last_activity; // time of last packet received 76 tstamp last_activity; // time of last packet received
59 77
60 u32 oseqno; 78 u32 oseqno;
61 u32 iseqno; 79 sliding_window iseqno;
62 u32 ismask; // bitmask with set bits for each received seqno (input seen mask)
63 80
64 pkt_queue queue; 81 pkt_queue queue;
65 82
66 crypto_ctx *octx, *ictx; 83 crypto_ctx *octx, *ictx;
67 84
69 86
70 void reset_dstaddr (); 87 void reset_dstaddr ();
71 88
72 void shutdown (); 89 void shutdown ();
73 void reset_connection (); 90 void reset_connection ();
74 void establish_connection (); 91 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
75 void rekey (); 92 void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing)
93 void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
76 94
77 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); 95 void send_auth (auth_subtype subtype, SOCKADDR *sa, const rsachallenge *k = 0);
78 void send_reset (SOCKADDR *dsa); 96 void send_reset (SOCKADDR *dsa);
79 void send_ping (SOCKADDR *dss, u8 pong = 0); 97 void send_ping (SOCKADDR *dss, u8 pong = 0);
80 void send_data_packet (tap_packet *pkt, bool broadcast = false); 98 void send_data_packet (tap_packet *pkt, bool broadcast = false);
81 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 99 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
82 void connect_request (int id); 100 void connect_request (int id);
83 101
84 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 102 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
85 103
86 void timer ();
87
88 connection(struct vpn *vpn_)
89 : vpn(vpn_)
90 {
91 octx = ictx = 0;
92 retry_cnt = 0;
93 connectmode = conf_node::C_ALWAYS; // initial setting
94 reset_connection ();
95 }
96
97 ~connection ()
98 {
99 shutdown ();
100 }
101
102 void script_node (); 104 void script_node ();
103 const char *script_node_up (); 105 const char *script_node_up ();
104 const char *script_node_down (); 106 const char *script_node_down ();
107
108 connection(struct vpn *vpn_);
109 ~connection ();
105 }; 110 };
106 111
107struct vpn 112struct vpn
108 { 113 {
109 int socket_fd; 114 int socket_fd;
110 int events; 115 int events;
111 116
112 tap_device *tap;
113
114 enum { 117 enum {
115 EVENT_RECONNECT = 1, 118 EVENT_RECONNECT = 1,
116 EVENT_SHUTDOWN = 2, 119 EVENT_SHUTDOWN = 2,
117 }; 120 };
121
122 void event_cb (tstamp &ts); time_watcher event;
123
124 tap_device *tap;
118 125
119 typedef vector<connection *> conns_vector; 126 typedef vector<connection *> conns_vector;
120 conns_vector conns; 127 conns_vector conns;
121 128
122 connection *find_router (); 129 connection *find_router ();
123 130
124 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa); 131 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
125 void reconnect_all (); 132 void reconnect_all ();
126 void shutdown_all (); 133 void shutdown_all ();
127 void connect_request (int id); 134 void connect_request (int id);
135
136 void vpn_ev (short revents); io_watcher vpn_ev_watcher;
137 void udp_ev (short revents); io_watcher udp_ev_watcher;
128 138
129 vpn (); 139 vpn ();
130 ~vpn (); 140 ~vpn ();
131 141
132 int setup (); 142 int setup ();
133 void main_loop ();
134 143
135 const char *script_if_up (); 144 const char *script_if_up ();
136 }; 145 };
137 146
138#endif 147#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines