ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.C
(Generate patch)

Comparing gvpe/src/connection.C (file contents):
Revision 1.55 by pcg, Tue Apr 26 00:55:56 2005 UTC vs.
Revision 1.59 by pcg, Mon Dec 5 12:58:09 2005 UTC

19 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20*/ 20*/
21 21
22#include "config.h" 22#include "config.h"
23 23
24#include <cassert>
25
26#include <list> 24#include <list>
27 25
28#include <openssl/rand.h> 26#include <openssl/rand.h>
29#include <openssl/evp.h> 27#include <openssl/evp.h>
30#include <openssl/rsa.h> 28#include <openssl/rsa.h>
465#if ENABLE_COMPRESSION 463#if ENABLE_COMPRESSION
466 f |= FEATURE_COMPRESSION; 464 f |= FEATURE_COMPRESSION;
467#endif 465#endif
468#if ENABLE_ROHC 466#if ENABLE_ROHC
469 f |= FEATURE_ROHC; 467 f |= FEATURE_ROHC;
468#endif
469#if ENABLE_BRIDGING
470 f |= FEATURE_BRIDGING;
470#endif 471#endif
471 return f; 472 return f;
472 } 473 }
473}; 474};
474 475
625 // mask out protocols we cannot establish 626 // mask out protocols we cannot establish
626 if (!conf->udp_port) protocol &= ~PROT_UDPv4; 627 if (!conf->udp_port) protocol &= ~PROT_UDPv4;
627 if (!conf->tcp_port) protocol &= ~PROT_TCPv4; 628 if (!conf->tcp_port) protocol &= ~PROT_TCPv4;
628 if (!conf->dns_port) protocol &= ~PROT_DNSv4; 629 if (!conf->dns_port) protocol &= ~PROT_DNSv4;
629 630
631 if (protocol
632 && (!conf->can_direct (THISNODE)
633 || !THISNODE->can_direct (conf)))
634 {
635 slog (L_DEBUG, _("%s: direct connection denied"), conf->nodename);
636 protocol = 0;
637 }
638
630 si.set (conf, protocol); 639 si.set (conf, protocol);
631} 640}
632 641
633// ensure sockinfo is valid, forward if necessary 642// ensure sockinfo is valid, forward if necessary
634const sockinfo & 643const sockinfo &
719} 728}
720 729
721void 730void
722connection::send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols) 731connection::send_connect_info (int rid, const sockinfo &rsi, u8 rprotocols)
723{ 732{
724 slog (L_TRACE, ">>%d PT_CONNECT_INFO(%d,%s)\n", 733 slog (L_TRACE, ">>%d PT_CONNECT_INFO(%d,%s)",
725 conf->id, rid, (const char *)rsi); 734 conf->id, rid, (const char *)rsi);
726 735
727 connect_info_packet *r = new connect_info_packet (conf->id, rid, rsi, rprotocols); 736 connect_info_packet *r = new connect_info_packet (conf->id, rid, rsi, rprotocols);
728 737
729 r->hmac_set (octx); 738 r->hmac_set (octx);
848{ 857{
849 if (ictx && octx) 858 if (ictx && octx)
850 send_data_packet (pkt); 859 send_data_packet (pkt);
851 else 860 else
852 { 861 {
853 if (!broadcast)//DDDD 862 if (!broadcast)
854 data_queue.put (new tap_packet (*pkt)); 863 data_queue.put (new tap_packet (*pkt));
855 864
856 establish_connection (); 865 establish_connection ();
857 } 866 }
858} 867}
1063 { 1072 {
1064 vpn->tap->send (d); 1073 vpn->tap->send (d);
1065 1074
1066 if (si != rsi) 1075 if (si != rsi)
1067 { 1076 {
1068 // fast re-sync on connection changes, useful especially for tcp/ip 1077 // fast re-sync on source address changes, useful especially for tcp/ip
1069 si = rsi; 1078 si = rsi;
1070 1079
1071 slog (L_INFO, _("%s(%s): socket address changed to %s"), 1080 slog (L_INFO, _("%s(%s): socket address changed to %s"),
1072 conf->nodename, (const char *)si, (const char *)rsi); 1081 conf->nodename, (const char *)si, (const char *)rsi);
1073 } 1082 }
1084 case vpn_packet::PT_CONNECT_REQ: 1093 case vpn_packet::PT_CONNECT_REQ:
1085 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx)) 1094 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx))
1086 { 1095 {
1087 connect_req_packet *p = (connect_req_packet *) pkt; 1096 connect_req_packet *p = (connect_req_packet *) pkt;
1088 1097
1089 assert (p->id > 0 && p->id <= vpn->conns.size ()); // hmac-auth does not mean we accept anything 1098 if (p->id > 0 && p->id <= vpn->conns.size ())
1090 connection *c = vpn->conns[p->id - 1];
1091 conf->protocols = p->protocols;
1092
1093 slog (L_TRACE, "<<%d PT_CONNECT_REQ(%d) [%d]\n",
1094 conf->id, p->id, c->ictx && c->octx);
1095
1096 if (c->ictx && c->octx)
1097 { 1099 {
1100 connection *c = vpn->conns[p->id - 1];
1101 conf->protocols = p->protocols;
1102
1103 slog (L_TRACE, "<<%d PT_CONNECT_REQ(%d) [%d]",
1104 conf->id, p->id, c->ictx && c->octx);
1105
1106 if (c->ictx && c->octx)
1107 {
1098 // send connect_info packets to both sides, in case one is 1108 // send connect_info packets to both sides, in case one is
1099 // behind a nat firewall (or both ;) 1109 // behind a nat firewall (or both ;)
1100 c->send_connect_info (conf->id, si, conf->protocols); 1110 c->send_connect_info (conf->id, si, conf->protocols);
1101 send_connect_info (c->conf->id, c->si, c->conf->protocols); 1111 send_connect_info (c->conf->id, c->si, c->conf->protocols);
1112 }
1113 else
1114 c->establish_connection ();
1102 } 1115 }
1103 else 1116 else
1104 c->establish_connection (); 1117 slog (L_WARN,
1118 _("received authenticated connection request from unknown node #%d, config file mismatch?"),
1119 p->id);
1105 } 1120 }
1106 1121
1107 break; 1122 break;
1108 1123
1109 case vpn_packet::PT_CONNECT_INFO: 1124 case vpn_packet::PT_CONNECT_INFO:
1110 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx)) 1125 if (ictx && octx && rsi == si && pkt->hmac_chk (ictx))
1111 { 1126 {
1112 connect_info_packet *p = (connect_info_packet *)pkt; 1127 connect_info_packet *p = (connect_info_packet *)pkt;
1113 1128
1114 if (p->id > 0 && p->id <= vpn->conns.size ()) // hmac-auth does not mean we accept anything 1129 if (p->id > 0 && p->id <= vpn->conns.size ())
1115 { 1130 {
1116 connection *c = vpn->conns[p->id - 1]; 1131 connection *c = vpn->conns[p->id - 1];
1117 1132
1118 c->conf->protocols = p->protocols; 1133 c->conf->protocols = p->protocols;
1119 protocol = best_protocol (c->conf->protocols & THISNODE->protocols & p->si.supported_protocols (c->conf)); 1134 protocol = best_protocol (c->conf->protocols & THISNODE->protocols & p->si.supported_protocols (c->conf));
1125 const sockinfo &dsi = forward_si (p->si); 1140 const sockinfo &dsi = forward_si (p->si);
1126 1141
1127 if (dsi.valid ()) 1142 if (dsi.valid ())
1128 c->send_auth_request (dsi, true); 1143 c->send_auth_request (dsi, true);
1129 } 1144 }
1145 else
1146 slog (L_WARN,
1147 _("received authenticated connection request from unknown node #%d, config file mismatch?"),
1148 p->id);
1130 } 1149 }
1131 1150
1132 break; 1151 break;
1133 1152
1134 default: 1153 default:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines