@ -113,7 +113,8 @@ typedef struct AppLayerParserProtoCtx_
uint64_t ( * StateGetTxCnt ) ( void * alstate ) ;
void * ( * StateGetTx ) ( void * alstate , uint64_t tx_id ) ;
AppLayerGetTxIteratorFunc StateGetTxIterator ;
int ( * StateGetProgressCompletionStatus ) ( uint8_t direction ) ;
int complete_ts ;
int complete_tc ;
int ( * StateGetEventInfoById ) ( int event_id , const char * * event_name ,
AppLayerEventType * event_type ) ;
int ( * StateGetEventInfo ) ( const char * event_name ,
@ -524,15 +525,19 @@ void AppLayerParserRegisterGetTxIterator(uint8_t ipproto, AppProto alproto,
SCReturn ;
}
void AppLayerParserRegister Get StateProgressCompletionStatus( AppProto alproto ,
int ( * StateGetProgressCompletionStatus ) ( uint8_t direction ) )
void AppLayerParserRegister StateProgressCompletionStatus(
AppProto alproto , const int ts , const int tc )
{
SCEnter ( ) ;
alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] .
StateGetProgressCompletionStatus = StateGetProgressCompletionStatus ;
BUG_ON ( ts = = 0 ) ;
BUG_ON ( tc = = 0 ) ;
BUG_ON ( ! AppProtoIsValid ( alproto ) ) ;
BUG_ON ( alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_ts ! = 0 & &
alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_ts ! = ts ) ;
BUG_ON ( alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_tc ! = 0 & &
alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_tc ! = tc ) ;
SCReturn ;
alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_ts = ts ;
alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_tc = tc ;
}
void AppLayerParserRegisterGetEventInfoById ( uint8_t ipproto , AppProto alproto ,
@ -1025,6 +1030,18 @@ next:
SCReturn ;
}
static inline int StateGetProgressCompletionStatus ( const AppProto alproto , const uint8_t flags )
{
if ( flags & STREAM_TOSERVER ) {
return alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_ts ;
} else if ( flags & STREAM_TOCLIENT ) {
return alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] . complete_tc ;
} else {
DEBUG_VALIDATE_BUG_ON ( 1 ) ;
return 0 ;
}
}
/**
* \ brief get the progress value for a tx / protocol
*
@ -1036,8 +1053,7 @@ int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
SCEnter ( ) ;
int r = 0 ;
if ( unlikely ( IS_DISRUPTED ( flags ) ) ) {
r = alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] .
StateGetProgressCompletionStatus ( flags ) ;
r = StateGetProgressCompletionStatus ( alproto , flags ) ;
} else {
r = alp_ctx . ctxs [ FlowGetProtoMapping ( ipproto ) ] [ alproto ] .
StateGetProgress ( alstate , flags ) ;
@ -1067,8 +1083,7 @@ int AppLayerParserGetStateProgressCompletionStatus(AppProto alproto,
uint8_t direction )
{
SCEnter ( ) ;
int r = alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] .
StateGetProgressCompletionStatus ( direction ) ;
int r = StateGetProgressCompletionStatus ( alproto , direction ) ;
SCReturnInt ( r ) ;
}
@ -1403,8 +1418,12 @@ bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
*/
int AppLayerParserIsEnabled ( AppProto alproto )
{
return ( alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ]
. StateGetProgressCompletionStatus ! = NULL ) ;
for ( int i = 0 ; i < FLOW_PROTO_APPLAYER_MAX ; i + + ) {
if ( alp_ctx . ctxs [ i ] [ alproto ] . StateGetProgress ! = NULL ) {
return 1 ;
}
}
return 0 ;
}
int AppLayerParserProtocolIsTxEventAware ( uint8_t ipproto , AppProto alproto )
@ -1500,7 +1519,6 @@ static void ValidateParserProtoDump(AppProto alproto, uint8_t ipproto)
{
uint8_t map = FlowGetProtoMapping ( ipproto ) ;
const AppLayerParserProtoCtx * ctx = & alp_ctx . ctxs [ map ] [ alproto ] ;
const AppLayerParserProtoCtx * ctx_def = & alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] ;
printf ( " ERROR: incomplete app-layer registration \n " ) ;
printf ( " AppLayer protocol %s ipproto %u \n " , AppProtoToString ( alproto ) , ipproto ) ;
printf ( " - option flags % " PRIx32 " \n " , ctx - > option_flags ) ;
@ -1511,7 +1529,7 @@ static void ValidateParserProtoDump(AppProto alproto, uint8_t ipproto)
printf ( " - StateGetTx %p StateGetTxCnt %p StateTransactionFree %p \n " ,
ctx - > StateGetTx , ctx - > StateGetTxCnt , ctx - > StateTransactionFree ) ;
printf ( " - GetTxData %p \n " , ctx - > GetTxData ) ;
printf ( " - StateGetProgress %p StateGetProgressCompletionStatus %p \n " , ctx - > StateGetProgres s, ctx_def - > StateGetProgressCompletionStatu s) ;
printf ( " - StateGetProgress %p \n " , ctx - > StateGetProgres s) ;
printf ( " - GetTxDetectState %p SetTxDetectState %p \n " , ctx - > GetTxDetectState , ctx - > SetTxDetectState ) ;
printf ( " Optional: \n " ) ;
printf ( " - LocalStorageAlloc %p LocalStorageFree %p \n " , ctx - > LocalStorageAlloc , ctx - > LocalStorageFree ) ;
@ -1528,7 +1546,6 @@ static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
{
uint8_t map = FlowGetProtoMapping ( ipproto ) ;
const AppLayerParserProtoCtx * ctx = & alp_ctx . ctxs [ map ] [ alproto ] ;
const AppLayerParserProtoCtx * ctx_def = & alp_ctx . ctxs [ FLOW_PROTO_DEFAULT ] [ alproto ] ;
if ( ctx - > Parser [ 0 ] = = NULL & & ctx - > Parser [ 1 ] = = NULL )
return ;
@ -1542,8 +1559,7 @@ static void ValidateParserProto(AppProto alproto, uint8_t ipproto)
if ( ! ( THREE_SET ( ctx - > StateGetTx , ctx - > StateGetTxCnt , ctx - > StateTransactionFree ) ) ) {
goto bad ;
}
/* special case: StateGetProgressCompletionStatus is used from 'default'. */
if ( ! ( BOTH_SET ( ctx - > StateGetProgress , ctx_def - > StateGetProgressCompletionStatus ) ) ) {
if ( ctx - > StateGetProgress = = NULL ) {
goto bad ;
}
/* local storage is optional, but needs both set if used */