From f59f90331d5185e93927ca10412235da1a79a24b Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 2 Jul 2013 10:14:59 +0200 Subject: [PATCH] Applayer: remove obsolete StateUpdateTransactionId Also, update StateTransactionFree to take an u64 tx id, so it's consistant with the rest of the engine. To reflect these changes, AppLayerRegisterTransactionIdFuncs has been renamed to AppLayerRegisterTxFreeFunc. HTP, DNS, SMB, DCERPC parsers updated. --- src/app-layer-dcerpc.c | 16 ---------------- src/app-layer-dns-tcp.c | 8 ++++---- src/app-layer-dns-udp.c | 31 ++++--------------------------- src/app-layer-htp.c | 6 +++--- src/app-layer-parser.c | 5 ++--- src/app-layer-parser.h | 8 +++----- src/app-layer-smb.c | 16 ---------------- 7 files changed, 16 insertions(+), 74 deletions(-) diff --git a/src/app-layer-dcerpc.c b/src/app-layer-dcerpc.c index b856c5d452..49a90a9269 100644 --- a/src/app-layer-dcerpc.c +++ b/src/app-layer-dcerpc.c @@ -1866,20 +1866,6 @@ static void DCERPCStateFree(void *s) { } } -/** - * \brief Update the transaction id based on the DCERPC state - */ -void DCERPCUpdateTransactionId(void *state, uint16_t *id) { - SCEnter(); - - DCERPCState *s = (DCERPCState *)state; - SCLogDebug("original id %"PRIu16, *id); - (*id) = s->dcerpc.transaction_id; - SCLogDebug("updated id %"PRIu16, *id); - - SCReturn; -} - void RegisterDCERPCParsers(void) { char *proto_name = "dcerpc"; @@ -1892,8 +1878,6 @@ void RegisterDCERPCParsers(void) { DCERPCParseResponse); AppLayerRegisterStateFuncs(ALPROTO_DCERPC, DCERPCStateAlloc, DCERPCStateFree); - AppLayerRegisterTransactionIdFuncs(ALPROTO_DCERPC, - DCERPCUpdateTransactionId, NULL); } /* UNITTESTS */ diff --git a/src/app-layer-dns-tcp.c b/src/app-layer-dns-tcp.c index 32cb0549d3..8a11496d79 100644 --- a/src/app-layer-dns-tcp.c +++ b/src/app-layer-dns-tcp.c @@ -598,12 +598,12 @@ void DNSStateUpdateTransactionId(void *state, uint16_t *id) { /** * \brief dns transaction cleanup callback */ -void DNSStateTransactionFree(void *state, uint16_t id) { +void DNSStateTransactionFree(void *state, uint64_t id) { SCEnter(); DNSState *s = state; - SCLogDebug("state %p, id %"PRIu16, s, id); + SCLogDebug("state %p, id %"PRIu64, s, id); /* we can't remove the actual transactions here */ @@ -621,8 +621,8 @@ void RegisterDNSTCPParsers(void) { DNSTCPResponseParse); AppLayerRegisterStateFuncs(ALPROTO_DNS_TCP, DNSStateAlloc, DNSStateFree); - AppLayerRegisterTransactionIdFuncs(ALPROTO_DNS_TCP, - DNSStateUpdateTransactionId, DNSStateTransactionFree); + AppLayerRegisterTxFreeFunc(ALPROTO_DNS_TCP, + DNSStateTransactionFree); AppLayerRegisterGetEventsFunc(ALPROTO_DNS_TCP, DNSGetEvents); AppLayerRegisterHasEventsFunc(ALPROTO_DNS_TCP, DNSHasEvents); diff --git a/src/app-layer-dns-udp.c b/src/app-layer-dns-udp.c index 2c51fa60b4..2e8f8bc247 100644 --- a/src/app-layer-dns-udp.c +++ b/src/app-layer-dns-udp.c @@ -293,38 +293,15 @@ static uint16_t DNSUdpProbingParser(uint8_t *input, uint32_t ilen) return ALPROTO_DNS_UDP; } -/** - * \brief Update the transaction id based on the dns state - */ -static void DNSStateUpdateTransactionId(void *state, uint16_t *id) { - SCEnter(); - - DNSState *s = state; - - SCLogDebug("original id %"PRIu16", s->transaction_max %"PRIu64, - *id, (s->transaction_max)); - - if ((s->transaction_max) > (*id)) { - SCLogDebug("original id %"PRIu16", updating with s->transaction_max %"PRIu64, - *id, (s->transaction_max)); - - (*id) = (s->transaction_max); - - SCLogDebug("updated id %"PRIu16, *id); - } - - SCReturn; -} - /** * \brief dns transaction cleanup callback */ -static void DNSStateTransactionFree(void *state, uint16_t id) { +static void DNSStateTransactionFree(void *state, uint64_t id) { SCEnter(); DNSState *s = state; - SCLogDebug("state %p, id %"PRIu16, s, id); + SCLogDebug("state %p, id %"PRIu64, s, id); /* we can't remove the actual transactions here */ @@ -342,8 +319,8 @@ void RegisterDNSUDPParsers(void) { DNSUDPResponseParse); AppLayerRegisterStateFuncs(ALPROTO_DNS_UDP, DNSStateAlloc, DNSStateFree); - AppLayerRegisterTransactionIdFuncs(ALPROTO_DNS_UDP, - DNSStateUpdateTransactionId, DNSStateTransactionFree); + AppLayerRegisterTxFreeFunc(ALPROTO_DNS_UDP, + DNSStateTransactionFree); AppLayerRegisterGetEventsFunc(ALPROTO_DNS_UDP, DNSGetEvents); AppLayerRegisterHasEventsFunc(ALPROTO_DNS_UDP, DNSHasEvents); diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 31c61f05ba..a8e55618e4 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -303,13 +303,13 @@ void HTPStateFree(void *state) * \warning We cannot actually free the transactions here. It seems that * HTP only accepts freeing of transactions in the response callback. */ -void HTPStateTransactionFree(void *state, uint16_t id) { +void HTPStateTransactionFree(void *state, uint64_t id) { SCEnter(); HtpState *s = (HtpState *)state; s->transaction_done = id; - SCLogDebug("state %p, id %"PRIu16, s, id); + SCLogDebug("state %p, id %"PRIu64, s, id); /* we can't remove the actual transactions here */ @@ -2439,7 +2439,7 @@ void RegisterHTPParsers(void) AlpProtoAdd(&alp_proto_ctx, proto_name, IPPROTO_TCP, ALPROTO_HTTP, "CONNECT|09|", 8, 0, STREAM_TOSERVER); AppLayerRegisterStateFuncs(ALPROTO_HTTP, HTPStateAlloc, HTPStateFree); - AppLayerRegisterTransactionIdFuncs(ALPROTO_HTTP, NULL, HTPStateTransactionFree); + AppLayerRegisterTxFreeFunc(ALPROTO_HTTP, HTPStateTransactionFree); AppLayerRegisterGetFilesFunc(ALPROTO_HTTP, HTPStateGetFiles); AppLayerRegisterGetAlstateProgressFunc(ALPROTO_HTTP, HTPStateGetAlstateProgress); AppLayerRegisterGetTxCnt(ALPROTO_HTTP, HTPStateGetTxCnt); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index c919e75c4e..0d73db58d1 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -734,10 +734,9 @@ void AppLayerRegisterStateFuncs(uint16_t proto, void *(*StateAlloc)(void), al_proto_table[proto].StateFree = StateFree; } -void AppLayerRegisterTransactionIdFuncs(uint16_t proto, - void (*StateUpdateTransactionId)(void *state, uint16_t *), void (*StateTransactionFree)(void *, uint16_t)) +void AppLayerRegisterTxFreeFunc(uint16_t proto, + void (*StateTransactionFree)(void *, uint64_t)) { - al_proto_table[proto].StateUpdateTransactionId = StateUpdateTransactionId; al_proto_table[proto].StateTransactionFree = StateTransactionFree; } diff --git a/src/app-layer-parser.h b/src/app-layer-parser.h index 9a949c1a79..7232d5bfe6 100644 --- a/src/app-layer-parser.h +++ b/src/app-layer-parser.h @@ -50,8 +50,7 @@ typedef struct AppLayerProto_ { void *(*StateAlloc)(void); void (*StateFree)(void *); - void (*StateUpdateTransactionId)(void *, uint16_t *); - void (*StateTransactionFree)(void *, uint16_t); + void (*StateTransactionFree)(void *, uint64_t); void *(*LocalStorageAlloc)(void); void (*LocalStorageFree)(void *); @@ -252,9 +251,6 @@ void AppLayerRegisterProbingParser(struct AlpProtoDetectCtx_ *, uint16_t, uint16 uint16_t (*ProbingParser)(uint8_t *, uint32_t)); void AppLayerRegisterStateFuncs(uint16_t proto, void *(*StateAlloc)(void), void (*StateFree)(void *)); -void AppLayerRegisterTransactionIdFuncs(uint16_t proto, - void (*StateTransactionId)(void *, uint16_t *), - void (*StateTransactionFree)(void *, uint16_t id)); void AppLayerRegisterLocalStorageFunc(uint16_t proto, void *(*LocalStorageAlloc)(void), void (*LocalStorageFree)(void *)); @@ -272,6 +268,8 @@ const char *AppLayerGetProtoString(int proto); void AppLayerRegisterTruncateFunc(uint16_t proto, void (*Truncate)(void *, uint8_t)); void AppLayerRegisterGetAlstateProgressFunc(uint16_t alproto, int (*StateGetAlstateProgress)(void *alstate, uint8_t direction)); +void AppLayerRegisterTxFreeFunc(uint16_t proto, + void (*StateTransactionFree)(void *, uint64_t)); void AppLayerRegisterGetTxCnt(uint16_t alproto, uint64_t (*StateGetTxCnt)(void *alstate)); void AppLayerRegisterGetTx(uint16_t alproto, diff --git a/src/app-layer-smb.c b/src/app-layer-smb.c index 399a36c4da..bc95303f8c 100644 --- a/src/app-layer-smb.c +++ b/src/app-layer-smb.c @@ -1354,20 +1354,6 @@ static void SMBStateFree(void *s) { SCReturn; } -/** - * \brief Update the transaction id based on the SMB state - */ -void SMBUpdateTransactionId(void *state, uint16_t *id) { - SCEnter(); - - SMBState *s = (SMBState *)state; - SCLogDebug("original id %"PRIu16, *id); - (*id) = s->transaction_id; - SCLogDebug("updated id %"PRIu16, *id); - - SCReturn; -} - #define SMB_PROBING_PARSER_MIN_DEPTH 8 static uint16_t SMBProbingParser(uint8_t *input, uint32_t ilen) @@ -1423,8 +1409,6 @@ void RegisterSMBParsers(void) { AppLayerRegisterProto(proto_name, ALPROTO_SMB, STREAM_TOSERVER, SMBParseRequest); AppLayerRegisterProto(proto_name, ALPROTO_SMB, STREAM_TOCLIENT, SMBParseResponse); AppLayerRegisterStateFuncs(ALPROTO_SMB, SMBStateAlloc, SMBStateFree); - AppLayerRegisterTransactionIdFuncs(ALPROTO_SMB, - SMBUpdateTransactionId, NULL); AppLayerRegisterProbingParser(&alp_proto_ctx, 139,