]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
detect: checking validity of rules with http protocol
authorPhilippe Antoine <contact@catenacyber.fr>
Fri, 28 Jan 2022 13:02:32 +0000 (14:02 +0100)
committerVictor Julien <vjulien@oisf.net>
Fri, 28 Jan 2022 17:53:08 +0000 (18:53 +0100)
We want to check that a rule beginning with alert http
can be valid, that is if either HTTP1 or HTTP2 is enabled.
So, AppLayerProtoDetectGetProtoName will do a more complex
check for this ALPROTO_HTTP (any).

src/app-layer-detect-proto.c

index accaf530c35f28958c05f360e9ee880b5da0552c..5b43b0a97cba659b29e9c9fe6f85501c4f48c4e4 100644 (file)
@@ -2190,6 +2190,18 @@ AppProto AppLayerProtoDetectGetProtoByName(const char *alproto_name)
 
 const char *AppLayerProtoDetectGetProtoName(AppProto alproto)
 {
+    // Special case for http (any version) :
+    // returns "http" if both versions are enabled
+    // and returns "http1" or "http2" if only one version is enabled
+    if (alproto == ALPROTO_HTTP) {
+        if (alpd_ctx.alproto_names[ALPROTO_HTTP1]) {
+            if (alpd_ctx.alproto_names[ALPROTO_HTTP2]) {
+                return "http";
+            } // else
+            return alpd_ctx.alproto_names[ALPROTO_HTTP1];
+        } // else
+        return alpd_ctx.alproto_names[ALPROTO_HTTP2];
+    }
     return alpd_ctx.alproto_names[alproto];
 }