… | |
… | |
644 | { |
644 | { |
645 | connection *r = vpn->find_router (); |
645 | connection *r = vpn->find_router (); |
646 | |
646 | |
647 | if (r) |
647 | if (r) |
648 | { |
648 | { |
649 | slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s"), |
649 | slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s (%s)"), |
650 | conf->nodename, r->conf->nodename); |
650 | conf->nodename, r->conf->nodename, (const char *)r->si); |
651 | return r->si; |
651 | return r->si; |
652 | } |
652 | } |
653 | else |
653 | else |
654 | slog (L_DEBUG, _("%s: node unreachable, no common protocol"), |
654 | slog (L_DEBUG, _("%s: node unreachable, no common protocol"), |
655 | conf->nodename); |
655 | conf->nodename); |
… | |
… | |
659 | } |
659 | } |
660 | |
660 | |
661 | void |
661 | void |
662 | connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
662 | connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
663 | { |
663 | { |
664 | bool ok; |
664 | if (!vpn->send_vpn_packet (pkt, si, tos)) |
665 | |
|
|
666 | switch (si.prot) |
|
|
667 | { |
|
|
668 | case PROT_IPv4: |
|
|
669 | ok = vpn->send_ipv4_packet (pkt, si, tos); break; |
|
|
670 | case PROT_UDPv4: |
|
|
671 | ok = vpn->send_udpv4_packet (pkt, si, tos); break; |
|
|
672 | #if ENABLE_TCP |
|
|
673 | case PROT_TCPv4: |
|
|
674 | ok = vpn->send_tcpv4_packet (pkt, si, tos); break; |
|
|
675 | #endif |
|
|
676 | #if ENABLE_ICMP |
|
|
677 | case PROT_ICMPv4: |
|
|
678 | ok = vpn->send_icmpv4_packet (pkt, si, tos); break; |
|
|
679 | #endif |
|
|
680 | #if ENABLE_DNS |
|
|
681 | case PROT_DNSv4: |
|
|
682 | ok = send_dnsv4_packet (pkt, si, tos); break; |
|
|
683 | #endif |
|
|
684 | |
|
|
685 | default: |
|
|
686 | slog (L_CRIT, _("%s: FATAL: trying to send packet with unsupported protocol"), (const char *)si); |
|
|
687 | ok = false; |
|
|
688 | } |
|
|
689 | |
|
|
690 | if (!ok) |
|
|
691 | reset_connection (); |
665 | reset_connection (); |
692 | } |
666 | } |
693 | |
667 | |
694 | void |
668 | void |
695 | connection::send_ping (const sockinfo &si, u8 pong) |
669 | connection::send_ping (const sockinfo &si, u8 pong) |
… | |
… | |
771 | && conf != THISNODE |
745 | && conf != THISNODE |
772 | && connectmode != conf_node::C_NEVER |
746 | && connectmode != conf_node::C_NEVER |
773 | && connectmode != conf_node::C_DISABLED |
747 | && connectmode != conf_node::C_DISABLED |
774 | && NOW > w.at) |
748 | && NOW > w.at) |
775 | { |
749 | { |
776 | double retry_int = double (retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2)) * 0.6; |
750 | w.at = TSTAMP_MAX; // first disable this watcher in case of recursion |
777 | |
751 | |
778 | if (retry_int < conf->max_retry) |
752 | double retry_int = double (retry_cnt & 3 |
779 | retry_cnt++; |
753 | ? (retry_cnt & 3) + 1 |
780 | else |
754 | : 1 << (retry_cnt >> 2)); |
781 | retry_int = conf->max_retry; |
|
|
782 | |
|
|
783 | w.start (NOW + retry_int); |
|
|
784 | |
755 | |
785 | reset_si (); |
756 | reset_si (); |
|
|
757 | |
|
|
758 | bool slow = si.prot & PROT_SLOW; |
786 | |
759 | |
787 | if (si.prot && !si.host) |
760 | if (si.prot && !si.host) |
788 | vpn->send_connect_request (conf->id); |
761 | vpn->send_connect_request (conf->id); |
789 | else |
762 | else |
790 | { |
763 | { |
791 | const sockinfo &dsi = forward_si (si); |
764 | const sockinfo &dsi = forward_si (si); |
|
|
765 | |
|
|
766 | slow = slow || (dsi.prot & PROT_SLOW); |
792 | |
767 | |
793 | if (dsi.valid () && auth_rate_limiter.can (dsi)) |
768 | if (dsi.valid () && auth_rate_limiter.can (dsi)) |
794 | { |
769 | { |
795 | if (retry_cnt < 4) |
770 | if (retry_cnt < 4) |
796 | send_auth_request (dsi, true); |
771 | send_auth_request (dsi, true); |
797 | else |
772 | else |
798 | send_ping (dsi, 0); |
773 | send_ping (dsi, 0); |
799 | } |
774 | } |
800 | } |
775 | } |
|
|
776 | |
|
|
777 | retry_int *= slow ? 3. : 0.7; |
|
|
778 | |
|
|
779 | if (retry_int < conf->max_retry) |
|
|
780 | retry_cnt++; |
|
|
781 | else |
|
|
782 | retry_int = conf->max_retry; |
|
|
783 | |
|
|
784 | w.start (NOW + retry_int); |
801 | } |
785 | } |
802 | } |
786 | } |
803 | |
787 | |
804 | void |
788 | void |
805 | connection::reset_connection () |
789 | connection::reset_connection () |