Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust/app-layer: derive functions for app-layer events - v10 #6318

Closed
wants to merge 18 commits into from

Conversation

jasonish
Copy link
Member

Previous PR: #5579

Redmine issue:
https://redmine.openinfosecfoundation.org/issues/4154

Changes from last PR:

  • Squash some fixup commits
  • Rebase, add modbus

This PR shows how we can use a Rust procedural macro to derive AppLayer event
functions from an emum.

Given an enum like:

#[derive(Debug, PartialEq, AppLayerEvent)]
pub enum DNSEvent {
    MalformedData,
    NotRequest,
    NotResponse,
    ZFlagSet,
}

supporting code will be added allowing the protocol to register
get_event_info and get_event_info_by_id callbacks like:

get_eventinfo: Some(DNSEvent::get_event_info),
get_eventinfo_byid: Some(DNSEvent::get_event_info_by_id),

All the parser needs to do is enumerate the different events, the macro will
take care of generating the support code.

The derive macro will implement this trait for app-layer
event enums.
Currently has one derive, AppLayerEvent to be used like:

  #[derive(AppLayerEvent)]
  pub enum DNSEvent {
      MalformedData,
      NotRequest,
      NotResponse,
      ZFlagSet,
  }

Code will be generated to:
- Convert enum to a c type string
- Convert string to enum variant
- Convert id to enum variant
Provide generic functions for get_event_info and
get_event_info_by_id. These functions can be used by any app-layer
event enum that implements AppLayerEvent.

Unfortunately the parser registration cannot use these functions
directly as generic functions cannot be #[no_mangle]. So they
do need small extern "C" wrappers around them.
Add generation of wrapper functions for get_event_info
and get_event_info_by_id to the derive macro. Eliminates
the need for the wrapper method to be created by the parser
author.
Implementations are not required if they're just going to return
-1. We allow None to be registered for that.
@codecov
Copy link

codecov bot commented Aug 30, 2021

Codecov Report

Merging #6318 (d9a18ff) into master (7551247) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #6318   +/-   ##
=======================================
  Coverage   76.95%   76.95%           
=======================================
  Files         611      611           
  Lines      185955   185955           
=======================================
  Hits       143102   143102           
  Misses      42853    42853           
Flag Coverage Δ
fuzzcorpus 52.87% <ø> (+0.01%) ⬆️
suricata-verify 51.10% <ø> (-0.02%) ⬇️
unittests 63.12% <ø> (ø)

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

This was referenced Aug 31, 2021
@victorjulien
Copy link
Member

Merged in #6324, thanks!

@jasonish jasonish deleted the derive-app-event/v10 branch September 2, 2021 19:58
AkakiAlice added a commit to AkakiAlice/suricata that referenced this pull request Oct 3, 2024
AkakiAlice added a commit to AkakiAlice/suricata that referenced this pull request Oct 3, 2024
AkakiAlice added a commit to AkakiAlice/suricata that referenced this pull request Oct 5, 2024
victorjulien pushed a commit to victorjulien/suricata that referenced this pull request Oct 8, 2024
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.

2 participants