@ -69,7 +69,9 @@ struct AppLayerThreadCtx_ {
typedef struct AppLayerCounters_ {
char * name ;
char * tx_name ;
uint16_t counter_id ;
uint16_t counter_tx_id ;
} AppLayerCounters ;
AppLayerCounters applayer_counters [ FLOW_PROTO_MAX ] [ ALPROTO_MAX ] ;
@ -98,6 +100,13 @@ static void AppLayerIncFlowCounter(ThreadVars *tv, Flow *f)
}
}
void AppLayerIncTxCounter ( ThreadVars * tv , Flow * f , uint64_t step )
{
if ( likely ( tv ) ) {
StatsAddUI64 ( tv , applayer_counters [ f - > protomap ] [ f - > alproto ] . counter_tx_id , step ) ;
}
}
int AppLayerHandleTCPData ( ThreadVars * tv , TcpReassemblyThreadCtx * ra_ctx ,
Packet * p , Flow * f ,
TcpSession * ssn , TcpStream * stream ,
@ -696,31 +705,49 @@ void AppLayerSetupCounters()
for ( alproto = 0 ; alproto < ALPROTO_MAX ; alproto + + ) {
if ( alprotos [ alproto ] = = 1 ) {
char * str = " app_layer.flow. " ;
char * tx_str = " app_layer.tx. " ;
char * alproto_str = AppLayerGetProtoName ( alproto ) ;
int alproto_len = strlen ( alproto_str ) + 1 ;
uint8_t ipproto_map = FlowGetProtoMapping ( ipprotos [ ipproto ] ) ;
size_t size ;
if ( AppLayerParserProtoIsRegistered ( ipprotos [ ipproto ] , alproto ) & &
AppLayerParserProtoIsRegistered ( other_ipproto , alproto ) )
{
applayer_counters[ ipproto_map ] [ alproto ] . name =
SCMalloc ( strlen ( str ) + alproto_len + strlen ( ipproto_suffix ) ) ;
size = strlen ( str ) + alproto_len + strlen ( ipproto_suffix ) ;
applayer_counters [ ipproto_map ] [ alproto ] . name = SCMalloc ( size ) ;
if ( applayer_counters [ ipproto_map ] [ alproto ] . name = = NULL ) {
return ;
}
snprintf ( applayer_counters [ ipproto_map ] [ alproto ] . name ,
strlen ( str ) + alproto_len + strlen ( ipproto_suffix ) ,
" %s%s%s " , str , alproto_str , ipproto_suffix ) ;
snprintf ( applayer_counters [ ipproto_map ] [ alproto ] . name , size ,
" %s%s%s " , str , alproto_str , ipproto_suffix ) ;
if ( AppLayerParserProtocolIsTxAware ( ipprotos [ ipproto ] , alproto ) ) {
size = strlen ( tx_str ) + alproto_len + strlen ( ipproto_suffix ) ;
applayer_counters [ ipproto_map ] [ alproto ] . tx_name = SCMalloc ( size ) ;
if ( applayer_counters [ ipproto_map ] [ alproto ] . tx_name = = NULL ) {
return ;
}
snprintf ( applayer_counters [ ipproto_map ] [ alproto ] . tx_name , size ,
" %s%s%s " , tx_str , alproto_str , ipproto_suffix ) ;
}
} else {
applayer_counters [ ipproto_map ] [ alproto ] . name =
SCMalloc ( strlen ( str ) + alproto_len ) ;
size = strlen ( str ) + alproto_len ;
applayer_counters [ ipproto_map ] [ alproto ] . name = SCMalloc ( size ) ;
if ( applayer_counters [ ipproto_map ] [ alproto ] . name = = NULL ) {
return ;
}
snprintf ( applayer_counters [ ipproto_map ] [ alproto ] . name ,
strlen ( str ) + alproto_len ,
" %s%s " , str , alproto_str ) ;
snprintf ( applayer_counters [ ipproto_map ] [ alproto ] . name , size ,
" %s%s " , str , alproto_str ) ;
if ( AppLayerParserProtocolIsTxAware ( ipprotos [ ipproto ] , alproto ) ) {
size = strlen ( tx_str ) + alproto_len ;
applayer_counters [ ipproto_map ] [ alproto ] . tx_name = SCMalloc ( size ) ;
if ( applayer_counters [ ipproto_map ] [ alproto ] . tx_name = = NULL ) {
return ;
}
snprintf ( applayer_counters [ ipproto_map ] [ alproto ] . tx_name , size ,
" %s%s " , tx_str , alproto_str ) ;
}
}
}
}
@ -742,6 +769,11 @@ void AppLayerRegisterThreadCounters(ThreadVars *tv)
uint8_t ipproto_map = FlowGetProtoMapping ( ipprotos [ ipproto ] ) ;
applayer_counters [ ipproto_map ] [ alproto ] . counter_id =
StatsRegisterCounter ( applayer_counters [ ipproto_map ] [ alproto ] . name , tv ) ;
if ( AppLayerParserProtocolIsTxAware ( ipprotos [ ipproto ] , alproto ) ) {
applayer_counters [ ipproto_map ] [ alproto ] . counter_tx_id =
StatsRegisterCounter ( applayer_counters [ ipproto_map ] [ alproto ] . tx_name , tv ) ;
}
}
}
}
@ -764,6 +796,10 @@ void AppLayerDeSetupCounters()
applayer_counters [ FlowGetProtoMapping ( ipprotos [ ipproto ] ) ] [ alproto ] . name = NULL ;
}
}
if ( applayer_counters [ FlowGetProtoMapping ( ipproto ) ] [ alproto ] . tx_name ) {
SCFree ( applayer_counters [ FlowGetProtoMapping ( ipproto ) ] [ alproto ] . tx_name ) ;
applayer_counters [ FlowGetProtoMapping ( ipproto ) ] [ alproto ] . tx_name = NULL ;
}
}
}
}