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.3 by pcg, Sun Mar 9 12:40:18 2003 UTC vs.
Revision 1.8 by pcg, Wed Mar 26 01:58:46 2003 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines