nfs: bound requestmap

Add to the hashmap only if there is not too many items in in

Ticket: 8418

(cherry picked from commit a50f494ef6)
pull/15420/head
Philippe Antoine 3 months ago
parent 6c63fec9cb
commit cc59c567f7

@ -91,6 +91,8 @@ static mut ALPROTO_NFS: AppProto = ALPROTO_UNKNOWN;
* Transaction lookup. * Transaction lookup.
*/ */
pub static mut NFS_CFG_MAX_REQ: usize = 512;
#[derive(AppLayerFrameType)] #[derive(AppLayerFrameType)]
pub enum NFSFrameType { pub enum NFSFrameType {
RPCPdu, RPCPdu,
@ -826,7 +828,9 @@ impl NFSState {
let mut xidmap = NFSRequestXidMap::new(r.progver, r.procedure, 0); let mut xidmap = NFSRequestXidMap::new(r.progver, r.procedure, 0);
xidmap.file_handle = w.handle.value.to_vec(); xidmap.file_handle = w.handle.value.to_vec();
self.requestmap.insert(r.hdr.xid, xidmap); if self.requestmap.len() < unsafe { NFS_CFG_MAX_REQ } {
self.requestmap.insert(r.hdr.xid, xidmap);
}
return self.process_write_record(r, w); return self.process_write_record(r, w);
} }
@ -2037,6 +2041,18 @@ pub unsafe extern "C" fn rs_nfs_register_parser() {
let _ = AppLayerRegisterParser(&parser, alproto); let _ = AppLayerRegisterParser(&parser, alproto);
} }
SCLogDebug!("Rust nfs parser registered."); SCLogDebug!("Rust nfs parser registered.");
let retval = conf_get("app-layer.protocols.nfs.max-requests");
if let Some(val) = retval {
if let Ok(v) = val.parse::<usize>() {
if v > 0 {
NFS_CFG_MAX_REQ = v;
} else {
SCLogError!("Invalid max-requests value, must be >0");
}
} else {
SCLogError!("Invalid max-requests value");
}
}
} else { } else {
SCLogDebug!("Protocol detector and parser disabled for nfs."); SCLogDebug!("Protocol detector and parser disabled for nfs.");
} }

@ -89,7 +89,9 @@ impl NFSState {
} }
SCLogDebug!("NFSv2: TS creating xidmap {}", r.hdr.xid); SCLogDebug!("NFSv2: TS creating xidmap {}", r.hdr.xid);
self.requestmap.insert(r.hdr.xid, xidmap); if self.requestmap.len() < unsafe { NFS_CFG_MAX_REQ } {
self.requestmap.insert(r.hdr.xid, xidmap);
}
} }
pub fn process_reply_record_v2(&mut self, r: &RpcReplyPacket, xidmap: &NFSRequestXidMap) { pub fn process_reply_record_v2(&mut self, r: &RpcReplyPacket, xidmap: &NFSRequestXidMap) {

@ -187,7 +187,9 @@ impl NFSState {
} }
} }
self.requestmap.insert(r.hdr.xid, xidmap); if self.requestmap.len() < unsafe { NFS_CFG_MAX_REQ } {
self.requestmap.insert(r.hdr.xid, xidmap);
}
} }
pub fn process_reply_record_v3(&mut self, r: &RpcReplyPacket, xidmap: &mut NFSRequestXidMap) { pub fn process_reply_record_v3(&mut self, r: &RpcReplyPacket, xidmap: &mut NFSRequestXidMap) {

@ -303,7 +303,9 @@ impl NFSState {
}; };
} }
self.requestmap.insert(r.hdr.xid, xidmap); if self.requestmap.len() < unsafe { NFS_CFG_MAX_REQ } {
self.requestmap.insert(r.hdr.xid, xidmap);
}
} }
fn compound_response<'b>( fn compound_response<'b>(

Loading…
Cancel
Save