From a77b9b36e5ae20ee5354baf3a5991bdbcb18cba1 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 17 Jan 2014 17:01:37 +0100 Subject: [PATCH] app-layer: parser cleanup Use f->protomap instead of calling FlowGetProtoMapping. Don't use TcpSession *ssn ptr for anything other than TCP --- src/app-layer-dcerpc-udp.c | 1 + src/app-layer-parser.c | 27 +++++++++++++-------------- src/detect-dns-query.c | 7 +++++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/app-layer-dcerpc-udp.c b/src/app-layer-dcerpc-udp.c index 2796fd8cf2..97858d6351 100644 --- a/src/app-layer-dcerpc-udp.c +++ b/src/app-layer-dcerpc-udp.c @@ -1049,6 +1049,7 @@ int DCERPCUDPParserTest01(void) { FLOW_INITIALIZE(&f); f.protoctx = (void *)&ssn; f.proto = IPPROTO_UDP; + f.protomap = FlowGetProtoMapping(f.proto); StreamTcpInitConfig(TRUE); diff --git a/src/app-layer-parser.c b/src/app-layer-parser.c index e526618e2b..c48227d463 100644 --- a/src/app-layer-parser.c +++ b/src/app-layer-parser.c @@ -725,19 +725,17 @@ int AppLayerParserParse(AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alp uint8_t flags, uint8_t *input, uint32_t input_len) { SCEnter(); - +#ifdef DEBUG_VALIDATION + BUG_ON(f->protomap != FlowGetProtoMapping(f->proto)); +#endif AppLayerParserState *pstate = NULL; - AppLayerParserProtoCtx *p = &alp_ctx.ctxs[FlowGetProtoMapping(f->proto)][alproto]; - TcpSession *ssn = NULL; + AppLayerParserProtoCtx *p = &alp_ctx.ctxs[f->protomap][alproto]; void *alstate = NULL; /* we don't have the parser registered for this protocol */ if (p->StateAlloc == NULL) goto end; - /* Used only if it's TCP */ - ssn = f->protoctx; - /* Do this check before calling AppLayerParse */ if (flags & STREAM_GAP) { SCLogDebug("stream gap detected (missing packets), " @@ -779,7 +777,7 @@ int AppLayerParserParse(AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alp /* invoke the parser */ if (p->Parser[(flags & STREAM_TOSERVER) ? 0 : 1](f, alstate, pstate, input, input_len, - alp_tctx->alproto_local_storage[FlowGetProtoMapping(f->proto)][alproto]) < 0) + alp_tctx->alproto_local_storage[f->protomap][alproto]) < 0) { goto error; } @@ -792,7 +790,9 @@ int AppLayerParserParse(AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alp FlowSetSessionNoApplayerInspectionFlag(f); /* Set the no reassembly flag for both the stream in this TcpSession */ - if (pstate->flags & APP_LAYER_PARSER_NO_REASSEMBLY) { + if (f->proto == IPPROTO_TCP && pstate->flags & APP_LAYER_PARSER_NO_REASSEMBLY) { + /* Used only if it's TCP */ + TcpSession *ssn = f->protoctx; if (ssn != NULL) { StreamTcpSetSessionNoReassemblyFlag(ssn, flags & STREAM_TOCLIENT ? 1 : 0); @@ -812,12 +812,10 @@ int AppLayerParserParse(AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alp end: SCReturnInt(0); error: - if (ssn != NULL) { - /* Set the no app layer inspection flag for both - * the stream in this Flow */ - FlowSetSessionNoApplayerInspectionFlag(f); - AppLayerParserSetEOF(pstate); - } + /* Set the no app layer inspection flag for both + * the stream in this Flow */ + FlowSetSessionNoApplayerInspectionFlag(f); + AppLayerParserSetEOF(pstate); SCReturnInt(-1); } @@ -1187,6 +1185,7 @@ static int AppLayerParserTest02(void) goto end; f->alproto = ALPROTO_TEST; f->proto = IPPROTO_UDP; + f->protomap = FlowGetProtoMapping(f->proto); StreamTcpInitConfig(TRUE); diff --git a/src/detect-dns-query.c b/src/detect-dns-query.c index d0e384ac07..f1e739f658 100644 --- a/src/detect-dns-query.c +++ b/src/detect-dns-query.c @@ -159,6 +159,7 @@ static int DetectDnsQueryTest01(void) { FLOW_INITIALIZE(&f); f.flags |= FLOW_IPV4; f.proto = IPPROTO_UDP; + f.protomap = FlowGetProtoMapping(f.proto); p->flow = &f; p->flags |= PKT_HAS_FLOW; @@ -278,6 +279,7 @@ static int DetectDnsQueryTest02(void) { FLOW_INITIALIZE(&f); f.flags |= FLOW_IPV4; f.proto = IPPROTO_UDP; + f.protomap = FlowGetProtoMapping(f.proto); f.alproto = ALPROTO_DNS; p1->flow = &f; @@ -437,6 +439,7 @@ static int DetectDnsQueryTest03(void) { f.protoctx = (void *)&ssn; f.flags |= FLOW_IPV4; f.proto = IPPROTO_TCP; + f.protomap = FlowGetProtoMapping(f.proto); p->flow = &f; p->flags |= PKT_HAS_FLOW|PKT_STREAM_EST; @@ -537,6 +540,7 @@ static int DetectDnsQueryTest04(void) { f.protoctx = (void *)&ssn; f.flags |= FLOW_IPV4; f.proto = IPPROTO_TCP; + f.protomap = FlowGetProtoMapping(f.proto); f.alproto = ALPROTO_DNS; p1->flow = &f; @@ -691,6 +695,7 @@ static int DetectDnsQueryTest05(void) { f.protoctx = (void *)&ssn; f.flags |= FLOW_IPV4; f.proto = IPPROTO_TCP; + f.protomap = FlowGetProtoMapping(f.proto); f.alproto = ALPROTO_DNS; p1->flow = &f; @@ -872,6 +877,7 @@ static int DetectDnsQueryTest06(void) { FLOW_INITIALIZE(&f); f.flags |= FLOW_IPV4; f.proto = IPPROTO_UDP; + f.protomap = FlowGetProtoMapping(f.proto); p->flow = &f; p->flags |= PKT_HAS_FLOW; @@ -1005,6 +1011,7 @@ static int DetectDnsQueryTest07(void) { FLOW_INITIALIZE(&f); f.flags |= FLOW_IPV4; f.proto = IPPROTO_UDP; + f.protomap = FlowGetProtoMapping(f.proto); f.alproto = ALPROTO_DNS; p1->flow = &f;