X-Git-Url: https://git.librecmc.org/?p=oweals%2Ftinc.git;a=blobdiff_plain;f=src%2Fnet.c;h=dd692e8e547e357e52ea073f273f88ca5a43565d;hp=fb15b5ee0a3c0d97dec643b3fd4cd1ec520b22f9;hb=afc05797077641baa33b024ffeaafd6cad3ff7a7;hpb=dc699f8b1265deb7606d553e36326527dbd29746 diff --git a/src/net.c b/src/net.c index fb15b5e..dd692e8 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.59 2000/11/04 10:37:27 guus Exp $ + $Id: net.c,v 1.35.4.66 2000/11/04 20:44:26 guus Exp $ */ #include "config.h" @@ -86,10 +86,7 @@ int execute_script(const char* name) { char *scriptname; pid_t pid; - char **env; - extern char **environment; /* From tincd.c; contains our env */ - - asprintf(&scriptname, "%s/%s", confbase, name); + char *s; if((pid = fork()) < 0) { @@ -100,16 +97,34 @@ int execute_script(const char* name) if(pid) { - free(scriptname); return 0; } /* Child here */ - env = xmalloc(sizeof(environment) + 1 * sizeof(char*)); - memcpy(&(env[1]), environment, sizeof(environment)); - asprintf(&(env[0]), "IFNAME=%s", interface_name); - execle(scriptname, NULL, env); + asprintf(&scriptname, "%s/%s", confbase, name); + asprintf(&s, "IFNAME=%s", interface_name); + putenv(s); + free(s); + + if(netname) + { + asprintf(&s, "NETNAME=%s", netname); + putenv(s); + free(s); + } + else + { + unsetenv("NETNAME"); + } + + if(chdir(confbase) < 0) + { + syslog(LOG_ERR, _("Couldn't chdir to `%s': %m"), + confbase); + } + + execl(scriptname, NULL); /* No return on success */ if(errno != ENOENT) /* Ignore if the file does not exist */ @@ -145,8 +160,6 @@ cp total_socket_out += outlen; - cl->want_ping = 1; - if((send(cl->socket, (char *) &(outpkt.len), outlen, 0)) < 0) { syslog(LOG_ERR, _("Error sending packet to %s (%s): %m"), @@ -343,10 +356,21 @@ cp } return -1; - } + } cl = subnet->owner; + if(cl == myself) + { + if(debug_lvl >= DEBUG_TRAFFIC) + { + syslog(LOG_NOTICE, _("Packet with destination %d.%d.%d.%d is looping back to us!"), + IP_ADDR_V(to)); + } + + return -1; + } + /* If we ourselves have indirectdata flag set, we should send only to our uplink! */ /* FIXME - check for indirection and reprogram it The Right Way(tm) this time. */ @@ -680,7 +704,6 @@ cp ncn->buffer = xmalloc(MAXBUFSIZE); ncn->buflen = 0; ncn->last_ping_time = time(NULL); - ncn->want_ping = 0; conn_list_add(ncn); @@ -863,9 +886,15 @@ int setup_network_connections(void) config_t const *cfg; cp if((cfg = get_config_val(config, pingtimeout)) == NULL) - timeout = 5; + timeout = 60; else - timeout = cfg->data.val; + { + timeout = cfg->data.val; + if(timeout < 1) + { + timeout = 86400; + } + } if(setup_tap_fd() < 0) return -1; @@ -903,7 +932,6 @@ cp void close_network_connections(void) { conn_list_t *p; - char *scriptname; cp for(p = conn_list; p != NULL; p = p->next) { @@ -920,10 +948,11 @@ cp myself = NULL; } - /* Execute tinc-down script right before shutting down the interface */ + close(tap_fd); + + /* Execute tinc-down script right after shutting down the interface */ execute_script("tinc-down"); - close(tap_fd); destroy_conn_list(); syslog(LOG_NOTICE, _("Terminating")); @@ -1001,7 +1030,6 @@ cp p->buffer = xmalloc(MAXBUFSIZE); p->buflen = 0; p->last_ping_time = time(NULL); - p->want_ping = 0; if(debug_lvl >= DEBUG_CONNECTIONS) syslog(LOG_NOTICE, _("Connection from %s port %d"), @@ -1155,7 +1183,7 @@ cp { if(p->last_ping_time + timeout < now) { - if(p->status.pinged && !p->status.got_pong) + if(p->status.pinged) { if(debug_lvl >= DEBUG_PROTOCOL) syslog(LOG_INFO, _("%s (%s) didn't respond to PING"), @@ -1163,12 +1191,9 @@ cp p->status.timeout = 1; terminate_connection(p); } - else if(p->want_ping) + else { send_ping(p); - p->last_ping_time = now; - p->status.pinged = 1; - p->status.got_pong = 0; } } }