rust/parser: Extend Rust parser for event-by-id

Extend the Rust parsing infrastructure with the "get event info by id"
calls. This changeset extends the parser structure, the C-based
registration handlers and the template parser.
pull/3998/head
Jeff Lucovsky 6 years ago committed by Victor Julien
parent 294d0e8cba
commit a5d9d37c34

@ -430,6 +430,13 @@ pub extern "C" fn rs_template_state_get_event_info(
return -1;
}
#[no_mangle]
pub extern "C" fn rs_template_state_get_event_info_by_id(_event_id: std::os::raw::c_int,
_event_name: *mut *const std::os::raw::c_char,
_event_type: *mut core::AppLayerEventType
) -> i8 {
return -1;
}
#[no_mangle]
pub extern "C" fn rs_template_state_get_tx_iterator(
_ipproto: u8,
@ -530,6 +537,7 @@ pub unsafe extern "C" fn rs_template_register_parser() {
set_de_state: rs_template_tx_set_detect_state,
get_events: Some(rs_template_state_get_events),
get_eventinfo: Some(rs_template_state_get_event_info),
get_eventinfo_byid : Some(rs_template_state_get_event_info_by_id),
localstorage_new: None,
localstorage_free: None,
get_tx_mpm_id: None,

@ -80,8 +80,10 @@ pub struct RustParser {
/// Function to get events
pub get_events: Option<GetEventsFn>,
/// Function to get an event description
/// Function to get an event id from a description
pub get_eventinfo: Option<GetEventInfoFn>,
/// Function to get an event description from an event id
pub get_eventinfo_byid: Option<GetEventInfoByIdFn>,
/// Function to allocate local storage
pub localstorage_new: Option<LocalStorageNewFn>,
@ -137,6 +139,7 @@ pub type StateGetProgressFn = extern "C" fn (*mut c_void, u8) -> c_int;
pub type GetDetectStateFn = extern "C" fn (*mut c_void) -> *mut DetectEngineState;
pub type SetDetectStateFn = extern "C" fn (*mut c_void, &mut DetectEngineState) -> c_int;
pub type GetEventInfoFn = extern "C" fn (*const c_char, *mut c_int, *mut AppLayerEventType) -> c_int;
pub type GetEventInfoByIdFn = extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> i8;
pub type GetEventsFn = extern "C" fn (*mut c_void) -> *mut AppLayerDecoderEvents;
pub type GetTxLoggedFn = extern "C" fn (*mut c_void, *mut c_void) -> u32;
pub type SetTxLoggedFn = extern "C" fn (*mut c_void, *mut c_void, u32);

@ -1410,7 +1410,8 @@ static void ValidateParserProtoDump(AppProto alproto, uint8_t ipproto)
printf("Optional:\n");
printf("- LocalStorageAlloc %p LocalStorageFree %p\n", ctx->LocalStorageAlloc, ctx->LocalStorageFree);
printf("- StateGetTxLogged %p StateSetTxLogged %p\n", ctx->StateGetTxLogged, ctx->StateSetTxLogged);
printf("- StateGetEvents %p StateGetEventInfo %p\n", ctx->StateGetEvents, ctx->StateGetEventInfo);
printf("- StateGetEvents %p StateGetEventInfo %p StateGetEventInfoById %p\n", ctx->StateGetEvents, ctx->StateGetEventInfo,
ctx->StateGetEventInfoById);
}
#define BOTH_SET(a, b) ((a) != NULL && (b) != NULL)

@ -145,6 +145,10 @@ int AppLayerRegisterParser(const struct AppLayerParser *p, AppProto alproto)
AppLayerParserRegisterGetEventInfo(p->ip_proto, alproto,
p->StateGetEventInfo);
}
if (p->StateGetEventInfoById) {
AppLayerParserRegisterGetEventInfoById(p->ip_proto, alproto,
p->StateGetEventInfoById);
}
if (p->StateGetEvents) {
AppLayerParserRegisterGetEventsFunc(p->ip_proto, alproto,
p->StateGetEvents);

@ -57,6 +57,8 @@ typedef struct AppLayerParser {
AppLayerDecoderEvents *(*StateGetEvents)(void *);
int (*StateGetEventInfo)(const char *event_name,
int *event_id, AppLayerEventType *event_type);
int (*StateGetEventInfoById)(int event_id, const char **event_name,
AppLayerEventType *event_type);
void *(*LocalStorageAlloc)(void);
void (*LocalStorageFree)(void *);

Loading…
Cancel
Save