|
|
|
|
@ -269,7 +269,7 @@ fn probe(input: &[u8]) -> nom::IResult<&[u8], ()> {
|
|
|
|
|
// C exports.
|
|
|
|
|
|
|
|
|
|
/// C entry point for a probing parser.
|
|
|
|
|
unsafe extern "C" fn rs_template_probing_parser(
|
|
|
|
|
unsafe extern "C" fn template_probing_parser(
|
|
|
|
|
_flow: *const Flow, _direction: u8, input: *const u8, input_len: u32, _rdir: *mut u8,
|
|
|
|
|
) -> AppProto {
|
|
|
|
|
// Need at least 2 bytes.
|
|
|
|
|
@ -282,7 +282,7 @@ unsafe extern "C" fn rs_template_probing_parser(
|
|
|
|
|
return ALPROTO_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" fn rs_template_state_new(
|
|
|
|
|
extern "C" fn template_state_new(
|
|
|
|
|
_orig_state: *mut c_void, _orig_proto: AppProto,
|
|
|
|
|
) -> *mut c_void {
|
|
|
|
|
let state = TemplateState::new();
|
|
|
|
|
@ -290,16 +290,16 @@ extern "C" fn rs_template_state_new(
|
|
|
|
|
return Box::into_raw(boxed) as *mut c_void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_state_free(state: *mut c_void) {
|
|
|
|
|
unsafe extern "C" fn template_state_free(state: *mut c_void) {
|
|
|
|
|
std::mem::drop(Box::from_raw(state as *mut TemplateState));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_state_tx_free(state: *mut c_void, tx_id: u64) {
|
|
|
|
|
unsafe extern "C" fn template_state_tx_free(state: *mut c_void, tx_id: u64) {
|
|
|
|
|
let state = cast_pointer!(state, TemplateState);
|
|
|
|
|
state.free_tx(tx_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_parse_request(
|
|
|
|
|
unsafe extern "C" fn template_parse_request(
|
|
|
|
|
_flow: *const Flow, state: *mut c_void, pstate: *mut c_void, stream_slice: StreamSlice,
|
|
|
|
|
_data: *const c_void,
|
|
|
|
|
) -> AppLayerResult {
|
|
|
|
|
@ -323,7 +323,7 @@ unsafe extern "C" fn rs_template_parse_request(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_parse_response(
|
|
|
|
|
unsafe extern "C" fn template_parse_response(
|
|
|
|
|
_flow: *const Flow, state: *mut c_void, pstate: *mut c_void, stream_slice: StreamSlice,
|
|
|
|
|
_data: *const c_void,
|
|
|
|
|
) -> AppLayerResult {
|
|
|
|
|
@ -341,7 +341,7 @@ unsafe extern "C" fn rs_template_parse_response(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_state_get_tx(state: *mut c_void, tx_id: u64) -> *mut c_void {
|
|
|
|
|
unsafe extern "C" fn template_state_get_tx(state: *mut c_void, tx_id: u64) -> *mut c_void {
|
|
|
|
|
let state = cast_pointer!(state, TemplateState);
|
|
|
|
|
match state.get_tx(tx_id) {
|
|
|
|
|
Some(tx) => {
|
|
|
|
|
@ -353,12 +353,12 @@ unsafe extern "C" fn rs_template_state_get_tx(state: *mut c_void, tx_id: u64) ->
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_state_get_tx_count(state: *mut c_void) -> u64 {
|
|
|
|
|
unsafe extern "C" fn template_state_get_tx_count(state: *mut c_void) -> u64 {
|
|
|
|
|
let state = cast_pointer!(state, TemplateState);
|
|
|
|
|
return state.tx_id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn rs_template_tx_get_alstate_progress(tx: *mut c_void, _direction: u8) -> c_int {
|
|
|
|
|
unsafe extern "C" fn template_tx_get_alstate_progress(tx: *mut c_void, _direction: u8) -> c_int {
|
|
|
|
|
let tx = cast_pointer!(tx, TemplateTransaction);
|
|
|
|
|
|
|
|
|
|
// Transaction is done if we have a response.
|
|
|
|
|
@ -368,8 +368,8 @@ unsafe extern "C" fn rs_template_tx_get_alstate_progress(tx: *mut c_void, _direc
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export_tx_data_get!(rs_template_get_tx_data, TemplateTransaction);
|
|
|
|
|
export_state_data_get!(rs_template_get_state_data, TemplateState);
|
|
|
|
|
export_tx_data_get!(template_get_tx_data, TemplateTransaction);
|
|
|
|
|
export_state_data_get!(template_get_state_data, TemplateState);
|
|
|
|
|
|
|
|
|
|
// Parser name as a C style string.
|
|
|
|
|
const PARSER_NAME: &[u8] = b"altemplate\0";
|
|
|
|
|
@ -380,28 +380,28 @@ pub(super) unsafe extern "C" fn template_register_parser() {
|
|
|
|
|
name: PARSER_NAME.as_ptr() as *const c_char,
|
|
|
|
|
default_port: default_port.as_ptr(),
|
|
|
|
|
ipproto: IPPROTO_TCP,
|
|
|
|
|
probe_ts: Some(rs_template_probing_parser),
|
|
|
|
|
probe_tc: Some(rs_template_probing_parser),
|
|
|
|
|
probe_ts: Some(template_probing_parser),
|
|
|
|
|
probe_tc: Some(template_probing_parser),
|
|
|
|
|
min_depth: 0,
|
|
|
|
|
max_depth: 16,
|
|
|
|
|
state_new: rs_template_state_new,
|
|
|
|
|
state_free: rs_template_state_free,
|
|
|
|
|
tx_free: rs_template_state_tx_free,
|
|
|
|
|
parse_ts: rs_template_parse_request,
|
|
|
|
|
parse_tc: rs_template_parse_response,
|
|
|
|
|
get_tx_count: rs_template_state_get_tx_count,
|
|
|
|
|
get_tx: rs_template_state_get_tx,
|
|
|
|
|
state_new: template_state_new,
|
|
|
|
|
state_free: template_state_free,
|
|
|
|
|
tx_free: template_state_tx_free,
|
|
|
|
|
parse_ts: template_parse_request,
|
|
|
|
|
parse_tc: template_parse_response,
|
|
|
|
|
get_tx_count: template_state_get_tx_count,
|
|
|
|
|
get_tx: template_state_get_tx,
|
|
|
|
|
tx_comp_st_ts: 1,
|
|
|
|
|
tx_comp_st_tc: 1,
|
|
|
|
|
tx_get_progress: rs_template_tx_get_alstate_progress,
|
|
|
|
|
tx_get_progress: template_tx_get_alstate_progress,
|
|
|
|
|
get_eventinfo: Some(TemplateEvent::get_event_info),
|
|
|
|
|
get_eventinfo_byid: Some(TemplateEvent::get_event_info_by_id),
|
|
|
|
|
localstorage_new: None,
|
|
|
|
|
localstorage_free: None,
|
|
|
|
|
get_tx_files: None,
|
|
|
|
|
get_tx_iterator: Some(state_get_tx_iterator::<TemplateState, TemplateTransaction>),
|
|
|
|
|
get_tx_data: rs_template_get_tx_data,
|
|
|
|
|
get_state_data: rs_template_get_state_data,
|
|
|
|
|
get_tx_data: template_get_tx_data,
|
|
|
|
|
get_state_data: template_get_state_data,
|
|
|
|
|
apply_tx_config: None,
|
|
|
|
|
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
|
|
|
|
|
get_frame_id_by_name: None,
|
|
|
|
|
|