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.9 by pcg, Wed Mar 26 14:39:52 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 major versions are incompatible,
33 incompatible version have different protocols. 34 * different minor versions probably are compatible ;)
34 */ 35 */
35 36
36#define PROTOCOL_MAJOR 2 37#define PROTOCOL_MAJOR 0
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_RESLEN]; // the encrypted ripemd160 hash
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
69 enum conf_node::connectmode connectmode; 85 enum conf_node::connectmode connectmode;
86 u8 prot_minor; // minor number of other side
70 87
71 void reset_dstaddr (); 88 void reset_dstaddr ();
72 89
73 void shutdown (); 90 void shutdown ();
74 void reset_connection (); 91 void reset_connection ();
75 void establish_connection (); 92 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
76 void rekey (); 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
77 95
78 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); 96 void send_auth_request (SOCKADDR *sa, bool initiate);
97 void send_auth_response (SOCKADDR *sa, const rsaid &id, const rsachallenge &chg);
79 void send_reset (SOCKADDR *dsa); 98 void send_reset (SOCKADDR *dsa);
80 void send_ping (SOCKADDR *dss, u8 pong = 0); 99 void send_ping (SOCKADDR *dss, u8 pong = 0);
81 void send_data_packet (tap_packet *pkt, bool broadcast = false); 100 void send_data_packet (tap_packet *pkt, bool broadcast = false);
82 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 101 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
83 void connect_request (int id); 102 void connect_request (int id);
84 103
85 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 104 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
86 105
87 void timer (); 106 void script_node ();
107 const char *script_node_up (int);
108 const char *script_node_down (int);
88 109
89 connection(struct vpn *vpn_) 110 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 () 111 ~connection ();
99 {
100 shutdown ();
101 }
102
103 void script_node ();
104 const char *script_node_up ();
105 const char *script_node_down ();
106 }; 112 };
107 113
108struct vpn 114struct vpn
109 { 115 {
110 int socket_fd; 116 int socket_fd;
111 int events; 117 int events;
112 118
113 tap_device *tap;
114
115 enum { 119 enum {
116 EVENT_RECONNECT = 1, 120 EVENT_RECONNECT = 1,
117 EVENT_SHUTDOWN = 2, 121 EVENT_SHUTDOWN = 2,
118 }; 122 };
123
124 void event_cb (tstamp &ts); time_watcher event;
125
126 tap_device *tap;
119 127
120 typedef vector<connection *> conns_vector; 128 typedef vector<connection *> conns_vector;
121 conns_vector conns; 129 conns_vector conns;
122 130
123 connection *find_router (); 131 connection *find_router ();
125 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY); 133 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
126 void reconnect_all (); 134 void reconnect_all ();
127 void shutdown_all (); 135 void shutdown_all ();
128 void connect_request (int id); 136 void connect_request (int id);
129 137
138 void vpn_ev (short revents); io_watcher vpn_ev_watcher;
139 void udp_ev (short revents); io_watcher udp_ev_watcher;
140
130 vpn (); 141 vpn ();
131 ~vpn (); 142 ~vpn ();
132 143
133 int setup (); 144 int setup ();
134 void main_loop ();
135 145
136 const char *script_if_up (); 146 const char *script_if_up (int);
137 }; 147 };
138 148
139#endif 149#endif
140 150

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines