Do not forward broadcast packets when TunnelServer is enabled.
[tinc] / src / net_packet.c
index 1730023..40d9451 100644 (file)
@@ -54,7 +54,6 @@
 
 int keylifetime = 0;
 int keyexpires = 0;
-EVP_CIPHER_CTX packet_ctx;
 static char lzo_wrkmem[LZO1X_999_MEM_COMPRESS > LZO1X_1_MEM_COMPRESS ? LZO1X_999_MEM_COMPRESS : LZO1X_1_MEM_COMPRESS];
 
 static void send_udppacket(node_t *, vpn_packet_t *);
@@ -104,15 +103,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;
        }
 }
 
@@ -271,6 +270,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++];
 
@@ -281,6 +282,8 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt)
                }
 
                inpkt = outpkt;
+
+               origlen -= MTU/64 + 20;
        }
 
        inpkt->priority = 0;
@@ -289,7 +292,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);
 }
@@ -342,7 +345,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt)
                return;
        }
 
-       if(!n->minmtu && (inpkt->data[12] | inpkt->data[13])) {
+       if(n->options & OPTION_PMTU_DISCOVERY && !n->minmtu && (inpkt->data[12] | inpkt->data[13])) {
                ifdebug(TRAFFIC) logger(LOG_INFO,
                                _("No minimum MTU established yet for %s (%s), forwarding via TCP"),
                                n->name, n->hostname);
@@ -485,9 +488,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;
 
@@ -545,12 +554,14 @@ void handle_incoming_vpn_data(int sock)
                n = try_harder(&from, &pkt);
                if(n)
                        update_node_udp(n, &from);
-               else {
+               else ifdebug(PROTOCOL) {
                        hostname = sockaddr2hostname(&from);
                        logger(LOG_WARNING, _("Received UDP packet from unknown source %s"), hostname);
                        free(hostname);
                        return;
                }
+               else
+                       return;
        }
 
        receive_udppacket(n, &pkt);