From a36af353bcf6ffceaeb14cdccbc35aad47e9e46e Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Thu, 19 Mar 2026 09:41:55 +0100 Subject: [PATCH] rust: bindgen SCFlowGetAppProtocol --- rust/sys/src/sys.rs | 3 +++ src/detect.c | 3 ++- src/flow-bindgen.h | 1 + src/flow.c | 5 +++++ src/flow.h | 7 ------- src/output-json-alert.c | 5 +++-- src/output-json-email-common.c | 3 ++- src/output-json-file.c | 3 ++- 8 files changed, 18 insertions(+), 12 deletions(-) diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index 87ca6972ff..4c8d9d0ca3 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -1755,6 +1755,9 @@ extern "C" { extern "C" { pub fn SCFlowGetDestinationPort(flow: *const Flow) -> u16; } +extern "C" { + pub fn SCFlowGetAppProtocol(f: *const Flow) -> AppProto; +} extern "C" { pub fn SCSRepCatGetByShortname(shortname: *const ::std::os::raw::c_char) -> u8; } diff --git a/src/detect.c b/src/detect.c index 704d5448a6..8287acb51e 100644 --- a/src/detect.c +++ b/src/detect.c @@ -29,6 +29,7 @@ #include "decode.h" #include "packet.h" #include "flow.h" +#include "flow-bindgen.h" #include "stream-tcp.h" #include "app-layer.h" #include "app-layer-parser.h" @@ -1012,7 +1013,7 @@ static DetectRunScratchpad DetectRunSetup(const DetectEngineCtx *de_ctx, { /* update flow flags with knowledge on disruptions */ flow_flags = FlowGetDisruptionFlags(pflow, flow_flags); - alproto = FlowGetAppProtocol(pflow); + alproto = SCFlowGetAppProtocol(pflow); if (p->proto == IPPROTO_TCP && pflow->protoctx && StreamReassembleRawHasDataReady(pflow->protoctx, p)) { p->flags |= PKT_DETECT_HAS_STREAMDATA; diff --git a/src/flow-bindgen.h b/src/flow-bindgen.h index 81631b9fb3..32d1af3fd6 100644 --- a/src/flow-bindgen.h +++ b/src/flow-bindgen.h @@ -25,5 +25,6 @@ void SCFlowGetLastTimeAsParts(const Flow *flow, uint64_t *secs, uint64_t *usecs) uint64_t SCFlowGetFlags(const Flow *flow); uint16_t SCFlowGetSourcePort(const Flow *flow); uint16_t SCFlowGetDestinationPort(const Flow *flow); +AppProto SCFlowGetAppProtocol(const Flow *f); #endif /* SURICATA_FLOW_BINDGEN_H */ diff --git a/src/flow.c b/src/flow.c index 48d603ccf1..4881463819 100644 --- a/src/flow.c +++ b/src/flow.c @@ -1231,6 +1231,11 @@ uint16_t SCFlowGetSourcePort(const Flow *flow) return flow->sp; } +AppProto SCFlowGetAppProtocol(const Flow *f) +{ + return f->alproto; +} + /** * \brief Get flow destination port. * diff --git a/src/flow.h b/src/flow.h index 9409f55d1a..03a18dc81c 100644 --- a/src/flow.h +++ b/src/flow.h @@ -576,12 +576,6 @@ SCFlowStorageId GetFlowBypassInfoID(void); void RegisterFlowBypassInfo(void); /** ----- Inline functions ----- */ - -static inline AppProto FlowGetAppProtocol(const Flow *f) -{ - return f->alproto; -} - static inline void *FlowGetAppState(const Flow *f) { return f->alstate; @@ -648,7 +642,6 @@ static inline bool FlowIsBypassed(const Flow *f) int FlowClearMemory(Flow *,uint8_t ); -AppProto FlowGetAppProtocol(const Flow *f); void *FlowGetAppState(const Flow *f); uint8_t FlowGetDisruptionFlags(const Flow *f, uint8_t flags); diff --git a/src/output-json-alert.c b/src/output-json-alert.c index 8c2c69eb05..db87622120 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -28,6 +28,7 @@ #include "packet.h" #include "detect.h" #include "flow.h" +#include "flow-bindgen.h" #include "conf.h" #include "stream.h" @@ -322,7 +323,7 @@ static void AlertAddPayload(AlertJsonOutputCtx *json_output_ctx, SCJsonBuilder * static void AlertAddAppLayer( const Packet *p, SCJsonBuilder *jb, const uint64_t tx_id, const uint16_t option_flags) { - const AppProto proto = FlowGetAppProtocol(p->flow); + const AppProto proto = SCFlowGetAppProtocol(p->flow); EveJsonSimpleAppLayerLogger *al = SCEveJsonSimpleGetLogger(proto); SCJsonBuilderMark mark = { 0, 0, 0 }; if (al && al->LogTx) { @@ -668,7 +669,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p) char xff_buffer[XFF_MAXLEN]; xff_buffer[0] = 0; if ((xff_cfg != NULL) && !(xff_cfg->flags & XFF_DISABLED) && p->flow != NULL) { - if (FlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) { + if (SCFlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) { if (pa->flags & PACKET_ALERT_FLAG_TX) { have_xff_ip = HttpXFFGetIPFromTx(p->flow, pa->tx_id, xff_cfg, xff_buffer, XFF_MAXLEN); diff --git a/src/output-json-email-common.c b/src/output-json-email-common.c index 9be14d63dc..b5e2dd29a8 100644 --- a/src/output-json-email-common.c +++ b/src/output-json-email-common.c @@ -51,6 +51,7 @@ #include "output-json.h" #include "output-json-email-common.h" +#include "flow-bindgen.h" #define LOG_EMAIL_DEFAULT 0 #define LOG_EMAIL_EXTENDED (1<<0) @@ -141,7 +142,7 @@ static bool EveEmailLogJsonData( MimeStateSMTP *mime_state; /* check if we have SMTP state or not */ - AppProto proto = FlowGetAppProtocol(f); + AppProto proto = SCFlowGetAppProtocol(f); switch (proto) { case ALPROTO_SMTP: smtp_state = (SMTPState *)state; diff --git a/src/output-json-file.c b/src/output-json-file.c index 0c22dadb47..3227a86c9d 100644 --- a/src/output-json-file.c +++ b/src/output-json-file.c @@ -66,6 +66,7 @@ #include "app-layer-htp-xff.h" #include "util-memcmp.h" #include "stream-tcp-reassemble.h" +#include "flow-bindgen.h" typedef struct OutputFileCtx_ { uint32_t file_cnt; @@ -104,7 +105,7 @@ SCJsonBuilder *JsonBuildFileInfoRecord(const Packet *p, const File *ff, void *tx int have_xff_ip = 0; char xff_buffer[XFF_MAXLEN]; if ((xff_cfg != NULL) && !(xff_cfg->flags & XFF_DISABLED)) { - if (FlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) { + if (SCFlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) { have_xff_ip = HttpXFFGetIPFromTx(p->flow, tx_id, xff_cfg, xff_buffer, XFF_MAXLEN); } if (have_xff_ip && xff_cfg->flags & XFF_OVERWRITE) {