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.50 by pcg, Fri Mar 18 01:53:05 2005 UTC vs.
Revision 1.55 by pcg, Tue Apr 26 00:55:56 2005 UTC

14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 15 GNU General Public License for more details.
16 16
17 You should have received a copy of the GNU General Public License 17 You should have received a copy of the GNU General Public License
18 along with gvpe; if not, write to the Free Software 18 along with gvpe; if not, write to the Free Software
19 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/ 20*/
21 21
22#include "config.h" 22#include "config.h"
23 23
24#include <cassert> 24#include <cassert>
95struct rsa_cache : list<rsa_entry> 95struct rsa_cache : list<rsa_entry>
96{ 96{
97 void cleaner_cb (time_watcher &w); time_watcher cleaner; 97 void cleaner_cb (time_watcher &w); time_watcher cleaner;
98 98
99 bool find (const rsaid &id, rsachallenge &chg) 99 bool find (const rsaid &id, rsachallenge &chg)
100 { 100 {
101 for (iterator i = begin (); i != end (); ++i) 101 for (iterator i = begin (); i != end (); ++i)
102 { 102 {
103 if (!memcmp (&id, &i->id, sizeof id) && i->expire > NOW) 103 if (!memcmp (&id, &i->id, sizeof id) && i->expire > NOW)
104 { 104 {
105 memcpy (&chg, &i->chg, sizeof chg); 105 memcpy (&chg, &i->chg, sizeof chg);
106 106
107 erase (i); 107 erase (i);
108 return true; 108 return true;
109 } 109 }
110 } 110 }
111 111
112 if (cleaner.at < NOW) 112 if (cleaner.at < NOW)
113 cleaner.start (NOW + RSA_TTL); 113 cleaner.start (NOW + RSA_TTL);
114 114
115 return false; 115 return false;
116 } 116 }
117 117
118 void gen (rsaid &id, rsachallenge &chg) 118 void gen (rsaid &id, rsachallenge &chg)
119 { 119 {
120 rsa_entry e; 120 rsa_entry e;
121 121
122 RAND_bytes ((unsigned char *)&id, sizeof id); 122 RAND_bytes ((unsigned char *)&id, sizeof id);
123 RAND_bytes ((unsigned char *)&chg, sizeof chg); 123 RAND_bytes ((unsigned char *)&chg, sizeof chg);
124 124
125 e.expire = NOW + RSA_TTL; 125 e.expire = NOW + RSA_TTL;
126 e.id = id; 126 e.id = id;
127 memcpy (&e.chg, &chg, sizeof chg); 127 memcpy (&e.chg, &chg, sizeof chg);
128 128
129 push_back (e); 129 push_back (e);
130 130
131 if (cleaner.at < NOW) 131 if (cleaner.at < NOW)
132 cleaner.start (NOW + RSA_TTL); 132 cleaner.start (NOW + RSA_TTL);
133 } 133 }
134 134
135 rsa_cache () 135 rsa_cache ()
136 : cleaner (this, &rsa_cache::cleaner_cb) 136 : cleaner (this, &rsa_cache::cleaner_cb)
137 { } 137 { }
138 138
139} rsa_cache; 139} rsa_cache;
140 140
141void rsa_cache::cleaner_cb (time_watcher &w) 141void rsa_cache::cleaner_cb (time_watcher &w)
142{ 142{
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
1174void connection::script_init_env (const char *ext)
1175{
1176 char *env;
1177 asprintf (&env, "IFUPDATA%s=%s", ext, conf->if_up_data); putenv (env);
1178 asprintf (&env, "NODENAME%s=%s", ext, conf->nodename); putenv (env);
1179 asprintf (&env, "MAC%s=%02x:%02x:%02x:%02x:%02x:%02x", ext,
1180 0xfe, 0xfd, 0x80, 0x00, conf->id >> 8,
1181 conf->id & 0xff); putenv (env);
1182}
1183
1172void connection::script_node () 1184void connection::script_init_connect_env ()
1173{ 1185{
1174 vpn->script_if_up (); 1186 vpn->script_init_env ();
1175 1187
1176 char *env; 1188 char *env;
1177 asprintf (&env, "DESTID=%d", conf->id); putenv (env); 1189 asprintf (&env, "DESTID=%d", conf->id); putenv (env);
1178 asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env); 1190 asprintf (&env, "DESTNODE=%s", conf->nodename); putenv (env);
1179 asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env); 1191 asprintf (&env, "DESTIP=%s", si.ntoa ()); putenv (env);
1180 asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); 1192 asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env);
1181} 1193}
1182 1194
1183const char *connection::script_node_up () 1195const char *connection::script_node_up ()
1184{ 1196{
1185 script_node (); 1197 script_init_connect_env ();
1186 1198
1187 putenv ("STATE=up"); 1199 putenv ("STATE=up");
1188 1200
1201 char *filename;
1202 asprintf (&filename,
1203 "%s/%s",
1204 confbase,
1189 return ::conf.script_node_up ? ::conf.script_node_up : "node-up"; 1205 ::conf.script_node_up ? ::conf.script_node_up : "node-up");
1206
1207 return filename;
1190} 1208}
1191 1209
1192const char *connection::script_node_down () 1210const char *connection::script_node_down ()
1193{ 1211{
1194 script_node (); 1212 script_init_connect_env ();
1195 1213
1196 putenv ("STATE=down"); 1214 putenv ("STATE=down");
1197 1215
1198 return ::conf.script_node_up ? ::conf.script_node_down : "node-down"; 1216 char *filename;
1217 asprintf (&filename,
1218 "%s/%s",
1219 confbase,
1220 ::conf.script_node_down ? ::conf.script_node_down : "node-down");
1221
1222 return filename;
1199} 1223}
1200 1224
1201connection::connection (struct vpn *vpn, conf_node *conf) 1225connection::connection (struct vpn *vpn, conf_node *conf)
1202: vpn(vpn), conf(conf) 1226: vpn(vpn), conf(conf)
1203, rekey (this, &connection::rekey_cb) 1227, rekey (this, &connection::rekey_cb)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines