]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: parser cleanup 790/head
authorVictor Julien <victor@inliniac.net>
Fri, 17 Jan 2014 16:01:37 +0000 (17:01 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 21 Jan 2014 15:18:17 +0000 (16:18 +0100)
Use f->protomap instead of calling FlowGetProtoMapping. Don't use
TcpSession *ssn ptr for anything other than TCP

src/app-layer-dcerpc-udp.c
src/app-layer-parser.c
src/detect-dns-query.c

index 2796fd8cf25e27a9677f553daf3db64c7b18931c..97858d6351cc08275d93d8e514484b35bcb30ce2 100644 (file)
@@ -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);
 
index e526618e2b1a4d630195218fb471a45263e669fc..c48227d463f303fabfeca25c1d558a593dbe73b1 100644 (file)
@@ -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);
 
index d0e384ac07a73df82feca35a5e57b6db0ca6268a..f1e739f658ee0562daa7063c7fb6a3a692258a11 100644 (file)
@@ -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;