… | |
… | |
478 | { |
478 | { |
479 | prot_major = PROTOCOL_MAJOR; |
479 | prot_major = PROTOCOL_MAJOR; |
480 | prot_minor = PROTOCOL_MINOR; |
480 | prot_minor = PROTOCOL_MINOR; |
481 | randsize = RAND_SIZE; |
481 | randsize = RAND_SIZE; |
482 | hmaclen = HMACLENGTH; |
482 | hmaclen = HMACLENGTH; |
483 | flags = ENABLE_COMPRESSION ? 0x81 : 0x80; |
483 | flags = 0; |
484 | challengelen = sizeof (rsachallenge); |
484 | challengelen = sizeof (rsachallenge); |
485 | features = get_features (); |
485 | features = get_features (); |
486 | |
486 | |
487 | cipher_nid = htonl (EVP_CIPHER_nid (CIPHER)); |
487 | cipher_nid = htonl (EVP_CIPHER_nid (CIPHER)); |
488 | digest_nid = htonl (EVP_MD_type (RSA_HASH)); |
488 | digest_nid = htonl (EVP_MD_type (RSA_HASH)); |
… | |
… | |
498 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
498 | slog (L_WARN, _("major version mismatch (remote %d <=> local %d)"), prot_major, PROTOCOL_MAJOR); |
499 | else if (randsize != RAND_SIZE) |
499 | else if (randsize != RAND_SIZE) |
500 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
500 | slog (L_WARN, _("rand size mismatch (remote %d <=> local %d)"), randsize, RAND_SIZE); |
501 | else if (hmaclen != HMACLENGTH) |
501 | else if (hmaclen != HMACLENGTH) |
502 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
502 | slog (L_WARN, _("hmac length mismatch (remote %d <=> local %d)"), hmaclen, HMACLENGTH); |
503 | #if 0 // this implementation should handle all flag settings |
|
|
504 | else if (flags != curflags ()) |
|
|
505 | slog (L_WARN, _("flag mismatch (remote %x <=> local %x)"), flags, curflags ()); |
|
|
506 | #endif |
|
|
507 | else if (challengelen != sizeof (rsachallenge)) |
503 | else if (challengelen != sizeof (rsachallenge)) |
508 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
504 | slog (L_WARN, _("challenge length mismatch (remote %d <=> local %d)"), challengelen, sizeof (rsachallenge)); |
509 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
505 | else if (cipher_nid != htonl (EVP_CIPHER_nid (CIPHER))) |
510 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
506 | slog (L_WARN, _("cipher mismatch (remote %x <=> local %x)"), ntohl (cipher_nid), EVP_CIPHER_nid (CIPHER)); |
511 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
507 | else if (digest_nid != htonl (EVP_MD_type (RSA_HASH))) |
… | |
… | |
644 | { |
640 | { |
645 | connection *r = vpn->find_router (); |
641 | connection *r = vpn->find_router (); |
646 | |
642 | |
647 | if (r) |
643 | if (r) |
648 | { |
644 | { |
649 | slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s"), |
645 | slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s (%s)"), |
650 | conf->nodename, r->conf->nodename); |
646 | conf->nodename, r->conf->nodename, (const char *)r->si); |
651 | return r->si; |
647 | return r->si; |
652 | } |
648 | } |
653 | else |
649 | else |
654 | slog (L_DEBUG, _("%s: node unreachable, no common protocol"), |
650 | slog (L_DEBUG, _("%s: node unreachable, no common protocol"), |
655 | conf->nodename); |
651 | conf->nodename); |
… | |
… | |
659 | } |
655 | } |
660 | |
656 | |
661 | void |
657 | void |
662 | connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
658 | connection::send_vpn_packet (vpn_packet *pkt, const sockinfo &si, int tos) |
663 | { |
659 | { |
664 | bool ok; |
660 | 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 (); |
661 | reset_connection (); |
692 | } |
662 | } |
693 | |
663 | |
694 | void |
664 | void |
695 | connection::send_ping (const sockinfo &si, u8 pong) |
665 | connection::send_ping (const sockinfo &si, u8 pong) |
… | |
… | |
771 | && conf != THISNODE |
741 | && conf != THISNODE |
772 | && connectmode != conf_node::C_NEVER |
742 | && connectmode != conf_node::C_NEVER |
773 | && connectmode != conf_node::C_DISABLED |
743 | && connectmode != conf_node::C_DISABLED |
774 | && NOW > w.at) |
744 | && NOW > w.at) |
775 | { |
745 | { |
776 | double retry_int = double (retry_cnt & 3 ? (retry_cnt & 3) : 1 << (retry_cnt >> 2)) * 0.6; |
746 | w.at = TSTAMP_MAX; // first disable this watcher in case of recursion |
777 | |
747 | |
778 | if (retry_int < conf->max_retry) |
748 | double retry_int = double (retry_cnt & 3 |
779 | retry_cnt++; |
749 | ? (retry_cnt & 3) + 1 |
780 | else |
750 | : 1 << (retry_cnt >> 2)); |
781 | retry_int = conf->max_retry; |
|
|
782 | |
|
|
783 | w.start (NOW + retry_int); |
|
|
784 | |
751 | |
785 | reset_si (); |
752 | reset_si (); |
|
|
753 | |
|
|
754 | bool slow = si.prot & PROT_SLOW; |
786 | |
755 | |
787 | if (si.prot && !si.host) |
756 | if (si.prot && !si.host) |
788 | vpn->send_connect_request (conf->id); |
757 | vpn->send_connect_request (conf->id); |
789 | else |
758 | else |
790 | { |
759 | { |
791 | const sockinfo &dsi = forward_si (si); |
760 | const sockinfo &dsi = forward_si (si); |
|
|
761 | |
|
|
762 | slow = slow || (dsi.prot & PROT_SLOW); |
792 | |
763 | |
793 | if (dsi.valid () && auth_rate_limiter.can (dsi)) |
764 | if (dsi.valid () && auth_rate_limiter.can (dsi)) |
794 | { |
765 | { |
795 | if (retry_cnt < 4) |
766 | if (retry_cnt < 4) |
796 | send_auth_request (dsi, true); |
767 | send_auth_request (dsi, true); |
797 | else |
768 | else |
798 | send_ping (dsi, 0); |
769 | send_ping (dsi, 0); |
799 | } |
770 | } |
800 | } |
771 | } |
|
|
772 | |
|
|
773 | retry_int *= slow ? 8. : 0.7; |
|
|
774 | |
|
|
775 | if (retry_int < conf->max_retry) |
|
|
776 | retry_cnt++; |
|
|
777 | else |
|
|
778 | retry_int = conf->max_retry; |
|
|
779 | |
|
|
780 | w.start (NOW + retry_int); |
801 | } |
781 | } |
802 | } |
782 | } |
803 | |
783 | |
804 | void |
784 | void |
805 | connection::reset_connection () |
785 | connection::reset_connection () |
… | |
… | |
813 | run_script (run_script_cb (this, &connection::script_node_down), false); |
793 | run_script (run_script_cb (this, &connection::script_node_down), false); |
814 | } |
794 | } |
815 | |
795 | |
816 | delete ictx; ictx = 0; |
796 | delete ictx; ictx = 0; |
817 | delete octx; octx = 0; |
797 | delete octx; octx = 0; |
|
|
798 | #if ENABLE_DNS |
|
|
799 | dnsv4_reset_connection (); |
|
|
800 | #endif |
818 | |
801 | |
819 | si.host = 0; |
802 | si.host = 0; |
820 | |
803 | |
821 | last_activity = 0; |
804 | last_activity = 0; |
822 | retry_cnt = 0; |
805 | retry_cnt = 0; |
… | |
… | |
961 | delete octx; |
944 | delete octx; |
962 | |
945 | |
963 | octx = new crypto_ctx (k, 1); |
946 | octx = new crypto_ctx (k, 1); |
964 | oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff; |
947 | oseqno = ntohl (*(u32 *)&k[CHG_SEQNO]) & 0x7fffffff; |
965 | |
948 | |
966 | // compatibility code, remove when no longer required |
|
|
967 | if (p->flags & 1) p->features |= FEATURE_COMPRESSION; |
|
|
968 | |
|
|
969 | conf->protocols = p->protocols; |
949 | conf->protocols = p->protocols; |
970 | features = p->features & config_packet::get_features (); |
950 | features = p->features & config_packet::get_features (); |
971 | |
951 | |
972 | send_auth_response (rsi, p->id, k); |
952 | send_auth_response (rsi, p->id, k); |
973 | |
953 | |