… | |
… | |
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; |
… | |
… | |
1344 | |
1352 | |
1345 | void connection::script_init_env (const char *ext) |
1353 | void 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 | |
1355 | void connection::script_init_connect_env () |
1363 | void 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 | |
1366 | inline const char * |
1375 | inline const char * |
1367 | connection::script_node_up () |
1376 | connection::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 | |
|
|
1391 | inline const char * |
|
|
1392 | connection::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 | |
1382 | inline const char * |
1407 | inline const char * |