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

Discard truncate fn/v2 #11411

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions rust/src/applayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ pub struct RustParser {

pub flags: u32,

/// Function to handle the end of data coming on one of the sides
/// due to the stream reaching its 'depth' limit.
pub truncate: Option<TruncateFn>,

pub get_frame_id_by_name: Option<GetFrameIdByName>,
pub get_frame_name_by_id: Option<GetFrameNameById>,
}
Expand Down Expand Up @@ -458,7 +454,6 @@ pub type GetTxIteratorFn = unsafe extern "C" fn (ipproto: u8, alproto: AppPro
pub type GetTxDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerTxData;
pub type GetStateDataFn = unsafe extern "C" fn(*mut c_void) -> *mut AppLayerStateData;
pub type ApplyTxConfigFn = unsafe extern "C" fn (*mut c_void, *mut c_void, c_int, AppLayerTxConfig);
pub type TruncateFn = unsafe extern "C" fn (*mut c_void, u8);
pub type GetFrameIdByName = unsafe extern "C" fn(*const c_char) -> c_int;
pub type GetFrameNameById = unsafe extern "C" fn(u8) -> *const c_char;

Expand Down Expand Up @@ -502,8 +497,6 @@ pub const APP_LAYER_PARSER_NO_INSPECTION_PAYLOAD : u16 = BIT_U16!(3);
pub const APP_LAYER_PARSER_BYPASS_READY : u16 = BIT_U16!(4);
pub const APP_LAYER_PARSER_EOF_TS : u16 = BIT_U16!(5);
pub const APP_LAYER_PARSER_EOF_TC : u16 = BIT_U16!(6);
pub const APP_LAYER_PARSER_TRUNC_TS : u16 = BIT_U16!(7);
pub const APP_LAYER_PARSER_TRUNC_TC : u16 = BIT_U16!(8);

pub const APP_LAYER_PARSER_OPT_ACCEPT_GAPS: u32 = BIT_U32!(0);

Expand Down
1 change: 0 additions & 1 deletion rust/src/applayertemplate/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ pub unsafe extern "C" fn rs_template_register_parser() {
get_state_data: rs_template_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/bittorrent_dht/bittorrent_dht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() {
get_state_data: rs_bittorrent_dht_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
32 changes: 0 additions & 32 deletions rust/src/dcerpc/dcerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,6 @@ pub struct DCERPCState {
pub tc_gap: bool,
pub ts_ssn_gap: bool,
pub tc_ssn_gap: bool,
pub ts_ssn_trunc: bool, /// true if Truncated in this direction
pub tc_ssn_trunc: bool,
pub flow: Option<*const core::Flow>,
state_data: AppLayerStateData,
}
Expand Down Expand Up @@ -354,8 +352,6 @@ impl DCERPCState {
tx.call_id = call_id;
tx.endianness = endianness;
self.tx_id += 1;
tx.req_done = self.ts_ssn_trunc;
tx.resp_done = self.tc_ssn_trunc;
if self.transactions.len() > unsafe { DCERPC_MAX_TX } {
let mut index = self.tx_index_completed;
for tx_old in &mut self.transactions.range_mut(self.tx_index_completed..) {
Expand Down Expand Up @@ -1187,33 +1183,6 @@ pub unsafe extern "C" fn rs_dcerpc_state_transaction_free(state: *mut std::os::r
dce_state.free_tx(tx_id);
}

#[no_mangle]
pub unsafe extern "C" fn rs_dcerpc_state_trunc(state: *mut std::os::raw::c_void, direction: u8) {
let dce_state = cast_pointer!(state, DCERPCState);
match direction.into() {
Direction::ToServer => {
dce_state.ts_ssn_trunc = true;
for tx in &mut dce_state.transactions {
tx.req_done = true;
if let Some(flow) = dce_state.flow {
sc_app_layer_parser_trigger_raw_stream_reassembly(flow, Direction::ToServer as i32);
}
}
SCLogDebug!("dce_state.ts_ssn_trunc = true; txs {}", dce_state.transactions.len());
}
Direction::ToClient => {
dce_state.tc_ssn_trunc = true;
for tx in &mut dce_state.transactions {
tx.resp_done = true;
if let Some(flow) = dce_state.flow {
sc_app_layer_parser_trigger_raw_stream_reassembly(flow, Direction::ToClient as i32);
}
}
SCLogDebug!("dce_state.tc_ssn_trunc = true; txs {}", dce_state.transactions.len());
}
}
}

#[no_mangle]
pub unsafe extern "C" fn rs_dcerpc_get_tx(
vtx: *mut std::os::raw::c_void, tx_id: u64,
Expand Down Expand Up @@ -1367,7 +1336,6 @@ pub unsafe extern "C" fn rs_dcerpc_register_parser() {
get_state_data: rs_dcerpc_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/dcerpc/dcerpc_udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,6 @@ pub unsafe extern "C" fn rs_dcerpc_udp_register_parser() {
get_state_data: rs_dcerpc_udp_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/dhcp/dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ pub unsafe extern "C" fn rs_dhcp_register_parser() {
get_state_data : rs_dhcp_get_state_data,
apply_tx_config : None,
flags : 0,
truncate : None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
2 changes: 0 additions & 2 deletions rust/src/dns/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,6 @@ pub unsafe extern "C" fn SCRegisterDnsUdpParser() {
get_state_data: rs_dns_get_state_data,
apply_tx_config: Some(apply_tx_config),
flags: 0,
truncate: None,
get_frame_id_by_name: Some(DnsFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(DnsFrameType::ffi_name_from_id),
};
Expand Down Expand Up @@ -1031,7 +1030,6 @@ pub unsafe extern "C" fn SCRegisterDnsTcpParser() {
get_state_data: rs_dns_get_state_data,
apply_tx_config: Some(apply_tx_config),
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
get_frame_id_by_name: Some(DnsFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(DnsFrameType::ffi_name_from_id),
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/enip/enip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ pub unsafe extern "C" fn SCEnipRegisterParsers() {
get_state_data: SCEnipTxGetState_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: Some(EnipFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(EnipFrameType::ffi_name_from_id),
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/http2/http2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,6 @@ pub unsafe extern "C" fn rs_http2_register_parser() {
get_state_data: rs_http2_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/ike/ike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ pub unsafe extern "C" fn rs_ike_register_parser() {
get_state_data: rs_ike_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/krb/krb5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ pub unsafe extern "C" fn rs_register_krb5_parser() {
get_state_data : rs_krb5_get_state_data,
apply_tx_config : None,
flags : 0,
truncate : None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/modbus/modbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ pub unsafe extern "C" fn rs_modbus_register_parser() {
get_state_data: rs_modbus_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/mqtt/mqtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ pub unsafe extern "C" fn SCMqttRegisterParser() {
get_state_data: rs_mqtt_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: Some(MQTTFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(MQTTFrameType::ffi_name_from_id),
};
Expand Down
2 changes: 0 additions & 2 deletions rust/src/nfs/nfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,6 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
get_state_data: rs_nfs_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(NFSFrameType::ffi_name_from_id),
};
Expand Down Expand Up @@ -2067,7 +2066,6 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() {
get_state_data: rs_nfs_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: Some(NFSFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(NFSFrameType::ffi_name_from_id),
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/ntp/ntp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ pub unsafe extern "C" fn rs_register_ntp_parser() {
get_state_data : rs_ntp_get_state_data,
apply_tx_config : None,
flags : 0,
truncate : None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/pgsql/pgsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,6 @@ pub unsafe extern "C" fn rs_pgsql_register_parser() {
get_state_data: rs_pgsql_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/quic/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ pub unsafe extern "C" fn rs_quic_register_parser() {
get_state_data: rs_quic_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/rdp/rdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ pub unsafe extern "C" fn rs_rdp_register_parser() {
get_state_data: rs_rdp_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/rfb/rfb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,6 @@ pub unsafe extern "C" fn rs_rfb_register_parser() {
get_state_data: rs_rfb_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: Some(RFBFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(RFBFrameType::ffi_name_from_id),
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/sip/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ pub unsafe extern "C" fn rs_sip_register_parser() {
get_state_data: rs_sip_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: Some(SIPFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(SIPFrameType::ffi_name_from_id),
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/smb/smb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,6 @@ pub unsafe extern "C" fn rs_smb_register_parser() {
get_state_data: rs_smb_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: Some(rs_smb_state_truncate),
inashivb marked this conversation as resolved.
Show resolved Hide resolved
get_frame_id_by_name: Some(SMBFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(SMBFrameType::ffi_name_from_id),
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/snmp/snmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ pub unsafe extern "C" fn rs_register_snmp_parser() {
get_state_data : rs_snmp_get_state_data,
apply_tx_config : None,
flags : 0,
truncate : None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/ssh/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ pub unsafe extern "C" fn rs_ssh_register_parser() {
get_state_data: rs_ssh_get_state_data,
apply_tx_config: None,
flags: 0,
truncate: None,
get_frame_id_by_name: None,
get_frame_name_by_id: None,
};
Expand Down
1 change: 0 additions & 1 deletion rust/src/telnet/telnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,6 @@ pub unsafe extern "C" fn rs_telnet_register_parser() {
get_state_data: rs_telnet_get_state_data,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
get_frame_id_by_name: Some(TelnetFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(TelnetFrameType::ffi_name_from_id),

Expand Down
1 change: 0 additions & 1 deletion rust/src/websocket/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ pub unsafe extern "C" fn rs_websocket_register_parser() {
get_state_data: rs_websocket_get_state_data,
apply_tx_config: None,
flags: 0, // do not accept gaps as there is no good way to resync
truncate: None,
get_frame_id_by_name: Some(WebSocketFrameType::ffi_id_from_name),
get_frame_name_by_id: Some(WebSocketFrameType::ffi_name_from_id),
};
Expand Down
46 changes: 5 additions & 41 deletions src/app-layer-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ typedef struct AppLayerParserProtoCtx_
void *(*LocalStorageAlloc)(void);
void (*LocalStorageFree)(void *);

void (*Truncate)(void *, uint8_t);

/** get FileContainer reference from the TX. MUST return a non-NULL reference if the TX
* has or may have files in the requested direction at some point. */
AppLayerGetFileState (*GetTxFiles)(void *, uint8_t);
Expand Down Expand Up @@ -201,9 +199,6 @@ FramesContainer *AppLayerFramesSetupContainer(Flow *f)
return f->alparser->frames;
}

static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
const AppProto alproto, void *alstate, const uint8_t direction);

#ifdef UNITTESTS
void UTHAppLayerParserStateGetIds(void *ptr, uint64_t *i1, uint64_t *i2, uint64_t *log, uint64_t *min)
{
Expand Down Expand Up @@ -468,16 +463,6 @@ void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
SCReturn;
}

void AppLayerParserRegisterTruncateFunc(uint8_t ipproto, AppProto alproto,
void (*Truncate)(void *, uint8_t))
{
SCEnter();

alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate = Truncate;

SCReturn;
}

void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto,
int (*StateGetProgress)(void *alstate, uint8_t direction))
{
Expand Down Expand Up @@ -947,11 +932,8 @@ void AppLayerParserTransactionsCleanup(Flow *f, const uint8_t pkt_dir)
AppLayerTxData *txd = AppLayerParserGetTxData(ipproto, alproto, tx);
if (txd != NULL && AppLayerParserHasFilesInDir(txd, pkt_dir)) {
if (pkt_dir_trunc == -1)
pkt_dir_trunc =
AppLayerParserStateIssetFlag(f->alparser,
(pkt_dir == STREAM_TOSERVER) ? APP_LAYER_PARSER_TRUNC_TS
: APP_LAYER_PARSER_TRUNC_TC) != 0;

pkt_dir_trunc = IS_DISRUPTED(
(pkt_dir == STREAM_TOSERVER) ? ts_disrupt_flags : tc_disrupt_flags);
AppLayerParserFileTxHousekeeping(f, tx, pkt_dir, (bool)pkt_dir_trunc);
}

Expand Down Expand Up @@ -1308,7 +1290,7 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
if (!(p->option_flags & APP_LAYER_PARSER_OPT_ACCEPT_GAPS)) {
SCLogDebug("app-layer parser does not accept gaps");
if (f->alstate != NULL && !FlowChangeProto(f)) {
AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
AppLayerParserTriggerRawStreamReassembly(f, direction);
}
AppLayerIncGapErrorCounter(tv, f);
goto error;
Expand Down Expand Up @@ -1468,9 +1450,9 @@ int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow
AppLayerIncTxCounter(tv, f, cur_tx_cnt - p_tx_cnt);
}

/* stream truncated, inform app layer */
/* stream truncated, trigger raw stream reassembly */
if (flags & STREAM_DEPTH)
AppLayerParserStreamTruncated(pstate, f->proto, alproto, f->alstate, flags);
AppLayerParserTriggerRawStreamReassembly(f, direction);
inashivb marked this conversation as resolved.
Show resolved Hide resolved

end:
/* update app progress */
Expand Down Expand Up @@ -1796,24 +1778,6 @@ uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag
SCReturnUInt(pstate->flags & flag);
}

static inline void AppLayerParserStreamTruncated(AppLayerParserState *pstate, const uint8_t ipproto,
const AppProto alproto, void *alstate, const uint8_t direction)
{
SCEnter();

if (direction & STREAM_TOSERVER) {
AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_TRUNC_TS);
} else {
AppLayerParserStateSetFlag(pstate, APP_LAYER_PARSER_TRUNC_TC);
}

if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate != NULL) {
alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].Truncate(alstate, direction);
}

SCReturn;
}

/***** Unittests *****/

#ifdef UNITTESTS
Expand Down
Loading
Loading