From: Philippe Antoine Date: Fri, 4 Nov 2022 08:38:51 +0000 (+0100) Subject: rust: cargo clippy --all-features --fix --allow-no-vcs X-Git-Tag: suricata-7.0.0-rc1~405 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc287018e53a2b263789338516a9c310ecd789b3;p=thirdparty%2Fsuricata.git rust: cargo clippy --all-features --fix --allow-no-vcs --- diff --git a/rust/src/applayer.rs b/rust/src/applayer.rs index dbebdb5387..9a3687b56a 100644 --- a/rust/src/applayer.rs +++ b/rust/src/applayer.rs @@ -167,7 +167,7 @@ impl AppLayerTxData { } pub fn set_event(&mut self, event: u8) { - core::sc_app_layer_decoder_events_set_event_raw(&mut self.events, event as u8); + core::sc_app_layer_decoder_events_set_event_raw(&mut self.events, event); } pub fn update_file_flags(&mut self, state_flags: u16) { @@ -583,7 +583,7 @@ pub unsafe fn get_event_info_by_id( event_name: *mut *const std::os::raw::c_char, event_type: *mut core::AppLayerEventType, ) -> i8 { - if let Some(e) = T::from_id(event_id as i32) { + if let Some(e) = T::from_id(event_id) { *event_name = e.to_cstring().as_ptr() as *const std::os::raw::c_char; *event_type = core::APP_LAYER_EVENT_TYPE_TRANSACTION; return 0; diff --git a/rust/src/bittorrent_dht/bittorrent_dht.rs b/rust/src/bittorrent_dht/bittorrent_dht.rs index 0e0d77fd87..1a788ae6e1 100644 --- a/rust/src/bittorrent_dht/bittorrent_dht.rs +++ b/rust/src/bittorrent_dht/bittorrent_dht.rs @@ -281,7 +281,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() { } if AppLayerProtoDetectPMRegisterPatternCS( - IPPROTO_UDP as u8, + IPPROTO_UDP, ALPROTO_BITTORRENT_DHT, BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char, BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1, @@ -292,7 +292,7 @@ pub unsafe extern "C" fn rs_bittorrent_dht_udp_register_parser() { SCLogDebug!("Failed to register protocol detection pattern for direction TOSERVER"); }; if AppLayerProtoDetectPMRegisterPatternCS( - IPPROTO_UDP as u8, + IPPROTO_UDP, ALPROTO_BITTORRENT_DHT, BITTORRENT_DHT_PAYLOAD_PREFIX.as_ptr() as *const c_char, BITTORRENT_DHT_PAYLOAD_PREFIX.len() as u16 - 1, diff --git a/rust/src/conf.rs b/rust/src/conf.rs index 94a868566d..0dae7a013a 100644 --- a/rust/src/conf.rs +++ b/rust/src/conf.rs @@ -181,7 +181,7 @@ pub fn get_memval(arg: &str) -> Result { if unit.is_empty() { unit = "B"; } - let unit = get_memunit(unit) as u64; + let unit = get_memunit(unit); if unit == 0 { return Err("Invalid memory unit"); } diff --git a/rust/src/dcerpc/dcerpc.rs b/rust/src/dcerpc/dcerpc.rs index 93ff511621..40609bda9f 100644 --- a/rust/src/dcerpc/dcerpc.rs +++ b/rust/src/dcerpc/dcerpc.rs @@ -362,7 +362,7 @@ impl DCERPCState { let mut index = 0; for i in 0..len { let tx = &self.transactions[i]; - if tx.id as u64 == tx_id { //+ 1 { + if tx.id == tx_id { //+ 1 { found = true; index = i; SCLogDebug!("tx {} progress {}/{}", tx.id, tx.req_done, tx.resp_done); @@ -839,7 +839,7 @@ impl DCERPCState { /// * Failure: -1 in case fragment length defined by header mismatches the data. pub fn handle_common_stub(&mut self, input: &[u8], bytes_consumed: u16, dir: Direction) -> i32 { let fraglen = self.get_hdr_fraglen().unwrap_or(0); - if fraglen < bytes_consumed as u16 + DCERPC_HDR_LEN { + if fraglen < bytes_consumed + DCERPC_HDR_LEN { return -1; } self.padleft = fraglen - DCERPC_HDR_LEN - bytes_consumed; @@ -1189,7 +1189,7 @@ pub extern "C" fn rs_dcerpc_state_free(state: *mut std::os::raw::c_void) { #[no_mangle] pub unsafe extern "C" fn rs_dcerpc_state_transaction_free(state: *mut std::os::raw::c_void, tx_id: u64) { let dce_state = cast_pointer!(state, DCERPCState); - SCLogDebug!("freeing tx {}", tx_id as u64); + SCLogDebug!("freeing tx {}", tx_id); dce_state.free_tx(tx_id); } @@ -1321,13 +1321,13 @@ pub unsafe extern "C" fn rs_dcerpc_probe_tcp(_f: *const core::Flow, direction: u fn register_pattern_probe() -> i8 { unsafe { - if AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_DCERPC, + if AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_DCERPC, b"|05 00|\0".as_ptr() as *const std::os::raw::c_char, 2, 0, Direction::ToServer.into(), rs_dcerpc_probe_tcp, 0, 0) < 0 { SCLogDebug!("TOSERVER => AppLayerProtoDetectPMRegisterPatternCSwPP FAILED"); return -1; } - if AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_DCERPC, + if AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_DCERPC, b"|05 00|\0".as_ptr() as *const std::os::raw::c_char, 2, 0, Direction::ToClient.into(), rs_dcerpc_probe_tcp, 0, 0) < 0 { SCLogDebug!("TOCLIENT => AppLayerProtoDetectPMRegisterPatternCSwPP FAILED"); diff --git a/rust/src/dcerpc/dcerpc_udp.rs b/rust/src/dcerpc/dcerpc_udp.rs index 85618ac200..b9ac7fe71f 100644 --- a/rust/src/dcerpc/dcerpc_udp.rs +++ b/rust/src/dcerpc/dcerpc_udp.rs @@ -92,7 +92,7 @@ impl DCERPCUDPState { let mut index = 0; for i in 0..len { let tx = &self.transactions[i]; - if tx.id as u64 == tx_id { //+ 1 { + if tx.id == tx_id { //+ 1 { found = true; index = i; SCLogDebug!("tx {} progress {}/{}", tx.id, tx.req_done, tx.resp_done); @@ -244,7 +244,7 @@ pub unsafe extern "C" fn rs_dcerpc_udp_state_transaction_free( state: *mut std::os::raw::c_void, tx_id: u64, ) { let dce_state = cast_pointer!(state, DCERPCUDPState); - SCLogDebug!("freeing tx {}", tx_id as u64); + SCLogDebug!("freeing tx {}", tx_id); dce_state.free_tx(tx_id); } @@ -319,7 +319,7 @@ pub unsafe extern "C" fn rs_dcerpc_probe_udp(_f: *const core::Flow, direction: u fn register_pattern_probe() -> i8 { unsafe { - if AppLayerProtoDetectPMRegisterPatternCSwPP(core::IPPROTO_UDP as u8, ALPROTO_DCERPC, + if AppLayerProtoDetectPMRegisterPatternCSwPP(core::IPPROTO_UDP, ALPROTO_DCERPC, b"|04 00|\0".as_ptr() as *const std::os::raw::c_char, 2, 0, Direction::ToServer.into(), rs_dcerpc_probe_udp, 0, 0) < 0 { SCLogDebug!("TOSERVER => AppLayerProtoDetectPMRegisterPatternCSwPP FAILED"); diff --git a/rust/src/dns/log.rs b/rust/src/dns/log.rs index 262a3c202f..0e131796ab 100644 --- a/rust/src/dns/log.rs +++ b/rust/src/dns/log.rs @@ -670,7 +670,7 @@ pub extern "C" fn rs_dns_log_json_answer(tx: &mut DNSTransaction, if let &Some(ref response) = &tx.response { for query in &response.queries { if dns_log_rrtype_enabled(query.rrtype, flags) { - return dns_log_json_answer(js, response, flags as u64).is_ok(); + return dns_log_json_answer(js, response, flags).is_ok(); } } } diff --git a/rust/src/http2/detect.rs b/rust/src/http2/detect.rs index 515c9f471e..59169aab26 100644 --- a/rust/src/http2/detect.rs +++ b/rust/src/http2/detect.rs @@ -29,13 +29,13 @@ fn http2_tx_has_frametype( ) -> std::os::raw::c_int { if direction == Direction::ToServer { for i in 0..tx.frames_ts.len() { - if tx.frames_ts[i].header.ftype as u8 == value { + if tx.frames_ts[i].header.ftype == value { return 1; } } } else { for i in 0..tx.frames_tc.len() { - if tx.frames_tc[i].header.ftype as u8 == value { + if tx.frames_tc[i].header.ftype == value { return 1; } } @@ -87,12 +87,12 @@ fn http2_tx_has_errorcode( for i in 0..tx.frames_tc.len() { match tx.frames_tc[i].data { HTTP2FrameTypeData::GOAWAY(goaway) => { - if goaway.errorcode as u32 == code { + if goaway.errorcode == code { return 1; } } HTTP2FrameTypeData::RSTSTREAM(rst) => { - if rst.errorcode as u32 == code { + if rst.errorcode == code { return 1; } } diff --git a/rust/src/mqtt/mqtt.rs b/rust/src/mqtt/mqtt.rs index 0f85b27653..b55e8d2952 100644 --- a/rust/src/mqtt/mqtt.rs +++ b/rust/src/mqtt/mqtt.rs @@ -526,7 +526,7 @@ impl MQTTState { while !current.is_empty() { SCLogDebug!("response: handling {}", current.len()); - match parse_message(current, self.protocol_version, self.max_msg_len as usize) { + match parse_message(current, self.protocol_version, self.max_msg_len) { Ok((rem, msg)) => { SCLogDebug!("response msg {:?}", msg); if let MQTTOperation::TRUNCATED(ref trunc) = msg.op { diff --git a/rust/src/mqtt/parser.rs b/rust/src/mqtt/parser.rs index 190f88d2c4..26984be118 100644 --- a/rust/src/mqtt/parser.rs +++ b/rust/src/mqtt/parser.rs @@ -166,7 +166,7 @@ pub fn parse_fixed_header(i: &[u8]) -> IResult<&[u8], FixedHeader> { FixedHeader { message_type: parse_message_type(flags.0), dup_flag: flags.1 != 0, - qos_level: flags.2 as u8, + qos_level: flags.2, retain: flags.3 != 0, remaining_length, }, @@ -207,7 +207,7 @@ fn parse_connect(i: &[u8]) -> IResult<&[u8], MQTTConnectData> { username_flag: flags.0 != 0, password_flag: flags.1 != 0, will_retain: flags.2 != 0, - will_qos: flags.3 as u8, + will_qos: flags.3, will_flag: flags.4 != 0, clean_session: flags.5 != 0, keepalive, diff --git a/rust/src/nfs/log.rs b/rust/src/nfs/log.rs index edcb21d833..f6fdc8f582 100644 --- a/rust/src/nfs/log.rs +++ b/rust/src/nfs/log.rs @@ -105,7 +105,7 @@ fn nfs_common_header(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder let s = format!("{:x}", c); js.set_string("hhash", &s)?; } - js.set_uint("id", tx.id as u64)?; + js.set_uint("id", tx.id)?; js.set_bool("file_tx", tx.is_file_tx)?; Ok(()) } diff --git a/rust/src/nfs/nfs.rs b/rust/src/nfs/nfs.rs index 9ca0fcf4fe..8335fe744a 100644 --- a/rust/src/nfs/nfs.rs +++ b/rust/src/nfs/nfs.rs @@ -1569,7 +1569,7 @@ pub extern "C" fn rs_nfs_parse_request_tcp_gap( input_len: u32) -> AppLayerResult { - state.parse_tcp_data_ts_gap(input_len as u32) + state.parse_tcp_data_ts_gap(input_len) } #[no_mangle] @@ -1598,7 +1598,7 @@ pub extern "C" fn rs_nfs_parse_response_tcp_gap( input_len: u32) -> AppLayerResult { - state.parse_tcp_data_tc_gap(input_len as u32) + state.parse_tcp_data_tc_gap(input_len) } /// C binding to parse an NFS/UDP request. Returns 1 on success, -1 on failure. @@ -1701,7 +1701,7 @@ pub unsafe extern "C" fn rs_nfs_tx_get_procedures(tx: &mut NFSTransaction, -> u8 { if i == 0 { - *procedure = tx.procedure as u32; + *procedure = tx.procedure; return 1; } @@ -1715,7 +1715,7 @@ pub unsafe extern "C" fn rs_nfs_tx_get_procedures(tx: &mut NFSTransaction, let idx = i as usize - 1; if idx < tdf.file_additional_procs.len() { let p = tdf.file_additional_procs[idx]; - *procedure = p as u32; + *procedure = p; return 1; } } @@ -1985,20 +1985,20 @@ pub unsafe extern "C" fn rs_nfs_register_parser() { let midstream = conf_get_bool("stream.midstream"); if midstream { - if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_TCP as u8, + 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 { 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 as u8, + 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); } } else { - AppLayerProtoDetectPPRegister(IPPROTO_TCP as u8, + AppLayerProtoDetectPPRegister(IPPROTO_TCP, default_port.as_ptr(), ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN, Direction::ToServer.into(), rs_nfs_probe, rs_nfs_probe); @@ -2062,13 +2062,13 @@ pub unsafe extern "C" fn rs_nfs_udp_register_parser() { let alproto = AppLayerRegisterProtocolDetection(&parser, 1); ALPROTO_NFS = alproto; - if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_UDP as u8, + 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 { SCLogDebug!("No NFSUDP app-layer configuration, enabling NFSUDP detection UDP detection on port {:?}.", default_port); - AppLayerProtoDetectPPRegister(IPPROTO_UDP as u8, + 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); diff --git a/rust/src/nfs/nfs3_records.rs b/rust/src/nfs/nfs3_records.rs index 8348ea7102..a4d90e4ae0 100644 --- a/rust/src/nfs/nfs3_records.rs +++ b/rust/src/nfs/nfs3_records.rs @@ -341,15 +341,15 @@ pub struct Nfs3RequestWrite<'a> { /// Complete data expected fn parse_nfs3_data_complete(i: &[u8], file_len: usize, fill_bytes: usize) -> IResult<&[u8], &[u8]> { - let (i, file_data) = take(file_len as usize)(i)?; + let (i, file_data) = take(file_len)(i)?; let (i, _) = cond(fill_bytes > 0, take(fill_bytes))(i)?; Ok((i, file_data)) } /// Partial data. We have all file_len, but need to consider fill_bytes fn parse_nfs3_data_partial(i: &[u8], file_len: usize, fill_bytes: usize) -> IResult<&[u8], &[u8]> { - let (i, file_data) = take(file_len as usize)(i)?; - let fill_bytes = cmp::min(fill_bytes as usize, i.len()); + let (i, file_data) = take(file_len)(i)?; + let fill_bytes = cmp::min(fill_bytes, i.len()); let (i, _) = cond(fill_bytes > 0, take(fill_bytes))(i)?; Ok((i, file_data)) } diff --git a/rust/src/nfs/nfs4.rs b/rust/src/nfs/nfs4.rs index 96ba21459e..bcfcb00532 100644 --- a/rust/src/nfs/nfs4.rs +++ b/rust/src/nfs/nfs4.rs @@ -104,7 +104,7 @@ impl NFSState { } self.ts_chunk_xid = r.hdr.xid; debug_validate_bug_on!(w.data.len() as u32 > w.write_len); - self.ts_chunk_left = w.write_len as u32 - w.data.len() as u32; + self.ts_chunk_left = w.write_len - w.data.len() as u32; } fn close_v4<'b>(&mut self, r: &RpcPacket<'b>, fh: &'b [u8]) { diff --git a/rust/src/nfs/rpc_records.rs b/rust/src/nfs/rpc_records.rs index 66075fd82d..d373ae936e 100644 --- a/rust/src/nfs/rpc_records.rs +++ b/rust/src/nfs/rpc_records.rs @@ -242,11 +242,11 @@ pub fn parse_rpc(start_i: &[u8], complete: bool) -> IResult<&[u8], RpcPacket> { let (i, verifier) = take(verifier_len as usize)(i)?; let consumed = start_i.len() - i.len(); - if consumed > rec_size as usize { + if consumed > rec_size { return Err(Err::Error(make_error(i, ErrorKind::LengthValue))); } - let data_size : u32 = (rec_size as usize - consumed) as u32; + let data_size : u32 = (rec_size - consumed) as u32; let (i, prog_data) = if !complete { rest(i)? } else { diff --git a/rust/src/pgsql/parser.rs b/rust/src/pgsql/parser.rs index 14be325c71..e4fffa5fa4 100644 --- a/rust/src/pgsql/parser.rs +++ b/rust/src/pgsql/parser.rs @@ -564,7 +564,7 @@ pub fn pgsql_parse_startup_parameters(i: &[u8]) -> IResult<&[u8], PgsqlStartupPa } } params.remove(index); - if user.value.len() == 0 { + if user.value.is_empty() { return Err(Err::Error(make_error(i, ErrorKind::Tag))); } return Ok((i, PgsqlStartupParameters{ diff --git a/rust/src/pgsql/pgsql.rs b/rust/src/pgsql/pgsql.rs index b6ed75b31c..0a0eaaaf4b 100644 --- a/rust/src/pgsql/pgsql.rs +++ b/rust/src/pgsql/pgsql.rs @@ -757,7 +757,7 @@ pub unsafe extern "C" fn rs_pgsql_register_parser() { SCLogError!("Invalid depth value"); } } - AppLayerParserSetStreamDepth(IPPROTO_TCP as u8, ALPROTO_PGSQL, stream_depth) + AppLayerParserSetStreamDepth(IPPROTO_TCP, ALPROTO_PGSQL, stream_depth) } if let Some(val) = conf_get("app-layer.protocols.pgsql.max-tx") { if let Ok(v) = val.parse::() { diff --git a/rust/src/smb/dcerpc.rs b/rust/src/smb/dcerpc.rs index 25fec7d12a..eea9f64d37 100644 --- a/rust/src/smb/dcerpc.rs +++ b/rust/src/smb/dcerpc.rs @@ -36,7 +36,7 @@ impl SMBCommonHdr { match vercmd.get_version() { 2 => { let (_, cmd2) = vercmd.get_smb2_cmd(); - let x = match cmd2 as u16 { + let x = match cmd2 { SMB2_COMMAND_READ => { 0 }, SMB2_COMMAND_WRITE => { 0 }, SMB2_COMMAND_IOCTL => { self.msg_id }, @@ -459,7 +459,7 @@ pub fn smb_read_dcerpc_record<'b>(state: &mut SMBState, SCLogDebug!("lets first see if we have prior data"); // msg_id 0 as this data crosses cmd/reply pairs let ehdr = SMBHashKeyHdrGuid::new(SMBCommonHdr::new(SMBHDR_TYPE_TRANS_FRAG, - hdr.ssn_id as u64, hdr.tree_id as u32, 0_u64), guid.to_vec()); + hdr.ssn_id, hdr.tree_id, 0_u64), guid.to_vec()); let mut prevdata = match state.ssnguid2vec_map.remove(&ehdr) { Some(s) => s, None => Vec::new(), diff --git a/rust/src/smb/log.rs b/rust/src/smb/log.rs index 747606ed06..9149b8c076 100644 --- a/rust/src/smb/log.rs +++ b/rust/src/smb/log.rs @@ -67,7 +67,7 @@ fn guid_to_string(guid: &Vec) -> String { fn smb_common_header(jsb: &mut JsonBuilder, state: &SMBState, tx: &SMBTransaction) -> Result<(), JsonError> { - jsb.set_uint("id", tx.id as u64)?; + jsb.set_uint("id", tx.id)?; if state.dialect != 0 { let dialect = &smb2_dialect_string(state.dialect); @@ -136,7 +136,7 @@ fn smb_common_header(jsb: &mut JsonBuilder, state: &SMBState, tx: &SMBTransactio } - jsb.set_uint("session_id", tx.hdr.ssn_id as u64)?; + jsb.set_uint("session_id", tx.hdr.ssn_id)?; jsb.set_uint("tree_id", tx.hdr.tree_id as u64)?; debug_add_progress(jsb, tx)?; diff --git a/rust/src/smb/smb.rs b/rust/src/smb/smb.rs index ac1c266ce8..195d4efd55 100644 --- a/rust/src/smb/smb.rs +++ b/rust/src/smb/smb.rs @@ -578,7 +578,7 @@ impl SMBCommonHdr { }; let msg_id = match rec_type { SMBHDR_TYPE_TRANS_FRAG | SMBHDR_TYPE_SHARE => { 0 }, - _ => { r.message_id as u64 }, + _ => { r.message_id }, }; SMBCommonHdr { @@ -597,7 +597,7 @@ impl SMBCommonHdr { // cf https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/ea4560b7-90da-4803-82b5-344754b92a79 let msg_id = match rec_type { SMBHDR_TYPE_TRANS_FRAG | SMBHDR_TYPE_SHARE => { 0 }, - _ => { r.message_id as u64 }, + _ => { r.message_id }, }; SMBCommonHdr { @@ -1209,7 +1209,7 @@ impl SMBState { let _smb1_hdr = Frame::new(flow, stream_slice, input, 32_i64, SMBFrameType::SMB1Hdr as u8); SCLogDebug!("SMBv1 HDR frame {:?}", _smb1_hdr); if input.len() > 32 { - let _smb1_data = Frame::new(flow, stream_slice, &input[32..], (nbss_len - 32) as i64, SMBFrameType::SMB1Data as u8); + let _smb1_data = Frame::new(flow, stream_slice, &input[32..], nbss_len - 32, SMBFrameType::SMB1Data as u8); SCLogDebug!("SMBv1 DATA frame {:?}", _smb1_data); } } @@ -1237,7 +1237,7 @@ impl SMBState { let _smb3_hdr = Frame::new(flow, stream_slice, input, 52_i64, SMBFrameType::SMB3Hdr as u8); SCLogDebug!("SMBv3 HDR frame {:?}", _smb3_hdr); if input.len() > 52 { - let _smb3_data = Frame::new(flow, stream_slice, &input[52..], (nbss_len - 52) as i64, SMBFrameType::SMB3Data as u8); + let _smb3_data = Frame::new(flow, stream_slice, &input[52..], nbss_len - 52, SMBFrameType::SMB3Data as u8); SCLogDebug!("SMBv3 DATA frame {:?}", _smb3_data); } } @@ -1385,7 +1385,7 @@ impl SMBState { consumed -= 3; } SCLogDebug!("smb record NOT found"); - return AppLayerResult::incomplete(consumed as u32, 8); + return AppLayerResult::incomplete(consumed, 8); }, } } @@ -1508,7 +1508,7 @@ impl SMBState { SCLogDebug!("setting consumed {} need {} needed {:?} total input {}", total_consumed, n, needed, stream_slice.len()); let need = n; - return AppLayerResult::incomplete(total_consumed as u32, need as u32); + return AppLayerResult::incomplete(total_consumed, need as u32); } // tracking a write record, which we don't need to // queue up at the stream level, but can feed to us @@ -1553,7 +1553,7 @@ impl SMBState { let _smb1_hdr = Frame::new(flow, stream_slice, input, SMB1_HEADER_SIZE as i64, SMBFrameType::SMB1Hdr as u8); SCLogDebug!("SMBv1 HDR frame {:?}", _smb1_hdr); if input.len() > SMB1_HEADER_SIZE { - let _smb1_data = Frame::new(flow, stream_slice, &input[SMB1_HEADER_SIZE..], (nbss_len - SMB1_HEADER_SIZE as i64) as i64, + let _smb1_data = Frame::new(flow, stream_slice, &input[SMB1_HEADER_SIZE..], nbss_len - SMB1_HEADER_SIZE as i64, SMBFrameType::SMB1Data as u8); SCLogDebug!("SMBv1 DATA frame {:?}", _smb1_data); } @@ -1581,7 +1581,7 @@ impl SMBState { let _smb3_hdr = Frame::new(flow, stream_slice, input, 52_i64, SMBFrameType::SMB3Hdr as u8); SCLogDebug!("SMBv3 HDR frame {:?}", _smb3_hdr); if input.len() > 52 { - let _smb3_data = Frame::new(flow, stream_slice, &input[52..], (nbss_len - 52) as i64, SMBFrameType::SMB3Data as u8); + let _smb3_data = Frame::new(flow, stream_slice, &input[52..], nbss_len - 52, SMBFrameType::SMB3Data as u8); SCLogDebug!("SMBv3 DATA frame {:?}", _smb3_data); } } @@ -1717,7 +1717,7 @@ impl SMBState { consumed -= 3; } SCLogDebug!("smb record NOT found"); - return AppLayerResult::incomplete(consumed as u32, 8); + return AppLayerResult::incomplete(consumed, 8); }, } } @@ -1829,7 +1829,7 @@ impl SMBState { SCLogDebug!("setting consumed {} need {} needed {:?} total input {}", total_consumed, n, needed, stream_slice.len()); let need = n; - return AppLayerResult::incomplete(total_consumed as u32, need as u32); + return AppLayerResult::incomplete(total_consumed, need as u32); } // tracking a read record, which we don't need to // queue up at the stream level, but can feed to us @@ -1973,7 +1973,7 @@ pub extern "C" fn rs_smb_parse_request_tcp_gap( input_len: u32) -> AppLayerResult { - state.parse_tcp_data_ts_gap(input_len as u32) + state.parse_tcp_data_ts_gap(input_len) } @@ -2008,7 +2008,7 @@ pub extern "C" fn rs_smb_parse_response_tcp_gap( input_len: u32) -> AppLayerResult { - state.parse_tcp_data_tc_gap(input_len as u32) + state.parse_tcp_data_tc_gap(input_len) } fn smb_probe_tcp_midstream(direction: Direction, slice: &[u8], rdir: *mut u8, begins: bool) -> i8 @@ -2182,7 +2182,7 @@ pub unsafe extern "C" fn rs_smb_state_tx_free(state: *mut ffi::c_void, tx_id: u64) { let state = cast_pointer!(state, SMBState); - SCLogDebug!("freeing tx {}", tx_id as u64); + SCLogDebug!("freeing tx {}", tx_id); state.free_tx(tx_id); } @@ -2279,24 +2279,24 @@ fn register_pattern_probe() -> i8 { let mut r = 0; unsafe { // SMB1 - r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_SMB, + r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_SMB, b"|ff|SMB\0".as_ptr() as *const std::os::raw::c_char, 8, 4, Direction::ToServer as u8, rs_smb_probe_begins_tcp, MIN_REC_SIZE, MIN_REC_SIZE); - r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_SMB, + r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_SMB, b"|ff|SMB\0".as_ptr() as *const std::os::raw::c_char, 8, 4, Direction::ToClient as u8, rs_smb_probe_begins_tcp, MIN_REC_SIZE, MIN_REC_SIZE); // SMB2/3 - r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_SMB, + r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_SMB, b"|fe|SMB\0".as_ptr() as *const std::os::raw::c_char, 8, 4, Direction::ToServer as u8, rs_smb_probe_begins_tcp, MIN_REC_SIZE, MIN_REC_SIZE); - r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_SMB, + r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_SMB, b"|fe|SMB\0".as_ptr() as *const std::os::raw::c_char, 8, 4, Direction::ToClient as u8, rs_smb_probe_begins_tcp, MIN_REC_SIZE, MIN_REC_SIZE); // SMB3 encrypted records - r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_SMB, + r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_SMB, b"|fd|SMB\0".as_ptr() as *const std::os::raw::c_char, 8, 4, Direction::ToServer as u8, smb3_probe_tcp, MIN_REC_SIZE, MIN_REC_SIZE); - r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP as u8, ALPROTO_SMB, + r |= AppLayerProtoDetectPMRegisterPatternCSwPP(IPPROTO_TCP, ALPROTO_SMB, b"|fd|SMB\0".as_ptr() as *const std::os::raw::c_char, 8, 4, Direction::ToClient as u8, smb3_probe_tcp, MIN_REC_SIZE, MIN_REC_SIZE); } @@ -2362,11 +2362,11 @@ pub unsafe extern "C" fn rs_smb_register_parser() { } let have_cfg = AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), - IPPROTO_TCP as u8, parser.name, ALPROTO_SMB, 0, + IPPROTO_TCP, parser.name, ALPROTO_SMB, 0, MIN_REC_SIZE, rs_smb_probe_tcp, rs_smb_probe_tcp); if have_cfg == 0 { - AppLayerProtoDetectPPRegister(IPPROTO_TCP as u8, default_port.as_ptr(), ALPROTO_SMB, + AppLayerProtoDetectPPRegister(IPPROTO_TCP, default_port.as_ptr(), ALPROTO_SMB, 0, MIN_REC_SIZE, Direction::ToServer as u8, rs_smb_probe_tcp, rs_smb_probe_tcp); } @@ -2385,7 +2385,7 @@ pub unsafe extern "C" fn rs_smb_register_parser() { Err(_) => { SCLogError!("Invalid depth value"); } } } - AppLayerParserSetStreamDepth(IPPROTO_TCP as u8, ALPROTO_SMB, stream_depth); + AppLayerParserSetStreamDepth(IPPROTO_TCP, ALPROTO_SMB, stream_depth); let retval = conf_get("app-layer.protocols.smb.max-read-size"); if let Some(val) = retval { match get_memval(val) { diff --git a/rust/src/smb/smb1_records.rs b/rust/src/smb/smb1_records.rs index 7eb245c3c5..569c7dfd94 100644 --- a/rust/src/smb/smb1_records.rs +++ b/rust/src/smb/smb1_records.rs @@ -115,7 +115,7 @@ pub fn parse_smb1_write_andx_request_record(i : &[u8], andx_offset: usize) -> IR let (i, file_data) = rest(i)?; let record = Smb1WriteRequestRecord { offset: high_offset.map(|ho| (ho as u64) << 32 | offset as u64).unwrap_or(0), - len: (((data_len_high as u32) << 16) as u32)|(data_len_low as u32), + len: ((data_len_high as u32) << 16)|(data_len_low as u32), fid, data: file_data, }; @@ -547,7 +547,7 @@ pub fn parse_smb_read_andx_response_record(i: &[u8]) -> IResult<&[u8], SmbRespon let (i, file_data) = rest(i)?; let record = SmbResponseReadAndXRecord { - len: (((data_len_high as u32) << 16)|data_len_low as u32), + len: ((data_len_high << 16)|data_len_low as u32), data: file_data, }; Ok((i, record)) diff --git a/rust/src/smb/smb2.rs b/rust/src/smb/smb2.rs index 741f053b34..dc0aeb5417 100644 --- a/rust/src/smb/smb2.rs +++ b/rust/src/smb/smb2.rs @@ -105,7 +105,7 @@ fn smb2_read_response_record_generic<'b>(state: &mut SMBState, r: &Smb2Record<'b { if smb2_create_new_tx(r.command) { let tx_hdr = SMBCommonHdr::from2(r, SMBHDR_TYPE_GENERICTX); - let tx = state.get_generic_tx(2, r.command as u16, &tx_hdr); + let tx = state.get_generic_tx(2, r.command, &tx_hdr); if let Some(tx) = tx { tx.set_status(r.nt_status, false); tx.response_done = true; @@ -786,7 +786,7 @@ pub fn smb2_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>) if let Some(SMBTransactionTypeData::TREECONNECT(ref mut tdn)) = tx.type_data { tdn.share_type = tr.share_type; tdn.is_pipe = is_pipe; - tdn.tree_id = r.tree_id as u32; + tdn.tree_id = r.tree_id; share_name = tdn.share_name.to_vec(); } // update hdr now that we have a tree_id diff --git a/rust/src/snmp/detect.rs b/rust/src/snmp/detect.rs index 75f6f05c71..88e6432b23 100644 --- a/rust/src/snmp/detect.rs +++ b/rust/src/snmp/detect.rs @@ -22,7 +22,7 @@ use crate::snmp::snmp::SNMPTransaction; #[no_mangle] pub unsafe extern "C" fn rs_snmp_tx_get_version(tx: &mut SNMPTransaction, version: *mut u32) { debug_assert!(tx.version != 0, "SNMP version is 0"); - *version = tx.version as u32; + *version = tx.version; } #[no_mangle] @@ -42,7 +42,7 @@ pub unsafe extern "C" fn rs_snmp_tx_get_community( pub unsafe extern "C" fn rs_snmp_tx_get_pdu_type(tx: &mut SNMPTransaction, pdu_type: *mut u32) { match tx.info { Some(ref info) => { - *pdu_type = info.pdu_type.0 as u32; + *pdu_type = info.pdu_type.0; } None => { *pdu_type = 0xffffffff; diff --git a/rust/src/ssh/ssh.rs b/rust/src/ssh/ssh.rs index 1f261b1dcd..21c4d1ad3e 100644 --- a/rust/src/ssh/ssh.rs +++ b/rust/src/ssh/ssh.rs @@ -201,7 +201,7 @@ impl SSHState { hdr.record_left_msg = parser::MessageCode::Kexinit; return AppLayerResult::incomplete( (il - rem.len()) as u32, - (head.pkt_len - 2) as u32 + head.pkt_len - 2 ); } else { diff --git a/rust/src/tftp/tftp.rs b/rust/src/tftp/tftp.rs index b5453c2d33..a75a3cae09 100644 --- a/rust/src/tftp/tftp.rs +++ b/rust/src/tftp/tftp.rs @@ -115,7 +115,7 @@ pub extern "C" fn rs_tftp_get_tx(state: &mut TFTPState, #[no_mangle] pub extern "C" fn rs_tftp_get_tx_cnt(state: &mut TFTPState) -> u64 { - return state.tx_id as u64; + return state.tx_id; } fn getstr(i: &[u8]) -> IResult<&[u8], &str> {