Skip to content

Conversation

@catenacyber
Copy link
Contributor

Link to ticket: https://redmine.openinfosecfoundation.org/issues/
https://redmine.openinfosecfoundation.org/issues/7762

Describe changes:

  • rust: bindgen SCAppLayerRegisterParser : final round !

#14665 with cargo test and plugin build fix

cc @jasonish

As will be needed such as AppLayerTxData
and bindgen it to rust.

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerGetFileState
and bindgen it to rust, and use default trait instead of new

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerStateData
and bindgen it to rust

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerGetTxIterTuple
and bindgen it to rust

Will make easier the bindgen of RustParser structure which uses
a callback which uses StreamSlice
and bindgen it to rust

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerResult

Keep From<> impl in sys crate that defines it
and bindgen it to rust

Will make easier the bindgen of RustParser structure which uses
a callback which uses AppLayerTxData

Move also the free function to C SCAppLayerTxDataCleanup
As suricata-sys crate defines AppLayerTxData for rust,
It must itself implement the Drop trait, and thus,
We need to define a feature surest
@catenacyber catenacyber force-pushed the bindgen-more-7762-v8.4.3 branch from 550973d to f502856 Compare January 21, 2026 15:26
@codecov
Copy link

codecov bot commented Jan 21, 2026

Codecov Report

❌ Patch coverage is 73.80952% with 77 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.11%. Comparing base (c333b28) to head (f502856).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14667      +/-   ##
==========================================
- Coverage   82.11%   82.11%   -0.01%     
==========================================
  Files        1011     1011              
  Lines      262812   262843      +31     
==========================================
+ Hits       215812   215834      +22     
- Misses      47000    47009       +9     
Flag Coverage Δ
fuzzcorpus 60.20% <73.37%> (+0.02%) ⬆️
livemode 18.73% <14.67%> (+0.02%) ⬆️
pcap 44.61% <66.21%> (+0.02%) ⬆️
suricata-verify 65.31% <79.45%> (+0.02%) ⬆️
unittests 59.26% <47.10%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa
Copy link

WARNING:

field baseline test %
TREX_GENERIC_stats_chk
.tcp.pkt_on_wrong_thread 0 236 -
.tcp.memuse 1824000000 912000000 50.0%
.tcp.reassembly_memuse 2403688 1185240 49.31%
.flow.tcp_reuse 0 6 -
.flow.end.tcp_state.syn_sent 0 6 -
.flow.end.tcp_state.time_wait 0 5 -
.flow.end.tcp_state.close_wait 0 1 -
.app_layer.flow.ftp 0 1 -
.app_layer.error.ftp.parser 0 1 -
.app_layer.error.dcerpc_tcp.parser 0 2 -
.app_layer.tx.ftp 0 3 -

Pipeline = 29228

Copy link
Member

@jasonish jasonish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI and QA issues unrelated.

let buf = stream_slice.as_slice();
let hdr = &mut state.transaction.srv_hdr;
state.transaction.tx_data.updated_tc = true;
state.transaction.tx_data.0.updated_tc = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this .0. pattern that this PR introduces, why was it added? I don't see an explanation for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was discussed in earlier versions of the PR : #14660 (comment)

Trying to sum up :

We move AppLayerTxData definition to C and bindgen it (because we bindgen function SCAppLayerRegisterParser whose arguments have AppLayerTxData)

We need to free memory of some fields of AppLayerTxData which are pointers so we implement Drop trait on it, this way, a WhateverTransaction having a AppLayerTxData field will do the right thing (ie free the memory).

But we cannot implement Drop on a type outside the current crate : suricata crate cannot implement Drop for AppLayerTxData in the suricata_sys crate
My first solution was to add the impl Drop for AppLayerTxData in rust/sys/src/lib.rs in #14660 but Jason did not like it and proposed to use a wrapper type in suricata crate.

So we have
pub struct AppLayerTxData(pub suricata_sys::sys::AppLayerTxData);
and we can implement Drop on suricata's AppLayerTxData
But we need to add the .0 to access its inner fields

Copy link
Member

@jasonish jasonish Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a pretty common pattern when you need to wrap something in a struct to work around some issues in Rust, one being where you can't define a trait on a struct from another crate.

From the Rust book: https://doc.rust-lang.org/book/ch20-02-advanced-traits.html#implementing-external-traits-with-the-newtype-pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@victorjulien do you approve this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants