frames: add FrameGetLastOpenByType

Getter for the most recent frame with unknown length (-1).
pull/11236/head
Victor Julien 3 years ago committed by Victor Julien
parent c7402d2d01
commit 803e8dd32e

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2022 Open Information Security Foundation
/* Copyright (C) 2007-2024 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -83,6 +83,32 @@ static void FrameDebug(const char *prefix, const Frames *frames, const Frame *fr
#endif
}
/**
* \note "open" means a frame that has no length set (len == -1)
* \todo perhaps we can search backwards */
Frame *FrameGetLastOpenByType(Frames *frames, const uint8_t frame_type)
{
Frame *candidate = NULL;
SCLogDebug(
"frames %p cnt %u, looking for last of type %" PRIu8, frames, frames->cnt, frame_type);
for (uint16_t i = 0; i < frames->cnt; i++) {
if (i < FRAMES_STATIC_CNT) {
Frame *frame = &frames->sframes[i];
FrameDebug("get_by_id(static)", frames, frame);
if (frame->type == frame_type && frame->len == -1)
candidate = frame;
} else {
const uint16_t o = i - FRAMES_STATIC_CNT;
Frame *frame = &frames->dframes[o];
FrameDebug("get_by_id(dynamic)", frames, frame);
if (frame->type == frame_type && frame->len == -1)
candidate = frame;
}
}
return candidate;
}
Frame *FrameGetById(Frames *frames, const int64_t id)
{
SCLogDebug("frames %p cnt %u, looking for %" PRIi64, frames, frames->cnt, id);

@ -88,6 +88,7 @@ void AppLayerFrameDump(Flow *f);
Frame *FrameGetByIndex(Frames *frames, const uint32_t idx);
Frame *FrameGetById(Frames *frames, const int64_t id);
Frame *FrameGetLastOpenByType(Frames *frames, const uint8_t frame_type);
Frame *AppLayerFrameGetById(Flow *f, const int direction, const FrameId frame_id);
FrameId AppLayerFrameGetId(Frame *r);

Loading…
Cancel
Save