FreeRTOS-Plus/ThirdParty/WolfSSL-FIPS-Ready/src/sniffer.c
/* See if input on the reassembly list is ready for consuming */
/* returns 1 for TRUE, 0 for FALSE */
See if input on the reassembly list is ready for consuming
returns 1 for TRUE, 0 for FALSE
See if input on the reassembly list is ready for consuming returns 1 for TRUE 0 for FALSE
static int HaveMoreInput(SnifferSession* session, const byte** sslFrame,
                         int* sslBytes, const byte** end, char* error)
{
    int            moreInput = 0;
    PacketBuffer** front = (session->flags.side == WOLFSSL_SERVER_END) ?
                      &session->cliReassemblyList : &session->srvReassemblyList;
    word32*        expected = (session->flags.side == WOLFSSL_SERVER_END) ?
                                  &session->cliExpected : &session->srvExpected;
    word32*          length = (session->flags.side == WOLFSSL_SERVER_END) ?
                               &session->sslServer->buffers.inputBuffer.length :
                               &session->sslClient->buffers.inputBuffer.length;
    byte**         myBuffer = (session->flags.side == WOLFSSL_SERVER_END) ?
                               &session->sslServer->buffers.inputBuffer.buffer :
                               &session->sslClient->buffers.inputBuffer.buffer;
    word32*      bufferSize = (session->flags.side == WOLFSSL_SERVER_END) ?
                           &session->sslServer->buffers.inputBuffer.bufferSize :
                           &session->sslClient->buffers.inputBuffer.bufferSize;
    WOLFSSL*           ssl  = (session->flags.side == WOLFSSL_SERVER_END) ?
                            session->sslServer : session->sslClient;
    word32*     reassemblyMemory = (session->flags.side == WOLFSSL_SERVER_END) ?
                  &session->cliReassemblyMemory : &session->srvReassemblyMemory;
    while (*front && ((*front)->begin == *expected) ) {
        word32 room = *bufferSize - *length;
        word32 packetLen = (*front)->end - (*front)->begin + 1;
        if (packetLen > room && *bufferSize < MAX_INPUT_SZ) {
            if (GrowInputBuffer(ssl, packetLen, *length) < 0) {
                SetError(MEMORY_STR, error, session, FATAL_ERROR_STATE);
                return 0;
            }
            room = *bufferSize - *length;   
        }
        if (packetLen <= room) {
            PacketBuffer* del = *front;
            byte*         buf = *myBuffer;
            XMEMCPY(&buf[*length], (*front)->data, packetLen);
            *length   += packetLen;
            *expected += packetLen;
            *front = (*front)->next;
            *reassemblyMemory -= packetLen;
            FreePacketBuffer(del);
            moreInput = 1;
        }
        else
            break;
    }
    if (moreInput) {
        *sslFrame = *myBuffer;
        *sslBytes = *length;
        *end      = *myBuffer + *length;
    }
    return moreInput;
}
static int HaveMoreInput ( SnifferSession * session , const byte * * sslFrame , int * sslBytes , const byte * * end , char * error ) { int moreInput = 0 ; PacketBuffer * * front = ( session -> flags . side == WOLFSSL_SERVER_END ) ? & session -> cliReassemblyList : & session -> srvReassemblyList ; word32 * expected = ( session -> flags . side == WOLFSSL_SERVER_END ) ? & session -> cliExpected : & session -> srvExpected ; word32 * length = ( session -> flags . side == WOLFSSL_SERVER_END ) ? & session -> sslServer -> buffers . inputBuffer . length : & session -> sslClient -> buffers . inputBuffer . length ; byte * * myBuffer = ( session -> flags . side == WOLFSSL_SERVER_END ) ? & session -> sslServer -> buffers . inputBuffer . buffer : & session -> sslClient -> buffers . inputBuffer . buffer ; word32 * bufferSize = ( session -> flags . side == WOLFSSL_SERVER_END ) ? & session -> sslServer -> buffers . inputBuffer . bufferSize : & session -> sslClient -> buffers . inputBuffer . bufferSize ; WOLFSSL * ssl = ( session -> flags . side == WOLFSSL_SERVER_END ) ? session -> sslServer : session -> sslClient ; word32 * reassemblyMemory = ( session -> flags . side == WOLFSSL_SERVER_END ) ? & session -> cliReassemblyMemory : & session -> srvReassemblyMemory ; while ( * front && ( ( * front ) -> begin == * expected ) ) { word32 room = * bufferSize - * length ; word32 packetLen = ( * front ) -> end - ( * front ) -> begin + 1 ; if ( packetLen > room && * bufferSize < MAX_INPUT_SZ ) { if ( GrowInputBuffer ( ssl , packetLen , * length ) < 0 ) { SetError ( MEMORY_STR , error , session , FATAL_ERROR_STATE ) ; return 0 ; } room = * bufferSize - * length ; } if ( packetLen <= room ) { PacketBuffer * del = * front ; byte * buf = * myBuffer ; XMEMCPY ( & buf [ * length ] , ( * front ) -> data , packetLen ) ; * length += packetLen ; * expected += packetLen ; * front = ( * front ) -> next ; * reassemblyMemory -= packetLen ; FreePacketBuffer ( del ) ; moreInput = 1 ; } else break ; } if ( moreInput ) { * sslFrame = * myBuffer ; * sslBytes = * length ; * end = * myBuffer + * length ; } return moreInput ; }
See if input on the reassembly list is ready for consuming
returns 1 for TRUE, 0 for FALSE
See if input on the reassembly list is ready for consuming returns 1 for TRUE 0 for FALSE
/* sequence and reassembly based on from, not to */ /* buffer is on receiving end */ /* bufferSize is now bigger */ /* remove used packet */