--- gvpe/src/protocol.h 2003/03/09 12:40:18 1.3 +++ gvpe/src/protocol.h 2003/04/02 03:06:22 1.13 @@ -20,120 +20,59 @@ #define VPE_PROTOCOL_H__ #include -#include // for tos etc. #include #include #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. - */ - -#define PROTOCOL_MAJOR 2 -#define PROTOCOL_MINOR 0 - -struct vpn; -struct vpn_packet; - -typedef u8 rsachallenge[RSA_KEYLEN - RSA_OVERHEAD]; // challenge data -typedef u8 rsaencrdata[RSA_KEYLEN]; // encrypted challenge - -struct crypto_ctx; - -enum auth_subtype { AUTH_INIT, AUTH_INITREPLY, AUTH_REPLY }; - -struct connection - { - conf_node *conf; - struct vpn *vpn; - - SOCKADDR sa; - int retry_cnt; - - time_t next_retry; // next connection retry - time_t next_rekey; // next rekying (actually current reset + reestablishing) - time_t last_activity; // time of last packet received - - u32 oseqno; - u32 iseqno; - u32 ismask; // bitmask with set bits for each received seqno (input seen mask) - - pkt_queue queue; - - crypto_ctx *octx, *ictx; - - enum conf_node::connectmode connectmode; - - void reset_dstaddr (); - - void shutdown (); - void reset_connection (); - void establish_connection (); - void rekey (); - - void send_auth (auth_subtype subtype, SOCKADDR *sa, rsachallenge *k = 0); - void send_reset (SOCKADDR *dsa); - void send_ping (SOCKADDR *dss, 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 timer (); - - connection(struct vpn *vpn_) - : vpn(vpn_) - { - octx = ictx = 0; - retry_cnt = 0; - connectmode = conf_node::C_ALWAYS; // initial setting - reset_connection (); - } - - ~connection () - { - shutdown (); - } - - void script_node (); - const char *script_node_up (); - const char *script_node_down (); - }; +#include "connection.h" struct vpn { - int socket_fd; - int events; + int udpv4_fd; + int ipv4_fd; - tap_device *tap; + int events; enum { EVENT_RECONNECT = 1, EVENT_SHUTDOWN = 2, }; + void event_cb (tstamp &ts); time_watcher event; + + tap_device *tap; + typedef vector conns_vector; conns_vector conns; 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 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 (); - void main_loop (); - const char *script_if_up (); + void dump_status (); + + const char *script_if_up (int); }; #endif