1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-22 17:39:53 +03:00

Cedar/Proto_OpenVPN.c: don't release data channel if it's not established, improve logic and debug messages

This commit is contained in:
Davide Beatrici 2018-11-19 21:30:42 +01:00
parent 264760aaf5
commit 03f80edfcd

View File

@ -509,29 +509,28 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
return; return;
} }
if (recv_packet->OpCode != OPENVPN_P_DATA_V1 && recv_packet->MySessionId != 0) c = se->Channels[recv_packet->KeyId];
{
Debug("RECV PACKET: %u %I64u\n", recv_packet->KeyId, recv_packet->MySessionId);
}
if (recv_packet->OpCode != OPENVPN_P_DATA_V1)
{
Debug(" PKT %u %u\n", recv_packet->OpCode, recv_packet->KeyId);
}
if (recv_packet->OpCode != OPENVPN_P_DATA_V1) if (recv_packet->OpCode != OPENVPN_P_DATA_V1)
{ {
// Control packet // Control packet
Debug("OvsProceccRecvPacket(): Received control packet. PacketId: %u, OpCode: %u, KeyId: %u, MySessionId: %I64u\n",
recv_packet->PacketId, recv_packet->OpCode, recv_packet->KeyId, recv_packet->MySessionId);
if (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2 || if (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2 ||
recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1) recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1)
{ {
// Connection request packet // Connection request packet
if (se->Channels[recv_packet->KeyId] != NULL) if (c != NULL && c->Status == OPENVPN_CHANNEL_STATUS_ESTABLISHED)
{ {
// Release when there is a channel data already // If there's already an established data channel, release it
OvsFreeChannel(se->Channels[recv_packet->KeyId]); OvsFreeChannel(se->Channels[recv_packet->KeyId]);
se->Channels[recv_packet->KeyId] = NULL; c = se->Channels[recv_packet->KeyId] = NULL;
Debug("OvsProceccRecvPacket(): Released established data channel: %u\n", recv_packet->KeyId);
} }
if (c == NULL)
{
// Create a new channel // Create a new channel
c = OvsNewChannel(se, recv_packet->KeyId); c = OvsNewChannel(se, recv_packet->KeyId);
if (se->ClientSessionId == 0) if (se->ClientSessionId == 0)
@ -539,9 +538,10 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
se->ClientSessionId = recv_packet->MySessionId; se->ClientSessionId = recv_packet->MySessionId;
} }
se->Channels[recv_packet->KeyId] = c; se->Channels[recv_packet->KeyId] = c;
Debug("OpenVPN New Channel :%u\n", recv_packet->KeyId); Debug("OvsProceccRecvPacket(): Created a new channel: %u\n", recv_packet->KeyId);
OvsLog(s, se, c, "LO_NEW_CHANNEL"); OvsLog(s, se, c, "LO_NEW_CHANNEL");
} }
}
/* else if (recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1) /* else if (recv_packet->OpCode == OPENVPN_P_CONTROL_SOFT_RESET_V1)
{ {
// Response to soft reset request packet // Response to soft reset request packet
@ -553,16 +553,8 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
OvsSendPacketNow(s, se, p); OvsSendPacketNow(s, se, p);
OvsFreePacket(p); OvsFreePacket(p);
}*/
else
{
// Packet other than the connection request
if (se->Channels[recv_packet->KeyId] != NULL)
{
c = se->Channels[recv_packet->KeyId];
} }
} */
if (c != NULL) if (c != NULL)
{ {
// Delete the send packet list by looking the packet ID in the ACK list of arrived packet // Delete the send packet list by looking the packet ID in the ACK list of arrived packet
@ -572,7 +564,6 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
{ {
// Add the Packet ID of arrived packet to the list // Add the Packet ID of arrived packet to the list
InsertIntDistinct(c->AckReplyList, recv_packet->PacketId); InsertIntDistinct(c->AckReplyList, recv_packet->PacketId);
Debug("Recv Packet ID (c=%u): %u\n", c->KeyId, recv_packet->PacketId);
if ((recv_packet->PacketId > c->MaxRecvPacketId) if ((recv_packet->PacketId > c->MaxRecvPacketId)
|| (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2) || (recv_packet->OpCode == OPENVPN_P_CONTROL_HARD_RESET_CLIENT_V2)
@ -589,10 +580,7 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
else else
{ {
// Data packet // Data packet
if (se->Channels[recv_packet->KeyId] != NULL) if (c != NULL && c->Status == OPENVPN_CHANNEL_STATUS_ESTABLISHED)
{
OPENVPN_CHANNEL *c = se->Channels[recv_packet->KeyId];
if (c->Status == OPENVPN_CHANNEL_STATUS_ESTABLISHED)
{ {
UINT size; UINT size;
UCHAR *data = s->TmpBuf; UCHAR *data = s->TmpBuf;
@ -635,7 +623,6 @@ void OvsProceccRecvPacket(OPENVPN_SERVER *s, UDPPACKET *p, UINT protocol)
} }
} }
} }
}
OvsFreePacket(recv_packet); OvsFreePacket(recv_packet);
} }