rust/nfs: replace rs_ naming with SC

pull/13170/head
Jason Ish 1 year ago committed by Victor Julien
parent 01ce0f92e8
commit 8c1bd60ab1

@ -75,6 +75,7 @@ documentation_style = "doxy"
include = [
"StreamSlice",
"AppLayerStateData",
"AppLayerGetFileState",
"AppLayerGetTxIterTuple",
"RdpState",
"SIPState",

@ -22,7 +22,7 @@ use crate::nfs::nfs::*;
use crc::crc32;
#[no_mangle]
pub extern "C" fn rs_nfs_tx_logging_is_filtered(state: &mut NFSState,
pub extern "C" fn SCNfsTxLoggingIsFiltered(state: &mut NFSState,
tx: &NFSTransaction)
-> u8
{
@ -110,21 +110,6 @@ fn nfs_common_header(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder
Ok(())
}
fn nfs_log_request(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder)
-> Result<(), JsonError>
{
nfs_common_header(state, tx, js)?;
js.set_string("type", "request")?;
Ok(())
}
#[no_mangle]
pub extern "C" fn rs_nfs_log_json_request(state: &mut NFSState, tx: &NFSTransaction,
js: &mut JsonBuilder) -> bool
{
nfs_log_request(state, tx, js).is_ok()
}
fn nfs_log_response(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder)
-> Result<(), JsonError>
{
@ -152,7 +137,7 @@ fn nfs_log_response(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder)
}
#[no_mangle]
pub extern "C" fn rs_nfs_log_json_response(state: &mut NFSState, tx: &NFSTransaction,
pub extern "C" fn SCNfsLogJsonResponse(state: &mut NFSState, tx: &NFSTransaction,
js: &mut JsonBuilder) -> bool
{
nfs_log_response(state, tx, js).is_ok()
@ -173,7 +158,7 @@ fn rpc_log_response(tx: &NFSTransaction, js: &mut JsonBuilder)
}
#[no_mangle]
pub extern "C" fn rs_rpc_log_json_response(tx: &NFSTransaction,
pub extern "C" fn SCNfsRpcLogJsonResponse(tx: &NFSTransaction,
js: &mut JsonBuilder) -> bool
{
rpc_log_response(tx, js).is_ok()

@ -162,8 +162,7 @@ impl NFSTransactionFile {
}
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_gettxfiles(tx: *mut std::ffi::c_void, direction: u8) -> AppLayerGetFileState {
unsafe extern "C" fn nfs_gettxfiles(tx: *mut std::ffi::c_void, direction: u8) -> AppLayerGetFileState {
let tx = cast_pointer!(tx, NFSTransaction);
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
let tx_dir : u8 = tdf.direction.into();
@ -1544,8 +1543,7 @@ impl NFSState {
}
/// Returns *mut NFSState
#[no_mangle]
pub extern "C" fn rs_nfs_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
extern "C" fn nfs_state_new(_orig_state: *mut std::os::raw::c_void, _orig_proto: AppProto) -> *mut std::os::raw::c_void {
let state = NFSState::new();
let boxed = Box::new(state);
SCLogDebug!("allocating state");
@ -1554,16 +1552,14 @@ pub extern "C" fn rs_nfs_state_new(_orig_state: *mut std::os::raw::c_void, _orig
/// Params:
/// - state: *mut NFSState as void pointer
#[no_mangle]
pub extern "C" fn rs_nfs_state_free(state: *mut std::os::raw::c_void) {
extern "C" fn nfs_state_free(state: *mut std::os::raw::c_void) {
// Just unbox...
SCLogDebug!("freeing state");
std::mem::drop(unsafe { Box::from_raw(state as *mut NFSState) });
}
/// C binding parse a NFS TCP request. Returns 1 on success, -1 on failure.
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_parse_request(flow: *const Flow,
unsafe extern "C" fn nfs_parse_request(flow: *const Flow,
state: *mut std::os::raw::c_void,
_pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice,
@ -1574,7 +1570,7 @@ pub unsafe extern "C" fn rs_nfs_parse_request(flow: *const Flow,
let flow = cast_pointer!(flow, Flow);
if stream_slice.is_gap() {
return rs_nfs_parse_request_tcp_gap(state, stream_slice.gap_size());
return nfs_parse_request_tcp_gap(state, stream_slice.gap_size());
}
SCLogDebug!("parsing {} bytes of request data", stream_slice.len());
@ -1582,8 +1578,7 @@ pub unsafe extern "C" fn rs_nfs_parse_request(flow: *const Flow,
state.parse_tcp_data_ts(flow, &stream_slice)
}
#[no_mangle]
pub extern "C" fn rs_nfs_parse_request_tcp_gap(
extern "C" fn nfs_parse_request_tcp_gap(
state: &mut NFSState,
input_len: u32)
-> AppLayerResult
@ -1591,8 +1586,7 @@ pub extern "C" fn rs_nfs_parse_request_tcp_gap(
state.parse_tcp_data_ts_gap(input_len)
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_parse_response(flow: *const Flow,
unsafe extern "C" fn nfs_parse_response(flow: *const Flow,
state: *mut std::os::raw::c_void,
_pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice,
@ -1603,7 +1597,7 @@ pub unsafe extern "C" fn rs_nfs_parse_response(flow: *const Flow,
let flow = cast_pointer!(flow, Flow);
if stream_slice.is_gap() {
return rs_nfs_parse_response_tcp_gap(state, stream_slice.gap_size());
return nfs_parse_response_tcp_gap(state, stream_slice.gap_size());
}
SCLogDebug!("parsing {} bytes of response data", stream_slice.len());
@ -1611,8 +1605,7 @@ pub unsafe extern "C" fn rs_nfs_parse_response(flow: *const Flow,
state.parse_tcp_data_tc(flow, &stream_slice)
}
#[no_mangle]
pub extern "C" fn rs_nfs_parse_response_tcp_gap(
extern "C" fn nfs_parse_response_tcp_gap(
state: &mut NFSState,
input_len: u32)
-> AppLayerResult
@ -1621,8 +1614,7 @@ pub extern "C" fn rs_nfs_parse_response_tcp_gap(
}
/// C binding to parse an NFS/UDP request. Returns 1 on success, -1 on failure.
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_parse_request_udp(f: *const Flow,
unsafe extern "C" fn nfs_parse_request_udp(f: *const Flow,
state: *mut std::os::raw::c_void,
_pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice,
@ -1635,8 +1627,7 @@ pub unsafe extern "C" fn rs_nfs_parse_request_udp(f: *const Flow,
state.parse_udp_ts(f, &stream_slice)
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_parse_response_udp(f: *const Flow,
unsafe extern "C" fn nfs_parse_response_udp(f: *const Flow,
state: *mut std::os::raw::c_void,
_pstate: *mut std::os::raw::c_void,
stream_slice: StreamSlice,
@ -1648,17 +1639,15 @@ pub unsafe extern "C" fn rs_nfs_parse_response_udp(f: *const Flow,
state.parse_udp_tc(f, &stream_slice)
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_state_get_tx_count(state: *mut std::os::raw::c_void)
pub unsafe extern "C" fn nfs_state_get_tx_count(state: *mut std::os::raw::c_void)
-> u64
{
let state = cast_pointer!(state, NFSState);
SCLogDebug!("rs_nfs_state_get_tx_count: returning {}", state.tx_id);
SCLogDebug!("nfs_state_get_tx_count: returning {}", state.tx_id);
return state.tx_id;
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_state_get_tx(state: *mut std::os::raw::c_void,
unsafe extern "C" fn nfs_state_get_tx(state: *mut std::os::raw::c_void,
tx_id: u64)
-> *mut std::os::raw::c_void
{
@ -1673,16 +1662,14 @@ pub unsafe extern "C" fn rs_nfs_state_get_tx(state: *mut std::os::raw::c_void,
}
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_state_tx_free(state: *mut std::os::raw::c_void,
unsafe extern "C" fn nfs_state_tx_free(state: *mut std::os::raw::c_void,
tx_id: u64)
{
let state = cast_pointer!(state, NFSState);
state.free_tx(tx_id);
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_tx_get_alstate_progress(tx: *mut std::os::raw::c_void,
unsafe extern "C" fn nfs_tx_get_alstate_progress(tx: *mut std::os::raw::c_void,
direction: u8)
-> std::os::raw::c_int
{
@ -1699,8 +1686,7 @@ pub unsafe extern "C" fn rs_nfs_tx_get_alstate_progress(tx: *mut std::os::raw::c
}
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_get_tx_data(
unsafe extern "C" fn nfs_get_tx_data(
tx: *mut std::os::raw::c_void)
-> *mut AppLayerTxData
{
@ -1708,13 +1694,13 @@ pub unsafe extern "C" fn rs_nfs_get_tx_data(
return &mut tx.tx_data;
}
export_state_data_get!(rs_nfs_get_state_data, NFSState);
export_state_data_get!(nfs_get_state_data, NFSState);
/// return procedure(s) in the tx. At 0 return the main proc,
/// otherwise get procs from the 'file_additional_procs'.
/// Keep calling until 0 is returned.
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_tx_get_procedures(tx: &mut NFSTransaction,
pub unsafe extern "C" fn SCNfsTxGetProcedures(tx: &mut NFSTransaction,
i: u16,
procedure: *mut u32)
-> u8
@ -1742,14 +1728,14 @@ pub unsafe extern "C" fn rs_nfs_tx_get_procedures(tx: &mut NFSTransaction,
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_tx_get_version(tx: &mut NFSTransaction,
pub unsafe extern "C" fn SCNfsTxGetVersion(tx: &mut NFSTransaction,
version: *mut u32)
{
*version = tx.nfs_version as u32;
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_init(context: &'static mut SuricataFileContext)
pub unsafe extern "C" fn SCNfsInit(context: &'static mut SuricataFileContext)
{
SURICATA_NFS_FILE_CONFIG = Some(context);
}
@ -1865,8 +1851,7 @@ pub fn nfs_probe_udp(i: &[u8], direction: Direction) -> i32 {
}
/// MIDSTREAM
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_probe_ms(
unsafe extern "C" fn nfs_probe_ms(
_flow: *const Flow,
direction: u8, input: *const u8,
len: u32, rdir: *mut u8) -> AppProto
@ -1875,7 +1860,7 @@ pub unsafe extern "C" fn rs_nfs_probe_ms(
return ALPROTO_UNKNOWN;
}
let slice: &[u8] = build_slice!(input, len as usize);
SCLogDebug!("rs_nfs_probe_ms: probing direction {:02x}", direction);
SCLogDebug!("nfs_probe_ms: probing direction {:02x}", direction);
let mut adirection : u8 = 0;
match nfs_probe_dir(slice, &mut adirection) {
1 => {
@ -1905,8 +1890,7 @@ pub unsafe extern "C" fn rs_nfs_probe_ms(
}
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_probe(_f: *const Flow,
unsafe extern "C" fn ffi_nfs_probe(_f: *const Flow,
direction: u8,
input: *const u8,
len: u32,
@ -1917,7 +1901,7 @@ pub unsafe extern "C" fn rs_nfs_probe(_f: *const Flow,
return ALPROTO_UNKNOWN;
}
let slice: &[u8] = build_slice!(input, len as usize);
SCLogDebug!("rs_nfs_probe: running probe");
SCLogDebug!("ffi_nfs_probe: running probe");
match nfs_probe(slice, direction.into()) {
1 => { ALPROTO_NFS },
-1 => { ALPROTO_FAILED },
@ -1926,8 +1910,7 @@ pub unsafe extern "C" fn rs_nfs_probe(_f: *const Flow,
}
/// TOSERVER probe function
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_probe_udp_ts(_f: *const Flow,
unsafe extern "C" fn nfs_probe_udp_ts(_f: *const Flow,
_direction: u8,
input: *const u8,
len: u32,
@ -1946,8 +1929,7 @@ pub unsafe extern "C" fn rs_nfs_probe_udp_ts(_f: *const Flow,
}
/// TOCLIENT probe function
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_probe_udp_tc(_f: *const Flow,
unsafe extern "C" fn nfs_probe_udp_tc(_f: *const Flow,
_direction: u8,
input: *const u8,
len: u32,
@ -1969,7 +1951,7 @@ pub unsafe extern "C" fn rs_nfs_probe_udp_tc(_f: *const Flow,
const PARSER_NAME: &[u8] = b"nfs\0";
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_register_parser() {
pub unsafe extern "C" fn SCRegisterNfsParser() {
let default_port = CString::new("[2049]").unwrap();
let parser = RustParser {
name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
@ -1979,24 +1961,24 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
probe_tc: None,
min_depth: 0,
max_depth: 16,
state_new: rs_nfs_state_new,
state_free: rs_nfs_state_free,
tx_free: rs_nfs_state_tx_free,
parse_ts: rs_nfs_parse_request,
parse_tc: rs_nfs_parse_response,
get_tx_count: rs_nfs_state_get_tx_count,
get_tx: rs_nfs_state_get_tx,
state_new: nfs_state_new,
state_free: nfs_state_free,
tx_free: nfs_state_tx_free,
parse_ts: nfs_parse_request,
parse_tc: nfs_parse_response,
get_tx_count: nfs_state_get_tx_count,
get_tx: nfs_state_get_tx,
tx_comp_st_ts: 1,
tx_comp_st_tc: 1,
tx_get_progress: rs_nfs_tx_get_alstate_progress,
tx_get_progress: nfs_tx_get_alstate_progress,
get_eventinfo: Some(NFSEvent::get_event_info),
get_eventinfo_byid : Some(NFSEvent::get_event_info_by_id),
localstorage_new: None,
localstorage_free: None,
get_tx_files: Some(rs_nfs_gettxfiles),
get_tx_files: Some(nfs_gettxfiles),
get_tx_iterator: Some(applayer::state_get_tx_iterator::<NFSState, NFSTransaction>),
get_tx_data: rs_nfs_get_tx_data,
get_state_data: rs_nfs_get_state_data,
get_tx_data: nfs_get_tx_data,
get_state_data: nfs_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
@ -2019,20 +2001,20 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
if midstream {
if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_TCP,
parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN,
rs_nfs_probe_ms, rs_nfs_probe_ms) == 0 {
nfs_probe_ms, nfs_probe_ms) == 0 {
SCLogDebug!("No NFSTCP app-layer configuration, enabling NFSTCP detection TCP detection on port {:?}.",
default_port);
/* register 'midstream' probing parsers if midstream is enabled. */
AppLayerProtoDetectPPRegister(IPPROTO_TCP,
default_port.as_ptr(), ALPROTO_NFS, 0,
NFS_MIN_FRAME_LEN, Direction::ToServer.into(),
rs_nfs_probe_ms, rs_nfs_probe_ms);
nfs_probe_ms, nfs_probe_ms);
}
} else {
AppLayerProtoDetectPPRegister(IPPROTO_TCP,
default_port.as_ptr(), ALPROTO_NFS, 0,
NFS_MIN_FRAME_LEN, Direction::ToServer.into(),
rs_nfs_probe, rs_nfs_probe);
ffi_nfs_probe, ffi_nfs_probe);
}
if AppLayerParserConfParserEnabled(
ip_proto_str.as_ptr(),
@ -2048,7 +2030,7 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
}
#[no_mangle]
pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
pub unsafe extern "C" fn SCRegisterNfsUdpParser() {
let default_port = CString::new("[2049]").unwrap();
let parser = RustParser {
name: PARSER_NAME.as_ptr() as *const std::os::raw::c_char,
@ -2058,24 +2040,24 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
probe_tc: None,
min_depth: 0,
max_depth: 16,
state_new: rs_nfs_state_new,
state_free: rs_nfs_state_free,
tx_free: rs_nfs_state_tx_free,
parse_ts: rs_nfs_parse_request_udp,
parse_tc: rs_nfs_parse_response_udp,
get_tx_count: rs_nfs_state_get_tx_count,
get_tx: rs_nfs_state_get_tx,
state_new: nfs_state_new,
state_free: nfs_state_free,
tx_free: nfs_state_tx_free,
parse_ts: nfs_parse_request_udp,
parse_tc: nfs_parse_response_udp,
get_tx_count: nfs_state_get_tx_count,
get_tx: nfs_state_get_tx,
tx_comp_st_ts: 1,
tx_comp_st_tc: 1,
tx_get_progress: rs_nfs_tx_get_alstate_progress,
tx_get_progress: nfs_tx_get_alstate_progress,
get_eventinfo: Some(NFSEvent::get_event_info),
get_eventinfo_byid : Some(NFSEvent::get_event_info_by_id),
localstorage_new: None,
localstorage_free: None,
get_tx_files: Some(rs_nfs_gettxfiles),
get_tx_files: Some(nfs_gettxfiles),
get_tx_iterator: Some(applayer::state_get_tx_iterator::<NFSState, NFSTransaction>),
get_tx_data: rs_nfs_get_tx_data,
get_state_data: rs_nfs_get_state_data,
get_tx_data: nfs_get_tx_data,
get_state_data: nfs_get_state_data,
apply_tx_config: None,
flags: 0,
get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
@ -2096,13 +2078,13 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_UDP,
parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN,
rs_nfs_probe_udp_ts, rs_nfs_probe_udp_tc) == 0 {
nfs_probe_udp_ts, nfs_probe_udp_tc) == 0 {
SCLogDebug!("No NFSUDP app-layer configuration, enabling NFSUDP detection UDP detection on port {:?}.",
default_port);
AppLayerProtoDetectPPRegister(IPPROTO_UDP,
default_port.as_ptr(), ALPROTO_NFS, 0,
NFS_MIN_FRAME_LEN, Direction::ToServer.into(),
rs_nfs_probe_udp_ts, rs_nfs_probe_udp_tc);
nfs_probe_udp_ts, nfs_probe_udp_tc);
}
if AppLayerParserConfParserEnabled(
ip_proto_str.as_ptr(),

@ -51,7 +51,7 @@ void RegisterNFSTCPParsers(void)
* the configuration file then it will be enabled by default. */
if (AppLayerProtoDetectConfProtoDetectionEnabled("tcp", proto_name)) {
rs_nfs_init(&sfc);
rs_nfs_register_parser();
SCNfsInit(&sfc);
SCRegisterNfsParser();
}
}

@ -62,8 +62,8 @@ static SuricataFileContext sfc = { &sbcfg };
void RegisterNFSUDPParsers(void)
{
rs_nfs_init(&sfc);
rs_nfs_udp_register_parser();
SCNfsInit(&sfc);
SCRegisterNfsUdpParser();
#ifdef UNITTESTS
AppLayerParserRegisterProtocolUnittests(IPPROTO_UDP, ALPROTO_NFS,

@ -111,7 +111,7 @@ static int DetectNfsProcedureMatch (DetectEngineThreadCtx *det_ctx,
uint16_t i;
for (i = 0; i < 256; i++) {
uint32_t procedure;
if (rs_nfs_tx_get_procedures(txv, i, &procedure) == 1) {
if (SCNfsTxGetProcedures(txv, i, &procedure) == 1) {
SCLogDebug("proc %u mode %u lo %u hi %u", procedure, dd->mode, dd->arg1, dd->arg2);
if (DetectU32Match(procedure, dd))
SCReturnInt(1);

@ -100,7 +100,7 @@ static int DetectNfsVersionMatch (DetectEngineThreadCtx *det_ctx,
const DetectU32Data *dd = (const DetectU32Data *)ctx;
uint32_t version;
rs_nfs_tx_get_version(txv, &version);
SCNfsTxGetVersion(txv, &version);
SCLogDebug("version %u mode %u lo %u hi %u", version, dd->mode, dd->arg1, dd->arg2);
if (DetectU32Match(version, dd))
SCReturnInt(1);

@ -53,7 +53,7 @@ bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
if (state) {
NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id);
if (tx) {
return rs_rpc_log_json_response(tx, jb);
return SCNfsRpcLogJsonResponse(tx, jb);
}
}
return false;
@ -65,7 +65,7 @@ bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, SCJsonBuilder *jb)
if (state) {
NFSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_NFS, state, tx_id);
if (tx) {
return rs_nfs_log_json_response(state, tx, jb);
return SCNfsLogJsonResponse(state, tx, jb);
}
}
return false;
@ -77,7 +77,7 @@ static int JsonNFSLogger(ThreadVars *tv, void *thread_data,
NFSTransaction *nfstx = tx;
OutputJsonThreadCtx *thread = thread_data;
if (rs_nfs_tx_logging_is_filtered(state, nfstx))
if (SCNfsTxLoggingIsFiltered(state, nfstx))
return TM_ECODE_OK;
SCJsonBuilder *jb = CreateEveHeader(p, LOG_DIR_PACKET, "nfs", NULL, thread->ctx);
@ -86,11 +86,11 @@ static int JsonNFSLogger(ThreadVars *tv, void *thread_data,
}
SCJbOpenObject(jb, "rpc");
rs_rpc_log_json_response(tx, jb);
SCNfsRpcLogJsonResponse(tx, jb);
SCJbClose(jb);
SCJbOpenObject(jb, "nfs");
rs_nfs_log_json_response(state, tx, jb);
SCNfsLogJsonResponse(state, tx, jb);
SCJbClose(jb);
MemBufferReset(thread->buffer);

Loading…
Cancel
Save