Log error first, try to close later.
[tinc] / src / net_packet.c
index c0bd247..aa5bea3 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net_packet.c,v 1.1.2.33 2003/07/12 17:41:46 guus Exp $
+    $Id: net_packet.c,v 1.1.2.37 2003/08/08 19:42:35 guus Exp $
 */
 
-#include "config.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-/* SunOS really wants sys/socket.h BEFORE net/if.h,
-   and FreeBSD wants these lines below the rest. */
-#include <arpa/inet.h>
-#include <sys/socket.h>
-#include <net/if.h>
-#ifdef HAVE_NETINET_IN_SYSTM_H
-#include <netinet/in_systm.h>
-#endif
-#ifdef HAVE_NETINET_IP_H
-#include <netinet/ip.h>
-#endif
-#ifdef HAVE_NETINET_TCP_H
-#include <netinet/tcp.h>
-#endif
+#include "system.h"
 
 #include <openssl/rand.h>
 #include <openssl/evp.h>
 #include <zlib.h>
 #include <lzo1x.h>
 
-#include <utils.h>
-#include <xalloc.h>
-#include <avl_tree.h>
-#include <list.h>
-
+#include "avl_tree.h"
 #include "conf.h"
 #include "connection.h"
-#include "meta.h"
+#include "device.h"
+#include "event.h"
+#include "graph.h"
+#include "list.h"
+#include "logger.h"
 #include "net.h"
 #include "netutl.h"
-#include "process.h"
 #include "protocol.h"
-#include "subnet.h"
-#include "graph.h"
 #include "process.h"
 #include "route.h"
-#include "device.h"
-#include "event.h"
-#include "logger.h"
-
-#include "system.h"
+#include "utils.h"
+#include "xalloc.h"
 
 int keylifetime = 0;
 int keyexpires = 0;
@@ -272,7 +239,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *inpkt)
                if(!n->status.waitingforkey)
                        send_req_key(n->nexthop->connection, myself, n);
 
-               n->status.waitingforkey = 1;
+               n->status.waitingforkey = true;
 
                return;
        }
@@ -339,14 +306,12 @@ static void send_udppacket(node_t *n, vpn_packet_t *inpkt)
                priority = origpriority;
                ifdebug(TRAFFIC) logger(LOG_DEBUG, _("Setting outgoing packet priority to %d"), priority);
                if(setsockopt(listen_socket[sock].udp, SOL_IP, IP_TOS, &priority, sizeof(priority)))    /* SO_PRIORITY doesn't seem to work */
-                       logger(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt",
-                                  strerror(errno));
+                       logger(LOG_ERR, _("System call `%s' failed: %s"), "setsockopt", strerror(errno));
        }
 #endif
 
        if((sendto(listen_socket[sock].udp, (char *) &inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0) {
-               logger(LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name,
-                          n->hostname, strerror(errno));
+               logger(LOG_ERR, _("Error sending packet to %s (%s): %s"), n->name, n->hostname, strerror(errno));
                return;
        }
 
@@ -356,7 +321,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *inpkt)
 /*
   send a packet to the given vpn ip.
 */
-void send_packet(node_t *n, vpn_packet_t *packet)
+void send_packet(const node_t *n, vpn_packet_t *packet)
 {
        node_t *via;
 
@@ -383,15 +348,15 @@ void send_packet(node_t *n, vpn_packet_t *packet)
                           n->name, via->name, n->via->hostname);
 
        if((myself->options | via->options) & OPTION_TCPONLY) {
-               if(send_tcppacket(via->connection, packet))
-                       terminate_connection(via->connection, 1);
+               if(!send_tcppacket(via->connection, packet))
+                       terminate_connection(via->connection, true);
        } else
                send_udppacket(via, packet);
 }
 
 /* Broadcast a packet using the minimum spanning tree */
 
-void broadcast_packet(node_t *from, vpn_packet_t *packet)
+void broadcast_packet(const node_t *from, vpn_packet_t *packet)
 {
        avl_node_t *node;
        connection_t *c;