… | |
… | |
786 | { |
786 | { |
787 | slog (L_INFO, _("%s(%s): connection lost"), |
787 | slog (L_INFO, _("%s(%s): connection lost"), |
788 | conf->nodename, (const char *)si); |
788 | conf->nodename, (const char *)si); |
789 | |
789 | |
790 | if (::conf.script_node_down) |
790 | if (::conf.script_node_down) |
791 | run_script (run_script_cb (this, &connection::script_node_down), false); |
791 | if (!run_script (run_script_cb (this, &connection::script_node_down), false)) |
|
|
792 | slog (L_WARN, _("node-down command execution failed, continuing.")); |
792 | } |
793 | } |
793 | |
794 | |
794 | delete ictx; ictx = 0; |
795 | delete ictx; ictx = 0; |
795 | delete octx; octx = 0; |
796 | delete octx; octx = 0; |
796 | #if ENABLE_DNS |
797 | #if ENABLE_DNS |
… | |
… | |
1017 | slog (L_INFO, _("%s(%s): connection established, protocol version %d.%d"), |
1018 | slog (L_INFO, _("%s(%s): connection established, protocol version %d.%d"), |
1018 | conf->nodename, (const char *)rsi, |
1019 | conf->nodename, (const char *)rsi, |
1019 | p->prot_major, p->prot_minor); |
1020 | p->prot_major, p->prot_minor); |
1020 | |
1021 | |
1021 | if (::conf.script_node_up) |
1022 | if (::conf.script_node_up) |
1022 | run_script (run_script_cb (this, &connection::script_node_up), false); |
1023 | if (!run_script (run_script_cb (this, &connection::script_node_up), false)) |
|
|
1024 | slog (L_WARN, _("node-up command execution failed, continuing.")); |
1023 | |
1025 | |
1024 | break; |
1026 | break; |
1025 | } |
1027 | } |
1026 | else |
1028 | else |
1027 | slog (L_ERR, _("%s(%s): sent and received challenge do not match"), |
1029 | slog (L_ERR, _("%s(%s): sent and received challenge do not match"), |
… | |
… | |
1167 | send_vpn_packet (p, si); |
1169 | send_vpn_packet (p, si); |
1168 | |
1170 | |
1169 | delete p; |
1171 | delete p; |
1170 | } |
1172 | } |
1171 | |
1173 | |
1172 | void connection::script_node () |
1174 | void connection::script_init_env () |
1173 | { |
1175 | { |
1174 | vpn->script_if_up (); |
1176 | vpn->script_init_env (); |
1175 | |
1177 | |
1176 | char *env; |
1178 | char *env; |
1177 | asprintf (&env, "DESTID=%d", conf->id); putenv (env); |
1179 | asprintf (&env, "DESTID=%d", conf->id); putenv (env); |
1178 | asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); |
1180 | asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); |
1179 | asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); |
1181 | asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); |
1180 | asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); |
1182 | asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); |
1181 | } |
1183 | } |
1182 | |
1184 | |
1183 | const char *connection::script_node_up () |
1185 | const char *connection::script_node_up () |
1184 | { |
1186 | { |
1185 | script_node (); |
1187 | script_init_env (); |
1186 | |
1188 | |
1187 | putenv ("STATE=up"); |
1189 | putenv ("STATE=up"); |
1188 | |
1190 | |
|
|
1191 | char *filename; |
|
|
1192 | asprintf (&filename, |
|
|
1193 | "%s/%s", |
|
|
1194 | confbase, |
1189 | return ::conf.script_node_up ? ::conf.script_node_up : "node-up"; |
1195 | ::conf.script_node_up ? ::conf.script_node_up : "node-up"); |
1190 | } |
1196 | } |
1191 | |
1197 | |
1192 | const char *connection::script_node_down () |
1198 | const char *connection::script_node_down () |
1193 | { |
1199 | { |
1194 | script_node (); |
1200 | script_init_env (); |
1195 | |
1201 | |
1196 | putenv ("STATE=down"); |
1202 | putenv ("STATE=down"); |
1197 | |
1203 | |
1198 | return ::conf.script_node_up ? ::conf.script_node_down : "node-down"; |
1204 | char *filename; |
|
|
1205 | asprintf (&filename, |
|
|
1206 | "%s/%s", |
|
|
1207 | confbase, |
|
|
1208 | ::conf.script_node_down ? ::conf.script_node_down : "node-down"); |
1199 | } |
1209 | } |
1200 | |
1210 | |
1201 | connection::connection (struct vpn *vpn, conf_node *conf) |
1211 | connection::connection (struct vpn *vpn, conf_node *conf) |
1202 | : vpn(vpn), conf(conf) |
1212 | : vpn(vpn), conf(conf) |
1203 | , rekey (this, &connection::rekey_cb) |
1213 | , rekey (this, &connection::rekey_cb) |