]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
packet: optimize json context cleaning
authorEric Leblond <el@stamus-networks.com>
Tue, 10 Jun 2025 09:43:12 +0000 (11:43 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 11 Jun 2025 18:49:19 +0000 (20:49 +0200)
We don't need to recycle the full alert array. This is going to
optimize packet recycle time.

src/decode.c
src/decode.h
src/packet.c

index 693f0273aa60936bd579765bfea2b238a91dee0f..9acbd0ab24809ea4c25295a1d953d32429f83be1 100644 (file)
@@ -145,11 +145,12 @@ PacketAlert *PacketAlertCreate(void)
     return pa_array;
 }
 
-void PacketAlertRecycle(PacketAlert *pa_array)
+void PacketAlertRecycle(PacketAlert *pa_array, uint16_t cnt)
 {
     if (pa_array == NULL)
         return;
-    for (int i = 0; i < packet_alert_max; i++) {
+    /* Clean json content for alerts attached to the packet */
+    for (int i = 0; i < cnt; i++) {
         struct PacketContextData *current_json = pa_array[i].json_info;
         while (current_json) {
             struct PacketContextData *next_json = current_json->next;
index 9bb97a13f436a51c692fb6714348664e2c6df8f2..397f4ca97003b9db7a9cf470493d9543166984cc 100644 (file)
@@ -294,7 +294,7 @@ typedef struct PacketAlerts_ {
 } PacketAlerts;
 
 PacketAlert *PacketAlertCreate(void);
-void PacketAlertRecycle(PacketAlert *pa_array);
+void PacketAlertRecycle(PacketAlert *pa_array, uint16_t cnt);
 
 void PacketAlertFree(PacketAlert *pa);
 
index 1bff85a6fc1022c80be4f460c96cda56f9b0ebf7..8cde411b8e17897e692a3e927663147a7eec5f5f 100644 (file)
@@ -123,11 +123,12 @@ void PacketReinit(Packet *p)
     p->BypassPacketsFlow = NULL;
 #define RESET_PKT_LEN(p) ((p)->pktlen = 0)
     RESET_PKT_LEN(p);
-    p->alerts.cnt = 0;
     p->alerts.discarded = 0;
     p->alerts.suppressed = 0;
     p->alerts.drop.action = 0;
-    PacketAlertRecycle(p->alerts.alerts);
+    if (p->alerts.cnt > 0)
+        PacketAlertRecycle(p->alerts.alerts, p->alerts.cnt);
+    p->alerts.cnt = 0;
     p->pcap_cnt = 0;
     p->tunnel_rtv_cnt = 0;
     p->tunnel_tpr_cnt = 0;