rust: SCLogDebug is real nop when built as release

Before, even if there were no outputs, all the arguments
were evaluated, which could turn expensive

All variables which are used only in certain build configurations
are now prefixed by underscore to avoid warnings
pull/6197/head
Philippe Antoine 5 years ago committed by Victor Julien
parent 20e8f90981
commit ef5755338f

@ -102,22 +102,22 @@ named!(pub parse_dcerpc_udp_header<DCERPCHdrUdp>,
serial_hi: serial_hi,
objectuuid: match parse_uuid(objectuuid) {
Ok((_, vect)) => assemble_uuid(vect),
Err(e) => {
SCLogDebug!("{}", e);
Err(_e) => {
SCLogDebug!("{}", _e);
vec![0]
},
},
interfaceuuid: match parse_uuid(interfaceuuid) {
Ok((_, vect)) => assemble_uuid(vect),
Err(e) => {
SCLogDebug!("{}", e);
Err(_e) => {
SCLogDebug!("{}", _e);
vec![0]
},
},
activityuuid: match parse_uuid(activityuuid){
Ok((_, vect)) => assemble_uuid(vect),
Err(e) => {
SCLogDebug!("{}", e);
Err(_e) => {
SCLogDebug!("{}", _e);
vec![0]
},
},

@ -111,10 +111,10 @@ impl FileTransferTracker {
self.file_is_truncated = true;
}
pub fn create(&mut self, name: &[u8], file_size: u64) {
pub fn create(&mut self, _name: &[u8], _file_size: u64) {
if self.file_open == true { panic!("close existing file first"); }
SCLogDebug!("CREATE: name {:?} file_size {}", name, file_size);
SCLogDebug!("CREATE: name {:?} file_size {}", _name, _file_size);
}
pub fn new_chunk(&mut self, config: &'static SuricataFileContext,
@ -245,7 +245,7 @@ impl FileTransferTracker {
if self.chunk_is_ooo == false {
loop {
let offset = self.tracked;
let _offset = self.tracked;
match self.chunks.remove(&self.tracked) {
Some(c) => {
let res = files.file_append(&self.track_id, &c.chunk, c.contains_gap);
@ -263,10 +263,10 @@ impl FileTransferTracker {
self.tracked += c.chunk.len() as u64;
self.cur_ooo -= c.chunk.len() as u64;
SCLogDebug!("STORED OOO CHUNK at offset {}, tracked now {}, stored len {}", offset, self.tracked, c.chunk.len());
SCLogDebug!("STORED OOO CHUNK at offset {}, tracked now {}, stored len {}", _offset, self.tracked, c.chunk.len());
},
_ => {
SCLogDebug!("NO STORED CHUNK found at offset {}", self.tracked);
SCLogDebug!("NO STORED CHUNK found at _offset {}", self.tracked);
break;
},
};

@ -101,11 +101,9 @@ pub extern "C" fn rs_ftp_pasv_response(input: *const u8, len: u32) -> u16 {
return dport;
},
Err(nom::Err::Incomplete(_)) => {
let buf = unsafe{std::slice::from_raw_parts(input, len as usize)};
SCLogDebug!("pasv incomplete: '{:?}'", String::from_utf8_lossy(buf));
},
Err(_) => {
let buf = unsafe{std::slice::from_raw_parts(input, len as usize)};
SCLogDebug!("pasv error on '{:?}'", String::from_utf8_lossy(buf));
},
}
@ -166,11 +164,9 @@ pub extern "C" fn rs_ftp_epsv_response(input: *const u8, len: u32) -> u16 {
return dport;
},
Err(nom::Err::Incomplete(_)) => {
let buf = unsafe{std::slice::from_raw_parts(input, len as usize)};
SCLogDebug!("epsv incomplete: '{:?}'", String::from_utf8_lossy(buf));
},
Err(_) => {
let buf = unsafe{std::slice::from_raw_parts(input, len as usize)};
SCLogDebug!("epsv incomplete: '{:?}'", String::from_utf8_lossy(buf));
},

@ -149,8 +149,8 @@ pub fn handle_ikev2(
state.ikev2_container.dh_group = kex.dh_group;
}
}
IkeV2PayloadContent::Nonce(ref n) => {
SCLogDebug!("Nonce: {:?}", n);
IkeV2PayloadContent::Nonce(ref _n) => {
SCLogDebug!("Nonce: {:?}", _n);
}
IkeV2PayloadContent::Notify(ref n) => {
SCLogDebug!("Notify: {:?}", n);
@ -207,8 +207,8 @@ pub fn handle_ikev2(
}
}
}
e => {
SCLogDebug!("parse_ikev2_payload_with_type: {:?}", e);
_e => {
SCLogDebug!("parse_ikev2_payload_with_type: {:?}", _e);
()
}
}
@ -285,8 +285,8 @@ fn add_proposals(state: &mut IKEState, prop: &Vec<IkeV2Proposal>, direction: u8)
}
_ => (),
},
IkeV2Transform::Unknown(tx_type, tx_id) => {
SCLogDebug!("Unknown proposal: type={:?}, id={}", tx_type, tx_id);
IkeV2Transform::Unknown(_tx_type, _tx_id) => {
SCLogDebug!("Unknown proposal: type={:?}, id={}", _tx_type, _tx_id);
state.set_event(IkeEvent::UnknownProposal);
}
_ => (),

@ -167,8 +167,7 @@ macro_rules!SCLogDebug {
#[cfg(not(feature = "debug"))]
#[macro_export]
macro_rules!SCLogDebug {
($last:expr) => { let _ = &$last; let _ = $crate::log::Level::Debug; };
($one:expr, $($arg:tt)*) => { let _ = &$one; SCLogDebug!($($arg)*); };
($($arg:tt)*) => ()
}
/// SCLogMessage wrapper. If the Suricata C context is not registered

@ -1017,9 +1017,9 @@ impl NFSState {
if self.ts_gap {
SCLogDebug!("TS trying to catch up after GAP (input {})", cur_i.len());
let mut cnt = 0;
let mut _cnt = 0;
while cur_i.len() > 0 {
cnt += 1;
_cnt += 1;
match nfs_probe(cur_i, STREAM_TOSERVER) {
1 => {
SCLogDebug!("expected data found");
@ -1028,13 +1028,13 @@ impl NFSState {
},
0 => {
SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.",
cur_i.len(), cnt);
cur_i.len(), _cnt);
return AppLayerResult::incomplete((i.len() - cur_i.len()) as u32, (cur_i.len() + 1) as u32);
},
-1 => {
cur_i = &cur_i[1..];
if cur_i.len() == 0 {
SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", cnt);
SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", _cnt);
}
},
_ => {
@ -1170,9 +1170,9 @@ impl NFSState {
if self.tc_gap {
SCLogDebug!("TC trying to catch up after GAP (input {})", cur_i.len());
let mut cnt = 0;
let mut _cnt = 0;
while cur_i.len() > 0 {
cnt += 1;
_cnt += 1;
match nfs_probe(cur_i, STREAM_TOCLIENT) {
1 => {
SCLogDebug!("expected data found");
@ -1181,13 +1181,13 @@ impl NFSState {
},
0 => {
SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.",
cur_i.len(), cnt);
cur_i.len(), _cnt);
return AppLayerResult::incomplete((i.len() - cur_i.len()) as u32, (cur_i.len() + 1) as u32);
},
-1 => {
cur_i = &cur_i[1..];
if cur_i.len() == 0 {
SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", cnt);
SCLogDebug!("all post-GAP data in this chunk was bad. Looped {} times.", _cnt);
}
},
_ => {

@ -186,8 +186,8 @@ impl NFSState {
self.commit_v4(r, fh);
}
}
&Nfs4RequestContent::Close(ref rd) => {
SCLogDebug!("CLOSEv4: {:?}", rd);
&Nfs4RequestContent::Close(ref _rd) => {
SCLogDebug!("CLOSEv4: {:?}", _rd);
}
&Nfs4RequestContent::Create(ref rd) => {
SCLogDebug!("CREATEv4: {:?}", rd);
@ -202,11 +202,11 @@ impl NFSState {
xidmap.file_name = rd.to_vec();
main_opcode = NFSPROC4_REMOVE;
}
&Nfs4RequestContent::SetClientId(ref rd) => {
&Nfs4RequestContent::SetClientId(ref _rd) => {
SCLogDebug!("SETCLIENTIDv4: client id {} r_netid {} r_addr {}",
String::from_utf8_lossy(&rd.client_id),
String::from_utf8_lossy(&rd.r_netid),
String::from_utf8_lossy(&rd.r_addr));
String::from_utf8_lossy(&_rd.client_id),
String::from_utf8_lossy(&_rd.r_netid),
String::from_utf8_lossy(&_rd.r_addr));
}
&_ => { },
}
@ -291,13 +291,13 @@ impl NFSState {
for c in &cr.commands {
SCLogDebug!("c {:?}", c);
match c {
&Nfs4ResponseContent::ReadDir(s, ref rd) => {
&Nfs4ResponseContent::ReadDir(_s, ref rd) => {
if let &Some(ref rd) = rd {
SCLogDebug!("READDIRv4: status {} eof {}", s, rd.eof);
SCLogDebug!("READDIRv4: status {} eof {}", _s, rd.eof);
for d in &rd.listing {
if let &Some(ref d) = d {
SCLogDebug!("READDIRv4: dir {}", String::from_utf8_lossy(&d.name));
if let &Some(ref _d) = d {
SCLogDebug!("READDIRv4: dir {}", String::from_utf8_lossy(&_d.name));
}
}
@ -329,9 +329,9 @@ impl NFSState {
self.process_read_record(r, &reply, Some(&xidmap));
}
},
&Nfs4ResponseContent::Open(s, ref rd) => {
if let &Some(ref rd) = rd {
SCLogDebug!("OPENv4: status {} opendata {:?}", s, rd);
&Nfs4ResponseContent::Open(_s, ref rd) => {
if let &Some(ref _rd) = rd {
SCLogDebug!("OPENv4: status {} opendata {:?}", _s, _rd);
insert_filename_with_getfh = true;
}
},

@ -273,10 +273,10 @@ pub fn smb_write_dcerpc_record<'b>(state: &mut SMBState,
i.iface.to_vec()
};
let uuid_str = uuid::Uuid::from_slice(&x.clone());
let uuid_str = uuid_str.map(|uuid_str| uuid_str.to_hyphenated().to_string()).unwrap();
let _uuid_str = uuid_str.map(|uuid_str| uuid_str.to_hyphenated().to_string()).unwrap();
let d = DCERPCIface::new(x,i.ver,i.ver_min);
SCLogDebug!("UUID {} version {}/{} bytes {:?}",
uuid_str,
_uuid_str,
i.ver, i.ver_min,i.iface);
ifaces.push(d);
}

@ -251,14 +251,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
true
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -279,14 +279,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
tx.vercmd.set_smb1_cmd(SMB1_COMMAND_TRANS2);
true
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO DATA RENAME ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -295,14 +295,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
false
}
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 SET_PATH_INFO PARAMS ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -334,14 +334,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
true
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA DISPOSITION ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -367,14 +367,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
tx.vercmd.set_smb1_cmd(SMB1_COMMAND_TRANS2);
true
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO DATA RENAME ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -383,14 +383,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
false
}
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 SET_FILE_INFO PARAMS ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -399,14 +399,14 @@ fn smb1_request_record_one<'b>(state: &mut SMBState, r: &SmbRecord<'b>, command:
false
}
},
Err(nom::Err::Incomplete(n)) => {
SCLogDebug!("TRANS2 INCOMPLETE {:?}", n);
Err(nom::Err::Incomplete(_n)) => {
SCLogDebug!("TRANS2 INCOMPLETE {:?}", _n);
events.push(SMBEvent::MalformedData);
false
},
Err(nom::Err::Error(e)) |
Err(nom::Err::Failure(e)) => {
SCLogDebug!("TRANS2 ERROR {:?}", e);
Err(nom::Err::Error(_e)) |
Err(nom::Err::Failure(_e)) => {
SCLogDebug!("TRANS2 ERROR {:?}", _e);
events.push(SMBEvent::MalformedData);
false
},
@ -883,11 +883,11 @@ pub fn smb1_trans_request_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>)
let mut frankenfid = pipe.fid.to_vec();
frankenfid.extend_from_slice(&u32_as_bytes(r.ssn_id));
let (filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) {
let (_filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) {
(n, x) => (n, x),
};
SCLogDebug!("smb1_trans_request_record: name {} is_dcerpc {}",
filename, is_dcerpc);
_filename, is_dcerpc);
pipe_dcerpc = is_dcerpc;
}
@ -924,11 +924,11 @@ pub fn smb1_trans_response_record<'b>(state: &mut SMBState, r: &SmbRecord<'b>)
let mut frankenfid = fid.to_vec();
frankenfid.extend_from_slice(&u32_as_bytes(r.ssn_id));
let (filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) {
let (_filename, is_dcerpc) = match state.get_service_for_guid(&frankenfid) {
(n, x) => (n, x),
};
SCLogDebug!("smb1_trans_response_record: name {} is_dcerpc {}",
filename, is_dcerpc);
_filename, is_dcerpc);
// if we get status 'BUFFER_OVERFLOW' this is only a part of
// the data. Store it in the ssn/tree for later use.

@ -579,20 +579,20 @@ pub fn smb2_response_record<'b>(state: &mut SMBState, r: &Smb2Record<'b>)
if r.nt_status == SMB_NTSTATUS_SUCCESS {
match parse_smb2_response_write(r.data)
{
Ok((_, wr)) => {
SCLogDebug!("SMBv2: Write response => {:?}", wr);
Ok((_, _wr)) => {
SCLogDebug!("SMBv2: Write response => {:?}", _wr);
/* search key-guid map */
let guid_key = SMBCommonHdr::new(SMBHDR_TYPE_GUID,
r.session_id, r.tree_id, r.message_id);
let guid_vec = match state.ssn2vec_map.remove(&guid_key) {
let _guid_vec = match state.ssn2vec_map.remove(&guid_key) {
Some(p) => p,
None => {
SCLogDebug!("SMBv2 response: GUID NOT FOUND");
Vec::new()
},
};
SCLogDebug!("SMBv2 write response for GUID {:?}", guid_vec);
SCLogDebug!("SMBv2 write response for GUID {:?}", _guid_vec);
}
_ => {
events.push(SMBEvent::MalformedData);

@ -20,6 +20,7 @@ use crate::smb::smb2::*;
use crate::smb::smb2_records::*;
use crate::smb::dcerpc::*;
use crate::smb::events::*;
#[cfg(feature = "debug")]
use crate::smb::funcs::*;
#[derive(Debug)]

@ -195,8 +195,8 @@ impl<'a> SNMPState<'a> {
Ok((_rem,SnmpGenericMessage::V1(msg))) |
Ok((_rem,SnmpGenericMessage::V2(msg))) => self.handle_snmp_v12(msg, direction),
Ok((_rem,SnmpGenericMessage::V3(msg))) => self.handle_snmp_v3(msg, direction),
Err(e) => {
SCLogDebug!("parse_snmp failed: {:?}", e);
Err(_e) => {
SCLogDebug!("parse_snmp failed: {:?}", _e);
self.set_event(SNMPEvent::MalformedData);
-1
},

@ -256,15 +256,15 @@ impl SSHState {
panic!("SSH invalid length record header");
}
}
Err(e) => {
SCLogDebug!("SSH invalid record header {}", e);
Err(_e) => {
SCLogDebug!("SSH invalid record header {}", _e);
self.set_event(SSHEvent::InvalidRecord);
return AppLayerResult::err();
}
}
}
Err(e) => {
SCLogDebug!("SSH invalid record {}", e);
Err(_e) => {
SCLogDebug!("SSH invalid record {}", _e);
self.set_event(SSHEvent::InvalidRecord);
return AppLayerResult::err();
}
@ -294,8 +294,8 @@ impl SSHState {
Err(nom::Err::Incomplete(_)) => {
return AppLayerResult::incomplete(0 as u32, (input.len() + 1) as u32);
}
Err(e) => {
SCLogDebug!("SSH invalid banner {}", e);
Err(_e) => {
SCLogDebug!("SSH invalid banner {}", _e);
self.set_event(SSHEvent::InvalidBanner);
return AppLayerResult::err();
}
@ -353,8 +353,8 @@ impl SSHState {
}
}
}
Err(e) => {
SCLogDebug!("SSH invalid banner {}", e);
Err(_e) => {
SCLogDebug!("SSH invalid banner {}", _e);
self.set_event(SSHEvent::InvalidBanner);
return AppLayerResult::err();
}

Loading…
Cancel
Save