From a297fd029a254b157da37d44a6ab36ee359d940b Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Tue, 10 Jun 2025 11:43:12 +0200 Subject: [PATCH] packet: optimize json context cleaning We don't need to recycle the full alert array. This is going to optimize packet recycle time. --- src/decode.c | 5 +++-- src/decode.h | 2 +- src/packet.c | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/decode.c b/src/decode.c index 693f0273aa..9acbd0ab24 100644 --- a/src/decode.c +++ b/src/decode.c @@ -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; diff --git a/src/decode.h b/src/decode.h index 9bb97a13f4..397f4ca970 100644 --- a/src/decode.h +++ b/src/decode.h @@ -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); diff --git a/src/packet.c b/src/packet.c index 1bff85a6fc..8cde411b8e 100644 --- a/src/packet.c +++ b/src/packet.c @@ -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;