diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 91e37a34f7..af7a0b24ff 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -584,6 +584,48 @@ error: SCReturnInt(-1); } +/** + * \brief get the highest loggable transaction id + */ +int HtpTransactionGetLoggableId(Flow *f) +{ + SCEnter(); + + /* Get the parser state (if any) */ + if (f->aldata == NULL) { + SCLogDebug("no aldata"); + goto error; + } + + AppLayerParserStateStore *parser_state_store = + (AppLayerParserStateStore *)f->aldata[app_layer_sid]; + + if (parser_state_store == NULL) { + SCLogDebug("no state store"); + goto error; + } + + int id = 0; + + HtpState *http_state = f->aldata[AlpGetStateIdx(ALPROTO_HTTP)]; + if (http_state == NULL) { + SCLogDebug("no http state"); + goto error; + } + + if (parser_state_store->id_flags & APP_LAYER_TRANSACTION_EOF) { + SCLogDebug("eof, return current transaction as well"); + id = (int)(list_size(http_state->connp->conn->transactions)); + } else { + id = (int)(parser_state_store->avail_id - 1); + } + + SCReturnInt(id); + +error: + SCReturnInt(-1); +} + /** * \brief Print the information and chunks of a Body * \param body pointer to the HtpBody holding the list diff --git a/src/app-layer-htp.h b/src/app-layer-htp.h index d1bceaabdf..0a14f11549 100644 --- a/src/app-layer-htp.h +++ b/src/app-layer-htp.h @@ -112,6 +112,7 @@ void HTPFreeConfig(void); htp_tx_t *HTPTransactionMain(const HtpState *); int HTPCallbackRequestBodyData(htp_tx_data_t *); +int HtpTransactionGetLoggableId(Flow *); void HtpBodyPrint(HtpBody *); void HtpBodyFree(HtpBody *); void AppLayerHtpRegisterExtraCallbacks(void); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index 7b2c23aa11..4090ff71e8 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -56,7 +56,7 @@ #include "util-debug.h" -static uint16_t app_layer_sid = 0; +uint16_t app_layer_sid = 0; static AppLayerProto al_proto_table[ALPROTO_MAX]; /**< Application layer protocol table mapped to their corresponding parsers */ diff --git a/src/app-layer-parser.h b/src/app-layer-parser.h index 2cc24eeadb..92fa761d53 100644 --- a/src/app-layer-parser.h +++ b/src/app-layer-parser.h @@ -215,6 +215,8 @@ extern uint16_t app_layer_sid; struct AlpProtoDetectCtx_; +extern uint16_t app_layer_sid; + /* prototypes */ void AppLayerParsersInitPostProcess(void); void RegisterAppLayerParsers(void); diff --git a/src/log-httplog.c b/src/log-httplog.c index a5d46f83f3..1c2bdc4595 100644 --- a/src/log-httplog.c +++ b/src/log-httplog.c @@ -129,7 +129,7 @@ TmEcode LogHttpLogIPv4(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P } size_t logged = (size_t)r; - r = AppLayerTransactionGetLoggableId(p->flow); + r = HtpTransactionGetLoggableId(p->flow); if (r < 0) { goto end; } @@ -245,7 +245,7 @@ TmEcode LogHttpLogIPv6(ThreadVars *tv, Packet *p, void *data, PacketQueue *pq, P } size_t logged = (size_t)r; - r = AppLayerTransactionGetLoggableId(p->flow); + r = HtpTransactionGetLoggableId(p->flow); if (r < 0) { goto end; }