X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_packet.c;h=3243670295d7cb747299488f24f96f20c46117f1;hp=7a73ef58b7937b8de95336f4332c2a8c0b9e5eba;hb=c11dc8079b60d9f8c5b1c7e8fecd90d0fac5a20c;hpb=92b8abc921dd15b710f67335562210eb713fbb39 diff --git a/src/net_packet.c b/src/net_packet.c index 7a73ef58..32436702 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -46,8 +46,16 @@ #include "utils.h" #include "xalloc.h" -#ifdef WSAEMSGSIZE +#ifdef HAVE_MINGW +#include #define EMSGSIZE WSAEMSGSIZE +#define EAGAIN WSATRY_AGAIN +#define EINTR WSAEINTR +#define sockstrerror(x) winerror(x) +#define sockerrno WSAGetLastError() +#else +#define sockstrerror(x) strerror(x) +#define sockerrno errno #endif int keylifetime = 0; @@ -72,7 +80,7 @@ void send_mtu_probe(node_t *n) { n->mtuevent = NULL; if(!n->status.reachable || !n->status.validkey) { - logger(LOG_DEBUG, "Trying to send MTU probe to unreachable node %s (%s)", n->name, n->hostname); + ifdebug(TRAFFIC) logger(LOG_INFO, "Trying to send MTU probe to unreachable or rekeying node %s (%s)", n->name, n->hostname); n->mtuprobes = 0; return; } @@ -91,6 +99,10 @@ void send_mtu_probe(node_t *n) { } if(n->mtuprobes == 30 || (n->mtuprobes < 30 && n->minmtu >= n->maxmtu)) { + if(n->minmtu > n->maxmtu) + n->minmtu = n->maxmtu; + else + n->maxmtu = n->minmtu; n->mtu = n->minmtu; ifdebug(TRAFFIC) logger(LOG_INFO, "Fixing MTU of %s (%s) to %d after %d probes", n->name, n->hostname, n->mtu, n->mtuprobes); n->mtuprobes = 31; @@ -135,7 +147,7 @@ void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) { if(!packet->data[0]) { packet->data[0] = 1; - send_packet(n, packet); + send_udppacket(n, packet); } else { if(len > n->maxmtu) len = n->maxmtu; @@ -365,10 +377,13 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { if(n->options & OPTION_PMTU_DISCOVERY && inpkt->len > n->minmtu && (inpkt->data[12] | inpkt->data[13])) { ifdebug(TRAFFIC) logger(LOG_INFO, - "Packet for %s (%s) larger than minimum MTU, forwarding via TCP", - n->name, n->hostname); + "Packet for %s (%s) larger than minimum MTU, forwarding via %s", + n->name, n->hostname, n != n->nexthop ? n->nexthop->name : "TCP"); - send_tcppacket(n->nexthop->connection, origpkt); + if(n != n->nexthop) + send_packet(n->nexthop, origpkt); + else + send_tcppacket(n->nexthop->connection, origpkt); return; } @@ -443,13 +458,13 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { #endif if((sendto(listen_socket[sock].udp, (char *) &inpkt->seqno, inpkt->len, 0, &(n->address.sa), SALEN(n->address.sa))) < 0) { - if(errno == EMSGSIZE) { + if(sockerrno == EMSGSIZE) { if(n->maxmtu >= origlen) n->maxmtu = origlen - 1; if(n->mtu >= origlen) n->mtu = origlen - 1; } else - 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, sockstrerror(sockerrno)); } end: @@ -521,12 +536,16 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { avl_node_t *node; edge_t *e; node_t *n = NULL; + static time_t last_hard_try = 0; for(node = edge_weight_tree->head; node; node = node->next) { e = node->data; - if(sockaddrcmp_noport(from, &e->address)) - continue; + if(sockaddrcmp_noport(from, &e->address)) { + if(last_hard_try == now) + continue; + last_hard_try = now; + } if(!n) n = e->to; @@ -551,8 +570,8 @@ void handle_incoming_vpn_data(int sock) { pkt.len = recvfrom(sock, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen); if(pkt.len < 0) { - if(errno != EAGAIN && errno != EINTR) - logger(LOG_ERR, "Receiving packet failed: %s", strerror(errno)); + if(sockerrno != EAGAIN && sockerrno != EINTR) + logger(LOG_ERR, "Receiving packet failed: %s", sockstrerror(sockerrno)); return; }