X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_packet.c;h=fc24c9a545a6ba72bd5ec0fe505b55580e368ea9;hb=0a786ffbb9d293d7704b8e264f3943a616ed25cc;hp=8313a54fd0e142c7a9106bd04bd43ddf3b5f661c;hpb=1a7a9078c093f77950192c32be009bbe463fe372;p=tinc diff --git a/src/net_packet.c b/src/net_packet.c index 8313a54f..fc24c9a5 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -282,9 +282,8 @@ static bool receive_udppacket(node_t *n, vpn_packet_t *inpkt) { } return false; } - inpkt->offset += 2 * sizeof(node_id_t); n->status.udppacket = true; - bool result = sptps_receive_data(&n->sptps, DATA(inpkt), inpkt->len - 2 * sizeof(node_id_t)); + bool result = sptps_receive_data(&n->sptps, DATA(inpkt), inpkt->len); n->status.udppacket = false; if(!result) { @@ -1191,15 +1190,13 @@ static void try_tx_sptps(node_t *n, bool mtu) { node_t *via = (n->via == myself) ? n->nexthop : n->via; - /* If the static relay doesn't support SPTPS, everything goes via TCP anyway. */ + /* If we do have a static relay, try everything with that one instead, if it supports relaying. */ - if((via->options >> 24) < 4) - return; - - /* If we do have a static relay, try everything with that one instead. */ - - if(via != n) + if(via != n) { + if((via->options >> 24) < 4) + return; return try_tx_sptps(via, mtu); + } /* Otherwise, try to establish UDP connectivity. */ @@ -1350,7 +1347,7 @@ static node_t *try_harder(const sockaddr_t *from, const vpn_packet_t *pkt) { if(!n->status.reachable || n == myself) continue; - if((n->status.sptps && !n->sptps.instate) || !n->status.validkey_in) + if(!n->status.validkey_in && !(n->status.sptps && n->sptps.instate)) continue; bool soft = false; @@ -1440,10 +1437,16 @@ skip_harder: return; } + pkt.offset = 0; + if(n->status.sptps) { - pkt.offset = 2 * sizeof(node_id_t); + bool relay_enabled = (n->options >> 24) >= 4; + if (relay_enabled) { + pkt.offset = 2 * sizeof(node_id_t); + pkt.len -= pkt.offset; + } - if(!memcmp(DSTID(&pkt), &nullid, sizeof nullid)) { + if(!memcmp(DSTID(&pkt), &nullid, sizeof nullid) || !relay_enabled) { direct = true; from = n; to = myself; @@ -1468,7 +1471,7 @@ skip_harder: /* If we're not the final recipient, relay the packet. */ if(to != myself) { - send_sptps_data(to, from, 0, DATA(&pkt), pkt.len - 2 * sizeof(node_id_t)); + send_sptps_data(to, from, 0, DATA(&pkt), pkt.len); try_tx_sptps(to, true); return; } @@ -1477,7 +1480,6 @@ skip_harder: from = n; } - pkt.offset = 0; if(!receive_udppacket(from, &pkt)) return;