--- gvpe/src/protocol.h 2003/03/22 22:36:25 1.7 +++ gvpe/src/protocol.h 2003/03/28 16:21:09 1.12 @@ -28,20 +28,26 @@ #include "conf.h" #include "iom.h" #include "util.h" +#include "sockinfo.h" #include "device.h" -/* Protocol version. Different versions are incompatible, - incompatible version have different protocols. +/* Protocol version. Different major versions are incompatible, + * different minor versions probably are compatible ;) */ -#define PROTOCOL_MAJOR 3 +#define PROTOCOL_MAJOR 0 #define PROTOCOL_MINOR 0 struct vpn; struct vpn_packet; -typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data +struct rsaid { + u8 id[RSA_IDLEN]; // the challenge id +}; + +typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data; typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge +typedef u8 rsaresponse[RSA_RESLEN]; // the encrypted ripemd160 hash struct crypto_ctx; @@ -60,17 +66,12 @@ ~pkt_queue (); }; -enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY }; - -struct auth_packet; - struct connection { conf_node *conf; struct vpn *vpn; - u32 seqrand; - SOCKADDR sa; + sockinfo si; // the current(!) destination ip to send packets to int retry_cnt; tstamp last_activity; // time of last packet received @@ -78,11 +79,14 @@ u32 oseqno; sliding_window iseqno; + u8 protocol; + pkt_queue queue; crypto_ctx *octx, *ictx; enum conf_node::connectmode connectmode; + u8 prot_minor; // minor number of other side void reset_dstaddr (); @@ -92,18 +96,23 @@ void rekey_cb (tstamp &ts); time_watcher rekey; // next rekying (actually current reset + reestablishing) void keepalive_cb (tstamp &ts); time_watcher keepalive; // next keepalive probe - void send_auth (auth_subtype subtype, SOCKADDR *sa, const rsachallenge *k = 0); - void send_reset (SOCKADDR *dsa); - void send_ping (SOCKADDR *dss, u8 pong = 0); + void send_auth_request (const sockinfo &si, bool initiate); + void send_auth_response (const sockinfo &si, const rsaid &id, const rsachallenge &chg); + void send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols); + void send_reset (const sockinfo &dsi); + void send_ping (const sockinfo &dsi, u8 pong = 0); void send_data_packet (tap_packet *pkt, bool broadcast = false); void inject_data_packet (tap_packet *pkt, bool broadcast = false); void connect_request (int id); - void recv_vpn_packet (vpn_packet *pkt, SOCKADDR *rsa); + void send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY); + void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); void script_node (); - const char *script_node_up (); - const char *script_node_down (); + const char *script_node_up (int); + const char *script_node_down (int); + + void dump_status (); connection(struct vpn *vpn_); ~connection (); @@ -111,7 +120,9 @@ struct vpn { - int socket_fd; + int udpv4_fd; + int ipv4_fd; + int events; enum { @@ -128,20 +139,27 @@ connection *find_router (); - void send_vpn_packet (vpn_packet *pkt, SOCKADDR *sa, int tos = IPTOS_RELIABILITY); void reconnect_all (); void shutdown_all (); void connect_request (int id); - void vpn_ev (short revents); io_watcher vpn_ev_watcher; - void udp_ev (short revents); io_watcher udp_ev_watcher; + void tap_ev (short revents); io_watcher tap_ev_watcher; + void ipv4_ev (short revents); io_watcher ipv4_ev_watcher; + void udpv4_ev (short revents); io_watcher udpv4_ev_watcher; + + void recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi); + + void send_udpv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY); + void send_ipv4_packet (vpn_packet *pkt, const sockinfo &si, int tos = IPTOS_RELIABILITY); vpn (); ~vpn (); int setup (); - const char *script_if_up (); + void dump_status (); + + const char *script_if_up (int); }; #endif