rust/ike: replace rs_ naming with SC

pull/13152/head
Jason Ish 1 year ago committed by Victor Julien
parent 717e06e351
commit bfa0acf278

@ -25,7 +25,7 @@ use std::os::raw::c_void;
use std::ptr;
#[no_mangle]
pub extern "C" fn rs_ike_state_get_exch_type(tx: &IKETransaction, exch_type: *mut u8) -> u8 {
pub extern "C" fn SCIkeStateGetExchType(tx: &IKETransaction, exch_type: *mut u8) -> u8 {
debug_validate_bug_on!(exch_type.is_null());
if tx.ike_version == 1 {
@ -46,7 +46,7 @@ pub extern "C" fn rs_ike_state_get_exch_type(tx: &IKETransaction, exch_type: *mu
}
#[no_mangle]
pub extern "C" fn rs_ike_state_get_spi_initiator(
pub extern "C" fn SCIkeStateGetSpiInitiator(
tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null());
@ -59,7 +59,7 @@ pub extern "C" fn rs_ike_state_get_spi_initiator(
}
#[no_mangle]
pub extern "C" fn rs_ike_state_get_spi_responder(
pub extern "C" fn SCIkeStateGetSpiResponder(
tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null());
@ -72,7 +72,7 @@ pub extern "C" fn rs_ike_state_get_spi_responder(
}
#[no_mangle]
pub extern "C" fn rs_ike_state_get_nonce(
pub extern "C" fn SCIkeStateGetNonce(
tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null());
@ -95,7 +95,7 @@ pub extern "C" fn rs_ike_state_get_nonce(
}
#[no_mangle]
pub extern "C" fn rs_ike_state_get_key_exchange(
pub extern "C" fn SCIkeStateGetKeyExchange(
tx: &IKETransaction, buffer: *mut *const u8, buffer_len: *mut u32,
) -> u8 {
debug_validate_bug_on!(buffer.is_null() || buffer_len.is_null());
@ -118,7 +118,7 @@ pub extern "C" fn rs_ike_state_get_key_exchange(
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_tx_get_vendor(
pub unsafe extern "C" fn SCIkeTxGetVendor(
_de: *mut DetectEngineThreadCtx, tx: *const c_void, _flags: u8, i: u32, buf: *mut *const u8,
len: *mut u32,
) -> bool {
@ -136,7 +136,7 @@ pub unsafe extern "C" fn rs_ike_tx_get_vendor(
}
#[no_mangle]
pub extern "C" fn rs_ike_state_get_sa_attribute(
pub extern "C" fn SCIkeStateGetSaAttribute(
tx: &IKETransaction, sa_type: *const std::os::raw::c_char, value: *mut u32,
) -> u8 {
debug_validate_bug_on!(value.is_null());
@ -207,7 +207,7 @@ pub extern "C" fn rs_ike_state_get_sa_attribute(
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_state_get_key_exchange_payload_length(
pub unsafe extern "C" fn SCIkeStateGetKeyExchangePayloadLength(
tx: &IKETransaction, value: *mut u32,
) -> u8 {
debug_validate_bug_on!(value.is_null());
@ -222,7 +222,7 @@ pub unsafe extern "C" fn rs_ike_state_get_key_exchange_payload_length(
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_state_get_nonce_payload_length(
pub unsafe extern "C" fn SCIkeStateGetNoncePayloadLength(
tx: &IKETransaction, value: *mut u32,
) -> u8 {
debug_validate_bug_on!(value.is_null());

@ -115,7 +115,6 @@ pub struct IKETransaction {
/// errors seen during exchange
pub errors: u32,
logged: LoggerFlags,
pub tx_data: applayer::AppLayerTxData,
}
@ -280,8 +279,7 @@ fn probe(input: &[u8], direction: Direction, rdir: *mut u8) -> bool {
// C exports.
/// C entry point for a probing parser.
#[no_mangle]
pub unsafe extern "C" fn rs_ike_probing_parser(
unsafe extern "C" fn ike_probing_parser(
_flow: *const Flow, direction: u8, input: *const u8, input_len: u32, rdir: *mut u8,
) -> AppProto {
if input_len < 28 {
@ -298,8 +296,7 @@ pub unsafe extern "C" fn rs_ike_probing_parser(
return ALPROTO_FAILED;
}
#[no_mangle]
pub extern "C" fn rs_ike_state_new(
extern "C" fn ike_state_new(
_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto,
) -> *mut std::os::raw::c_void {
let state = IKEState::default();
@ -307,20 +304,17 @@ pub extern "C" fn rs_ike_state_new(
return Box::into_raw(boxed) as *mut _;
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_state_free(state: *mut std::os::raw::c_void) {
unsafe extern "C" fn ike_state_free(state: *mut std::os::raw::c_void) {
// Just unbox...
std::mem::drop(Box::from_raw(state as *mut IKEState));
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_state_tx_free(state: *mut std::os::raw::c_void, tx_id: u64) {
unsafe extern "C" fn ike_state_tx_free(state: *mut std::os::raw::c_void, tx_id: u64) {
let state = cast_pointer!(state, IKEState);
state.free_tx(tx_id);
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_parse_request(
unsafe extern "C" fn ike_parse_request(
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
) -> AppLayerResult {
@ -328,8 +322,7 @@ pub unsafe extern "C" fn rs_ike_parse_request(
return state.handle_input(stream_slice.as_slice(), Direction::ToServer);
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_parse_response(
unsafe extern "C" fn ike_parse_response(
_flow: *const Flow, state: *mut std::os::raw::c_void, _pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice, _data: *const std::os::raw::c_void,
) -> AppLayerResult {
@ -337,8 +330,7 @@ pub unsafe extern "C" fn rs_ike_parse_response(
return state.handle_input(stream_slice.as_slice(), Direction::ToClient);
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_state_get_tx(
unsafe extern "C" fn ike_state_get_tx(
state: *mut std::os::raw::c_void, tx_id: u64,
) -> *mut std::os::raw::c_void {
let state = cast_pointer!(state, IKEState);
@ -352,41 +344,17 @@ pub unsafe extern "C" fn rs_ike_state_get_tx(
}
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_state_get_tx_count(state: *mut std::os::raw::c_void) -> u64 {
unsafe extern "C" fn ike_state_get_tx_count(state: *mut std::os::raw::c_void) -> u64 {
let state = cast_pointer!(state, IKEState);
return state.tx_id;
}
#[no_mangle]
pub extern "C" fn rs_ike_state_progress_completion_status(_direction: u8) -> std::os::raw::c_int {
// This parser uses 1 to signal transaction completion status.
return 1;
}
#[no_mangle]
pub extern "C" fn rs_ike_tx_get_alstate_progress(
extern "C" fn ike_tx_get_alstate_progress(
_tx: *mut std::os::raw::c_void, _direction: u8,
) -> std::os::raw::c_int {
return 1;
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_tx_get_logged(
_state: *mut std::os::raw::c_void, tx: *mut std::os::raw::c_void,
) -> u32 {
let tx = cast_pointer!(tx, IKETransaction);
return tx.logged.get();
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_tx_set_logged(
_state: *mut std::os::raw::c_void, tx: *mut std::os::raw::c_void, logged: u32,
) {
let tx = cast_pointer!(tx, IKETransaction);
tx.logged.set(logged);
}
static mut ALPROTO_IKE: AppProto = ALPROTO_UNKNOWN;
// Parser name as a C style string.
@ -403,20 +371,20 @@ pub unsafe extern "C" fn rs_ike_register_parser() {
name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
default_port: default_port.as_ptr(),
ipproto: core::IPPROTO_UDP,
probe_ts: Some(rs_ike_probing_parser),
probe_tc: Some(rs_ike_probing_parser),
probe_ts: Some(ike_probing_parser),
probe_tc: Some(ike_probing_parser),
min_depth: 0,
max_depth: 16,
state_new: rs_ike_state_new,
state_free: rs_ike_state_free,
tx_free: rs_ike_state_tx_free,
parse_ts: rs_ike_parse_request,
parse_tc: rs_ike_parse_response,
get_tx_count: rs_ike_state_get_tx_count,
get_tx: rs_ike_state_get_tx,
state_new: ike_state_new,
state_free: ike_state_free,
tx_free: ike_state_tx_free,
parse_ts: ike_parse_request,
parse_tc: ike_parse_response,
get_tx_count: ike_state_get_tx_count,
get_tx: ike_state_get_tx,
tx_comp_st_ts: 1,
tx_comp_st_tc: 1,
tx_get_progress: rs_ike_tx_get_alstate_progress,
tx_get_progress: ike_tx_get_alstate_progress,
get_eventinfo: Some(IkeEvent::get_event_info),
get_eventinfo_byid: Some(IkeEvent::get_event_info_by_id),
localstorage_new: None,

@ -226,7 +226,7 @@ fn log_ikev2(tx: &IKETransaction, jb: &mut JsonBuilder) -> Result<(), JsonError>
}
#[no_mangle]
pub unsafe extern "C" fn rs_ike_logger_log(
pub unsafe extern "C" fn SCIkeLoggerLog(
state: &mut IKEState, tx: *mut std::os::raw::c_void, flags: u32, js: &mut JsonBuilder,
) -> bool {
let tx = cast_pointer!(tx, IKETransaction);

@ -105,7 +105,7 @@ static int DetectIkeChosenSaMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8
const DetectIkeChosenSaData *dd = (const DetectIkeChosenSaData *)ctx;
uint32_t value;
if (!rs_ike_state_get_sa_attribute(txv, dd->sa_type, &value))
if (!SCIkeStateGetSaAttribute(txv, dd->sa_type, &value))
SCReturnInt(0);
if (value == dd->sa_value)
SCReturnInt(1);

@ -87,7 +87,7 @@ static int DetectIkeExchTypeMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8
SCEnter();
uint8_t exch_type;
if (!rs_ike_state_get_exch_type(txv, &exch_type))
if (!SCIkeStateGetExchType(txv, &exch_type))
SCReturnInt(0);
const DetectU8Data *du8 = (const DetectU8Data *)ctx;

@ -91,7 +91,7 @@ static int DetectIkeKeyExchangePayloadLengthMatch(DetectEngineThreadCtx *det_ctx
SCEnter();
uint32_t length;
if (!rs_ike_state_get_key_exchange_payload_length(txv, &length))
if (!SCIkeStateGetKeyExchangePayloadLength(txv, &length))
SCReturnInt(0);
const DetectU32Data *du32 = (const DetectU32Data *)ctx;
return DetectU32Match(length, du32);

@ -78,7 +78,7 @@ static InspectionBuffer *GetKeyExchangeData(DetectEngineThreadCtx *det_ctx,
const uint8_t *b = NULL;
uint32_t b_len = 0;
if (rs_ike_state_get_key_exchange(txv, &b, &b_len) != 1)
if (SCIkeStateGetKeyExchange(txv, &b, &b_len) != 1)
return NULL;
if (b == NULL || b_len == 0)
return NULL;

@ -87,7 +87,7 @@ static int DetectIkeNoncePayloadLengthMatch(DetectEngineThreadCtx *det_ctx, Flow
SCEnter();
uint32_t length;
if (!rs_ike_state_get_nonce_payload_length(txv, &length))
if (!SCIkeStateGetNoncePayloadLength(txv, &length))
SCReturnInt(0);
const DetectU32Data *du32 = (const DetectU32Data *)ctx;
return DetectU32Match(length, du32);

@ -78,7 +78,7 @@ static InspectionBuffer *GetNonceData(DetectEngineThreadCtx *det_ctx,
const uint8_t *b = NULL;
uint32_t b_len = 0;
if (rs_ike_state_get_nonce(txv, &b, &b_len) != 1)
if (SCIkeStateGetNonce(txv, &b, &b_len) != 1)
return NULL;
if (b == NULL || b_len == 0)
return NULL;

@ -95,7 +95,7 @@ static InspectionBuffer *GetInitiatorData(DetectEngineThreadCtx *det_ctx,
const uint8_t *b = NULL;
uint32_t b_len = 0;
if (rs_ike_state_get_spi_initiator(txv, &b, &b_len) != 1)
if (SCIkeStateGetSpiInitiator(txv, &b, &b_len) != 1)
return NULL;
if (b == NULL || b_len == 0)
return NULL;
@ -115,7 +115,7 @@ static InspectionBuffer *GetResponderData(DetectEngineThreadCtx *det_ctx,
const uint8_t *b = NULL;
uint32_t b_len = 0;
if (rs_ike_state_get_spi_responder(txv, &b, &b_len) != 1)
if (SCIkeStateGetSpiResponder(txv, &b, &b_len) != 1)
return NULL;
if (b == NULL || b_len == 0)
return NULL;

@ -53,7 +53,7 @@ void DetectIkeVendorRegister(void)
sigmatch_table[DETECT_IKE_VENDOR].flags |= SIGMATCH_INFO_STICKY_BUFFER;
DetectAppLayerMultiRegister(
"ike.vendor", ALPROTO_IKE, SIG_FLAG_TOSERVER, 1, rs_ike_tx_get_vendor, 1);
"ike.vendor", ALPROTO_IKE, SIG_FLAG_TOSERVER, 1, SCIkeTxGetVendor, 1);
g_ike_vendor_buffer_id = DetectBufferTypeGetByName("ike.vendor");

@ -68,7 +68,7 @@ bool EveIKEAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *js)
if (state) {
IKETransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_IKE, state, tx_id);
if (tx) {
return rs_ike_logger_log(state, tx, LOG_IKE_EXTENDED, js);
return SCIkeLoggerLog(state, tx, LOG_IKE_EXTENDED, js);
}
}
@ -86,7 +86,7 @@ static int JsonIKELogger(ThreadVars *tv, void *thread_data, const Packet *p, Flo
}
LogIKEFileCtx *ike_ctx = thread->ikelog_ctx;
if (!rs_ike_logger_log(state, tx, ike_ctx->flags, jb)) {
if (!SCIkeLoggerLog(state, tx, ike_ctx->flags, jb)) {
goto error;
}

Loading…
Cancel
Save