… | |
… | |
672 | ///////////////////////////////////////////////////////////////////////////// |
672 | ///////////////////////////////////////////////////////////////////////////// |
673 | |
673 | |
674 | void |
674 | void |
675 | connection::connection_established () |
675 | connection::connection_established () |
676 | { |
676 | { |
677 | slog (L_TRACE, _("%s: possible connection establish (ictx %d, octx %d)"), conf->nodename, !!ictx, !!octx); |
677 | slog (L_NOISE, _("%s: possible connection establish (ictx %d, octx %d)"), conf->nodename, !!ictx, !!octx); |
678 | |
678 | |
679 | if (ictx && octx) |
679 | if (ictx && octx) |
680 | { |
680 | { |
681 | // make sure rekeying timeouts are slightly asymmetric |
681 | // make sure rekeying timeouts are slightly asymmetric |
682 | ev::tstamp rekey_interval = ::conf.rekey + (conf->id > THISNODE->id ? 10 : 0); |
682 | ev::tstamp rekey_interval = ::conf.rekey + (conf->id > THISNODE->id ? 10 : 0); |
… | |
… | |
696 | { |
696 | { |
697 | if (p->len) send_vpn_packet (p, si, IPTOS_RELIABILITY); |
697 | if (p->len) send_vpn_packet (p, si, IPTOS_RELIABILITY); |
698 | delete p; |
698 | delete p; |
699 | } |
699 | } |
700 | } |
700 | } |
|
|
701 | |
|
|
702 | vpn->connection_established (this); |
701 | } |
703 | } |
702 | else |
704 | else |
703 | { |
705 | { |
704 | retry_cnt = 0; |
706 | retry_cnt = 0; |
705 | establish_connection.start (5); |
707 | establish_connection.start (5); |
… | |
… | |
709 | } |
711 | } |
710 | |
712 | |
711 | void |
713 | void |
712 | connection::reset_si () |
714 | connection::reset_si () |
713 | { |
715 | { |
|
|
716 | if (vpn->can_direct (THISNODE, conf)) |
714 | protocol = best_protocol (THISNODE->protocols & conf->protocols); |
717 | protocol = best_protocol (THISNODE->protocols & conf->connectable_protocols ()); |
715 | |
718 | else |
716 | // mask out endpoints we can't connect to |
|
|
717 | if (!conf->udp_port) protocol &= ~PROT_UDPv4; |
|
|
718 | if (!conf->tcp_port) protocol &= ~PROT_TCPv4; |
|
|
719 | if (!conf->dns_port) protocol &= ~PROT_DNSv4; |
|
|
720 | |
|
|
721 | if (protocol |
|
|
722 | && (!conf->can_direct (THISNODE) |
|
|
723 | || !THISNODE->can_direct (conf))) |
|
|
724 | { |
719 | { |
725 | slog (L_DEBUG, _("%s: direct connection denied"), conf->nodename); |
720 | slog (L_TRACE, _("%s: direct connection denied by config."), conf->nodename); |
726 | protocol = 0; |
721 | protocol = 0; |
727 | } |
722 | } |
728 | |
723 | |
729 | si.set (conf, protocol); |
724 | si.set (conf, protocol); |
|
|
725 | |
|
|
726 | is_direct = si.valid (); |
730 | } |
727 | } |
731 | |
728 | |
732 | // ensure sockinfo is valid, forward if necessary |
729 | // ensure sockinfo is valid, forward if necessary |
733 | const sockinfo & |
730 | const sockinfo & |
734 | connection::forward_si (const sockinfo &si) const |
731 | connection::forward_si (const sockinfo &si) const |
735 | { |
732 | { |
736 | if (!si.valid ()) |
733 | if (!si.valid ()) |
737 | { |
734 | { |
738 | connection *r = vpn->find_router (); |
735 | connection *r = vpn->find_router_for (this); |
739 | |
736 | |
740 | if (r) |
737 | if (r) |
741 | { |
738 | { |
742 | slog (L_DEBUG, _("%s: no common protocol, trying indirectly through %s (%s)"), |
739 | slog (L_DEBUG, _("%s: no common protocol, trying to route through %s."), |
743 | conf->nodename, r->conf->nodename, (const char *)r->si); |
740 | conf->nodename, r->conf->nodename); |
744 | return r->si; |
741 | return r->si; |
745 | } |
742 | } |
746 | else |
743 | else |
747 | slog (L_DEBUG, _("%s: node unreachable, no common protocol, no router"), |
744 | slog (L_DEBUG, _("%s: node unreachable, no common protocol or no router available."), |
748 | conf->nodename); |
745 | conf->nodename); |
749 | } |
746 | } |
750 | |
747 | |
751 | return si; |
748 | return si; |
752 | } |
749 | } |
… | |
… | |
762 | connection::send_ping (const sockinfo &si, u8 pong) |
759 | connection::send_ping (const sockinfo &si, u8 pong) |
763 | { |
760 | { |
764 | ping_packet *pkt = new ping_packet; |
761 | ping_packet *pkt = new ping_packet; |
765 | |
762 | |
766 | pkt->setup (conf->id, pong ? ping_packet::PT_PONG : ping_packet::PT_PING); |
763 | pkt->setup (conf->id, pong ? ping_packet::PT_PONG : ping_packet::PT_PING); |
|
|
764 | |
|
|
765 | slog (L_TRACE, "%s << %s [%s]", conf->nodename, pong ? "PT_PONG" : "PT_PING", (const char *)si); |
|
|
766 | |
767 | send_vpn_packet (pkt, si, IPTOS_LOWDELAY); |
767 | send_vpn_packet (pkt, si, IPTOS_LOWDELAY); |
768 | |
768 | |
769 | delete pkt; |
769 | delete pkt; |
770 | } |
770 | } |
771 | |
771 | |
… | |
… | |
790 | |
790 | |
791 | rsachallenge chg; |
791 | rsachallenge chg; |
792 | rsa_cache.gen (pkt->id, chg); |
792 | rsa_cache.gen (pkt->id, chg); |
793 | rsa_encrypt (conf->rsa_key, chg, pkt->encr); |
793 | rsa_encrypt (conf->rsa_key, chg, pkt->encr); |
794 | |
794 | |
795 | slog (L_TRACE, ">>%d PT_AUTH_REQ [%s]", conf->id, (const char *)si); |
795 | slog (L_TRACE, "%s >> PT_AUTH_REQ [%s]", conf->nodename, (const char *)si); |
796 | |
796 | |
797 | send_vpn_packet (pkt, si, IPTOS_RELIABILITY | IPTOS_LOWDELAY); // rsa is very very costly |
797 | send_vpn_packet (pkt, si, IPTOS_RELIABILITY | IPTOS_LOWDELAY); // rsa is very very costly |
798 | |
798 | |
799 | delete pkt; |
799 | delete pkt; |
800 | } |
800 | } |
… | |
… | |
808 | |
808 | |
809 | rsa_hash (id, chg, pkt->response); |
809 | rsa_hash (id, chg, pkt->response); |
810 | |
810 | |
811 | pkt->hmac_set (octx); |
811 | pkt->hmac_set (octx); |
812 | |
812 | |
813 | slog (L_TRACE, ">>%d PT_AUTH_RES [%s]", conf->id, (const char *)si); |
813 | slog (L_TRACE, "%s << PT_AUTH_RES [%s]", conf->nodename, (const char *)si); |
814 | |
814 | |
815 | send_vpn_packet (pkt, si, IPTOS_RELIABILITY); // rsa is very very costly |
815 | send_vpn_packet (pkt, si, IPTOS_RELIABILITY); // rsa is very very costly |
816 | |
816 | |
817 | delete pkt; |
817 | delete pkt; |
818 | } |
818 | } |
819 | |
819 | |
820 | void |
820 | void |
821 | connection::send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols) |
821 | connection::send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols) |
822 | { |
822 | { |
823 | slog (L_TRACE, ">>%d PT_CONNECT_INFO(%d,%s)", |
823 | slog (L_TRACE, "%s << PT_CONNECT_INFO(%s,%s)", conf->nodename, |
824 | conf->id, rid, (const char *)rsi); |
824 | vpn->conns[rid - 1]->conf->nodename, (const char *)rsi); |
825 | |
825 | |
826 | connect_info_packet *r = new connect_info_packet (conf->id, rid, rsi, rprotocols); |
826 | connect_info_packet *r = new connect_info_packet (conf->id, rid, rsi, rprotocols); |
827 | |
827 | |
828 | r->hmac_set (octx); |
828 | r->hmac_set (octx); |
829 | send_vpn_packet (r, si); |
829 | send_vpn_packet (r, si); |
… | |
… | |
856 | |
856 | |
857 | reset_si (); |
857 | reset_si (); |
858 | |
858 | |
859 | bool slow = si.prot & PROT_SLOW; |
859 | bool slow = si.prot & PROT_SLOW; |
860 | |
860 | |
861 | if (si.prot && !si.host) |
861 | if (si.prot && !si.host && vpn->can_direct (THISNODE, conf)) |
862 | { |
862 | { |
863 | slog (L_TRACE, _("%s: connection request (indirect)"), conf->nodename); |
|
|
864 | /*TODO*/ /* start the timer so we don't recurse endlessly */ |
863 | /*TODO*/ /* start the timer so we don't recurse endlessly */ |
865 | w.start (1); |
864 | w.start (1); |
866 | vpn->send_connect_request (conf->id); |
865 | vpn->send_connect_request (this); |
867 | } |
866 | } |
868 | else |
867 | else |
869 | { |
868 | { |
870 | slog (L_TRACE, _("%s: connection request (direct)"), conf->nodename, !!ictx, !!octx); |
869 | if (si.valid ()) |
|
|
870 | slog (L_DEBUG, _("%s: sending direct connection request to %s."), |
|
|
871 | conf->nodename, (const char *)si); |
871 | |
872 | |
872 | const sockinfo &dsi = forward_si (si); |
873 | const sockinfo &dsi = forward_si (si); |
873 | |
874 | |
874 | slow = slow || (dsi.prot & PROT_SLOW); |
875 | slow = slow || (dsi.prot & PROT_SLOW); |
875 | |
876 | |
… | |
… | |
915 | dnsv4_reset_connection (); |
916 | dnsv4_reset_connection (); |
916 | #endif |
917 | #endif |
917 | |
918 | |
918 | si.host = 0; |
919 | si.host = 0; |
919 | |
920 | |
920 | last_activity = 0; |
921 | last_activity = 0.; |
|
|
922 | //last_si_change = 0.; |
921 | retry_cnt = 0; |
923 | retry_cnt = 0; |
922 | |
924 | |
923 | rekey.stop (); |
925 | rekey.stop (); |
924 | keepalive.stop (); |
926 | keepalive.stop (); |
925 | establish_connection.stop (); |
927 | establish_connection.stop (); |
… | |
… | |
932 | send_reset (si); |
934 | send_reset (si); |
933 | |
935 | |
934 | reset_connection (); |
936 | reset_connection (); |
935 | } |
937 | } |
936 | |
938 | |
|
|
939 | // poor-man's rekeying |
937 | inline void |
940 | inline void |
938 | connection::rekey_cb (ev::timer &w, int revents) |
941 | connection::rekey_cb (ev::timer &w, int revents) |
939 | { |
942 | { |
940 | reset_connection (); |
943 | reset_connection (); |
941 | establish_connection (); |
944 | establish_connection (); |
… | |
… | |
996 | void |
999 | void |
997 | connection::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) |
1000 | connection::recv_vpn_packet (vpn_packet *pkt, const sockinfo &rsi) |
998 | { |
1001 | { |
999 | last_activity = ev_now (); |
1002 | last_activity = ev_now (); |
1000 | |
1003 | |
1001 | slog (L_NOISE, "<<%d received packet type %d from %d to %d", |
1004 | slog (L_NOISE, "%s >> received packet type %d from %d to %d.", |
1002 | conf->id, pkt->typ (), pkt->src (), pkt->dst ()); |
1005 | conf->nodename, pkt->typ (), pkt->src (), pkt->dst ()); |
1003 | |
1006 | |
1004 | if (connectmode == conf_node::C_DISABLED) |
1007 | if (connectmode == conf_node::C_DISABLED) |
1005 | return; |
1008 | return; |
1006 | |
1009 | |
1007 | switch (pkt->typ ()) |
1010 | switch (pkt->typ ()) |
1008 | { |
1011 | { |
1009 | case vpn_packet::PT_PING: |
1012 | case vpn_packet::PT_PING: |
|
|
1013 | slog (L_TRACE, "%s >> PT_PING", conf->nodename); |
|
|
1014 | |
1010 | // we send pings instead of auth packets after some retries, |
1015 | // we send pings instead of auth packets after some retries, |
1011 | // so reset the retry counter and establish a connection |
1016 | // so reset the retry counter and establish a connection |
1012 | // when we receive a ping. |
1017 | // when we receive a ping. |
1013 | if (!ictx) |
1018 | if (!ictx) |
1014 | { |
1019 | { |
1015 | if (auth_rate_limiter.can (rsi)) |
1020 | if (auth_rate_limiter.can (rsi)) |
1016 | send_auth_request (rsi, true); |
1021 | send_auth_request (rsi, true); |
1017 | } |
1022 | } |
1018 | else |
1023 | else |
|
|
1024 | // we would love to change thre socket address here, but ping's aren't |
|
|
1025 | // authenticated, so we best ignore it. |
1019 | send_ping (rsi, 1); // pong |
1026 | send_ping (rsi, 1); // pong |
1020 | |
1027 | |
1021 | break; |
1028 | break; |
1022 | |
1029 | |
1023 | case vpn_packet::PT_PONG: |
1030 | case vpn_packet::PT_PONG: |
|
|
1031 | slog (L_TRACE, "%s >> PT_PONG", conf->nodename); |
1024 | break; |
1032 | break; |
1025 | |
1033 | |
1026 | case vpn_packet::PT_RESET: |
1034 | case vpn_packet::PT_RESET: |
1027 | { |
1035 | { |
1028 | reset_connection (); |
1036 | reset_connection (); |
1029 | |
1037 | |
1030 | config_packet *p = (config_packet *) pkt; |
1038 | config_packet *p = (config_packet *) pkt; |
1031 | |
1039 | |
1032 | if (!p->chk_config ()) |
1040 | if (!p->chk_config ()) |
1033 | { |
1041 | { |
1034 | slog (L_WARN, _("%s(%s): protocol mismatch, disabling node"), |
1042 | slog (L_WARN, _("%s(%s): protocol mismatch, disabling node."), |
1035 | conf->nodename, (const char *)rsi); |
1043 | conf->nodename, (const char *)rsi); |
1036 | connectmode = conf_node::C_DISABLED; |
1044 | connectmode = conf_node::C_DISABLED; |
1037 | } |
1045 | } |
1038 | else if (connectmode == conf_node::C_ALWAYS) |
1046 | else if (connectmode == conf_node::C_ALWAYS) |
1039 | establish_connection (); |
1047 | establish_connection (); |
… | |
… | |
1043 | case vpn_packet::PT_AUTH_REQ: |
1051 | case vpn_packet::PT_AUTH_REQ: |
1044 | if (auth_rate_limiter.can (rsi)) |
1052 | if (auth_rate_limiter.can (rsi)) |
1045 | { |
1053 | { |
1046 | auth_req_packet *p = (auth_req_packet *) pkt; |
1054 | auth_req_packet *p = (auth_req_packet *) pkt; |
1047 | |
1055 | |
1048 | slog (L_TRACE, "<<%d PT_AUTH_REQ(%d)", conf->id, p->initiate); |
1056 | slog (L_TRACE, "%s << PT_AUTH_REQ(%s)", conf->nodename, p->initiate ? "initiate" : "reply"); |
1049 | |
1057 | |
1050 | if (p->chk_config () && !strncmp (p->magic, MAGIC, 8)) |
1058 | if (p->chk_config () && !strncmp (p->magic, MAGIC, 8)) |
1051 | { |
1059 | { |
1052 | if (p->prot_minor != PROTOCOL_MINOR) |
1060 | if (p->prot_minor != PROTOCOL_MINOR) |
1053 | slog (L_INFO, _("%s(%s): protocol minor version mismatch: ours is %d, %s's is %d."), |
1061 | slog (L_INFO, _("%s(%s): protocol minor version mismatch: ours is %d, %s's is %d."), |
… | |
… | |
1081 | |
1089 | |
1082 | break; |
1090 | break; |
1083 | } |
1091 | } |
1084 | } |
1092 | } |
1085 | else |
1093 | else |
1086 | slog (L_WARN, _("%s(%s): protocol mismatch"), |
1094 | slog (L_WARN, _("%s(%s): protocol mismatch."), |
1087 | conf->nodename, (const char *)rsi); |
1095 | conf->nodename, (const char *)rsi); |
1088 | |
1096 | |
1089 | send_reset (rsi); |
1097 | send_reset (rsi); |
1090 | } |
1098 | } |
1091 | |
1099 | |
1092 | break; |
1100 | break; |
1093 | |
1101 | |
1094 | case vpn_packet::PT_AUTH_RES: |
1102 | case vpn_packet::PT_AUTH_RES: |
1095 | { |
1103 | { |
1096 | auth_res_packet *p = (auth_res_packet *) pkt; |
1104 | auth_res_packet *p = (auth_res_packet *)pkt; |
1097 | |
1105 | |
1098 | slog (L_TRACE, "<<%d PT_AUTH_RES", conf->id); |
1106 | slog (L_TRACE, "%s << PT_AUTH_RES", conf->nodename); |
1099 | |
1107 | |
1100 | if (p->chk_config ()) |
1108 | if (p->chk_config ()) |
1101 | { |
1109 | { |
1102 | if (p->prot_minor != PROTOCOL_MINOR) |
1110 | if (p->prot_minor != PROTOCOL_MINOR) |
1103 | slog (L_INFO, _("%s(%s): protocol minor version mismatch: ours is %d, %s's is %d."), |
1111 | slog (L_INFO, _("%s(%s): protocol minor version mismatch: ours is %d, %s's is %d."), |
… | |
… | |
1106 | |
1114 | |
1107 | rsachallenge chg; |
1115 | rsachallenge chg; |
1108 | |
1116 | |
1109 | if (!rsa_cache.find (p->id, chg)) |
1117 | if (!rsa_cache.find (p->id, chg)) |
1110 | { |
1118 | { |
1111 | slog (L_ERR, _("%s(%s): unrequested auth response ignored"), |
1119 | slog (L_ERR, _("%s(%s): unrequested auth response, ignoring."), |
1112 | conf->nodename, (const char *)rsi); |
1120 | conf->nodename, (const char *)rsi); |
1113 | break; |
1121 | break; |
1114 | } |
1122 | } |
1115 | else |
1123 | else |
1116 | { |
1124 | { |
1117 | crypto_ctx *cctx = new crypto_ctx (chg, 0); |
1125 | crypto_ctx *cctx = new crypto_ctx (chg, 0); |
1118 | |
1126 | |
1119 | if (!p->hmac_chk (cctx)) |
1127 | if (!p->hmac_chk (cctx)) |
1120 | { |
1128 | { |
1121 | slog (L_ERR, _("%s(%s): hmac authentication error on auth response, received invalid packet\n" |
1129 | slog (L_ERR, _("%s(%s): hmac authentication error on auth response, received invalid packet\n" |
1122 | "could be an attack, or just corruption or a synchronization error"), |
1130 | "could be an attack, or just corruption or a synchronization error."), |
1123 | conf->nodename, (const char *)rsi); |
1131 | conf->nodename, (const char *)rsi); |
1124 | break; |
1132 | break; |
1125 | } |
1133 | } |
1126 | else |
1134 | else |
1127 | { |
1135 | { |
… | |
… | |
1138 | iseqno.reset (ntohl (*(u32 *)&chg[CHG_SEQNO]) & 0x7fffffff); // at least 2**31 sequence numbers are valid |
1146 | iseqno.reset (ntohl (*(u32 *)&chg[CHG_SEQNO]) & 0x7fffffff); // at least 2**31 sequence numbers are valid |
1139 | |
1147 | |
1140 | si = rsi; |
1148 | si = rsi; |
1141 | protocol = rsi.prot; |
1149 | protocol = rsi.prot; |
1142 | |
1150 | |
|
|
1151 | slog (L_INFO, _("%s(%s): connection established (%s), protocol version %d.%d."), |
|
|
1152 | conf->nodename, (const char *)rsi, |
|
|
1153 | is_direct ? "direct" : "routed", |
|
|
1154 | p->prot_major, p->prot_minor); |
|
|
1155 | |
1143 | connection_established (); |
1156 | connection_established (); |
1144 | |
|
|
1145 | slog (L_INFO, _("%s(%s): connection established, protocol version %d.%d"), |
|
|
1146 | conf->nodename, (const char *)rsi, |
|
|
1147 | p->prot_major, p->prot_minor); |
|
|
1148 | |
1157 | |
1149 | if (::conf.script_node_up) |
1158 | if (::conf.script_node_up) |
1150 | { |
1159 | { |
1151 | run_script_cb *cb = new run_script_cb; |
1160 | run_script_cb *cb = new run_script_cb; |
1152 | cb->set<connection, &connection::script_node_up> (this); |
1161 | cb->set<connection, &connection::script_node_up> (this); |
… | |
… | |
1154 | } |
1163 | } |
1155 | |
1164 | |
1156 | break; |
1165 | break; |
1157 | } |
1166 | } |
1158 | else |
1167 | else |
1159 | slog (L_ERR, _("%s(%s): sent and received challenge do not match"), |
1168 | slog (L_ERR, _("%s(%s): sent and received challenge do not match."), |
1160 | conf->nodename, (const char *)rsi); |
1169 | conf->nodename, (const char *)rsi); |
1161 | } |
1170 | } |
1162 | |
1171 | |
1163 | delete cctx; |
1172 | delete cctx; |
1164 | } |
1173 | } |
… | |
… | |
1180 | { |
1189 | { |
1181 | vpndata_packet *p = (vpndata_packet *)pkt; |
1190 | vpndata_packet *p = (vpndata_packet *)pkt; |
1182 | |
1191 | |
1183 | if (!p->hmac_chk (ictx)) |
1192 | if (!p->hmac_chk (ictx)) |
1184 | slog (L_ERR, _("%s(%s): hmac authentication error, received invalid packet\n" |
1193 | slog (L_ERR, _("%s(%s): hmac authentication error, received invalid packet\n" |
1185 | "could be an attack, or just corruption or a synchronization error"), |
1194 | "could be an attack, or just corruption or a synchronization error."), |
1186 | conf->nodename, (const char *)rsi); |
1195 | conf->nodename, (const char *)rsi); |
1187 | else |
1196 | else |
1188 | { |
1197 | { |
1189 | u32 seqno; |
1198 | u32 seqno; |
1190 | tap_packet *d = p->unpack (this, seqno); |
1199 | tap_packet *d = p->unpack (this, seqno); |
|
|
1200 | int seqclass = iseqno.seqno_classify (seqno); |
1191 | |
1201 | |
1192 | if (iseqno.recv_ok (seqno)) |
1202 | if (seqclass == 0) // ok |
1193 | { |
1203 | { |
1194 | vpn->tap->send (d); |
1204 | vpn->tap->send (d); |
1195 | |
1205 | |
1196 | if (si != rsi) |
1206 | if (si != rsi) |
1197 | { |
1207 | { |
1198 | // fast re-sync on source address changes, useful especially for tcp/ip |
1208 | // fast re-sync on source address changes, useful especially for tcp/ip |
|
|
1209 | //if (last_si_change < ev_now () + 5.) |
1199 | si = rsi; |
1210 | // { |
1200 | |
|
|
1201 | slog (L_INFO, _("%s(%s): socket address changed to %s"), |
1211 | slog (L_INFO, _("%s(%s): changing socket address to %s."), |
1202 | conf->nodename, (const char *)si, (const char *)rsi); |
1212 | conf->nodename, (const char *)si, (const char *)rsi); |
|
|
1213 | |
|
|
1214 | si = rsi; |
|
|
1215 | // } |
|
|
1216 | //else |
|
|
1217 | // slog (L_INFO, _("%s(%s): accepted packet from %s, not (yet) redirecting traffic."), |
|
|
1218 | // conf->nodename, (const char *)si, (const char *)rsi); |
1203 | } |
1219 | } |
|
|
1220 | } |
|
|
1221 | else if (seqclass == 1) // far history |
|
|
1222 | slog (L_ERR, _("received very old packet (received %08lx, expected %08lx). " |
|
|
1223 | "possible replay attack, or just packet duplication/delay, ignoring."), seqno, iseqno.seq + 1); |
|
|
1224 | else if (seqclass == 2) // in-window duplicate, happens often on wireless |
|
|
1225 | slog (L_DEBUG, _("received recent duplicated packet (received %08lx, expected %08lx). " |
|
|
1226 | "possible replay attack, or just packet duplication, ignoring."), seqno, iseqno.seq + 1); |
|
|
1227 | else if (seqclass == 3) // reset |
|
|
1228 | { |
|
|
1229 | slog (L_ERR, _("received out-of-sync (far future) packet (received %08lx, expected %08lx). " |
|
|
1230 | "probably just massive packet loss, sending reset."), seqno, iseqno.seq + 1); |
|
|
1231 | send_reset (rsi); |
1204 | } |
1232 | } |
1205 | |
1233 | |
1206 | delete d; |
1234 | delete d; |
1207 | break; |
1235 | break; |
1208 | } |
1236 | } |
… | |
… | |
1219 | if (p->id > 0 && p->id <= vpn->conns.size ()) |
1247 | if (p->id > 0 && p->id <= vpn->conns.size ()) |
1220 | { |
1248 | { |
1221 | connection *c = vpn->conns[p->id - 1]; |
1249 | connection *c = vpn->conns[p->id - 1]; |
1222 | conf->protocols = p->protocols; |
1250 | conf->protocols = p->protocols; |
1223 | |
1251 | |
1224 | slog (L_TRACE, "<<%d PT_CONNECT_REQ(%d) [%d]", |
1252 | slog (L_TRACE, "%s << PT_CONNECT_REQ(%s) [%d]", |
1225 | conf->id, p->id, c->ictx && c->octx); |
1253 | conf->nodename, vpn->conns[p->id - 1]->conf->nodename, c->ictx && c->octx); |
1226 | |
1254 | |
1227 | if (c->ictx && c->octx) |
1255 | if (c->ictx && c->octx) |
1228 | { |
1256 | { |
1229 | // send connect_info packets to both sides, in case one is |
1257 | // send connect_info packets to both sides, in case one is |
1230 | // behind a nat firewall (or both ;) |
1258 | // behind a nat firewall (or both ;) |
… | |
… | |
1253 | |
1281 | |
1254 | c->conf->protocols = p->protocols; |
1282 | c->conf->protocols = p->protocols; |
1255 | protocol = best_protocol (c->conf->protocols & THISNODE->protocols & p->si.supported_protocols (c->conf)); |
1283 | protocol = best_protocol (c->conf->protocols & THISNODE->protocols & p->si.supported_protocols (c->conf)); |
1256 | p->si.upgrade_protocol (protocol, c->conf); |
1284 | p->si.upgrade_protocol (protocol, c->conf); |
1257 | |
1285 | |
1258 | slog (L_TRACE, "<<%d PT_CONNECT_INFO(%d,%s) (%d)", |
1286 | slog (L_TRACE, "%s << PT_CONNECT_INFO(%s,%s) [%d]", |
|
|
1287 | conf->nodename, vpn->conns[p->id - 1]->conf->nodename, |
1259 | conf->id, p->id, (const char *)p->si, !c->ictx && !c->octx); |
1288 | (const char *)p->si, !c->ictx && !c->octx); |
1260 | |
1289 | |
1261 | const sockinfo &dsi = forward_si (p->si); |
1290 | const sockinfo &dsi = forward_si (p->si); |
1262 | |
1291 | |
1263 | if (dsi.valid ()) |
1292 | if (dsi.valid ()) |
1264 | c->send_auth_request (dsi, true); |
1293 | c->send_auth_request (dsi, true); |
… | |
… | |
1303 | |
1332 | |
1304 | void connection::send_connect_request (int id) |
1333 | void connection::send_connect_request (int id) |
1305 | { |
1334 | { |
1306 | connect_req_packet *p = new connect_req_packet (conf->id, id, conf->protocols); |
1335 | connect_req_packet *p = new connect_req_packet (conf->id, id, conf->protocols); |
1307 | |
1336 | |
1308 | slog (L_TRACE, ">>%d PT_CONNECT_REQ(%d)", conf->id, id); |
1337 | slog (L_TRACE, "%s >> PT_CONNECT_REQ(%s)", |
|
|
1338 | conf->nodename, vpn->conns[id - 1]->conf->nodename); |
1309 | p->hmac_set (octx); |
1339 | p->hmac_set (octx); |
1310 | send_vpn_packet (p, si); |
1340 | send_vpn_packet (p, si); |
1311 | |
1341 | |
1312 | delete p; |
1342 | delete p; |
1313 | } |
1343 | } |