… | |
… | |
91 | rsachallenge chg; |
91 | rsachallenge chg; |
92 | }; |
92 | }; |
93 | |
93 | |
94 | struct rsa_cache : list<rsa_entry> |
94 | struct rsa_cache : list<rsa_entry> |
95 | { |
95 | { |
96 | void cleaner_cb (ev::timer &w, int revents); ev::timer cleaner; |
96 | inline void cleaner_cb (ev::timer &w, int revents); ev::timer cleaner; |
97 | |
97 | |
98 | bool find (const rsaid &id, rsachallenge &chg) |
98 | bool find (const rsaid &id, rsachallenge &chg) |
99 | { |
99 | { |
100 | for (iterator i = begin (); i != end (); ++i) |
100 | for (iterator i = begin (); i != end (); ++i) |
101 | { |
101 | { |
… | |
… | |
130 | if (!cleaner.is_active ()) |
130 | if (!cleaner.is_active ()) |
131 | cleaner.again (); |
131 | cleaner.again (); |
132 | } |
132 | } |
133 | |
133 | |
134 | rsa_cache () |
134 | rsa_cache () |
135 | : cleaner (this, &rsa_cache::cleaner_cb) |
|
|
136 | { |
135 | { |
|
|
136 | cleaner.set<rsa_cache, &rsa_cache::cleaner_cb> (this); |
137 | cleaner.set (RSA_TTL, RSA_TTL); |
137 | cleaner.set (RSA_TTL, RSA_TTL); |
138 | } |
138 | } |
139 | |
139 | |
140 | } rsa_cache; |
140 | } rsa_cache; |
141 | |
141 | |
… | |
… | |
745 | send_vpn_packet (r, si); |
745 | send_vpn_packet (r, si); |
746 | |
746 | |
747 | delete r; |
747 | delete r; |
748 | } |
748 | } |
749 | |
749 | |
750 | void |
750 | inline void |
751 | connection::establish_connection_cb (ev::timer &w, int revents) |
751 | connection::establish_connection_cb (ev::timer &w, int revents) |
752 | { |
752 | { |
753 | if (!ictx |
753 | if (!ictx |
754 | && conf != THISNODE |
754 | && conf != THISNODE |
755 | && connectmode != conf_node::C_NEVER |
755 | && connectmode != conf_node::C_NEVER |
… | |
… | |
808 | conf->nodename, (const char *)si); |
808 | conf->nodename, (const char *)si); |
809 | |
809 | |
810 | if (::conf.script_node_down) |
810 | if (::conf.script_node_down) |
811 | { |
811 | { |
812 | run_script_cb cb; |
812 | run_script_cb cb; |
813 | callback_set (cb, this, connection, script_node_down); |
813 | cb.set<connection, &connection::script_node_down> (this); |
814 | if (!run_script (cb, false)) |
814 | if (!run_script (cb, false)) |
815 | slog (L_WARN, _("node-down command execution failed, continuing.")); |
815 | slog (L_WARN, _("node-down command execution failed, continuing.")); |
816 | } |
816 | } |
817 | } |
817 | } |
818 | |
818 | |
… | |
… | |
839 | send_reset (si); |
839 | send_reset (si); |
840 | |
840 | |
841 | reset_connection (); |
841 | reset_connection (); |
842 | } |
842 | } |
843 | |
843 | |
844 | void |
844 | inline void |
845 | connection::rekey_cb (ev::timer &w, int revents) |
845 | connection::rekey_cb (ev::timer &w, int revents) |
846 | { |
846 | { |
847 | reset_connection (); |
847 | reset_connection (); |
848 | establish_connection (); |
848 | establish_connection (); |
849 | } |
849 | } |
… | |
… | |
1047 | p->prot_major, p->prot_minor); |
1047 | p->prot_major, p->prot_minor); |
1048 | |
1048 | |
1049 | if (::conf.script_node_up) |
1049 | if (::conf.script_node_up) |
1050 | { |
1050 | { |
1051 | run_script_cb cb; |
1051 | run_script_cb cb; |
1052 | callback_set (cb, this, connection, script_node_up); |
1052 | cb.set<connection, &connection::script_node_up> (this); |
1053 | if (!run_script (cb, false)) |
1053 | if (!run_script (cb, false)) |
1054 | slog (L_WARN, _("node-up command execution failed, continuing.")); |
1054 | slog (L_WARN, _("node-up command execution failed, continuing.")); |
1055 | } |
1055 | } |
1056 | |
1056 | |
1057 | break; |
1057 | break; |
… | |
… | |
1176 | send_reset (rsi); |
1176 | send_reset (rsi); |
1177 | break; |
1177 | break; |
1178 | } |
1178 | } |
1179 | } |
1179 | } |
1180 | |
1180 | |
|
|
1181 | inline void |
1181 | void connection::keepalive_cb (ev::timer &w, int revents) |
1182 | connection::keepalive_cb (ev::timer &w, int revents) |
1182 | { |
1183 | { |
1183 | if (ev_now () >= last_activity + ::conf.keepalive + 30) |
1184 | if (ev_now () >= last_activity + ::conf.keepalive + 30) |
1184 | { |
1185 | { |
1185 | reset_connection (); |
1186 | reset_connection (); |
1186 | establish_connection (); |
1187 | establish_connection (); |
… | |
… | |
1231 | asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); |
1232 | asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); |
1232 | asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); |
1233 | asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); |
1233 | asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); |
1234 | asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); |
1234 | } |
1235 | } |
1235 | |
1236 | |
|
|
1237 | inline const char * |
1236 | const char *connection::script_node_up () |
1238 | connection::script_node_up () |
1237 | { |
1239 | { |
1238 | script_init_connect_env (); |
1240 | script_init_connect_env (); |
1239 | |
1241 | |
1240 | putenv ((char *)"STATE=up"); |
1242 | putenv ((char *)"STATE=up"); |
1241 | |
1243 | |
… | |
… | |
1246 | ::conf.script_node_up ? ::conf.script_node_up : "node-up"); |
1248 | ::conf.script_node_up ? ::conf.script_node_up : "node-up"); |
1247 | |
1249 | |
1248 | return filename; |
1250 | return filename; |
1249 | } |
1251 | } |
1250 | |
1252 | |
|
|
1253 | inline const char * |
1251 | const char *connection::script_node_down () |
1254 | connection::script_node_down () |
1252 | { |
1255 | { |
1253 | script_init_connect_env (); |
1256 | script_init_connect_env (); |
1254 | |
1257 | |
1255 | putenv ((char *)"STATE=down"); |
1258 | putenv ((char *)"STATE=down"); |
1256 | |
1259 | |
… | |
… | |
1263 | return filename; |
1266 | return filename; |
1264 | } |
1267 | } |
1265 | |
1268 | |
1266 | connection::connection (struct vpn *vpn, conf_node *conf) |
1269 | connection::connection (struct vpn *vpn, conf_node *conf) |
1267 | : vpn(vpn), conf(conf) |
1270 | : vpn(vpn), conf(conf) |
1268 | , rekey (this, &connection::rekey_cb) |
|
|
1269 | , keepalive (this, &connection::keepalive_cb) |
|
|
1270 | , establish_connection (this, &connection::establish_connection_cb) |
|
|
1271 | #if ENABLE_DNS |
1271 | #if ENABLE_DNS |
1272 | , dns (0) |
1272 | , dns (0) |
1273 | #endif |
1273 | #endif |
1274 | { |
1274 | { |
|
|
1275 | rekey .set<connection, &connection::rekey_cb > (this); |
|
|
1276 | keepalive .set<connection, &connection::keepalive_cb > (this); |
|
|
1277 | establish_connection.set<connection, &connection::establish_connection_cb> (this); |
|
|
1278 | |
1275 | octx = ictx = 0; |
1279 | octx = ictx = 0; |
1276 | retry_cnt = 0; |
1280 | retry_cnt = 0; |
1277 | |
1281 | |
1278 | if (!conf->protocols) // make sure some protocol is enabled |
1282 | if (!conf->protocols) // make sure some protocol is enabled |
1279 | conf->protocols = PROT_UDPv4; |
1283 | conf->protocols = PROT_UDPv4; |