X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_packet.c;h=aca84683e5aaa5a500758803bdcaf90ba435ac8e;hp=0126d418326261770dc5bf1f252d11be167ddbd1;hb=b5ccce296848aab72d574ca3de14af5fdf3efa4d;hpb=e012e752f4f1a2b06dfab4640bbbea8f084999ff diff --git a/src/net_packet.c b/src/net_packet.c index 0126d418..aca84683 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -70,6 +70,11 @@ void send_mtu_probe(node_t *n) n->mtuprobes++; n->mtuevent = NULL; + if(!n->status.reachable) { + logger(LOG_DEBUG, _("Trying to send MTU probe to unreachable node %s (%s)"), n->name, n->hostname); + return; + } + if(n->mtuprobes >= 10 && !n->minmtu) { ifdebug(TRAFFIC) logger(LOG_INFO, _("No response to MTU probes from %s (%s)"), n->name, n->hostname); return; @@ -82,7 +87,7 @@ void send_mtu_probe(node_t *n) return; } - len = n->minmtu + 1 + random() % (n->maxmtu - n->minmtu); + len = n->minmtu + 1 + rand() % (n->maxmtu - n->minmtu); if(len < 64) len = 64; @@ -103,15 +108,15 @@ void send_mtu_probe(node_t *n) event_add(n->mtuevent); } -void mtu_probe_h(node_t *n, vpn_packet_t *packet) { +void mtu_probe_h(node_t *n, vpn_packet_t *packet, length_t len) { ifdebug(TRAFFIC) logger(LOG_INFO, _("Got MTU probe length %d from %s (%s)"), packet->len, n->name, n->hostname); if(!packet->data[0]) { packet->data[0] = 1; send_packet(n, packet); } else { - if(n->minmtu < packet->len) - n->minmtu = packet->len; + if(n->minmtu < len) + n->minmtu = len; } } @@ -270,6 +275,8 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) /* Decompress the packet */ + length_t origlen = inpkt->len; + if(n->incompression) { outpkt = pkt[nextpkt++]; @@ -280,6 +287,8 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) } inpkt = outpkt; + + origlen -= MTU/64 + 20; } inpkt->priority = 0; @@ -288,7 +297,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) n->connection->last_ping_time = now; if(!inpkt->data[12] && !inpkt->data[13]) - mtu_probe_h(n, inpkt); + mtu_probe_h(n, inpkt, origlen); else receive_packet(n, inpkt); } @@ -324,6 +333,11 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) cp(); + if(!n->status.reachable) { + ifdebug(TRAFFIC) logger(LOG_INFO, _("Trying to send UDP packet to unreachable node %s (%s)"), n->name, n->hostname); + return; + } + /* Make sure we have a valid key */ if(!n->status.validkey) { @@ -341,9 +355,9 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) return; } - if(n->options & OPTION_PMTU_DISCOVERY && !n->minmtu && (inpkt->data[12] | inpkt->data[13])) { + if(n->options & OPTION_PMTU_DISCOVERY && inpkt->len > n->minmtu && (inpkt->data[12] | inpkt->data[13])) { ifdebug(TRAFFIC) logger(LOG_INFO, - _("No minimum MTU established yet for %s (%s), forwarding via TCP"), + _("Packet for %s (%s) larger than minimum MTU, forwarding via TCP"), n->name, n->hostname); send_tcppacket(n->nexthop->connection, origpkt); @@ -484,9 +498,15 @@ void broadcast_packet(const node_t *from, vpn_packet_t *packet) ifdebug(TRAFFIC) logger(LOG_INFO, _("Broadcasting packet of %d bytes from %s (%s)"), packet->len, from->name, from->hostname); - if(from != myself) + if(from != myself) { send_packet(myself, packet); + // In TunnelServer mode, do not forward broadcast packets. + // The MST might not be valid and create loops. + if(tunnelserver) + return; + } + for(node = connection_tree->head; node; node = node->next) { c = node->data; @@ -532,7 +552,8 @@ void handle_incoming_vpn_data(int sock) pkt.len = recvfrom(sock, (char *) &pkt.seqno, MAXSIZE, 0, &from.sa, &fromlen); if(pkt.len < 0) { - logger(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno)); + if(errno != EAGAIN && errno != EINTR) + logger(LOG_ERR, _("Receiving packet failed: %s"), strerror(errno)); return; }