]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: trunc parser per direction
authorVictor Julien <vjulien@oisf.net>
Sat, 5 Feb 2022 07:53:58 +0000 (08:53 +0100)
committerVictor Julien <vjulien@oisf.net>
Fri, 30 Sep 2022 07:46:05 +0000 (09:46 +0200)
rust/src/applayer.rs
src/app-layer-parser.c
src/app-layer-parser.h

index f44b5b63b9a2f8237cac4f121a5ace1a86c64bcf..fa275f96824f7c650a68da4403071640c683c292 100644 (file)
@@ -430,6 +430,8 @@ pub const APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD : u16 = BIT_U16!(3);
 pub const APP_LAYER_PARSER_BYPASS_READY : u16 = BIT_U16!(4);
 pub const APP_LAYER_PARSER_EOF_TS : u16 = BIT_U16!(5);
 pub const APP_LAYER_PARSER_EOF_TC : u16 = BIT_U16!(6);
+pub const APP_LAYER_PARSER_TRUNC_TS : u16 = BIT_U16!(7);
+pub const APP_LAYER_PARSER_TRUNC_TC : u16 = BIT_U16!(8);
 
 pub const APP_LAYER_PARSER_OPT_ACCEPT_GAPS: u32 = BIT_U32!(0);
 pub const APP_LAYER_PARSER_OPT_UNIDIR_TXS: u32 = BIT_U32!(1);
index 3bc32d1e06ab326cf46c13be4b2f1a11e87370b2..550a658a2775ef803b94d34f8efed71c5daf7308 100644 (file)
@@ -226,6 +226,9 @@ FramesContainer *AppLayerFramesSetupContainer(Flow *f)
     return f->alparser->frames;
 }
 
+static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
+        const AppProto alproto, void *alstate, const uint8_t direction);
+
 #ifdef UNITTESTS
 void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
 {
@@ -1290,8 +1293,7 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
         if (!(p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
             SCLogDebug("app-layer parser does not accept gaps");
             if (f->alstate != NULL && !FlowChangeProto(f)) {
-                AppLayerParserStreamTruncated(f->proto, alproto, f->alstate,
-                        flags);
+                AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
             }
             AppLayerIncGapErrorCounter(tv, f);
             goto error;
@@ -1437,7 +1439,7 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
 
     /* stream truncated, inform app layer */
     if (flags & STREAM_DEPTH)
-        AppLayerParserStreamTruncated(f->proto, alproto, alstate, flags);
+        AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
 
  end:
     /* update app progress */
@@ -1755,14 +1757,20 @@ uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag
     SCReturnUInt(pstate->flags & flag);
 }
 
-
-void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate,
-                                   uint8_t direction)
+static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
+        const AppProto alproto, void *alstate, const uint8_t direction)
 {
     SCEnter();
 
-    if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate != NULL)
+    if (direction & STREAM_TOSERVER) {
+        AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_TRUNC_TS);
+    } else {
+        AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_TRUNC_TC);
+    }
+
+    if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate != NULL) {
         alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate(alstate, direction);
+    }
 
     SCReturn;
 }
index 21565af316d66dc2cdcd3465ba3fab1e707ee884..c1ef0339407596a75d8bb6534fa03365adf2feb2 100644 (file)
@@ -38,6 +38,8 @@
 #define APP_LAYER_PARSER_BYPASS_READY          BIT_U16(4)
 #define APP_LAYER_PARSER_EOF_TS                BIT_U16(5)
 #define APP_LAYER_PARSER_EOF_TC                BIT_U16(6)
+#define APP_LAYER_PARSER_TRUNC_TS              BIT_U16(7)
+#define APP_LAYER_PARSER_TRUNC_TC              BIT_U16(8)
 
 /* Flags for AppLayerParserProtoCtx. */
 #define APP_LAYER_PARSER_OPT_ACCEPT_GAPS        BIT_U32(0)
@@ -289,9 +291,6 @@ void AppLayerParserRegisterProtocolParsers(void);
 void AppLayerParserStateSetFlag(AppLayerParserState *pstate, uint16_t flag);
 uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag);
 
-void AppLayerParserStreamTruncated(uint8_t ipproto, AppProto alproto, void *alstate,
-                        uint8_t direction);
-
 AppLayerParserState *AppLayerParserStateAlloc(void);
 void AppLayerParserStateFree(AppLayerParserState *pstate);