ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.C
(Generate patch)

Comparing gvpe/src/connection.C (file contents):
Revision 1.81 by pcg, Fri Aug 15 18:31:13 2008 UTC vs.
Revision 1.84 by pcg, Sat Jul 18 05:59:16 2009 UTC

1148 si = rsi; 1148 si = rsi;
1149 protocol = rsi.prot; 1149 protocol = rsi.prot;
1150 1150
1151 slog (L_INFO, _("%s(%s): connection established (%s), protocol version %d.%d."), 1151 slog (L_INFO, _("%s(%s): connection established (%s), protocol version %d.%d."),
1152 conf->nodename, (const char *)rsi, 1152 conf->nodename, (const char *)rsi,
1153 is_direct ? "direct" : "routed", 1153 is_direct ? "direct" : "forwarded",
1154 p->prot_major, p->prot_minor); 1154 p->prot_major, p->prot_minor);
1155 1155
1156 connection_established (); 1156 connection_established ();
1157 1157
1158 if (::conf.script_node_up) 1158 if (::conf.script_node_up)
1210 // { 1210 // {
1211 slog (L_INFO, _("%s(%s): changing socket address to %s."), 1211 slog (L_INFO, _("%s(%s): changing socket address to %s."),
1212 conf->nodename, (const char *)si, (const char *)rsi); 1212 conf->nodename, (const char *)si, (const char *)rsi);
1213 1213
1214 si = rsi; 1214 si = rsi;
1215
1216 if (::conf.script_node_change)
1217 {
1218 run_script_cb *cb = new run_script_cb;
1219 cb->set<connection, &connection::script_node_change> (this);
1220 run_script_queued (cb, _("node-change command execution failed, continuing."));
1221 }
1222
1215 // } 1223 // }
1216 //else 1224 //else
1217 // slog (L_INFO, _("%s(%s): accepted packet from %s, not (yet) redirecting traffic."), 1225 // slog (L_INFO, _("%s(%s): accepted packet from %s, not (yet) redirecting traffic."),
1218 // conf->nodename, (const char *)si, (const char *)rsi); 1226 // conf->nodename, (const char *)si, (const char *)rsi);
1219 } 1227 }
1240 break; 1248 break;
1241 1249
1242 case vpn_packet::PT_CONNECT_REQ: 1250 case vpn_packet::PT_CONNECT_REQ:
1243 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx)) 1251 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx))
1244 { 1252 {
1245 connect_req_packet *p = (connect_req_packet *) pkt; 1253 connect_req_packet *p = (connect_req_packet *)pkt;
1246 1254
1247 if (p->id > 0 && p->id <= vpn->conns.size ()) 1255 if (p->id > 0 && p->id <= vpn->conns.size ())
1248 { 1256 {
1249 connection *c = vpn->conns[p->id - 1]; 1257 connection *c = vpn->conns[p->id - 1];
1250 conf->protocols = p->protocols; 1258 conf->protocols = p->protocols;
1307} 1315}
1308 1316
1309inline void 1317inline void
1310connection::keepalive_cb (ev::timer &w, int revents) 1318connection::keepalive_cb (ev::timer &w, int revents)
1311{ 1319{
1312 if (ev_now () >= last_activity + ::conf.keepalive + 30) 1320 if (ev_now () >= last_activity + ::conf.keepalive + 15)
1313 { 1321 {
1314 reset_connection (); 1322 reset_connection ();
1315 establish_connection (); 1323 establish_connection ();
1316 } 1324 }
1317 else if (ev_now () < last_activity + ::conf.keepalive) 1325 else if (ev_now () < last_activity + ::conf.keepalive)
1318 w.start (last_activity + ::conf.keepalive - ev::now ()); 1326 w.start (last_activity + ::conf.keepalive - ev::now ());
1319 else if (conf->connectmode != conf_node::C_ONDEMAND 1327 else if (conf->connectmode != conf_node::C_ONDEMAND
1320 || THISNODE->connectmode != conf_node::C_ONDEMAND) 1328 || THISNODE->connectmode != conf_node::C_ONDEMAND)
1321 { 1329 {
1322 send_ping (si); 1330 send_ping (si);
1323 w.start (5); 1331 w.start (3);
1324 } 1332 }
1325 else if (ev_now () < last_activity + ::conf.keepalive + 10) 1333 else if (ev_now () < last_activity + ::conf.keepalive + 10)
1326 // hold ondemand connections implicitly a few seconds longer 1334 // hold ondemand connections implicitly a few seconds longer
1327 // should delete octx, though, or something like that ;) 1335 // should delete octx, though, or something like that ;)
1328 w.start (last_activity + ::conf.keepalive + 10 - ev::now ()); 1336 w.start (last_activity + ::conf.keepalive + 10 - ev::now ());
1344 1352
1345void connection::script_init_env (const char *ext) 1353void connection::script_init_env (const char *ext)
1346{ 1354{
1347 char *env; 1355 char *env;
1348 asprintf (&env, "IFUPDATA%s=%s", ext, conf->if_up_data); putenv (env); 1356 asprintf (&env, "IFUPDATA%s=%s", ext, conf->if_up_data); putenv (env);
1349 asprintf (&env, "NODENAME%s=%s", ext, conf->nodename); putenv (env); 1357 asprintf (&env, "NODENAME%s=%s", ext, conf->nodename); putenv (env);
1350 asprintf (&env, "MAC%s=%02x:%02x:%02x:%02x:%02x:%02x", ext, 1358 asprintf (&env, "MAC%s=%02x:%02x:%02x:%02x:%02x:%02x", ext,
1351 0xfe, 0xfd, 0x80, 0x00, conf->id >> 8, 1359 0xfe, 0xfd, 0x80, 0x00, conf->id >> 8,
1352 conf->id & 0xff); putenv (env); 1360 conf->id & 0xff); putenv (env);
1353} 1361}
1354 1362
1355void connection::script_init_connect_env () 1363void connection::script_init_connect_env ()
1356{ 1364{
1357 vpn->script_init_env (); 1365 vpn->script_init_env ();
1358 1366
1359 char *env; 1367 char *env;
1360 asprintf (&env, "DESTID=%d", conf->id); putenv (env); 1368 asprintf (&env, "DESTID=%d", conf->id); putenv (env);
1369 asprintf (&env, "DESTSI=%s", (const char *)si); putenv (env);
1361 asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); 1370 asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env);
1362 asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); 1371 asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env);
1363 asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); 1372 asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env);
1364} 1373}
1365 1374
1366inline const char * 1375inline const char *
1367connection::script_node_up () 1376connection::script_node_up ()
1368{ 1377{
1373 char *filename; 1382 char *filename;
1374 asprintf (&filename, 1383 asprintf (&filename,
1375 "%s/%s", 1384 "%s/%s",
1376 confbase, 1385 confbase,
1377 ::conf.script_node_up ? ::conf.script_node_up : "node-up"); 1386 ::conf.script_node_up ? ::conf.script_node_up : "node-up");
1387
1388 return filename;
1389}
1390
1391inline const char *
1392connection::script_node_change ()
1393{
1394 script_init_connect_env ();
1395
1396 putenv ((char *)"STATE=change");
1397
1398 char *filename;
1399 asprintf (&filename,
1400 "%s/%s",
1401 confbase,
1402 ::conf.script_node_change ? ::conf.script_node_change : "node-change");
1378 1403
1379 return filename; 1404 return filename;
1380} 1405}
1381 1406
1382inline const char * 1407inline const char *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines