… | |
… | |
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> |
… | |
… | |
848 | { |
848 | { |
849 | if (ictx && octx) |
849 | if (ictx && octx) |
850 | send_data_packet (pkt); |
850 | send_data_packet (pkt); |
851 | else |
851 | else |
852 | { |
852 | { |
853 | if (!broadcast)//DDDD |
853 | if (!broadcast) |
854 | data_queue.put (new tap_packet (*pkt)); |
854 | data_queue.put (new tap_packet (*pkt)); |
855 | |
855 | |
856 | establish_connection (); |
856 | establish_connection (); |
857 | } |
857 | } |
858 | } |
858 | } |
… | |
… | |
1063 | { |
1063 | { |
1064 | vpn->tap->send (d); |
1064 | vpn->tap->send (d); |
1065 | |
1065 | |
1066 | if (si != rsi) |
1066 | if (si != rsi) |
1067 | { |
1067 | { |
1068 | // fast re-sync on connection changes, useful especially for tcp/ip |
1068 | // fast re-sync on source address changes, useful especially for tcp/ip |
1069 | si = rsi; |
1069 | si = rsi; |
1070 | |
1070 | |
1071 | slog (L_INFO, _("%s(%s): socket address changed to %s"), |
1071 | slog (L_INFO, _("%s(%s): socket address changed to %s"), |
1072 | conf->nodename, (const char *)si, (const char *)rsi); |
1072 | conf->nodename, (const char *)si, (const char *)rsi); |
1073 | } |
1073 | } |
… | |
… | |
1169 | send_vpn_packet (p, si); |
1169 | send_vpn_packet (p, si); |
1170 | |
1170 | |
1171 | delete p; |
1171 | delete p; |
1172 | } |
1172 | } |
1173 | |
1173 | |
|
|
1174 | void 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 | |
1174 | void connection::script_init_env () |
1184 | void connection::script_init_connect_env () |
1175 | { |
1185 | { |
1176 | vpn->script_init_env (); |
1186 | vpn->script_init_env (); |
1177 | |
1187 | |
1178 | char *env; |
1188 | char *env; |
1179 | asprintf (&env, "DESTID=%d", conf->id); putenv (env); |
1189 | asprintf (&env, "DESTID=%d", conf->id); putenv (env); |
… | |
… | |
1182 | asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); |
1192 | asprintf (&env, "DESTPORT=%d", ntohs (si.port)); putenv (env); |
1183 | } |
1193 | } |
1184 | |
1194 | |
1185 | const char *connection::script_node_up () |
1195 | const char *connection::script_node_up () |
1186 | { |
1196 | { |
1187 | script_init_env (); |
1197 | script_init_connect_env (); |
1188 | |
1198 | |
1189 | putenv ("STATE=up"); |
1199 | putenv ("STATE=up"); |
1190 | |
1200 | |
1191 | char *filename; |
1201 | char *filename; |
1192 | asprintf (&filename, |
1202 | asprintf (&filename, |
1193 | "%s/%s", |
1203 | "%s/%s", |
1194 | confbase, |
1204 | confbase, |
1195 | ::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; |
1196 | } |
1208 | } |
1197 | |
1209 | |
1198 | const char *connection::script_node_down () |
1210 | const char *connection::script_node_down () |
1199 | { |
1211 | { |
1200 | script_init_env (); |
1212 | script_init_connect_env (); |
1201 | |
1213 | |
1202 | putenv ("STATE=down"); |
1214 | putenv ("STATE=down"); |
1203 | |
1215 | |
1204 | char *filename; |
1216 | char *filename; |
1205 | asprintf (&filename, |
1217 | asprintf (&filename, |
1206 | "%s/%s", |
1218 | "%s/%s", |
1207 | confbase, |
1219 | confbase, |
1208 | ::conf.script_node_down ? ::conf.script_node_down : "node-down"); |
1220 | ::conf.script_node_down ? ::conf.script_node_down : "node-down"); |
|
|
1221 | |
|
|
1222 | return filename; |
1209 | } |
1223 | } |
1210 | |
1224 | |
1211 | connection::connection (struct vpn *vpn, conf_node *conf) |
1225 | connection::connection (struct vpn *vpn, conf_node *conf) |
1212 | : vpn(vpn), conf(conf) |
1226 | : vpn(vpn), conf(conf) |
1213 | , rekey (this, &connection::rekey_cb) |
1227 | , rekey (this, &connection::rekey_cb) |