@@ -5129,6 +5129,12 @@ static void RemoveStaleSessions(void)
5129
5129
}
5130
5130
}
5131
5131
5132
+ void ssl_RemoveStaleSessions (void )
5133
+ {
5134
+ LOCK_SESSION ();
5135
+ RemoveStaleSessions ();
5136
+ UNLOCK_SESSION ();
5137
+ }
5132
5138
5133
5139
/* Create a new Sniffer Session */
5134
5140
static SnifferSession * CreateSession (IpInfo * ipInfo , TcpInfo * tcpInfo ,
@@ -7620,6 +7626,106 @@ int ssl_LoadSecretsFromKeyLogFile(const char* keylogfile, char* error)
7620
7626
#endif /* WOLFSSL_SNIFFER_KEYLOGFILE */
7621
7627
7622
7628
7629
+ /*
7630
+ * Removes a session from the SessionTable based on client/server IP & ports
7631
+ * Returns 0 if a session was found and freed, -1 otherwise
7632
+ */
7633
+ int ssl_RemoveSession (const char * clientIp , int clientPort ,
7634
+ const char * serverIp , int serverPort ,
7635
+ char * error )
7636
+ {
7637
+ IpAddrInfo clientAddr ;
7638
+ IpAddrInfo serverAddr ;
7639
+ IpInfo ipInfo ;
7640
+ TcpInfo tcpInfo ;
7641
+ SnifferSession * session ;
7642
+ int ret = -1 ; /* Default to not found */
7643
+ word32 row ;
7644
+
7645
+ if (clientIp == NULL || serverIp == NULL) {
7646
+ SetError (BAD_IPVER_STR , error , NULL , 0 );
7647
+ return ret ;
7648
+ }
7649
+
7650
+ /* Set up client IP address */
7651
+ clientAddr .version = IPV4 ;
7652
+ clientAddr .ip4 = XINET_ADDR (clientIp );
7653
+ if (clientAddr .ip4 == XINADDR_NONE ) {
7654
+ #ifdef FUSION_RTOS
7655
+ if (XINET_PTON (AF_INET6 , clientIp , clientAddr .ip6 ,
7656
+ sizeof (clientAddr .ip4 )) == 1 )
7657
+ #else
7658
+ if (XINET_PTON (AF_INET6 , clientIp , clientAddr .ip6 ) == 1 )
7659
+ #endif
7660
+ {
7661
+ clientAddr .version = IPV6 ;
7662
+ }
7663
+ else {
7664
+ SetError (BAD_IPVER_STR , error , NULL , 0 );
7665
+ return ret ;
7666
+ }
7667
+ }
7668
+
7669
+ /* Set up server IP address */
7670
+ serverAddr .version = IPV4 ;
7671
+ serverAddr .ip4 = XINET_ADDR (serverIp );
7672
+ if (serverAddr .ip4 == XINADDR_NONE ) {
7673
+ #ifdef FUSION_RTOS
7674
+ if (XINET_PTON (AF_INET6 , serverIp , serverAddr .ip6 ,
7675
+ sizeof (serverAddr .ip4 )) == 1 )
7676
+ #else
7677
+ if (XINET_PTON (AF_INET6 , serverIp , serverAddr .ip6 ) == 1 )
7678
+ #endif
7679
+ {
7680
+ serverAddr .version = IPV6 ;
7681
+ }
7682
+ else {
7683
+ SetError (BAD_IPVER_STR , error , NULL , 0 );
7684
+ return ret ;
7685
+ }
7686
+ }
7687
+
7688
+ XMEMSET (& ipInfo , 0 , sizeof (ipInfo ));
7689
+ XMEMSET (& tcpInfo , 0 , sizeof (tcpInfo ));
7690
+
7691
+ /* Set up client->server direction */
7692
+ ipInfo .src = clientAddr ;
7693
+ ipInfo .dst = serverAddr ;
7694
+ tcpInfo .srcPort = clientPort ;
7695
+ tcpInfo .dstPort = serverPort ;
7696
+
7697
+ /* Calculate the hash row for this session */
7698
+ row = SessionHash (& ipInfo , & tcpInfo );
7699
+
7700
+ LOCK_SESSION ();
7701
+
7702
+ /* Search only the specific row in the session table */
7703
+ session = SessionTable [row ];
7704
+
7705
+ while (session ) {
7706
+ SnifferSession * next = session -> next ;
7707
+
7708
+ /* Check if this session matches the specified client/server IP/port */
7709
+ if (MatchAddr (session -> client , clientAddr ) &&
7710
+ MatchAddr (session -> server , serverAddr ) &&
7711
+ session -> cliPort == clientPort &&
7712
+ session -> srvPort == serverPort ) {
7713
+
7714
+ /* Use RemoveSession to remove and free the session */
7715
+ RemoveSession (session , NULL , NULL , row );
7716
+ ret = 0 ; /* Session found and freed */
7717
+ break ;
7718
+ }
7719
+
7720
+ session = next ;
7721
+ }
7722
+
7723
+ UNLOCK_SESSION ();
7724
+
7725
+ return ret ;
7726
+ }
7727
+
7728
+
7623
7729
#undef ERROR_OUT
7624
7730
7625
7731
#endif /* WOLFSSL_SNIFFER */
0 commit comments