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.12 by pcg, Fri Mar 28 16:21:09 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"
31#include "sockinfo.h"
29#include "device.h" 32#include "device.h"
30 33
31/* Protocol version. Different versions are incompatible, 34/* Protocol version. Different major versions are incompatible,
32 incompatible version have different protocols. 35 * different minor versions probably are compatible ;)
33 */ 36 */
34 37
35#define PROTOCOL_MAJOR 2 38#define PROTOCOL_MAJOR 0
36#define PROTOCOL_MINOR 0 39#define PROTOCOL_MINOR 0
37 40
38struct vpn; 41struct vpn;
39struct vpn_packet; 42struct vpn_packet;
40 43
44struct rsaid {
45 u8 id[RSA_IDLEN]; // the challenge id
46};
47
41typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data 48typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data;
42typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge 49typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge
50typedef u8 rsaresponse[RSA_RESLEN]; // the encrypted ripemd160 hash
43 51
44struct crypto_ctx; 52struct crypto_ctx;
45 53
46enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY }; 54// a very simple fifo pkt-queue
55class pkt_queue
56 {
57 tap_packet *queue[QUEUEDEPTH];
58 int i, j;
59
60 public:
61
62 void put (tap_packet *p);
63 tap_packet *get ();
64
65 pkt_queue ();
66 ~pkt_queue ();
67 };
47 68
48struct connection 69struct connection
49 { 70 {
50 conf_node *conf; 71 conf_node *conf;
51 struct vpn *vpn; 72 struct vpn *vpn;
52 73
53 SOCKADDR sa; 74 sockinfo si; // the current(!) destination ip to send packets to
54 int retry_cnt; 75 int retry_cnt;
55 76
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 77 tstamp last_activity; // time of last packet received
59 78
60 u32 oseqno; 79 u32 oseqno;
61 u32 iseqno; 80 sliding_window iseqno;
62 u32 ismask; // bitmask with set bits for each received seqno (input seen mask) 81
82 u8 protocol;
63 83
64 pkt_queue queue; 84 pkt_queue queue;
65 85
66 crypto_ctx *octx, *ictx; 86 crypto_ctx *octx, *ictx;
67 87
68 enum conf_node::connectmode connectmode; 88 enum conf_node::connectmode connectmode;
89 u8 prot_minor; // minor number of other side
69 90
70 void reset_dstaddr (); 91 void reset_dstaddr ();
71 92
72 void shutdown (); 93 void shutdown ();
73 void reset_connection (); 94 void reset_connection ();
74 void establish_connection (); 95 void establish_connection_cb (tstamp &ts); time_watcher establish_connection;
75 void rekey (); 96 void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing)
97 void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe
76 98
77 void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); 99 void send_auth_request (const sockinfo &si, bool initiate);
78 void send_reset (SOCKADDR *dsa); 100 void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg);
79 void send_ping (SOCKADDR *dss, u8 pong = 0); 101 void send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols);
102 void send_reset (const sockinfo &dsi);
103 void send_ping (const sockinfo &dsi, u8 pong = 0);
80 void send_data_packet (tap_packet *pkt, bool broadcast = false); 104 void send_data_packet (tap_packet *pkt, bool broadcast = false);
81 void inject_data_packet (tap_packet *pkt, bool broadcast = false); 105 void inject_data_packet (tap_packet *pkt, bool broadcast = false);
82 void connect_request (int id); 106 void connect_request (int id);
83 107
108 void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
84 void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); 109 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
85
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 110
102 void script_node (); 111 void script_node ();
103 const char *script_node_up (); 112 const char *script_node_up (int);
104 const char *script_node_down (); 113 const char *script_node_down (int);
114
115 void dump_status ();
116
117 connection(struct vpn *vpn_);
118 ~connection ();
105 }; 119 };
106 120
107struct vpn 121struct vpn
108 { 122 {
109 int socket_fd; 123 int udpv4_fd;
124 int ipv4_fd;
125
110 int events; 126 int events;
111
112 tap_device *tap;
113 127
114 enum { 128 enum {
115 EVENT_RECONNECT = 1, 129 EVENT_RECONNECT = 1,
116 EVENT_SHUTDOWN = 2, 130 EVENT_SHUTDOWN = 2,
117 }; 131 };
118 132
133 void event_cb (tstamp &ts); time_watcher event;
134
135 tap_device *tap;
136
119 typedef vector<connection *> conns_vector; 137 typedef vector<connection *> conns_vector;
120 conns_vector conns; 138 conns_vector conns;
121 139
122 connection *find_router (); 140 connection *find_router ();
123 141
124 void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa);
125 void reconnect_all (); 142 void reconnect_all ();
126 void shutdown_all (); 143 void shutdown_all ();
127 void connect_request (int id); 144 void connect_request (int id);
145
146 void tap_ev (short revents); io_watcher tap_ev_watcher;
147 void ipv4_ev (short revents); io_watcher ipv4_ev_watcher;
148 void udpv4_ev (short revents); io_watcher udpv4_ev_watcher;
149
150 void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi);
151
152 void send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
153 void send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY);
128 154
129 vpn (); 155 vpn ();
130 ~vpn (); 156 ~vpn ();
131 157
132 int setup (); 158 int setup ();
133 void main_loop ();
134 159
160 void dump_status ();
161
135 const char *script_if_up (); 162 const char *script_if_up (int);
136 }; 163 };
137 164
138#endif 165#endif
139 166

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines