--- gvpe/src/connection.C 2008/08/15 18:35:24 1.82 +++ gvpe/src/connection.C 2010/12/02 07:15:14 1.88 @@ -1,6 +1,6 @@ /* connection.C -- manage a single connection - Copyright (C) 2003-2008 Marc Lehmann + Copyright (C) 2003-2008,2010 Marc Lehmann This file is part of GVPE. @@ -52,7 +52,8 @@ # define RAND_pseudo_bytes RAND_bytes #endif -#define MAGIC "vped\xbd\xc6\xdb\x82" // 8 bytes of magic +#define MAGIC_OLD "vped\xbd\xc6\xdb\x82" // 8 bytes of magic (still used in the protocol) +#define MAGIC "gvpe\xbd\xc6\xdb\x82" // 8 bytes of magic (understood but not generated) #define ULTRA_FAST 1 #define HLOG 15 @@ -426,7 +427,7 @@ #if ENABLE_COMPRESSION u8 cdata[MAX_MTU]; - if (conn->features & ENABLE_COMPRESSION) + if (conn->features & FEATURE_COMPRESSION) { u32 cl = lzf_compress (d, l, cdata + 2, (l - 2) & ~7); @@ -615,7 +616,7 @@ auth_req_packet (int dst, bool initiate_, u8 protocols_) { config_packet::setup (PT_AUTH_REQ, dst); - strncpy (magic, MAGIC, 8); + strncpy (magic, MAGIC_OLD, 8); initiate = !!initiate_; protocols = protocols_; @@ -1015,7 +1016,7 @@ // we send pings instead of auth packets after some retries, // so reset the retry counter and establish a connection // when we receive a ping. - if (!ictx) + if (!(ictx && octx)) { if (auth_rate_limiter.can (rsi)) send_auth_request (rsi, true); @@ -1055,7 +1056,8 @@ slog (L_TRACE, "%s >> PT_AUTH_REQ(%s)", conf->nodename, p->initiate ? "initiate" : "reply"); - if (p->chk_config () && !strncmp (p->magic, MAGIC, 8)) + if (p->chk_config () + && (!strncmp (p->magic, MAGIC_OLD, 8) || !strncmp (p->magic, MAGIC, 8))) { if (p->prot_minor != PROTOCOL_MINOR) slog (L_INFO, _("%s(%s): protocol minor version mismatch: ours is %d, %s's is %d."), @@ -1212,6 +1214,14 @@ conf->nodename, (const char *)si, (const char *)rsi); si = rsi; + + if (::conf.script_node_change) + { + run_script_cb *cb = new run_script_cb; + cb->set (this); + run_script_queued (cb, _("node-change command execution failed, continuing.")); + } + // } //else // slog (L_INFO, _("%s(%s): accepted packet from %s, not (yet) redirecting traffic."), @@ -1242,7 +1252,7 @@ case vpn_packet::PT_CONNECT_REQ: if (ictx && octx && rsi == si && pkt->hmac_chk (ictx)) { - connect_req_packet *p = (connect_req_packet *) pkt; + connect_req_packet *p = (connect_req_packet *)pkt; if (p->id > 0 && p->id <= vpn->conns.size ()) { @@ -1309,7 +1319,7 @@ inline void connection::keepalive_cb (ev::timer &w, int revents) { - if (ev_now () >= last_activity + ::conf.keepalive + 30) + if (ev_now () >= last_activity + ::conf.keepalive + 15) { reset_connection (); establish_connection (); @@ -1320,7 +1330,7 @@ || THISNODE->connectmode != conf_node::C_ONDEMAND) { send_ping (si); - w.start (5); + w.start (3); } else if (ev_now () < last_activity + ::conf.keepalive + 10) // hold ondemand connections implicitly a few seconds longer @@ -1346,10 +1356,10 @@ { char *env; asprintf (&env, "IFUPDATA%s=%s", ext, conf->if_up_data); putenv (env); - asprintf (&env, "NODENAME%s=%s", ext, conf->nodename); putenv (env); + asprintf (&env, "NODENAME%s=%s", ext, conf->nodename); putenv (env); asprintf (&env, "MAC%s=%02x:%02x:%02x:%02x:%02x:%02x", ext, 0xfe, 0xfd, 0x80, 0x00, conf->id >> 8, - conf->id & 0xff); putenv (env); + conf->id & 0xff); putenv (env); } void connection::script_init_connect_env () @@ -1357,10 +1367,11 @@ vpn->script_init_env (); char *env; - asprintf (&env, "DESTID=%d", conf->id); putenv (env); - asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); - asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); - asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); + asprintf (&env, "DESTID=%d", conf->id); putenv (env); + asprintf (&env, "DESTSI=%s", (const char *)si); putenv (env); + asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); + asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); + asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); } inline const char * @@ -1378,6 +1389,22 @@ return filename; } + +inline const char * +connection::script_node_change () +{ + script_init_connect_env (); + + putenv ((char *)"STATE=change"); + + char *filename; + asprintf (&filename, + "%s/%s", + confbase, + ::conf.script_node_change ? ::conf.script_node_change : "node-change"); + + return filename; +} inline const char * connection::script_node_down ()