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.1 by pcg, Sat Mar 1 15:53:03 2003 UTC vs.
Revision 1.8 by pcg, Wed Mar 26 01:58:46 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 1
36#define PROTOCOL_MINOR 0 38#define PROTOCOL_MINOR 0
37 39
38struct vpn; 40struct vpn;
39struct vpn_packet; 41struct vpn_packet;
40 42
43struct rsaid {
44 u8 id[RSA_IDLEN]; // the challenge id
45};
46
41typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data 47typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data;
42typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge 48typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
49typedef u8 rsaresponse[RSA_HASHLEN]; // the ripemd160(!) hash of the challenge
43 50
44struct crypto_ctx; 51struct crypto_ctx;
45 52
46enum 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 };
47 67
48struct connection 68struct connection
49 { 69 {
50 conf_node *conf; 70 conf_node *conf;
51 struct vpn *vpn; 71 struct vpn *vpn;
52 72
53 SOCKADDR sa; 73 SOCKADDR sa; // the current(!) destination ip to send packets to
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
85 enum conf_node::connectmode connectmode;
86
68 void reset_dstaddr (); 87 void reset_dstaddr ();
69 88
70 void shutdown (); 89 void shutdown ();
71 void reset_connection (); 90 void reset_connection ();
72 void establish_connection (); 91 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
73 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
74 94
75 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);
76 void send_reset (SOCKADDR *dsa); 97 void send_reset (SOCKADDR *dsa);
77 void send_ping (SOCKADDR *dss, u8 pong = 0); 98 void send_ping (SOCKADDR *dss, u8 pong = 0);
78 void send_data_packet (tap_packet *pkt, bool broadcast = false); 99 void send_data_packet (tap_packet *pkt, bool broadcast = false);
79 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 100 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
80 void connect_request (int id); 101 void connect_request (int id);
81 102
82 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 103 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa);
83 104
84 void timer (); 105 void script_node ();
106 const char *script_node_up (int);
107 const char *script_node_down (int);
85 108
86 connection(struct vpn *vpn_) 109 connection(struct vpn *vpn_);
87 : vpn(vpn_)
88 {
89 octx = ictx = 0;
90 retry_cnt = 0;
91 reset_connection ();
92 }
93
94 ~connection () 110 ~connection ();
95 {
96 shutdown ();
97 }
98
99 void script_node ();
100 const char *script_node_up ();
101 const char *script_node_down ();
102 }; 111 };
103 112
104struct vpn 113struct vpn
105 { 114 {
106 int socket_fd; 115 int socket_fd;
107 int events; 116 int events;
108 117
109 tap_device *tap;
110
111 enum { 118 enum {
112 EVENT_RECONNECT = 1, 119 EVENT_RECONNECT = 1,
113 EVENT_SHUTDOWN = 2, 120 EVENT_SHUTDOWN = 2,
114 }; 121 };
122
123 void event_cb (tstamp &ts); time_watcher event;
124
125 tap_device *tap;
115 126
116 typedef vector<connection *> conns_vector; 127 typedef vector<connection *> conns_vector;
117 conns_vector conns; 128 conns_vector conns;
118 129
119 connection *find_router (); 130 connection *find_router ();
120 131
121 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa); 132 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY);
122 void reconnect_all (); 133 void reconnect_all ();
123 void shutdown_all (); 134 void shutdown_all ();
124 void connect_request (int id); 135 void connect_request (int id);
136
137 void vpn_ev (short revents); io_watcher vpn_ev_watcher;
138 void udp_ev (short revents); io_watcher udp_ev_watcher;
125 139
126 vpn (); 140 vpn ();
127 ~vpn (); 141 ~vpn ();
128 142
129 int setup (); 143 int setup ();
130 void main_loop ();
131 144
132 const char *script_if_up (); 145 const char *script_if_up (int);
133 }; 146 };
134 147
135#endif 148#endif
136 149

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines