mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Update ssl_RemoveSession to use SessionHash for direct row calculation
Co-Authored-By: lealem@wolfssl.com <lealem@wolfssl.com>
This commit is contained in:
@@ -7630,9 +7630,11 @@ int ssl_RemoveSession(const char* clientIp, int clientPort,
|
|||||||
{
|
{
|
||||||
IpAddrInfo clientAddr = {0};
|
IpAddrInfo clientAddr = {0};
|
||||||
IpAddrInfo serverAddr = {0};
|
IpAddrInfo serverAddr = {0};
|
||||||
|
IpInfo ipInfo;
|
||||||
|
TcpInfo tcpInfo;
|
||||||
SnifferSession* session;
|
SnifferSession* session;
|
||||||
int ret = -1; /* Default to not found */
|
int ret = -1; /* Default to not found */
|
||||||
word32 i;
|
word32 row;
|
||||||
|
|
||||||
if (clientIp == NULL || serverIp == NULL) {
|
if (clientIp == NULL || serverIp == NULL) {
|
||||||
SetError(BAD_IPVER_STR, error, NULL, 0);
|
SetError(BAD_IPVER_STR, error, NULL, 0);
|
||||||
@@ -7679,33 +7681,40 @@ int ssl_RemoveSession(const char* clientIp, int clientPort,
|
|||||||
|
|
||||||
/* No need to ensure IP versions match - client could use IPv4 while server uses IPv6 */
|
/* No need to ensure IP versions match - client could use IPv4 while server uses IPv6 */
|
||||||
|
|
||||||
|
/* Set up IpInfo and TcpInfo for SessionHash */
|
||||||
|
XMEMSET(&ipInfo, 0, sizeof(ipInfo));
|
||||||
|
XMEMSET(&tcpInfo, 0, sizeof(tcpInfo));
|
||||||
|
|
||||||
|
/* Set up client->server direction */
|
||||||
|
ipInfo.src = clientAddr;
|
||||||
|
ipInfo.dst = serverAddr;
|
||||||
|
tcpInfo.srcPort = clientPort;
|
||||||
|
tcpInfo.dstPort = serverPort;
|
||||||
|
|
||||||
|
/* Calculate the hash row for this session */
|
||||||
|
row = SessionHash(&ipInfo, &tcpInfo);
|
||||||
|
|
||||||
LOCK_SESSION();
|
LOCK_SESSION();
|
||||||
|
|
||||||
/* Search through all rows in the session table */
|
/* Search only the specific row in the session table */
|
||||||
for (i = 0; i < HASH_SIZE; i++) {
|
session = SessionTable[row];
|
||||||
session = SessionTable[i];
|
|
||||||
|
|
||||||
while (session) {
|
while (session) {
|
||||||
SnifferSession* next = session->next;
|
SnifferSession* next = session->next;
|
||||||
|
|
||||||
/* Check if this session matches the specified client/server IP/port */
|
/* Check if this session matches the specified client/server IP/port */
|
||||||
if (MatchAddr(session->client, clientAddr) &&
|
if (MatchAddr(session->client, clientAddr) &&
|
||||||
MatchAddr(session->server, serverAddr) &&
|
MatchAddr(session->server, serverAddr) &&
|
||||||
session->cliPort == clientPort &&
|
session->cliPort == clientPort &&
|
||||||
session->srvPort == serverPort) {
|
session->srvPort == serverPort) {
|
||||||
|
|
||||||
/* Use RemoveSession to remove and free the session */
|
/* Use RemoveSession to remove and free the session */
|
||||||
RemoveSession(session, NULL, NULL, i);
|
RemoveSession(session, NULL, NULL, row);
|
||||||
ret = 0; /* Session found and freed */
|
ret = 0; /* Session found and freed */
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
session = next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0) {
|
session = next;
|
||||||
break; /* Session found and freed, exit the loop */
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UNLOCK_SESSION();
|
UNLOCK_SESSION();
|
||||||
|
Reference in New Issue
Block a user