* 02110-1301, USA.
*/
-use std::string::String;
use crate::jsonbuilder::{JsonBuilder, JsonError};
-use crate::nfs::types::*;
use crate::nfs::nfs::*;
+use crate::nfs::types::*;
use crc::crc32;
+use std::string::String;
#[no_mangle]
-pub extern "C" fn SCNfsTxLoggingIsFiltered(state: &mut NFSState,
- tx: &NFSTransaction)
- -> u8
-{
+pub extern "C" fn SCNfsTxLoggingIsFiltered(state: &mut NFSState, tx: &NFSTransaction) -> u8 {
// TODO probably best to make this configurable
if state.nfs_version <= 3 && tx.procedure == NFSPROC3_GETATTR {
return 0;
}
-fn nfs_rename_object(tx: &NFSTransaction, js: &mut JsonBuilder)
- -> Result<(), JsonError>
-{
+fn nfs_rename_object(tx: &NFSTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
let from_str = String::from_utf8_lossy(&tx.file_name);
js.set_string("from", &from_str)?;
let to_vec = match tx.type_data {
- Some(NFSTransactionTypeData::RENAME(ref x)) => { x.to_vec() },
- _ => { Vec::new() }
+ Some(NFSTransactionTypeData::RENAME(ref x)) => x.to_vec(),
+ _ => Vec::new(),
};
let to_str = String::from_utf8_lossy(&to_vec);
Ok(())
}
-fn nfs_creds_object(tx: &NFSTransaction, js: &mut JsonBuilder)
- -> Result<(), JsonError>
-{
+fn nfs_creds_object(tx: &NFSTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
let mach_name = String::from_utf8_lossy(&tx.request_machine_name);
js.set_string("machine_name", &mach_name)?;
js.set_uint("uid", tx.request_uid as u64)?;
Ok(())
}
-fn nfs_file_object(tx: &NFSTransaction, js: &mut JsonBuilder)
- -> Result<(), JsonError>
-{
+fn nfs_file_object(tx: &NFSTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.set_bool("first", tx.is_first)?;
js.set_bool("last", tx.is_last)?;
c
}
-fn nfs_common_header(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder)
- -> Result<(), JsonError>
-{
+fn nfs_common_header(
+ state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder,
+) -> Result<(), JsonError> {
js.set_uint("version", state.nfs_version as u64)?;
let proc_string = if state.nfs_version < 4 {
nfs3_procedure_string(tx.procedure)
Ok(())
}
-fn nfs_log_response(state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder)
- -> Result<(), JsonError>
-{
+fn nfs_log_response(
+ state: &NFSState, tx: &NFSTransaction, js: &mut JsonBuilder,
+) -> Result<(), JsonError> {
nfs_common_header(state, tx, js)?;
js.set_string("type", "response")?;
}
#[no_mangle]
-pub extern "C" fn SCNfsLogJsonResponse(state: &mut NFSState, tx: &NFSTransaction,
- js: &mut JsonBuilder) -> bool
-{
+pub extern "C" fn SCNfsLogJsonResponse(
+ state: &mut NFSState, tx: &NFSTransaction, js: &mut JsonBuilder,
+) -> bool {
nfs_log_response(state, tx, js).is_ok()
}
-fn rpc_log_response(tx: &NFSTransaction, js: &mut JsonBuilder)
- -> Result<(), JsonError>
-{
+fn rpc_log_response(tx: &NFSTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.set_uint("xid", tx.xid as u64)?;
js.set_string("status", &rpc_status_string(tx.rpc_response_status))?;
js.set_string("auth_type", &rpc_auth_type_string(tx.auth_type))?;
}
#[no_mangle]
-pub extern "C" fn SCNfsRpcLogJsonResponse(tx: &NFSTransaction,
- js: &mut JsonBuilder) -> bool
-{
+pub extern "C" fn SCNfsRpcLogJsonResponse(tx: &NFSTransaction, js: &mut JsonBuilder) -> bool {
rpc_log_response(tx, js).is_ok()
}
//! NFS application layer, parser, logger module.
-pub mod types;
-pub mod rpc_records;
-pub mod nfs_records;
-pub mod nfs2_records;
-pub mod nfs3_records;
-pub mod nfs4_records;
+pub mod log;
pub mod nfs;
pub mod nfs2;
+pub mod nfs2_records;
pub mod nfs3;
+pub mod nfs3_records;
pub mod nfs4;
-pub mod log;
+pub mod nfs4_records;
+pub mod nfs_records;
+pub mod rpc_records;
+pub mod types;
use crate::applayer;
use crate::applayer::*;
+use crate::conf::*;
+use crate::core::*;
use crate::direction::Direction;
use crate::direction::DIR_BOTH;
+use crate::filecontainer::*;
+use crate::filetracker::*;
use crate::flow::Flow;
use crate::frames::*;
-use crate::core::*;
-use crate::conf::*;
-use crate::filetracker::*;
-use crate::filecontainer::*;
-use crate::nfs::types::*;
-use crate::nfs::rpc_records::*;
-use crate::nfs::nfs_records::*;
use crate::nfs::nfs2_records::*;
use crate::nfs::nfs3_records::*;
+use crate::nfs::nfs_records::*;
+use crate::nfs::rpc_records::*;
+use crate::nfs::types::*;
pub static mut SURICATA_NFS_FILE_CONFIG: Option<&'static SuricataFileContext> = None;
return Self {
file_tracker: FileTransferTracker::new(),
..Default::default()
- }
+ };
}
pub fn update_file_flags(&mut self, flow_file_flags: u16) {
- let dir_flag = if self.direction == Direction::ToServer { STREAM_TOSERVER } else { STREAM_TOCLIENT };
+ let dir_flag = if self.direction == Direction::ToServer {
+ STREAM_TOSERVER
+ } else {
+ STREAM_TOCLIENT
+ };
self.file_tracker.file_flags = unsafe { FileFlowFlagsToFlags(flow_file_flags, dir_flag) };
}
}
-unsafe extern "C" fn 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();
+ let tx_dir: u8 = tdf.direction.into();
if direction & tx_dir != 0 {
if let Some(sfcm) = { SURICATA_NFS_FILE_CONFIG } {
- return AppLayerGetFileState { fc: &mut tdf.file_tracker.file, cfg: sfcm.files_sbcfg }
+ return AppLayerGetFileState {
+ fc: &mut tdf.file_tracker.file,
+ cfg: sfcm.files_sbcfg,
+ };
}
}
}
#[derive(Debug)]
pub struct NFSTransaction {
- pub id: u64, /// internal id
- pub xid: u32, /// nfs req/reply pair id
+ pub id: u64,
+ /// internal id
+ pub xid: u32,
+ /// nfs req/reply pair id
pub procedure: u32,
/// file name of the object we're dealing with. In case of RENAME
/// this is the 'from' or original name.
id: 0,
xid: 0,
procedure: 0,
- file_name:Vec::new(),
- request_machine_name:Vec::new(),
- request_uid:0,
- request_gid:0,
- rpc_response_status:0,
- nfs_response_status:0,
+ file_name: Vec::new(),
+ request_machine_name: Vec::new(),
+ request_uid: 0,
+ request_gid: 0,
+ rpc_response_status: 0,
+ nfs_response_status: 0,
auth_type: 0,
is_first: false,
is_last: false,
request_done: false,
response_done: false,
- nfs_version:0,
+ nfs_version: 0,
is_file_tx: false,
is_file_closed: false,
- file_handle:Vec::new(),
+ file_handle: Vec::new(),
type_data: None,
tx_data: AppLayerTxData::new(),
- }
+ };
}
pub fn free(&mut self) {
pub progver: u32,
pub procedure: u32,
pub chunk_offset: u64,
- pub file_name:Vec<u8>,
+ pub file_name: Vec<u8>,
/// READ replies can use this to get to the handle the request used
- pub file_handle:Vec<u8>,
+ pub file_handle: Vec<u8>,
pub gssapi_proc: u32,
pub gssapi_service: u32,
progver,
procedure,
chunk_offset,
- file_name:Vec::new(),
- file_handle:Vec::new(),
+ file_name: Vec::new(),
+ file_handle: Vec::new(),
gssapi_proc: 0,
gssapi_service: 0,
}
}
/// little wrapper around the FileTransferTracker::new_chunk method
-pub fn filetracker_newchunk(ft: &mut FileTransferTracker, name: &[u8], data: &[u8],
- chunk_offset: u64, chunk_size: u32, fill_bytes: u8, is_last: bool, xid: &u32)
-{
+pub fn filetracker_newchunk(
+ ft: &mut FileTransferTracker, name: &[u8], data: &[u8], chunk_offset: u64, chunk_size: u32,
+ fill_bytes: u8, is_last: bool, xid: &u32,
+) {
if let Some(sfcm) = unsafe { SURICATA_NFS_FILE_CONFIG } {
- ft.new_chunk(sfcm, name, data, chunk_offset,
- chunk_size, fill_bytes, is_last, xid);
+ ft.new_chunk(
+ sfcm,
+ name,
+ data,
+ chunk_offset,
+ chunk_size,
+ fill_bytes,
+ is_last,
+ xid,
+ );
}
}
-fn filetracker_trunc(ft: &mut FileTransferTracker)
-{
+fn filetracker_trunc(ft: &mut FileTransferTracker) {
if let Some(sfcm) = unsafe { SURICATA_NFS_FILE_CONFIG } {
ft.trunc(sfcm);
}
}
-pub fn filetracker_close(ft: &mut FileTransferTracker)
-{
+pub fn filetracker_close(ft: &mut FileTransferTracker) {
if let Some(sfcm) = unsafe { SURICATA_NFS_FILE_CONFIG } {
ft.close(sfcm);
}
}
-fn filetracker_update(ft: &mut FileTransferTracker, data: &[u8], gap_size: u32) -> u32
-{
+fn filetracker_update(ft: &mut FileTransferTracker, data: &[u8], gap_size: u32) -> u32 {
if let Some(sfcm) = unsafe { SURICATA_NFS_FILE_CONFIG } {
ft.update(sfcm, data, gap_size)
} else {
}
}
-
#[derive(Debug)]
pub struct NFSState {
state_data: AppLayerStateData,
pub fn new() -> NFSState {
NFSState {
state_data: AppLayerStateData::new(),
- requestmap:HashMap::new(),
- namemap:HashMap::new(),
+ requestmap: HashMap::new(),
+ namemap: HashMap::new(),
transactions: Vec::new(),
- ts_chunk_xid:0,
- tc_chunk_xid:0,
- ts_chunk_left:0,
- tc_chunk_left:0,
- ts_chunk_fh:Vec::new(),
- ts_ssn_gap:false,
- tc_ssn_gap:false,
- ts_gap:false,
- tc_gap:false,
- is_udp:false,
- check_post_gap_file_txs:false,
- post_gap_files_checked:false,
- nfs_version:0,
- tx_id:0,
+ ts_chunk_xid: 0,
+ tc_chunk_xid: 0,
+ ts_chunk_left: 0,
+ tc_chunk_left: 0,
+ ts_chunk_fh: Vec::new(),
+ ts_ssn_gap: false,
+ tc_ssn_gap: false,
+ ts_gap: false,
+ tc_gap: false,
+ is_udp: false,
+ check_post_gap_file_txs: false,
+ post_gap_files_checked: false,
+ nfs_version: 0,
+ tx_id: 0,
ts: 0,
}
}
tx_old.request_done = true;
tx_old.response_done = true;
tx_old.is_file_closed = true;
- tx_old.tx_data.set_event(NFSEvent::TooManyTransactions as u8);
+ tx_old
+ .tx_data
+ .set_event(NFSEvent::TooManyTransactions as u8);
break;
}
}
}
pub fn get_tx_by_xid(&mut self, tx_xid: u32) -> Option<&mut NFSTransaction> {
- return self.transactions.iter_mut().find(|tx| !tx.is_file_tx && tx.xid == tx_xid);
+ return self
+ .transactions
+ .iter_mut()
+ .find(|tx| !tx.is_file_tx && tx.xid == tx_xid);
}
/// Set an event. The event is set on the most recent transaction.
}
// TODO maybe not enough users to justify a func
- pub fn mark_response_tx_done(&mut self, xid: u32, rpc_status: u32, nfs_status: u32, resp_handle: &[u8])
- {
+ pub fn mark_response_tx_done(
+ &mut self, xid: u32, rpc_status: u32, nfs_status: u32, resp_handle: &[u8],
+ ) {
if let Some(mytx) = self.get_tx_by_xid(xid) {
mytx.tx_data.updated_tc = true;
mytx.tx_data.updated_ts = true;
if mytx.file_handle.is_empty() && !resp_handle.is_empty() {
mytx.file_handle = resp_handle.to_vec();
}
-
- SCLogDebug!("process_reply_record: tx ID {} XID {:04X} REQUEST {} RESPONSE {}",
- mytx.id, mytx.xid, mytx.request_done, mytx.response_done);
+
+ SCLogDebug!(
+ "process_reply_record: tx ID {} XID {:04X} REQUEST {} RESPONSE {}",
+ mytx.id,
+ mytx.xid,
+ mytx.request_done,
+ mytx.response_done
+ );
} else {
//SCLogNotice!("process_reply_record: not TX found for XID {}", r.hdr.xid);
}
}
- fn add_rpc_udp_ts_pdu(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64) -> Option<Frame> {
- let rpc_udp_ts_pdu = Frame::new(flow, stream_slice, input, rpc_len, NFSFrameType::RPCPdu as u8, None);
+ fn add_rpc_udp_ts_pdu(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64,
+ ) -> Option<Frame> {
+ let rpc_udp_ts_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ rpc_len,
+ NFSFrameType::RPCPdu as u8,
+ None,
+ );
SCLogDebug!("rpc_udp_pdu ts frame {:?}", rpc_udp_ts_pdu);
rpc_udp_ts_pdu
}
- fn add_rpc_udp_ts_creds(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], creds_len: i64) {
- let _rpc_udp_ts_creds = Frame::new(flow, stream_slice, input, creds_len, NFSFrameType::RPCCreds as u8, None);
+ fn add_rpc_udp_ts_creds(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], creds_len: i64,
+ ) {
+ let _rpc_udp_ts_creds = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ creds_len,
+ NFSFrameType::RPCCreds as u8,
+ None,
+ );
SCLogDebug!("rpc_creds ts frame {:?}", _rpc_udp_ts_creds);
}
- fn add_rpc_tcp_ts_pdu(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64) -> Option<Frame> {
- let rpc_tcp_ts_pdu = Frame::new(flow, stream_slice, input, rpc_len, NFSFrameType::RPCPdu as u8, None);
+ fn add_rpc_tcp_ts_pdu(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64,
+ ) -> Option<Frame> {
+ let rpc_tcp_ts_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ rpc_len,
+ NFSFrameType::RPCPdu as u8,
+ None,
+ );
SCLogDebug!("rpc_tcp_pdu ts frame {:?}", rpc_tcp_ts_pdu);
rpc_tcp_ts_pdu
}
- fn add_rpc_tcp_ts_creds(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], creds_len: i64) {
- let _rpc_tcp_ts_creds = Frame::new(flow, stream_slice, input, creds_len, NFSFrameType::RPCCreds as u8, None);
+ fn add_rpc_tcp_ts_creds(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], creds_len: i64,
+ ) {
+ let _rpc_tcp_ts_creds = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ creds_len,
+ NFSFrameType::RPCCreds as u8,
+ None,
+ );
SCLogDebug!("rpc_tcp_ts_creds {:?}", _rpc_tcp_ts_creds);
}
- fn add_nfs_ts_frame(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs_len: i64) {
- let _nfs_req_pdu = Frame::new(flow, stream_slice, input, nfs_len, NFSFrameType::NFSPdu as u8, None);
+ fn add_nfs_ts_frame(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs_len: i64,
+ ) {
+ let _nfs_req_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ nfs_len,
+ NFSFrameType::NFSPdu as u8,
+ None,
+ );
SCLogDebug!("nfs_ts_pdu Frame {:?}", _nfs_req_pdu);
}
- fn add_nfs4_ts_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs4_len: i64) {
- let _nfs4_ts_pdu = Frame::new(flow, stream_slice, input, nfs4_len, NFSFrameType::NFS4Pdu as u8, None);
+ fn add_nfs4_ts_frames(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs4_len: i64,
+ ) {
+ let _nfs4_ts_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ nfs4_len,
+ NFSFrameType::NFS4Pdu as u8,
+ None,
+ );
SCLogDebug!("nfs4_ts_pdu Frame: {:?}", _nfs4_ts_pdu);
if nfs4_len > 8 {
- let _nfs4_ts_hdr = Frame::new(flow, stream_slice, input, 8, NFSFrameType::NFS4Hdr as u8, None);
+ let _nfs4_ts_hdr = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ 8,
+ NFSFrameType::NFS4Hdr as u8,
+ None,
+ );
SCLogDebug!("nfs4_ts_hdr Frame {:?}", _nfs4_ts_hdr);
- let _nfs4_ts_ops = Frame::new(flow, stream_slice, &input[8..], nfs4_len - 8, NFSFrameType::NFS4Ops as u8, None);
+ let _nfs4_ts_ops = Frame::new(
+ flow,
+ stream_slice,
+ &input[8..],
+ nfs4_len - 8,
+ NFSFrameType::NFS4Ops as u8,
+ None,
+ );
SCLogDebug!("nfs4_ts_ops Frame {:?}", _nfs4_ts_ops);
}
}
- fn add_rpc_udp_tc_pdu(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64) -> Option<Frame> {
- let rpc_udp_tc_pdu = Frame::new(flow, stream_slice, input, rpc_len, NFSFrameType::RPCPdu as u8, None);
+ fn add_rpc_udp_tc_pdu(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64,
+ ) -> Option<Frame> {
+ let rpc_udp_tc_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ rpc_len,
+ NFSFrameType::RPCPdu as u8,
+ None,
+ );
SCLogDebug!("rpc_tc_pdu frame {:?}", rpc_udp_tc_pdu);
rpc_udp_tc_pdu
}
- fn add_rpc_udp_tc_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64) {
+ fn add_rpc_udp_tc_frames(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_len: i64,
+ ) {
if rpc_len > 8 {
- let _rpc_udp_tc_hdr = Frame::new(flow, stream_slice, input, 8, NFSFrameType::RPCHdr as u8, None);
- let _rpc_udp_tc_data = Frame::new(flow, stream_slice, &input[8..], rpc_len - 8, NFSFrameType::RPCData as u8, None);
+ let _rpc_udp_tc_hdr = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ 8,
+ NFSFrameType::RPCHdr as u8,
+ None,
+ );
+ let _rpc_udp_tc_data = Frame::new(
+ flow,
+ stream_slice,
+ &input[8..],
+ rpc_len - 8,
+ NFSFrameType::RPCData as u8,
+ None,
+ );
SCLogDebug!("rpc_udp_tc_hdr frame {:?}", _rpc_udp_tc_hdr);
SCLogDebug!("rpc_udp_tc_data frame {:?}", _rpc_udp_tc_data);
}
}
- fn add_rpc_tcp_tc_pdu(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_tcp_len: i64) -> Option<Frame> {
- let rpc_tcp_tc_pdu = Frame::new(flow, stream_slice, input, rpc_tcp_len, NFSFrameType::RPCPdu as u8, None);
+ fn add_rpc_tcp_tc_pdu(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_tcp_len: i64,
+ ) -> Option<Frame> {
+ let rpc_tcp_tc_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ rpc_tcp_len,
+ NFSFrameType::RPCPdu as u8,
+ None,
+ );
SCLogDebug!("rpc_tcp_pdu tc frame {:?}", rpc_tcp_tc_pdu);
rpc_tcp_tc_pdu
}
- fn add_rpc_tcp_tc_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_tcp_len: i64) {
+ fn add_rpc_tcp_tc_frames(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], rpc_tcp_len: i64,
+ ) {
if rpc_tcp_len > 12 {
- let _rpc_tcp_tc_hdr = Frame::new(flow, stream_slice, input, 12, NFSFrameType::RPCHdr as u8, None);
- let _rpc_tcp_tc_data = Frame::new(flow, stream_slice, &input[12..], rpc_tcp_len - 12, NFSFrameType::RPCData as u8, None);
+ let _rpc_tcp_tc_hdr = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ 12,
+ NFSFrameType::RPCHdr as u8,
+ None,
+ );
+ let _rpc_tcp_tc_data = Frame::new(
+ flow,
+ stream_slice,
+ &input[12..],
+ rpc_tcp_len - 12,
+ NFSFrameType::RPCData as u8,
+ None,
+ );
SCLogDebug!("rpc_tcp_tc_hdr frame {:?}", _rpc_tcp_tc_hdr);
SCLogDebug!("rpc_tcp_tc_data frame {:?}", _rpc_tcp_tc_data);
}
}
- fn add_nfs_tc_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs_len: i64) {
+ fn add_nfs_tc_frames(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs_len: i64,
+ ) {
if nfs_len > 0 {
- let _nfs_tc_pdu = Frame::new(flow, stream_slice, input, nfs_len, NFSFrameType::NFSPdu as u8, None);
+ let _nfs_tc_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ nfs_len,
+ NFSFrameType::NFSPdu as u8,
+ None,
+ );
SCLogDebug!("nfs_tc_pdu frame {:?}", _nfs_tc_pdu);
- let _nfs_res_status = Frame::new(flow, stream_slice, input, 4, NFSFrameType::NFSStatus as u8, None);
+ let _nfs_res_status = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ 4,
+ NFSFrameType::NFSStatus as u8,
+ None,
+ );
SCLogDebug!("nfs_tc_status frame {:?}", _nfs_res_status);
}
}
- fn add_nfs4_tc_frames(&mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs4_len: i64) {
+ fn add_nfs4_tc_frames(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, input: &[u8], nfs4_len: i64,
+ ) {
if nfs4_len > 0 {
- let _nfs4_tc_pdu = Frame::new(flow, stream_slice, input, nfs4_len, NFSFrameType::NFS4Pdu as u8, None);
+ let _nfs4_tc_pdu = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ nfs4_len,
+ NFSFrameType::NFS4Pdu as u8,
+ None,
+ );
SCLogDebug!("nfs4_tc_pdu frame {:?}", _nfs4_tc_pdu);
- let _nfs4_tc_status = Frame::new(flow, stream_slice, input, 4, NFSFrameType::NFS4Status as u8, None);
+ let _nfs4_tc_status = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ 4,
+ NFSFrameType::NFS4Status as u8,
+ None,
+ );
SCLogDebug!("nfs4_tc_status frame {:?}", _nfs4_tc_status);
}
if nfs4_len > 8 {
- let _nfs4_tc_hdr = Frame::new(flow, stream_slice, input, 8, NFSFrameType::NFS4Hdr as u8, None);
+ let _nfs4_tc_hdr = Frame::new(
+ flow,
+ stream_slice,
+ input,
+ 8,
+ NFSFrameType::NFS4Hdr as u8,
+ None,
+ );
SCLogDebug!("nfs4_tc_hdr frame {:?}", _nfs4_tc_hdr);
- let _nfs4_tc_ops = Frame::new(flow, stream_slice, &input[8..], nfs4_len - 8, NFSFrameType::NFS4Ops as u8, None);
+ let _nfs4_tc_ops = Frame::new(
+ flow,
+ stream_slice,
+ &input[8..],
+ nfs4_len - 8,
+ NFSFrameType::NFS4Ops as u8,
+ None,
+ );
SCLogDebug!("nfs4_tc_ops frame {:?}", _nfs4_tc_ops);
}
}
- fn post_gap_housekeeping_for_files(&mut self)
- {
+ fn post_gap_housekeeping_for_files(&mut self) {
let mut post_gap_txs = false;
for tx in &mut self.transactions {
if let Some(NFSTransactionTypeData::FILE(ref mut f)) = tx.type_data {
* can handle gaps. For the file transactions we set the current
* (flow) time and prune them in 60 seconds if no update for them
* was received. */
- fn post_gap_housekeeping(&mut self, dir: Direction)
- {
+ fn post_gap_housekeeping(&mut self, dir: Direction) {
if self.ts_ssn_gap && dir == Direction::ToServer {
for tx in &mut self.transactions {
if tx.id >= self.tx_id {
Ok((_, lookup)) => {
SCLogDebug!("LOOKUP {:?}", lookup);
xidmap.file_name = lookup.name_vec;
- },
+ }
_ => {
self.set_event(NFSEvent::MalformedData);
- },
+ }
};
}
SCLogDebug!("xidmap_handle2name: name {:?}", n);
xidmap.file_name = n.to_vec();
} else {
- SCLogDebug!("xidmap_handle2name: object {:?} not found", xidmap.file_handle);
+ SCLogDebug!(
+ "xidmap_handle2name: object {:?} not found",
+ xidmap.file_handle
+ );
}
}
/// complete request record
- fn process_request_record(&mut self, flow: *const Flow, stream_slice: &StreamSlice, r: &RpcPacket) {
- SCLogDebug!("REQUEST {} procedure {} ({}) blob size {}",
- r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
+ fn process_request_record(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, r: &RpcPacket,
+ ) {
+ SCLogDebug!(
+ "REQUEST {} procedure {} ({}) blob size {}",
+ r.hdr.xid,
+ r.procedure,
+ self.requestmap.len(),
+ r.prog_data.len()
+ );
match r.progver {
4 => {
self.add_nfs4_ts_frames(flow, stream_slice, r.prog_data, r.prog_data_size as i64);
self.process_request_record_v4(r)
- },
+ }
3 => {
self.add_nfs_ts_frame(flow, stream_slice, r.prog_data, r.prog_data_size as i64);
self.process_request_record_v3(r)
- },
+ }
2 => {
self.add_nfs_ts_frame(flow, stream_slice, r.prog_data, r.prog_data_size as i64);
self.process_request_record_v2(r)
- },
- _ => { },
+ }
+ _ => {}
}
}
- pub fn new_file_tx(&mut self, file_handle: &[u8], file_name: &[u8], direction: Direction)
- -> &mut NFSTransaction
- {
+ pub fn new_file_tx(
+ &mut self, file_handle: &[u8], file_name: &[u8], direction: Direction,
+ ) -> &mut NFSTransaction {
let mut tx = self.new_tx();
tx.file_name = file_name.to_vec();
tx.file_handle = file_handle.to_vec();
d.update_file_flags(tx.tx_data.file_flags);
}
tx.tx_data.init_files_opened();
- tx.tx_data.file_tx = if direction == Direction::ToServer { STREAM_TOSERVER } else { STREAM_TOCLIENT }; // TODO direction to flag func?
- SCLogDebug!("new_file_tx: TX FILE created: ID {} NAME {}",
- tx.id, String::from_utf8_lossy(file_name));
+ tx.tx_data.file_tx = if direction == Direction::ToServer {
+ STREAM_TOSERVER
+ } else {
+ STREAM_TOCLIENT
+ }; // TODO direction to flag func?
+ SCLogDebug!(
+ "new_file_tx: TX FILE created: ID {} NAME {}",
+ tx.id,
+ String::from_utf8_lossy(file_name)
+ );
self.transactions.push(tx);
let tx_ref = self.transactions.last_mut();
return tx_ref.unwrap();
}
- pub fn get_file_tx_by_handle(&mut self, file_handle: &[u8], direction: Direction)
- -> Option<&mut NFSTransaction>
- {
+ pub fn get_file_tx_by_handle(
+ &mut self, file_handle: &[u8], direction: Direction,
+ ) -> Option<&mut NFSTransaction> {
let fh = file_handle.to_vec();
for tx in &mut self.transactions {
if let Some(NFSTransactionTypeData::FILE(ref mut d)) = tx.type_data {
- if tx.is_file_tx && !tx.is_file_closed &&
- direction == d.direction &&
- tx.file_handle == fh
+ if tx.is_file_tx
+ && !tx.is_file_closed
+ && direction == d.direction
+ && tx.file_handle == fh
{
tx.tx_data.update_file_flags(self.state_data.file_flags);
d.update_file_flags(tx.tx_data.file_flags);
let found = match self.get_file_tx_by_handle(&file_handle, Direction::ToServer) {
Some(tx) => {
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
- filetracker_newchunk(&mut tdf.file_tracker,
- &file_name, w.file_data, w.offset,
- w.file_len, fill_bytes as u8, is_last, &r.hdr.xid);
+ filetracker_newchunk(
+ &mut tdf.file_tracker,
+ &file_name,
+ w.file_data,
+ w.offset,
+ w.file_len,
+ fill_bytes as u8,
+ is_last,
+ &r.hdr.xid,
+ );
tdf.chunk_count += 1;
if is_last {
tdf.file_last_xid = r.hdr.xid;
} else {
false
}
- },
- None => { false },
+ }
+ None => false,
};
if !found {
let tx = self.new_file_tx(&file_handle, &file_name, Direction::ToServer);
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
- filetracker_newchunk(&mut tdf.file_tracker,
- &file_name, w.file_data, w.offset,
- w.file_len, fill_bytes as u8, is_last, &r.hdr.xid);
+ filetracker_newchunk(
+ &mut tdf.file_tracker,
+ &file_name,
+ w.file_data,
+ w.offset,
+ w.file_len,
+ fill_bytes as u8,
+ is_last,
+ &r.hdr.xid,
+ );
tx.procedure = NFSPROC3_WRITE;
tx.xid = r.hdr.xid;
tx.is_first = true;
debug_validate_bug_on!(w.file_data.len() as u32 > w.count);
self.ts_chunk_left = w.count - w.file_data.len() as u32;
self.ts_chunk_fh = file_handle;
- SCLogDebug!("REQUEST chunk_xid {:04X} chunk_left {}", self.ts_chunk_xid, self.ts_chunk_left);
+ SCLogDebug!(
+ "REQUEST chunk_xid {:04X} chunk_left {}",
+ self.ts_chunk_xid,
+ self.ts_chunk_left
+ );
}
0
}
- fn process_partial_write_request_record<'b>(&mut self, r: &RpcPacket<'b>, w: &Nfs3RequestWrite<'b>) -> u32 {
- SCLogDebug!("REQUEST {} procedure {} blob size {}", r.hdr.xid, r.procedure, r.prog_data.len());
+ fn process_partial_write_request_record<'b>(
+ &mut self, r: &RpcPacket<'b>, w: &Nfs3RequestWrite<'b>,
+ ) -> u32 {
+ SCLogDebug!(
+ "REQUEST {} procedure {} blob size {}",
+ r.hdr.xid,
+ r.procedure,
+ r.prog_data.len()
+ );
let mut xidmap = NFSRequestXidMap::new(r.progver, r.procedure, 0);
xidmap.file_handle = w.handle.value.to_vec();
return self.process_write_record(r, w);
}
- fn process_reply_record(&mut self, flow: *const Flow, stream_slice: &StreamSlice, r: &RpcReplyPacket) -> u32 {
+ fn process_reply_record(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice, r: &RpcReplyPacket,
+ ) -> u32 {
let mut xidmap;
match self.requestmap.remove(&r.hdr.xid) {
- Some(p) => { xidmap = p; },
+ Some(p) => {
+ xidmap = p;
+ }
_ => {
- SCLogDebug!("REPLY: xid {:04X} NOT FOUND. GAPS? TS:{} TC:{}",
- r.hdr.xid, self.ts_ssn_gap, self.tc_ssn_gap);
+ SCLogDebug!(
+ "REPLY: xid {:04X} NOT FOUND. GAPS? TS:{} TC:{}",
+ r.hdr.xid,
+ self.ts_ssn_gap,
+ self.tc_ssn_gap
+ );
// TODO we might be able to try to infer from the size + data
// that this is a READ reply and pass the data to the file API anyway?
return 0;
- },
+ }
}
- SCLogDebug!("process_reply_record: removed xid {:04X} from requestmap",
- r.hdr.xid);
+ SCLogDebug!(
+ "process_reply_record: removed xid {:04X} from requestmap",
+ r.hdr.xid
+ );
if self.nfs_version == 0 {
self.nfs_version = xidmap.progver as u16;
self.add_nfs_tc_frames(flow, stream_slice, r.prog_data, r.prog_data_size as i64);
self.process_reply_record_v2(r, &xidmap);
return 0;
- },
+ }
3 => {
SCLogDebug!("NFSv3 reply record");
self.add_nfs_tc_frames(flow, stream_slice, r.prog_data, r.prog_data_size as i64);
self.process_reply_record_v3(r, &mut xidmap);
return 0;
- },
+ }
4 => {
SCLogDebug!("NFSv4 reply record");
self.add_nfs4_tc_frames(flow, stream_slice, r.prog_data, r.prog_data_size as i64);
self.process_reply_record_v4(r, &mut xidmap);
return 0;
- },
+ }
_ => {
SCLogDebug!("Invalid NFS version");
self.set_event(NFSEvent::NonExistingVersion);
return 0;
- },
+ }
}
}
self.tc_chunk_left
};
if chunk_left == 0 {
- return 0
+ return 0;
}
let xid = if direction == Direction::ToServer {
self.ts_chunk_xid
} else {
self.tc_chunk_xid
};
- SCLogDebug!("filetracker_update: chunk left {}, input {} chunk_xid {:04X}", chunk_left, data.len(), xid);
+ SCLogDebug!(
+ "filetracker_update: chunk left {}, input {} chunk_xid {:04X}",
+ chunk_left,
+ data.len(),
+ xid
+ );
let file_handle;
// we have the data that we expect
match self.requestmap.remove(&xid) {
None => {
SCLogDebug!("no file handle found for XID {:04X}", xid);
- return 0
- },
+ return 0;
+ }
Some(xidmap) => {
file_handle = xidmap.file_handle.to_vec();
- },
+ }
}
}
} else {
match self.requestmap.get(&xid) {
None => {
SCLogDebug!("no file handle found for XID {:04X}", xid);
- return 0
- },
+ return 0;
+ }
Some(xidmap) => {
file_handle = xidmap.file_handle.to_vec();
- },
+ }
}
}
}
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
if ssn_gap {
let queued_data = tdf.file_tracker.get_queued_size();
- if queued_data > 2000000 { // TODO should probably be configurable
- SCLogDebug!("QUEUED size {} while we've seen GAPs. Truncating file.", queued_data);
+ if queued_data > 2000000 {
+ // TODO should probably be configurable
+ SCLogDebug!(
+ "QUEUED size {} while we've seen GAPs. Truncating file.",
+ queued_data
+ );
filetracker_trunc(&mut tdf.file_tracker);
}
}
if direction == Direction::ToClient {
tx.response_done = true;
tx.is_file_closed = true;
- SCLogDebug!("TX {} response is done now that the file track is ready", tx.id);
+ SCLogDebug!(
+ "TX {} response is done now that the file track is ready",
+ tx.id
+ );
} else {
tx.request_done = true;
tx.is_file_closed = true;
- SCLogDebug!("TX {} request is done now that the file track is ready", tx.id);
+ SCLogDebug!(
+ "TX {} request is done now that the file track is ready",
+ tx.id
+ );
}
}
cs
} else {
0
}
- },
- None => { 0 },
+ }
+ None => 0,
};
return consumed;
}
/// xidmapr is an Option as it's already removed from the map if we
/// have a complete record. Otherwise we do a lookup ourselves.
- pub fn process_read_record<'b>(&mut self, r: &RpcReplyPacket<'b>,
- reply: &NfsReplyRead<'b>, xidmapr: Option<&NFSRequestXidMap>) -> u32
- {
+ pub fn process_read_record<'b>(
+ &mut self, r: &RpcReplyPacket<'b>, reply: &NfsReplyRead<'b>,
+ xidmapr: Option<&NFSRequestXidMap>,
+ ) -> u32 {
let file_name;
let file_handle;
let chunk_offset;
file_handle = xidmap.file_handle.to_vec();
chunk_offset = xidmap.chunk_offset;
nfs_version = xidmap.progver;
- },
+ }
None => {
if let Some(xidmap) = self.requestmap.get(&r.hdr.xid) {
file_name = xidmap.file_name.to_vec();
} else {
return 0;
}
- },
+ }
}
SCLogDebug!("chunk_offset {}", chunk_offset);
let mut is_last = reply.eof;
- SCLogDebug!("XID {} is_last {} fill_bytes {} reply.count {} reply.data_len {} reply.data.len() {}",
- r.hdr.xid, is_last, fill_bytes, reply.count, reply.data_len, reply.data.len());
+ SCLogDebug!(
+ "XID {} is_last {} fill_bytes {} reply.count {} reply.data_len {} reply.data.len() {}",
+ r.hdr.xid,
+ is_last,
+ fill_bytes,
+ reply.count,
+ reply.data_len,
+ reply.data.len()
+ );
if nfs_version == 2 {
let size = match parse_nfs2_attribs(reply.attr_blob) {
Ok((_, ref attr)) => attr.asize,
_ => 0,
};
- SCLogDebug!("NFSv2 READ reply record: File size {}. Offset {} data len {}: total {}",
- size, chunk_offset, reply.data_len, chunk_offset + reply.data_len as u64);
+ SCLogDebug!(
+ "NFSv2 READ reply record: File size {}. Offset {} data len {}: total {}",
+ size,
+ chunk_offset,
+ reply.data_len,
+ chunk_offset + reply.data_len as u64
+ );
if size as u64 == chunk_offset + reply.data_len as u64 {
is_last = true;
}
-
}
let is_partial = reply.data.len() < reply.count as usize;
Some(tx) => {
SCLogDebug!("updated TX {:?}", tx);
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
- filetracker_newchunk(&mut tdf.file_tracker,
- &file_name, reply.data, chunk_offset,
- reply.count, fill_bytes as u8, is_last, &r.hdr.xid);
+ filetracker_newchunk(
+ &mut tdf.file_tracker,
+ &file_name,
+ reply.data,
+ chunk_offset,
+ reply.count,
+ fill_bytes as u8,
+ is_last,
+ &r.hdr.xid,
+ );
tdf.chunk_count += 1;
if is_last {
tdf.file_last_xid = r.hdr.xid;
} else {
false
}
- },
- None => { false },
+ }
+ None => false,
};
if !found {
let tx = self.new_file_tx(&file_handle, &file_name, Direction::ToClient);
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
- filetracker_newchunk(&mut tdf.file_tracker,
- &file_name, reply.data, chunk_offset,
- reply.count, fill_bytes as u8, is_last, &r.hdr.xid);
- tx.procedure = if nfs_version < 4 { NFSPROC3_READ } else { NFSPROC4_READ };
+ filetracker_newchunk(
+ &mut tdf.file_tracker,
+ &file_name,
+ reply.data,
+ chunk_offset,
+ reply.count,
+ fill_bytes as u8,
+ is_last,
+ &r.hdr.xid,
+ );
+ tx.procedure = if nfs_version < 4 {
+ NFSPROC3_READ
+ } else {
+ NFSPROC4_READ
+ };
tx.xid = r.hdr.xid;
tx.is_first = true;
if is_last {
self.tc_chunk_left = reply.count - reply.data.len() as u32;
}
- SCLogDebug!("REPLY {} to procedure {} blob size {} / {}: chunk_left {} chunk_xid {:04X}",
- r.hdr.xid, NFSPROC3_READ, r.prog_data.len(), reply.count, self.tc_chunk_left,
- self.tc_chunk_xid);
+ SCLogDebug!(
+ "REPLY {} to procedure {} blob size {} / {}: chunk_left {} chunk_xid {:04X}",
+ r.hdr.xid,
+ NFSPROC3_READ,
+ r.prog_data.len(),
+ reply.count,
+ self.tc_chunk_left,
+ self.tc_chunk_xid
+ );
0
}
- fn process_partial_read_reply_record<'b>(&mut self, r: &RpcReplyPacket<'b>, reply: &NfsReplyRead<'b>) -> u32 {
- SCLogDebug!("REPLY {} to procedure READ blob size {} / {}",
- r.hdr.xid, r.prog_data.len(), reply.count);
+ fn process_partial_read_reply_record<'b>(
+ &mut self, r: &RpcReplyPacket<'b>, reply: &NfsReplyRead<'b>,
+ ) -> u32 {
+ SCLogDebug!(
+ "REPLY {} to procedure READ blob size {} / {}",
+ r.hdr.xid,
+ r.prog_data.len(),
+ reply.count
+ );
return self.process_read_record(r, reply, None);
}
}
/// Handle partial records
- fn parse_tcp_partial_data_ts<'b>(&mut self, base_input: &'b[u8], cur_i: &'b[u8],
- phdr: &RpcRequestPacketPartial, rec_size: usize) -> AppLayerResult {
+ fn parse_tcp_partial_data_ts<'b>(
+ &mut self, base_input: &'b [u8], cur_i: &'b [u8], phdr: &RpcRequestPacketPartial,
+ rec_size: usize,
+ ) -> AppLayerResult {
// special case: avoid buffering file write blobs
// as these can be large.
if rec_size >= 512 && cur_i.len() >= 44 {
// quick peek, are we in WRITE mode?
if phdr.procedure == NFSPROC3_WRITE {
- SCLogDebug!("CONFIRMED WRITE: large record {}, file chunk xfer", rec_size);
+ SCLogDebug!(
+ "CONFIRMED WRITE: large record {}, file chunk xfer",
+ rec_size
+ );
// lets try to parse the RPC record. Might fail with Incomplete.
match parse_rpc(cur_i, false) {
}
/// Parsing function, handling TCP chunks fragmentation
- pub fn parse_tcp_data_ts(&mut self, flow: *const Flow, stream_slice: &StreamSlice) -> AppLayerResult {
+ pub fn parse_tcp_data_ts(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice,
+ ) -> AppLayerResult {
let mut cur_i = stream_slice.as_slice();
// take care of in progress file chunk transfers
// and skip buffer beyond it
SCLogDebug!("expected data found");
self.ts_gap = false;
break;
- },
+ }
0 => {
SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.",
cur_i.len(), _cnt);
- return AppLayerResult::incomplete(stream_slice.len() - cur_i.len() as u32, (cur_i.len() + 1) as u32);
- },
+ return AppLayerResult::incomplete(
+ stream_slice.len() - cur_i.len() as u32,
+ (cur_i.len() + 1) as u32,
+ );
+ }
-1 => {
cur_i = &cur_i[1..];
if cur_i.is_empty() {
- 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
+ );
}
- },
+ }
_ => {
return AppLayerResult::err();
- },
+ }
}
}
SCLogDebug!("TS GAP handling done (input {})", cur_i.len());
}
- while !cur_i.is_empty() { // min record size
+ while !cur_i.is_empty() {
+ // min record size
self.add_rpc_tcp_ts_pdu(flow, stream_slice, cur_i, cur_i.len() as i64);
match parse_rpc_request_partial(cur_i) {
Ok((_, ref rpc_phdr)) => {
// Handle partial records
if rec_size > cur_i.len() {
- return self.parse_tcp_partial_data_ts(stream_slice.as_slice(), cur_i, rpc_phdr, rec_size);
+ return self.parse_tcp_partial_data_ts(
+ stream_slice.as_slice(),
+ cur_i,
+ rpc_phdr,
+ rec_size,
+ );
}
// we have the full records size worth of data,
// go to the next record.
match parse_rpc(cur_i, true) {
Ok((_, ref rpc_record)) => {
- self.add_rpc_tcp_ts_creds(flow, stream_slice, &cur_i[RPC_TCP_PRE_CREDS..], (rpc_record.creds_len + 8) as i64);
+ self.add_rpc_tcp_ts_creds(
+ flow,
+ stream_slice,
+ &cur_i[RPC_TCP_PRE_CREDS..],
+ (rpc_record.creds_len + 8) as i64,
+ );
self.process_request_record(flow, stream_slice, rpc_record);
}
Err(Err::Incomplete(_)) => {
self.set_event(NFSEvent::MalformedData);
}
- Err(Err::Error(_e)) |
- Err(Err::Failure(_e)) => {
+ Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
SCLogDebug!("Parsing failed: {:?}", _e);
}
// looks for.
let n = usize::from(n);
let need = if n > 28 { n } else { 28 };
- return AppLayerResult::incomplete(stream_slice.len() - cur_i.len() as u32, need as u32);
+ return AppLayerResult::incomplete(
+ stream_slice.len() - cur_i.len() as u32,
+ need as u32,
+ );
}
return AppLayerResult::err();
}
/* This error is fatal. If we failed to parse the RPC hdr we don't
* have a length and we don't know where the next record starts. */
- Err(Err::Error(_e)) |
- Err(Err::Failure(_e)) => {
+ Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
SCLogDebug!("Parsing failed: {:?}", _e);
return AppLayerResult::err();
}
}
- };
+ }
self.post_gap_housekeeping(Direction::ToServer);
if self.check_post_gap_file_txs && !self.post_gap_files_checked {
}
/// Handle partial records
- fn parse_tcp_partial_data_tc<'b>(&mut self, base_input: &'b[u8], cur_i: &'b[u8],
- phdr: &RpcPacketHeader, rec_size: usize) -> AppLayerResult {
+ fn parse_tcp_partial_data_tc<'b>(
+ &mut self, base_input: &'b [u8], cur_i: &'b [u8], phdr: &RpcPacketHeader, rec_size: usize,
+ ) -> AppLayerResult {
// special case: avoid buffering file read blobs
// as these can be large.
- if rec_size >= 512 && cur_i.len() >= 128 {//36 {
+ if rec_size >= 512 && cur_i.len() >= 128 {
+ //36 {
// large record, likely file xfer
SCLogDebug!("large record {}, likely file xfer", rec_size);
// quick peek, are in READ mode?
if self.peek_reply_record(phdr) == NFSPROC3_READ {
- SCLogDebug!("CONFIRMED large READ record {}, likely file chunk xfer", rec_size);
+ SCLogDebug!(
+ "CONFIRMED large READ record {}, likely file chunk xfer",
+ rec_size
+ );
// we should have enough data to parse the RPC record
match parse_rpc_reply(cur_i, false) {
}
/// Parsing function, handling TCP chunks fragmentation
- pub fn parse_tcp_data_tc(&mut self, flow: *const Flow, stream_slice: &StreamSlice) -> AppLayerResult {
+ pub fn parse_tcp_data_tc(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice,
+ ) -> AppLayerResult {
let mut cur_i = stream_slice.as_slice();
// take care of in progress file chunk transfers
// and skip buffer beyond it
SCLogDebug!("expected data found");
self.tc_gap = false;
break;
- },
+ }
0 => {
SCLogDebug!("incomplete, queue and retry with the next block (input {}). Looped {} times.",
cur_i.len(), _cnt);
- return AppLayerResult::incomplete(stream_slice.len() - cur_i.len() as u32, (cur_i.len() + 1) as u32);
- },
+ return AppLayerResult::incomplete(
+ stream_slice.len() - cur_i.len() as u32,
+ (cur_i.len() + 1) as u32,
+ );
+ }
-1 => {
cur_i = &cur_i[1..];
if cur_i.is_empty() {
- 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
+ );
}
- },
+ }
_ => {
return AppLayerResult::err();
}
let rec_size = (rpc_phdr.frag_len + 4) as usize;
// see if we have all data available
if rec_size > cur_i.len() {
- return self.parse_tcp_partial_data_tc(stream_slice.as_slice(), cur_i, rpc_phdr, rec_size);
+ return self.parse_tcp_partial_data_tc(
+ stream_slice.as_slice(),
+ cur_i,
+ rpc_phdr,
+ rec_size,
+ );
}
// we have the full data of the record, lets parse
match parse_rpc_reply(cur_i, true) {
Ok((_, ref rpc_record)) => {
- self.add_rpc_tcp_tc_frames(flow, stream_slice, cur_i, cur_i.len() as i64);
+ self.add_rpc_tcp_tc_frames(
+ flow,
+ stream_slice,
+ cur_i,
+ cur_i.len() as i64,
+ );
self.process_reply_record(flow, stream_slice, rpc_record);
}
Err(Err::Incomplete(_)) => {
// bad.
self.set_event(NFSEvent::MalformedData);
}
- Err(Err::Error(_e)) |
- Err(Err::Failure(_e)) => {
+ Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
SCLogDebug!("Parsing failed: {:?}", _e);
}
// looks for.
let n = usize::from(n);
let need = if n > 12 { n } else { 12 };
- return AppLayerResult::incomplete(stream_slice.len() - cur_i.len() as u32, need as u32);
+ return AppLayerResult::incomplete(
+ stream_slice.len() - cur_i.len() as u32,
+ need as u32,
+ );
}
return AppLayerResult::err();
}
/* This error is fatal. If we failed to parse the RPC hdr we don't
* have a length and we don't know where the next record starts. */
- Err(Err::Error(_e)) |
- Err(Err::Failure(_e)) => {
+ Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
self.set_event(NFSEvent::MalformedData);
SCLogDebug!("Parsing failed: {:?}", _e);
return AppLayerResult::err();
}
}
- };
+ }
self.post_gap_housekeeping(Direction::ToClient);
if self.check_post_gap_file_txs && !self.post_gap_files_checked {
self.post_gap_housekeeping_for_files();
AppLayerResult::ok()
}
/// Parsing function
- pub fn parse_udp_ts(&mut self, flow: *const Flow, stream_slice: &StreamSlice) -> AppLayerResult {
+ pub fn parse_udp_ts(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice,
+ ) -> AppLayerResult {
let input = stream_slice.as_slice();
SCLogDebug!("parse_udp_ts ({})", input.len());
self.add_rpc_udp_ts_pdu(flow, stream_slice, input, input.len() as i64);
match parse_rpc_udp_request(input) {
Ok((_, ref rpc_record)) => {
self.is_udp = true;
- self.add_rpc_udp_ts_creds(flow, stream_slice, &input[RPC_UDP_PRE_CREDS..], (rpc_record.creds_len + 8) as i64);
+ self.add_rpc_udp_ts_creds(
+ flow,
+ stream_slice,
+ &input[RPC_UDP_PRE_CREDS..],
+ (rpc_record.creds_len + 8) as i64,
+ );
match rpc_record.progver {
3 => {
self.process_request_record(flow, stream_slice, rpc_record);
- },
+ }
2 => {
- self.add_nfs_ts_frame(flow, stream_slice, rpc_record.prog_data, rpc_record.prog_data_size as i64);
+ self.add_nfs_ts_frame(
+ flow,
+ stream_slice,
+ rpc_record.prog_data,
+ rpc_record.prog_data_size as i64,
+ );
self.process_request_record_v2(rpc_record);
- },
- _ => { },
+ }
+ _ => {}
}
- },
- Err(Err::Incomplete(_)) => {
- },
- Err(Err::Error(_e)) |
- Err(Err::Failure(_e)) => {
+ }
+ Err(Err::Incomplete(_)) => {}
+ Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
SCLogDebug!("Parsing failed: {:?}", _e);
}
}
}
/// Parsing function
- pub fn parse_udp_tc(&mut self, flow: *const Flow, stream_slice: &StreamSlice) -> AppLayerResult {
+ pub fn parse_udp_tc(
+ &mut self, flow: *const Flow, stream_slice: &StreamSlice,
+ ) -> AppLayerResult {
let input = stream_slice.as_slice();
SCLogDebug!("parse_udp_tc ({})", input.len());
self.add_rpc_udp_tc_pdu(flow, stream_slice, input, input.len() as i64);
self.is_udp = true;
self.add_rpc_udp_tc_frames(flow, stream_slice, input, input.len() as i64);
self.process_reply_record(flow, stream_slice, rpc_record);
- },
- Err(Err::Incomplete(_)) => {
- },
- Err(Err::Error(_e)) |
- Err(Err::Failure(_e)) => {
+ }
+ Err(Err::Incomplete(_)) => {}
+ Err(Err::Error(_e)) | Err(Err::Failure(_e)) => {
SCLogDebug!("Parsing failed: {:?}", _e);
}
}
}
/// Returns *mut NFSState
-extern "C" fn 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");
}
/// C binding parse a NFS TCP request. Returns 1 on success, -1 on failure.
-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,
- _data: *const std::os::raw::c_void,
- ) -> AppLayerResult
-{
+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, _data: *const std::os::raw::c_void,
+) -> AppLayerResult {
let state = cast_pointer!(state, NFSState);
let flow = cast_pointer!(flow, Flow);
state.parse_tcp_data_ts(flow, &stream_slice)
}
-extern "C" fn nfs_parse_request_tcp_gap(
- state: &mut NFSState,
- input_len: u32)
- -> AppLayerResult
-{
+extern "C" fn nfs_parse_request_tcp_gap(state: &mut NFSState, input_len: u32) -> AppLayerResult {
state.parse_tcp_data_ts_gap(input_len)
}
-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,
- _data: *const std::os::raw::c_void,
- ) -> AppLayerResult
-{
+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, _data: *const std::os::raw::c_void,
+) -> AppLayerResult {
let state = cast_pointer!(state, NFSState);
let flow = cast_pointer!(flow, Flow);
state.parse_tcp_data_tc(flow, &stream_slice)
}
-extern "C" fn nfs_parse_response_tcp_gap(
- state: &mut NFSState,
- input_len: u32)
- -> AppLayerResult
-{
+extern "C" fn nfs_parse_response_tcp_gap(state: &mut NFSState, input_len: u32) -> AppLayerResult {
state.parse_tcp_data_tc_gap(input_len)
}
/// C binding to parse an NFS/UDP request. Returns 1 on success, -1 on failure.
-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,
- _data: *const std::os::raw::c_void,
- ) -> AppLayerResult
-{
+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, _data: *const std::os::raw::c_void,
+) -> AppLayerResult {
let state = cast_pointer!(state, NFSState);
SCLogDebug!("parsing {} bytes of request data", stream_slice.len());
state.parse_udp_ts(f, &stream_slice)
}
-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,
- _data: *const std::os::raw::c_void,
- ) -> AppLayerResult
-{
+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, _data: *const std::os::raw::c_void,
+) -> AppLayerResult {
let state = cast_pointer!(state, NFSState);
SCLogDebug!("parsing {} bytes of response data", stream_slice.len());
state.parse_udp_tc(f, &stream_slice)
}
-pub unsafe extern "C" fn nfs_state_get_tx_count(state: *mut std::os::raw::c_void)
- -> u64
-{
+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!("nfs_state_get_tx_count: returning {}", state.tx_id);
return state.tx_id;
}
-unsafe extern "C" fn nfs_state_get_tx(state: *mut std::os::raw::c_void,
- tx_id: u64)
- -> *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 {
let state = cast_pointer!(state, NFSState);
match state.get_tx_by_id(tx_id) {
Some(tx) => {
}
}
-unsafe extern "C" fn nfs_state_tx_free(state: *mut std::os::raw::c_void,
- tx_id: u64)
-{
+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);
}
-unsafe extern "C" fn nfs_tx_get_alstate_progress(tx: *mut std::os::raw::c_void,
- direction: u8)
- -> std::os::raw::c_int
-{
+unsafe extern "C" fn nfs_tx_get_alstate_progress(
+ tx: *mut std::os::raw::c_void, direction: u8,
+) -> std::os::raw::c_int {
let tx = cast_pointer!(tx, NFSTransaction);
if direction == u8::from(Direction::ToServer) && tx.request_done {
SCLogDebug!("TOSERVER progress 1");
}
}
-unsafe extern "C" fn nfs_get_tx_data(
- tx: *mut std::os::raw::c_void)
- -> *mut AppLayerTxData
-{
+unsafe extern "C" fn nfs_get_tx_data(tx: *mut std::os::raw::c_void) -> *mut AppLayerTxData {
let tx = cast_pointer!(tx, NFSTransaction);
return &mut tx.tx_data;
}
/// otherwise get procs from the 'file_additional_procs'.
/// Keep calling until 0 is returned.
#[no_mangle]
-pub unsafe extern "C" fn SCNfsTxGetProcedures(tx: &mut NFSTransaction,
- i: u16,
- procedure: *mut u32)
- -> u8
-{
+pub unsafe extern "C" fn SCNfsTxGetProcedures(
+ tx: &mut NFSTransaction, i: u16, procedure: *mut u32,
+) -> u8 {
if i == 0 {
*procedure = tx.procedure;
return 1;
}
#[no_mangle]
-pub unsafe extern "C" fn SCNfsTxGetVersion(tx: &mut NFSTransaction,
- version: *mut u32)
-{
+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 SCNfsInit(context: &'static mut SuricataFileContext)
-{
+pub unsafe extern "C" fn SCNfsInit(context: &'static mut SuricataFileContext) {
SURICATA_NFS_FILE_CONFIG = Some(context);
}
};
unsafe { *rdir = dir as u8 };
return 1;
- },
+ }
Err(Err::Incomplete(_)) => {
return 0;
- },
+ }
Err(_) => {
return -1;
- },
+ }
}
}
if direction == Direction::ToClient {
match parse_rpc_reply(i, false) {
Ok((_, ref rpc)) => {
- if rpc.hdr.frag_len >= 24 && rpc.hdr.frag_len <= 35000 && rpc.hdr.msgtype == 1 && rpc.reply_state == 0 && rpc.accept_state == 0 {
- SCLogDebug!("TC PROBE LEN {} XID {} TYPE {}", rpc.hdr.frag_len, rpc.hdr.xid, rpc.hdr.msgtype);
+ if rpc.hdr.frag_len >= 24
+ && rpc.hdr.frag_len <= 35000
+ && rpc.hdr.msgtype == 1
+ && rpc.reply_state == 0
+ && rpc.accept_state == 0
+ {
+ SCLogDebug!(
+ "TC PROBE LEN {} XID {} TYPE {}",
+ rpc.hdr.frag_len,
+ rpc.hdr.xid,
+ rpc.hdr.msgtype
+ );
return 1;
} else {
return -1;
}
- },
- Err(Err::Incomplete(_)) => {
- match parse_rpc_packet_header (i) {
- Ok((_, ref rpc_hdr)) => {
- if rpc_hdr.frag_len >= 24 && rpc_hdr.frag_len <= 35000 && rpc_hdr.xid != 0 && rpc_hdr.msgtype == 1 {
- SCLogDebug!("TC PROBE LEN {} XID {} TYPE {}", rpc_hdr.frag_len, rpc_hdr.xid, rpc_hdr.msgtype);
- return 1;
- } else {
- return -1;
- }
- },
- Err(Err::Incomplete(_)) => {
- return 0;
- },
- Err(_) => {
+ }
+ Err(Err::Incomplete(_)) => match parse_rpc_packet_header(i) {
+ Ok((_, ref rpc_hdr)) => {
+ if rpc_hdr.frag_len >= 24
+ && rpc_hdr.frag_len <= 35000
+ && rpc_hdr.xid != 0
+ && rpc_hdr.msgtype == 1
+ {
+ SCLogDebug!(
+ "TC PROBE LEN {} XID {} TYPE {}",
+ rpc_hdr.frag_len,
+ rpc_hdr.xid,
+ rpc_hdr.msgtype
+ );
+ return 1;
+ } else {
return -1;
- },
+ }
+ }
+ Err(Err::Incomplete(_)) => {
+ return 0;
+ }
+ Err(_) => {
+ return -1;
}
},
Err(_) => {
return -1;
- },
+ }
}
} else {
match parse_rpc(i, false) {
Ok((_, ref rpc)) => {
- if rpc.hdr.frag_len >= 40 && rpc.hdr.msgtype == 0 &&
- rpc.rpcver == 2 && (rpc.progver == 3 || rpc.progver == 4) &&
- rpc.program == 100003 &&
- rpc.procedure <= NFSPROC3_COMMIT
+ if rpc.hdr.frag_len >= 40
+ && rpc.hdr.msgtype == 0
+ && rpc.rpcver == 2
+ && (rpc.progver == 3 || rpc.progver == 4)
+ && rpc.program == 100003
+ && rpc.procedure <= NFSPROC3_COMMIT
{
return rpc_auth_type_known(rpc.creds_flavor) as i32;
} else {
return -1;
}
- },
+ }
Err(Err::Incomplete(_)) => {
return 0;
- },
+ }
Err(_) => {
return -1;
- },
+ }
}
}
}
if direction == Direction::ToClient {
match parse_rpc_udp_reply(i) {
Ok((_, ref rpc)) => {
- if i.len() >= 32 && rpc.hdr.msgtype == 1 && rpc.reply_state == 0 && rpc.accept_state == 0 {
- SCLogDebug!("TC PROBE LEN {} XID {} TYPE {}", rpc.hdr.frag_len, rpc.hdr.xid, rpc.hdr.msgtype);
+ if i.len() >= 32
+ && rpc.hdr.msgtype == 1
+ && rpc.reply_state == 0
+ && rpc.accept_state == 0
+ {
+ SCLogDebug!(
+ "TC PROBE LEN {} XID {} TYPE {}",
+ rpc.hdr.frag_len,
+ rpc.hdr.xid,
+ rpc.hdr.msgtype
+ );
return 1;
} else {
return -1;
}
- },
+ }
Err(_) => {
return -1;
- },
+ }
}
} else {
match parse_rpc_udp_request(i) {
Ok((_, ref rpc)) => {
- if i.len() >= 48 && rpc.hdr.msgtype == 0 && rpc.progver == 3 && rpc.program == 100003 {
+ if i.len() >= 48
+ && rpc.hdr.msgtype == 0
+ && rpc.progver == 3
+ && rpc.program == 100003
+ {
return 1;
- } else if i.len() >= 48 && rpc.hdr.msgtype == 0 && rpc.progver == 2 && rpc.program == 100003 {
+ } else if i.len() >= 48
+ && rpc.hdr.msgtype == 0
+ && rpc.progver == 2
+ && rpc.program == 100003
+ {
SCLogDebug!("NFSv2!");
return 1;
} else {
return -1;
}
- },
+ }
Err(_) => {
return -1;
- },
+ }
}
}
}
/// MIDSTREAM
unsafe extern "C" fn nfs_probe_ms(
- _flow: *const Flow,
- direction: u8, input: *const u8,
- len: u32, rdir: *mut u8) -> AppProto
-{
+ _flow: *const Flow, direction: u8, input: *const u8, len: u32, rdir: *mut u8,
+) -> AppProto {
if input.is_null() {
return ALPROTO_UNKNOWN;
}
let slice: &[u8] = build_slice!(input, len as usize);
SCLogDebug!("nfs_probe_ms: probing direction {:02x}", direction);
- let mut adirection : u8 = 0;
+ let mut adirection: u8 = 0;
match nfs_probe_dir(slice, &mut adirection) {
1 => {
if adirection == u8::from(Direction::ToServer) {
}
match nfs_probe(slice, adirection.into()) {
1 => {
- SCLogDebug!("nfs_probe success: dir {:02x} adir {:02x}", direction, adirection);
+ SCLogDebug!(
+ "nfs_probe success: dir {:02x} adir {:02x}",
+ direction,
+ adirection
+ );
if (direction & DIR_BOTH) != adirection {
*rdir = adirection;
}
ALPROTO_NFS
- },
- 0 => { ALPROTO_UNKNOWN },
- _ => { ALPROTO_FAILED },
+ }
+ 0 => ALPROTO_UNKNOWN,
+ _ => ALPROTO_FAILED,
}
- },
- 0 => {
- ALPROTO_UNKNOWN
- },
- _ => {
- ALPROTO_FAILED
}
+ 0 => ALPROTO_UNKNOWN,
+ _ => ALPROTO_FAILED,
}
}
-unsafe extern "C" fn ffi_nfs_probe(_f: *const Flow,
- direction: u8,
- input: *const u8,
- len: u32,
- _rdir: *mut u8)
- -> AppProto
-{
+unsafe extern "C" fn ffi_nfs_probe(
+ _f: *const Flow, direction: u8, input: *const u8, len: u32, _rdir: *mut u8,
+) -> AppProto {
if input.is_null() {
return ALPROTO_UNKNOWN;
}
let slice: &[u8] = build_slice!(input, len as usize);
SCLogDebug!("ffi_nfs_probe: running probe");
match nfs_probe(slice, direction.into()) {
- 1 => { ALPROTO_NFS },
- -1 => { ALPROTO_FAILED },
- _ => { ALPROTO_UNKNOWN },
+ 1 => ALPROTO_NFS,
+ -1 => ALPROTO_FAILED,
+ _ => ALPROTO_UNKNOWN,
}
}
/// TOSERVER probe function
-unsafe extern "C" fn nfs_probe_udp_ts(_f: *const Flow,
- _direction: u8,
- input: *const u8,
- len: u32,
- _rdir: *mut u8)
- -> AppProto
-{
+unsafe extern "C" fn nfs_probe_udp_ts(
+ _f: *const Flow, _direction: u8, input: *const u8, len: u32, _rdir: *mut u8,
+) -> AppProto {
if input.is_null() {
return ALPROTO_UNKNOWN;
}
let slice: &[u8] = build_slice!(input, len as usize);
match nfs_probe_udp(slice, Direction::ToServer) {
- 1 => { ALPROTO_NFS },
- -1 => { ALPROTO_FAILED },
- _ => { ALPROTO_UNKNOWN },
+ 1 => ALPROTO_NFS,
+ -1 => ALPROTO_FAILED,
+ _ => ALPROTO_UNKNOWN,
}
}
/// TOCLIENT probe function
-unsafe extern "C" fn nfs_probe_udp_tc(_f: *const Flow,
- _direction: u8,
- input: *const u8,
- len: u32,
- _rdir: *mut u8)
- -> AppProto
-{
+unsafe extern "C" fn nfs_probe_udp_tc(
+ _f: *const Flow, _direction: u8, input: *const u8, len: u32, _rdir: *mut u8,
+) -> AppProto {
if input.is_null() {
return ALPROTO_UNKNOWN;
}
let slice: &[u8] = build_slice!(input, len as usize);
match nfs_probe_udp(slice, Direction::ToClient) {
- 1 => { ALPROTO_NFS },
- -1 => { ALPROTO_FAILED },
- _ => { ALPROTO_UNKNOWN },
+ 1 => ALPROTO_NFS,
+ -1 => ALPROTO_FAILED,
+ _ => ALPROTO_UNKNOWN,
}
}
tx_comp_st_tc: 1,
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),
+ get_eventinfo_byid: Some(NFSEvent::get_event_info_by_id),
localstorage_new: None,
localstorage_free: None,
get_tx_files: Some(nfs_gettxfiles),
let ip_proto_str = CString::new("tcp").unwrap();
- if AppLayerProtoDetectConfProtoDetectionEnabled(
- ip_proto_str.as_ptr(),
- parser.name,
- ) != 0
- {
+ if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
let alproto = AppLayerRegisterProtocolDetection(&parser, 1);
ALPROTO_NFS = alproto;
let midstream = conf_get_bool("stream.midstream");
if midstream {
- if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_TCP,
- parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN,
- nfs_probe_ms, nfs_probe_ms) == 0 {
+ if AppLayerProtoDetectPPParseConfPorts(
+ ip_proto_str.as_ptr(),
+ IPPROTO_TCP,
+ parser.name,
+ ALPROTO_NFS,
+ 0,
+ NFS_MIN_FRAME_LEN,
+ 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(),
- nfs_probe_ms, nfs_probe_ms);
+ AppLayerProtoDetectPPRegister(
+ IPPROTO_TCP,
+ default_port.as_ptr(),
+ ALPROTO_NFS,
+ 0,
+ NFS_MIN_FRAME_LEN,
+ Direction::ToServer.into(),
+ nfs_probe_ms,
+ nfs_probe_ms,
+ );
}
} else {
- AppLayerProtoDetectPPRegister(IPPROTO_TCP,
- default_port.as_ptr(), ALPROTO_NFS, 0,
- NFS_MIN_FRAME_LEN, Direction::ToServer.into(),
- ffi_nfs_probe, ffi_nfs_probe);
- }
- if AppLayerParserConfParserEnabled(
- ip_proto_str.as_ptr(),
- parser.name,
- ) != 0
- {
+ AppLayerProtoDetectPPRegister(
+ IPPROTO_TCP,
+ default_port.as_ptr(),
+ ALPROTO_NFS,
+ 0,
+ NFS_MIN_FRAME_LEN,
+ Direction::ToServer.into(),
+ ffi_nfs_probe,
+ ffi_nfs_probe,
+ );
+ }
+ if AppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
let _ = AppLayerRegisterParser(&parser, alproto);
}
SCLogDebug!("Rust nfs parser registered.");
tx_comp_st_tc: 1,
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),
+ get_eventinfo_byid: Some(NFSEvent::get_event_info_by_id),
localstorage_new: None,
localstorage_free: None,
get_tx_files: Some(nfs_gettxfiles),
let ip_proto_str = CString::new("udp").unwrap();
- if AppLayerProtoDetectConfProtoDetectionEnabled(
- ip_proto_str.as_ptr(),
- parser.name,
- ) != 0
- {
+ if AppLayerProtoDetectConfProtoDetectionEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
let alproto = AppLayerRegisterProtocolDetection(&parser, 1);
ALPROTO_NFS = alproto;
- if AppLayerProtoDetectPPParseConfPorts(ip_proto_str.as_ptr(), IPPROTO_UDP,
- parser.name, ALPROTO_NFS, 0, NFS_MIN_FRAME_LEN,
- 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(),
- nfs_probe_udp_ts, nfs_probe_udp_tc);
- }
- if AppLayerParserConfParserEnabled(
+ if AppLayerProtoDetectPPParseConfPorts(
ip_proto_str.as_ptr(),
+ IPPROTO_UDP,
parser.name,
- ) != 0
+ ALPROTO_NFS,
+ 0,
+ NFS_MIN_FRAME_LEN,
+ 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(),
+ nfs_probe_udp_ts,
+ nfs_probe_udp_tc,
+ );
+ }
+ if AppLayerParserConfParserEnabled(ip_proto_str.as_ptr(), parser.name) != 0 {
let _ = AppLayerRegisterParser(&parser, alproto);
}
if let Some(val) = conf_get("app-layer.protocols.nfs.max-tx") {
// written by Victor Julien
use crate::nfs::nfs::*;
-use crate::nfs::types::*;
-use crate::nfs::rpc_records::*;
use crate::nfs::nfs2_records::*;
+use crate::nfs::rpc_records::*;
+use crate::nfs::types::*;
-use nom7::IResult;
use nom7::number::streaming::be_u32;
+use nom7::IResult;
impl NFSState {
/// complete request record
pub fn process_request_record_v2(&mut self, r: &RpcPacket) {
- SCLogDebug!("NFSv2: REQUEST {} procedure {} ({}) blob size {}",
- r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
+ SCLogDebug!(
+ "NFSv2: REQUEST {} procedure {} ({}) blob size {}",
+ r.hdr.xid,
+ r.procedure,
+ self.requestmap.len(),
+ r.prog_data.len()
+ );
let mut xidmap = NFSRequestXidMap::new(r.progver, r.procedure, 0);
let aux_file_name = Vec::new();
Ok((_, ar)) => {
xidmap.file_handle = ar.handle.value.to_vec();
self.xidmap_handle2name(&mut xidmap);
- },
+ }
_ => {
self.set_event(NFSEvent::MalformedData);
- },
+ }
};
} else if r.procedure == NFSPROC3_READ {
match parse_nfs2_request_read(r.prog_data) {
xidmap.chunk_offset = read_record.offset as u64;
xidmap.file_handle = read_record.handle.value.to_vec();
self.xidmap_handle2name(&mut xidmap);
- },
+ }
_ => {
self.set_event(NFSEvent::MalformedData);
- },
+ }
};
}
if !(r.procedure == NFSPROC3_COMMIT || // commit handled separately
r.procedure == NFSPROC3_WRITE || // write handled in file tx
- r.procedure == NFSPROC3_READ) // read handled in file tx at reply
+ r.procedure == NFSPROC3_READ)
+ // read handled in file tx at reply
{
let mut tx = self.new_tx();
tx.xid = r.hdr.xid;
tx.request_machine_name = u.machine_name_buf.to_vec();
tx.request_uid = u.uid;
tx.request_gid = u.gid;
- },
- _ => { },
+ }
+ _ => {}
}
- SCLogDebug!("NFSv2: TX created: ID {} XID {} PROCEDURE {}",
- tx.id, tx.xid, tx.procedure);
+ SCLogDebug!(
+ "NFSv2: TX created: ID {} XID {} PROCEDURE {}",
+ tx.id,
+ tx.xid,
+ tx.procedure
+ );
self.transactions.push(tx);
}
SCLogDebug!("NFSv2: READ reply record");
self.process_read_record(r, reply, Some(xidmap));
nfs_status = reply.status;
- },
+ }
_ => {
self.set_event(NFSEvent::MalformedData);
- },
+ }
}
} else {
- let stat : u32 = match be_u32(r.prog_data) as IResult<&[u8],_> {
+ let stat: u32 = match be_u32(r.prog_data) as IResult<&[u8], _> {
Ok((_, stat)) => stat,
- _ => 0
+ _ => 0,
};
nfs_status = stat;
}
- SCLogDebug!("NFSv2: REPLY {} to procedure {} blob size {}",
- r.hdr.xid, xidmap.procedure, r.prog_data.len());
+ SCLogDebug!(
+ "NFSv2: REPLY {} to procedure {} blob size {}",
+ r.hdr.xid,
+ xidmap.procedure,
+ r.prog_data.len()
+ );
self.mark_response_tx_done(r.hdr.xid, r.reply_state, nfs_status, &resp_handle);
}
use crate::nfs::nfs_records::*;
use nom7::bytes::streaming::take;
-use nom7::combinator::{rest, cond};
+use nom7::combinator::{cond, rest};
use nom7::number::streaming::be_u32;
use nom7::IResult;
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs2Handle<'a> {
- pub value: &'a[u8],
+ pub value: &'a [u8],
}
pub fn parse_nfs2_handle(i: &[u8]) -> IResult<&[u8], Nfs2Handle> {
Ok((i, Nfs2Handle { value }))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs2RequestLookup<'a> {
pub handle: Nfs2Handle<'a>,
pub name_vec: Vec<u8>,
Ok((i, req))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs2RequestRead<'a> {
pub handle: Nfs2Handle<'a>,
pub offset: u32,
Ok((i, reply))
}
-#[derive(Debug,PartialEq, Eq)]
-pub struct Nfs2Attributes<> {
+#[derive(Debug, PartialEq, Eq)]
+pub struct Nfs2Attributes {
pub atype: u32,
pub asize: u32,
}
use crate::direction::Direction;
use crate::nfs::nfs::*;
-use crate::nfs::types::*;
-use crate::nfs::rpc_records::*;
use crate::nfs::nfs3_records::*;
+use crate::nfs::rpc_records::*;
+use crate::nfs::types::*;
-use nom7::IResult;
use nom7::number::streaming::be_u32;
+use nom7::IResult;
impl NFSState {
/// complete NFS3 request record
pub fn process_request_record_v3(&mut self, r: &RpcPacket) {
- SCLogDebug!("REQUEST {} procedure {} ({}) blob size {}",
- r.hdr.xid, r.procedure, self.requestmap.len(), r.prog_data.len());
+ SCLogDebug!(
+ "REQUEST {} procedure {} ({}) blob size {}",
+ r.hdr.xid,
+ r.procedure,
+ self.requestmap.len(),
+ r.prog_data.len()
+ );
let mut xidmap = NFSRequestXidMap::new(r.progver, r.procedure, 0);
let mut aux_file_name = Vec::new();
if r.procedure == NFSPROC3_LOOKUP {
self.process_request_record_lookup(r, &mut xidmap);
-
} else if r.procedure == NFSPROC3_ACCESS {
if let Ok((_, rd)) = parse_nfs3_request_access(r.prog_data) {
xidmap.file_handle = rd.handle.value.to_vec();
if !(r.procedure == NFSPROC3_COMMIT || // commit handled separately
r.procedure == NFSPROC3_WRITE || // write handled in file tx
- r.procedure == NFSPROC3_READ) // read handled in file tx at reply
+ r.procedure == NFSPROC3_READ)
+ // read handled in file tx at reply
{
let mut tx = self.new_tx();
tx.xid = r.hdr.xid;
tx.request_machine_name = u.machine_name_buf.to_vec();
tx.request_uid = u.uid;
tx.request_gid = u.gid;
- },
- _ => { },
+ }
+ _ => {}
}
- SCLogDebug!("TX created: ID {} XID {} PROCEDURE {}",
- tx.id, tx.xid, tx.procedure);
+ SCLogDebug!(
+ "TX created: ID {} XID {} PROCEDURE {}",
+ tx.id,
+ tx.xid,
+ tx.procedure
+ );
self.transactions.push(tx);
-
} else if r.procedure == NFSPROC3_READ {
-
- let found = self.get_file_tx_by_handle(&xidmap.file_handle, Direction::ToClient).is_some();
+ let found = self
+ .get_file_tx_by_handle(&xidmap.file_handle, Direction::ToClient)
+ .is_some();
if !found {
- let tx = self.new_file_tx(&xidmap.file_handle, &xidmap.file_name, Direction::ToClient);
+ let tx =
+ self.new_file_tx(&xidmap.file_handle, &xidmap.file_name, Direction::ToClient);
tx.procedure = NFSPROC3_READ;
tx.xid = r.hdr.xid;
tx.is_first = true;
nfs_status = rd.status;
SCLogDebug!("LOOKUP handle {:?}", rd.handle);
- self.namemap.insert(rd.handle.value.to_vec(), xidmap.file_name.to_vec());
+ self.namemap
+ .insert(rd.handle.value.to_vec(), xidmap.file_name.to_vec());
resp_handle = rd.handle.value.to_vec();
} else {
self.set_event(NFSEvent::MalformedData);
if let Some(h) = rd.handle {
SCLogDebug!("handle {:?}", h);
- self.namemap.insert(h.value.to_vec(), xidmap.file_name.to_vec());
+ self.namemap
+ .insert(h.value.to_vec(), xidmap.file_name.to_vec());
resp_handle = h.value.to_vec();
}
} else {
// cut off final eof field
let d = if rd.data.len() >= 4 {
- &rd.data[..rd.data.len()-4_usize]
+ &rd.data[..rd.data.len() - 4_usize]
} else {
rd.data
};
SCLogDebug!("e {:?}", e);
if let Some(ref h) = e.handle {
SCLogDebug!("h {:?}", h);
- self.namemap.insert(h.value.to_vec(),
- e.name_vec.to_vec());
+ self.namemap.insert(h.value.to_vec(), e.name_vec.to_vec());
}
}
}
}
// for all other record types only parse the status
else {
- let stat : u32 = match be_u32(r.prog_data) as IResult<&[u8],_> {
+ let stat: u32 = match be_u32(r.prog_data) as IResult<&[u8], _> {
Ok((_, stat)) => stat,
- _ => 0
+ _ => 0,
};
nfs_status = stat;
}
- SCLogDebug!("REPLY {} to procedure {} blob size {}",
- r.hdr.xid, xidmap.procedure, r.prog_data.len());
+ SCLogDebug!(
+ "REPLY {} to procedure {} blob size {}",
+ r.hdr.xid,
+ xidmap.procedure,
+ r.prog_data.len()
+ );
if xidmap.procedure != NFSPROC3_READ {
self.mark_response_tx_done(r.hdr.xid, r.reply_state, nfs_status, &resp_handle);
//! Nom parsers for RPC & NFSv3
-use std::cmp;
use crate::nfs::nfs_records::*;
use nom7::bytes::streaming::take;
use nom7::combinator::{complete, cond, rest, verify};
use nom7::multi::{length_data, many0};
use nom7::number::streaming::{be_u32, be_u64};
use nom7::IResult;
+use std::cmp;
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs3Handle<'a> {
many0(complete(parse_nfs3_response_readdirplus_entry_cond))(input)
}
-
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs3RequestReaddirplus<'a> {
pub handle: Nfs3Handle<'a>,
let (i, count) = be_u32(i)?;
let (i, stable) = verify(be_u32, |&v| v <= 2)(i)?;
let (i, file_len) = verify(be_u32, |&v| v <= count)(i)?;
- let fill_bytes = if file_len % 4 != 0 { 4 - file_len % 4 } else { 0 };
+ let fill_bytes = if file_len % 4 != 0 {
+ 4 - file_len % 4
+ } else {
+ 0
+ };
// Handle the various file data parsing logics
let (i, file_data) = if complete {
parse_nfs3_data_complete(i, file_len as usize, fill_bytes as usize)?
let (i, count) = be_u32(i)?;
let (i, eof) = verify(be_u32, |&v| v <= 1)(i)?;
let (i, data_len) = verify(be_u32, |&v| v <= count)(i)?;
- let fill_bytes = if data_len % 4 != 0 { 4 - data_len % 4 } else { 0 };
+ let fill_bytes = if data_len % 4 != 0 {
+ 4 - data_len % 4
+ } else {
+ 0
+ };
// Handle the various file data parsing logics
let (i, data) = if complete {
parse_nfs3_data_complete(i, data_len as usize, fill_bytes as usize)?
#[test]
fn test_nfs3_request_access() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x20, /*handle_len: (32)*/
#[test]
fn test_nfs3_request_commit() {
-
// packet_bytes -- used [READ Call] message digest
#[rustfmt::skip]
let buf: &[u8] = &[
#[test]
fn test_nfs3_request_read() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x20, /*handle_len: (32)*/
#[test]
fn test_nfs3_request_lookup() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
// [handle]
#[test]
fn test_nfs3_response_readdirplus() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x00, /*status*/
let (r, entries) = many0_nfs3_response_readdirplus_entries(data_buf).unwrap();
assert_eq!(r.len(), 4);
- assert_eq!(entries[0], Nfs3ResponseReaddirplusEntry { entry: Some(entry0) });
- assert_eq!(entries[1], Nfs3ResponseReaddirplusEntry { entry: Some(entry1) });
+ assert_eq!(
+ entries[0],
+ Nfs3ResponseReaddirplusEntry {
+ entry: Some(entry0)
+ }
+ );
+ assert_eq!(
+ entries[1],
+ Nfs3ResponseReaddirplusEntry {
+ entry: Some(entry1)
+ }
+ );
}
#[test]
fn test_nfs3_response_readdirplus_entry() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x01, /*value_follows*/
let (_, response) = parse_nfs3_response_readdirplus_entry_cond(buf).unwrap();
match response {
- Nfs3ResponseReaddirplusEntry { entry: Some(entry_c) } => {
+ Nfs3ResponseReaddirplusEntry {
+ entry: Some(entry_c),
+ } => {
assert_eq!(entry_c.name_vec, ".".as_bytes());
assert_eq!(entry_c.handle, Some(entry_handle));
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
#[test]
fn test_nfs3_request_readdirplus() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x24, /*handle_len*/
#[test]
fn test_nfs3_request_write() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
// [handle]
#[test]
fn test_nfs3_reply_read() {
-
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x00, /*Status: NFS3_OK (0)*/
let found = match self.get_file_tx_by_handle(&file_handle, Direction::ToServer) {
Some(tx) => {
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
- filetracker_newchunk(&mut tdf.file_tracker,
- &file_name, w.data, w.offset,
- w.write_len, fill_bytes as u8, is_last, &r.hdr.xid);
+ filetracker_newchunk(
+ &mut tdf.file_tracker,
+ &file_name,
+ w.data,
+ w.offset,
+ w.write_len,
+ fill_bytes as u8,
+ is_last,
+ &r.hdr.xid,
+ );
tdf.chunk_count += 1;
if is_last {
tdf.file_last_xid = r.hdr.xid;
if !found {
let tx = self.new_file_tx(&file_handle, &file_name, Direction::ToServer);
if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
- filetracker_newchunk(&mut tdf.file_tracker,
- &file_name, w.data, w.offset,
- w.write_len, fill_bytes as u8, is_last, &r.hdr.xid);
+ filetracker_newchunk(
+ &mut tdf.file_tracker,
+ &file_name,
+ w.data,
+ w.offset,
+ w.write_len,
+ fill_bytes as u8,
+ is_last,
+ &r.hdr.xid,
+ );
tx.procedure = NFSPROC4_WRITE;
tx.xid = r.hdr.xid;
tx.is_first = true;
}
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 - 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]) {
}
fn new_tx_v4(
- &mut self, r: &RpcPacket, xidmap: &NFSRequestXidMap, procedure: u32,
- _aux_opcodes: &[u32],
+ &mut self, r: &RpcPacket, xidmap: &NFSRequestXidMap, procedure: u32, _aux_opcodes: &[u32],
) {
let mut tx = self.new_tx();
tx.xid = r.hdr.xid;
match *c {
Nfs4ResponseContent::ReadDir(_s, Some(ref rd)) => {
SCLogDebug!("READDIRv4: status {} eof {}", _s, rd.eof);
-
+
#[allow(clippy::manual_flatten)]
for d in &rd.listing {
if let Some(_d) = d {
}
}
- pub fn process_reply_record_v4(
- &mut self, r: &RpcReplyPacket, xidmap: &mut NFSRequestXidMap,
- ) {
+ pub fn process_reply_record_v4(&mut self, r: &RpcReplyPacket, xidmap: &mut NFSRequestXidMap) {
if xidmap.procedure == NFSPROC4_COMPOUND {
let mut data = r.prog_data;
//! Nom parsers for NFSv4 records
use nom7::bytes::streaming::{tag, take};
-use nom7::combinator::{complete, cond, map, peek, verify, rest};
+use nom7::combinator::{complete, cond, map, peek, rest, verify};
use nom7::error::{make_error, ErrorKind};
use nom7::multi::{count, many_till};
use nom7::number::streaming::{be_u32, be_u64};
use crate::nfs::types::*;
/*https://datatracker.ietf.org/doc/html/rfc7530 - section 16.16 File Delegation Types */
-const OPEN_DELEGATE_NONE: u32 = 0;
-const OPEN_DELEGATE_READ: u32 = 1;
-const OPEN_DELEGATE_WRITE: u32 = 2;
+const OPEN_DELEGATE_NONE: u32 = 0;
+const OPEN_DELEGATE_READ: u32 = 1;
+const OPEN_DELEGATE_WRITE: u32 = 2;
const RPCSEC_GSS: u32 = 6;
// Linux defines NFSD_MAX_OPS_PER_COMPOUND to 16 (tested in Linux 5.15.1).
const NFSD_MAX_OPS_PER_COMPOUND: usize = 64;
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Nfs4RequestContent<'a> {
PutFH(Nfs4Handle<'a>),
GetFH,
GetAttr(Nfs4Attr),
SetAttr(Nfs4RequestSetAttr<'a>),
Renew(u64),
- Remove(&'a[u8]),
+ Remove(&'a [u8]),
DelegReturn(Nfs4StateId<'a>),
SetClientId(Nfs4RequestSetClientId<'a>),
SetClientIdConfirm,
LayoutGet(Nfs4RequestLayoutGet<'a>),
GetDevInfo(Nfs4RequestGetDevInfo<'a>),
LayoutReturn(Nfs4RequestLayoutReturn<'a>),
- DestroySession(&'a[u8]),
- DestroyClientID(&'a[u8]),
+ DestroySession(&'a [u8]),
+ DestroyClientID(&'a [u8]),
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4Attr {
attr_mask: u64,
}
Ok((i, attr))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4StateId<'a> {
pub seqid: u32,
- pub data: &'a[u8],
+ pub data: &'a [u8],
}
fn nfs4_parse_stateid(i: &[u8]) -> IResult<&[u8], Nfs4StateId> {
Ok((i, state))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4Handle<'a> {
pub len: u32,
- pub value: &'a[u8],
+ pub value: &'a [u8],
}
fn nfs4_parse_handle(i: &[u8]) -> IResult<&[u8], Nfs4Handle> {
pub return_type: u32,
pub length: u64,
pub stateid: Nfs4StateId<'a>,
- pub lrf_data: &'a[u8],
+ pub lrf_data: &'a [u8],
}
fn nfs4_req_layoutreturn(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestGetDevInfo<'a> {
- pub device_id: &'a[u8],
+ pub device_id: &'a [u8],
pub layout_type: u32,
pub maxcount: u32,
pub notify_mask: u32,
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestCreateSession<'a> {
- pub client_id: &'a[u8],
+ pub client_id: &'a [u8],
pub seqid: u32,
- pub machine_name: &'a[u8],
+ pub machine_name: &'a [u8],
}
fn nfs4_req_create_session(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
map(nfs4_parse_handle, Nfs4RequestContent::PutFH)(i)
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestSetClientId<'a> {
- pub client_id: &'a[u8],
- pub r_netid: &'a[u8],
- pub r_addr: &'a[u8],
+ pub client_id: &'a [u8],
+ pub r_netid: &'a [u8],
+ pub r_addr: &'a [u8],
}
fn nfs4_req_setclientid(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
let req = Nfs4RequestContent::SetClientId(Nfs4RequestSetClientId {
client_id,
r_netid,
- r_addr
+ r_addr,
});
Ok((i, req))
}
Ok((i, Nfs4RequestContent::SetClientIdConfirm))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestCreate<'a> {
pub ftype4: u32,
- pub filename: &'a[u8],
- pub link_content: &'a[u8],
+ pub filename: &'a [u8],
+ pub link_content: &'a [u8],
}
fn nfs4_req_create(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
Ok((i, req))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Nfs4OpenRequestContent<'a> {
- Exclusive4(&'a[u8]),
+ Exclusive4(&'a [u8]),
Unchecked4(Nfs4Attr),
Guarded4(Nfs4Attr),
}
0 => nfs4_req_open_unchecked4(i)?,
1 => nfs4_req_open_guarded4(i)?,
2 => nfs4_req_open_exclusive4(i)?,
- _ => { return Err(Err::Error(make_error(i, ErrorKind::Switch))); }
+ _ => {
+ return Err(Err::Error(make_error(i, ErrorKind::Switch)));
+ }
};
Ok((i, data))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestOpen<'a> {
pub open_type: u32,
- pub filename: &'a[u8],
+ pub filename: &'a [u8],
pub open_data: Option<Nfs4OpenRequestContent<'a>>,
}
let req = Nfs4RequestContent::Open(Nfs4RequestOpen {
open_type,
filename,
- open_data
+ open_data,
});
Ok((i, req))
}
Ok((i, Nfs4RequestContent::ReadDir))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestRename<'a> {
- pub oldname: &'a[u8],
- pub newname: &'a[u8],
+ pub oldname: &'a [u8],
+ pub newname: &'a [u8],
}
fn nfs4_req_rename(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
let (i, oldname) = nfs4_parse_nfsstring(i)?;
let (i, newname) = nfs4_parse_nfsstring(i)?;
- let req = Nfs4RequestContent::Rename(Nfs4RequestRename {
- oldname,
- newname
- });
+ let req = Nfs4RequestContent::Rename(Nfs4RequestRename { oldname, newname });
Ok((i, req))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestLookup<'a> {
- pub filename: &'a[u8],
+ pub filename: &'a [u8],
}
fn nfs4_req_destroy_session(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
}
fn nfs4_req_secinfo_no_name(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
- map(be_u32, Nfs4RequestContent::SecInfoNoName) (i)
+ map(be_u32, Nfs4RequestContent::SecInfoNoName)(i)
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestSetAttr<'a> {
pub stateid: Nfs4StateId<'a>,
}
map(nfs4_parse_attrbits, Nfs4RequestContent::GetAttr)(i)
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestWrite<'a> {
pub stateid: Nfs4StateId<'a>,
pub offset: u64,
pub stable: u32,
pub write_len: u32,
- pub data: &'a[u8],
+ pub data: &'a [u8],
}
fn nfs4_req_write(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
Ok((i, req))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestRead<'a> {
pub stateid: Nfs4StateId<'a>,
pub offset: u64,
Ok((i, Nfs4RequestContent::Close(stateid)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestOpenConfirm<'a> {
pub stateid: Nfs4StateId<'a>,
}
fn nfs4_req_open_confirm(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
let (i, _seq_id) = be_u32(i)?;
let (i, stateid) = nfs4_parse_stateid(i)?;
- let req = Nfs4RequestContent::OpenConfirm(Nfs4RequestOpenConfirm {
- stateid
- });
+ let req = Nfs4RequestContent::OpenConfirm(Nfs4RequestOpenConfirm { stateid });
Ok((i, req))
}
}
fn nfs4_req_reclaim_complete(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
- map(verify(be_u32, |&v| v <= 1), Nfs4RequestContent::ReclaimComplete) (i)
+ map(
+ verify(be_u32, |&v| v <= 1),
+ Nfs4RequestContent::ReclaimComplete,
+ )(i)
}
fn nfs4_req_destroy_clientid(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
Ok((i, req))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestExchangeId<'a> {
- pub client_string: &'a[u8],
- pub nii_domain: &'a[u8],
- pub nii_name: &'a[u8],
+ pub client_string: &'a [u8],
+ pub nii_domain: &'a [u8],
+ pub nii_name: &'a [u8],
}
fn nfs4_req_exchangeid(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
let req = Nfs4RequestContent::ExchangeId(Nfs4RequestExchangeId {
client_string: eia_clientstring,
nii_domain,
- nii_name
+ nii_name,
});
Ok((i, req))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestSequence<'a> {
- pub ssn_id: &'a[u8],
+ pub ssn_id: &'a [u8],
}
fn nfs4_req_sequence(i: &[u8]) -> IResult<&[u8], Nfs4RequestContent> {
let (i, _slot_id) = be_u32(i)?;
let (i, _high_slot_id) = be_u32(i)?;
let (i, _cache_this) = be_u32(i)?;
- let req = Nfs4RequestContent::Sequence(Nfs4RequestSequence {
- ssn_id
- });
+ let req = Nfs4RequestContent::Sequence(Nfs4RequestSequence { ssn_id });
Ok((i, req))
}
NFSPROC4_LAYOUTRETURN => nfs4_req_layoutreturn(i)?,
NFSPROC4_DESTROY_SESSION => nfs4_req_destroy_session(i)?,
NFSPROC4_DESTROY_CLIENTID => nfs4_req_destroy_clientid(i)?,
- _ => { return Err(Err::Error(make_error(i, ErrorKind::Switch))); }
+ _ => {
+ return Err(Err::Error(make_error(i, ErrorKind::Switch)));
+ }
};
Ok((i, cmd_data))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4RequestCompoundRecord<'a> {
pub commands: Vec<Nfs4RequestContent<'a>>,
}
Ok((i, Nfs4RequestCompoundRecord { commands }))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub enum Nfs4ResponseContent<'a> {
PutFH(u32),
PutRootFH(u32),
}
// might need improvement with a stateid_present = yes case
-fn nfs4_res_layoutreturn(i:&[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
+fn nfs4_res_layoutreturn(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
let (i, status) = be_u32(i)?;
let (i, _stateid_present) = verify(be_u32, |&v| v <= 1)(i)?;
Ok((i, Nfs4ResponseContent::LayoutReturn(status)))
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseCreateSession<'a> {
- pub ssn_id: &'a[u8],
+ pub ssn_id: &'a [u8],
pub seq_id: u32,
}
let (i, _flags) = be_u32(i)?;
let (i, _fore_chan_attrs) = take(28_usize)(i)?;
let (i, _back_chan_attrs) = take(28_usize)(i)?;
- Ok((i, Nfs4ResponseCreateSession {
- ssn_id,
- seq_id
- }))
+ Ok((i, Nfs4ResponseCreateSession { ssn_id, seq_id }))
}
fn nfs4_res_create_session(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
let (i, status) = be_u32(i)?;
let (i, create_ssn_data) = cond(status == 0, nfs4_parse_res_create_session)(i)?;
- Ok((i, Nfs4ResponseContent::CreateSession( status, create_ssn_data )))
+ Ok((
+ i,
+ Nfs4ResponseContent::CreateSession(status, create_ssn_data),
+ ))
}
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseExchangeId<'a> {
- pub client_id: &'a[u8],
+ pub client_id: &'a [u8],
pub eir_minorid: u64,
- pub eir_majorid: &'a[u8],
- pub nii_domain: &'a[u8],
- pub nii_name: &'a[u8],
+ pub eir_majorid: &'a [u8],
+ pub nii_domain: &'a [u8],
+ pub nii_name: &'a [u8],
}
fn nfs4_parse_res_exchangeid(i: &[u8]) -> IResult<&[u8], Nfs4ResponseExchangeId> {
let (i, nii_name) = nfs4_parse_nfsstring(i)?;
let (i, _nii_date_sec) = be_u64(i)?;
let (i, _nii_date_nsec) = be_u32(i)?;
- Ok((i, Nfs4ResponseExchangeId {
- client_id,
- eir_minorid,
- eir_majorid,
- nii_domain,
- nii_name,
- }))
+ Ok((
+ i,
+ Nfs4ResponseExchangeId {
+ client_id,
+ eir_minorid,
+ eir_majorid,
+ nii_domain,
+ nii_name,
+ },
+ ))
}
fn nfs4_res_reclaim_complete(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
- map(be_u32, Nfs4ResponseContent::ReclaimComplete) (i)
+ map(be_u32, Nfs4ResponseContent::ReclaimComplete)(i)
}
fn nfs4_res_exchangeid(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
let (i, status) = be_u32(i)?;
let (i, xchngid_data) = cond(status == 0, nfs4_parse_res_exchangeid)(i)?;
- Ok((i, Nfs4ResponseContent::ExchangeId( status, xchngid_data)))
+ Ok((i, Nfs4ResponseContent::ExchangeId(status, xchngid_data)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseWrite {
pub count: u32,
pub committed: u32,
Ok((i, Nfs4ResponseContent::Write(status, wd)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseRead<'a> {
pub eof: bool,
pub count: u32,
- pub data: &'a[u8],
+ pub data: &'a [u8],
}
fn nfs4_res_read_ok(i: &[u8]) -> IResult<&[u8], Nfs4ResponseRead> {
let (i, read_len) = be_u32(i)?;
let (i, read_data) = take(read_len as usize)(i)?;
let resp = Nfs4ResponseRead {
- eof: eof==1,
+ eof: eof == 1,
count: read_len,
data: read_data,
};
Ok((i, Nfs4ResponseContent::Read(status, rd)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseOpen<'a> {
pub stateid: Nfs4StateId<'a>,
pub result_flags: u32,
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseOpenDelegateWrite<'a> {
pub stateid: Nfs4StateId<'a>,
- pub who: &'a[u8],
+ pub who: &'a [u8],
}
fn nfs4_res_open_ok_delegate_write(i: &[u8]) -> IResult<&[u8], Nfs4ResponseFileDelegation> {
let (i, _ace_flags) = be_u32(i)?;
let (i, _ace_mask) = be_u32(i)?;
let (i, who) = nfs4_parse_nfsstring(i)?;
- Ok((i, Nfs4ResponseFileDelegation::DelegateWrite(Nfs4ResponseOpenDelegateWrite {
- stateid,
- who,
- })))
+ Ok((
+ i,
+ Nfs4ResponseFileDelegation::DelegateWrite(Nfs4ResponseOpenDelegateWrite { stateid, who }),
+ ))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseOpenDelegateRead<'a> {
pub stateid: Nfs4StateId<'a>,
}
let (i, _ace_mask) = be_u32(i)?;
let (i, who_len) = be_u32(i)?;
let (i, _who) = take(who_len as usize)(i)?;
- Ok((i, Nfs4ResponseFileDelegation::DelegateRead(Nfs4ResponseOpenDelegateRead {
- stateid,
- })))
+ Ok((
+ i,
+ Nfs4ResponseFileDelegation::DelegateRead(Nfs4ResponseOpenDelegateRead { stateid }),
+ ))
}
fn nfs4_parse_file_delegation(i: &[u8]) -> IResult<&[u8], Nfs4ResponseFileDelegation> {
let (i, file_delegation) = match delegation_type {
OPEN_DELEGATE_READ => nfs4_res_open_ok_delegate_read(i)?,
OPEN_DELEGATE_WRITE => nfs4_res_open_ok_delegate_write(i)?,
- OPEN_DELEGATE_NONE => (i, Nfs4ResponseFileDelegation::DelegateNone(OPEN_DELEGATE_NONE)),
- _ => { return Err(Err::Error(make_error(i, ErrorKind::Switch))); }
+ OPEN_DELEGATE_NONE => (
+ i,
+ Nfs4ResponseFileDelegation::DelegateNone(OPEN_DELEGATE_NONE),
+ ),
+ _ => {
+ return Err(Err::Error(make_error(i, ErrorKind::Switch)));
+ }
};
Ok((i, file_delegation))
}
#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseGetDevInfo<'a> {
pub layout_type: u32,
- pub r_netid: &'a[u8],
- pub r_addr: &'a[u8],
+ pub r_netid: &'a [u8],
+ pub r_addr: &'a [u8],
pub notify_mask: u32,
}
let (i, r_netid) = nfs4_parse_nfsstring(i)?;
let (i, r_addr) = nfs4_parse_nfsstring(i)?;
let (i, notify_mask) = be_u32(i)?;
- Ok((i, Nfs4ResponseGetDevInfo {
- layout_type,
- r_netid,
- r_addr,
- notify_mask,
- }))
+ Ok((
+ i,
+ Nfs4ResponseGetDevInfo {
+ layout_type,
+ r_netid,
+ r_addr,
+ notify_mask,
+ },
+ ))
}
fn nfs4_res_getdevinfo(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
let (i, status) = be_u32(i)?;
let (i, getdevinfo) = cond(status == 0, nfs4_parse_res_getdevinfo)(i)?;
- Ok((i, Nfs4ResponseContent::GetDevInfo( status, getdevinfo )))
+ Ok((i, Nfs4ResponseContent::GetDevInfo(status, getdevinfo)))
}
/*https://datatracker.ietf.org/doc/html/rfc5661#section-13.1*/
pub stateid: Nfs4StateId<'a>,
pub length: u64,
pub layout_type: u32,
- pub device_id: &'a[u8],
+ pub device_id: &'a [u8],
pub file_handles: Vec<Nfs4Handle<'a>>,
}
fn nfs4_parse_res_layoutget(i: &[u8]) -> IResult<&[u8], Nfs4ResponseLayoutGet> {
- let (i, _return_on_close) = verify(be_u32, |&v| v <= 1)(i)?;
+ let (i, _return_on_close) = verify(be_u32, |&v| v <= 1)(i)?;
let (i, stateid) = nfs4_parse_stateid(i)?;
let (i, _layout_seg) = be_u32(i)?;
let (i, _offset) = be_u64(i)?;
return Err(Err::Error(make_error(i, ErrorKind::Count)));
}
let (i, file_handles) = count(nfs4_parse_handle, fh_handles as usize)(i)?;
- Ok((i, Nfs4ResponseLayoutGet {
- stateid,
- length,
- layout_type,
- device_id,
- file_handles,
- }))
+ Ok((
+ i,
+ Nfs4ResponseLayoutGet {
+ stateid,
+ length,
+ layout_type,
+ device_id,
+ file_handles,
+ },
+ ))
}
fn nfs4_res_layoutget(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
let (i, status) = be_u32(i)?;
let (i, lyg_data) = cond(status == 0, nfs4_parse_res_layoutget)(i)?;
- Ok((i, Nfs4ResponseContent::LayoutGet( status, lyg_data )))
+ Ok((i, Nfs4ResponseContent::LayoutGet(status, lyg_data)))
}
// #[derive(Debug, PartialEq)]
Ok((i, Nfs4ResponseContent::SecInfoNoName(status)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseReaddirEntry<'a> {
- pub name: &'a[u8],
+ pub name: &'a [u8],
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseReaddir<'a> {
pub eof: bool,
pub listing: Vec<Option<Nfs4ResponseReaddirEntry<'a>>>,
Ok((i, Nfs4ResponseContent::Commit(status)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseAccess {
pub supported_types: u32,
pub access_rights: u32,
let (i, access_rights) = be_u32(i)?;
let resp = Nfs4ResponseAccess {
supported_types,
- access_rights
+ access_rights,
};
Ok((i, resp))
}
Ok((i, Nfs4ResponseContent::Access(status, ad)))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseSequence<'a> {
- pub ssn_id: &'a[u8],
+ pub ssn_id: &'a [u8],
}
fn nfs4_res_sequence_ok(i: &[u8]) -> IResult<&[u8], Nfs4ResponseSequence> {
}
fn nfs4_res_destroy_session(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
- map(be_u32, Nfs4ResponseContent::DestroySession) (i)
+ map(be_u32, Nfs4ResponseContent::DestroySession)(i)
}
fn nfs4_res_destroy_clientid(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
- map(be_u32, Nfs4ResponseContent::DestroyClientID) (i)
+ map(be_u32, Nfs4ResponseContent::DestroyClientID)(i)
}
fn nfs4_res_compound_command(i: &[u8]) -> IResult<&[u8], Nfs4ResponseContent> {
NFSPROC4_LAYOUTRETURN => nfs4_res_layoutreturn(i)?,
NFSPROC4_DESTROY_SESSION => nfs4_res_destroy_session(i)?,
NFSPROC4_DESTROY_CLIENTID => nfs4_res_destroy_clientid(i)?,
- _ => { return Err(Err::Error(make_error(i, ErrorKind::Switch))); }
+ _ => {
+ return Err(Err::Error(make_error(i, ErrorKind::Switch)));
+ }
};
Ok((i, cmd_data))
}
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct Nfs4ResponseCompoundRecord<'a> {
pub status: u32,
pub commands: Vec<Nfs4ResponseContent<'a>>,
#[test]
fn test_nfs4_request_compound() {
- // Operations: SEQUENCE, PUTFH, CLOSE
+ // Operations: SEQUENCE, PUTFH, CLOSE
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x00, /*Tag*/
];
let (_, req_client_id) = nfs4_parse_nfsstring(&buf[12..64]).unwrap();
- let (_, req_r_netid) = nfs4_parse_nfsstring(&buf[68 ..76]).unwrap();
+ let (_, req_r_netid) = nfs4_parse_nfsstring(&buf[68..76]).unwrap();
let (_, req_r_adrr) = nfs4_parse_nfsstring(&buf[76..100]).unwrap();
let (_, resquest) = nfs4_req_setclientid(&buf[4..]).unwrap();
match resquest {
- Nfs4RequestContent::SetClientId( req_setclientid ) => {
+ Nfs4RequestContent::SetClientId(req_setclientid) => {
assert_eq!(req_setclientid.client_id, req_client_id);
assert_eq!(req_setclientid.r_netid, req_r_netid);
assert_eq!(req_setclientid.r_addr, req_r_adrr);
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
match request {
Nfs4RequestContent::Open(req_open) => {
assert_eq!(req_open.open_type, 1);
- assert_eq!(req_open.open_data, Some(Nfs4OpenRequestContent::Unchecked4(attr_buf)));
+ assert_eq!(
+ req_open.open_data,
+ Some(Nfs4OpenRequestContent::Unchecked4(attr_buf))
+ );
assert_eq!(req_open.filename, filename_buf);
}
- _ => { panic!("Failure, {:?}", request); }
+ _ => {
+ panic!("Failure, {:?}", request);
+ }
}
}
assert_eq!(req_write.write_len, 5);
assert_eq!(req_write.data, "test\n".as_bytes());
}
- _ => { panic!("Failure, {:?}", request); }
+ _ => {
+ panic!("Failure, {:?}", request);
+ }
}
}
assert_eq!(req_exchangeid.nii_domain, nii_domain_buf);
assert_eq!(req_exchangeid.nii_name, nii_name_buf);
}
- _ => { panic!("Failure, {:?}", request); }
+ _ => {
+ panic!("Failure, {:?}", request);
+ }
}
}
Nfs4RequestContent::Close(req_stateid) => {
assert_eq!(req_stateid, stateid_buf);
}
- _ => { panic!("Failure, {:?}", request); }
+ _ => {
+ panic!("Failure, {:?}", request);
+ }
}
}
Nfs4RequestContent::Sequence(seq_buf) => {
assert_eq!(seq_buf.ssn_id, &buf[4..20]);
}
- _ => { panic!("Failure, {:?}", req_sequence); }
+ _ => {
+ panic!("Failure, {:?}", req_sequence);
+ }
}
}
Nfs4RequestContent::Lookup(req_lookup) => {
assert_eq!(req_lookup.filename, filename_buf);
}
- _ => { panic!("Failure, {:?}", request); }
+ _ => {
+ panic!("Failure, {:?}", request);
+ }
}
}
assert_eq!(putfh_handle.value, handle_buf.value);
assert_eq!(putfh_handle.len, handle_buf.len);
}
- _ => { panic!("Failure, {:?}", result); }
+ _ => {
+ panic!("Failure, {:?}", result);
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x2b, /*opcode*/
0xe0, 0x14, 0x82, 0x00, 0x00, 0x00, 0x02, 0xd2, // create_session
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x04, 0x14,
- 0x00, 0x10, 0x03, 0x88, 0x00, 0x00, 0x0d, 0x64,
- 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x01, 0x0c, 0x09, 0x5e, 0x92,
- 0x00, 0x00, 0x00, 0x09, 0x6e, 0x65, 0x74, 0x61,
- 0x70, 0x70, 0x2d, 0x32, 0x36, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
+ 0x04, 0x14, 0x00, 0x10, 0x03, 0x88, 0x00, 0x00, 0x0d, 0x64, 0x00, 0x00, 0x00, 0x08,
+ 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x09, 0x5e, 0x92, 0x00, 0x00, 0x00, 0x09,
+ 0x6e, 0x65, 0x74, 0x61, 0x70, 0x70, 0x2d, 0x32, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
let (_, request) = nfs4_req_create_session(&buf[4..]).unwrap();
match request {
- Nfs4RequestContent::CreateSession( create_ssn ) => {
+ Nfs4RequestContent::CreateSession(create_ssn) => {
assert_eq!(create_ssn.client_id, &buf[4..12]);
assert_eq!(create_ssn.seqid, 1);
assert_eq!(create_ssn.machine_name, b"netapp-26");
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x32, /*opcode*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // layoutget
- 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x02, 0x82, 0x14, 0xe0, 0x5b, 0x00, 0x89, 0xd9,
- 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x02, 0x82, 0x14, 0xe0, 0x5b, 0x00, 0x89, 0xd9, 0x04, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
];
let (_, stateid_buf) = nfs4_parse_stateid(&buf[40..56]).unwrap();
let (_, request) = nfs4_req_layoutget(&buf[4..]).unwrap();
match request {
- Nfs4RequestContent::LayoutGet( lyg_data ) => {
+ Nfs4RequestContent::LayoutGet(lyg_data) => {
assert_eq!(lyg_data.layout_type, 1);
assert_eq!(lyg_data.min_length, 4096);
assert_eq!(lyg_data.stateid, stateid_buf);
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x2f, /*opcode*/
0x01, 0x01, 0x00, 0x00, 0x00, 0xf2, 0xfa, 0x80, // getdevinfo
- 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x3e, 0x20,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06,
+ 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01,
+ 0x3e, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x06,
];
let (_, request) = nfs4_req_getdevinfo(&buf[4..]).unwrap();
match request {
- Nfs4RequestContent::GetDevInfo( getdevifo ) => {
+ Nfs4RequestContent::GetDevInfo(getdevifo) => {
assert_eq!(getdevifo.device_id, &buf[4..20]);
assert_eq!(getdevifo.layout_type, 1);
assert_eq!(getdevifo.maxcount, 81440);
assert_eq!(getdevifo.notify_mask, 6);
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x33, /*opcode*/
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, // layoutreturn
- 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x01, 0x03, 0x82, 0x14, 0xe0,
- 0x5b, 0x00, 0x89, 0xd9, 0x04, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01,
+ 0x03, 0x82, 0x14, 0xe0, 0x5b, 0x00, 0x89, 0xd9, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
];
let (_, stateid_buf) = nfs4_parse_stateid(&buf[36..52]).unwrap();
let (_, request) = nfs4_req_layoutreturn(&buf[4..]).unwrap();
match request {
- Nfs4RequestContent::LayoutReturn( layoutreturn ) => {
+ Nfs4RequestContent::LayoutReturn(layoutreturn) => {
assert_eq!(layoutreturn.layout_type, 1);
assert_eq!(layoutreturn.return_type, 1);
assert_eq!(layoutreturn.stateid, stateid_buf);
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let (_, request) = nfs4_req_destroy_session(&buf[4..]).unwrap();
match request {
- Nfs4RequestContent::DestroySession( ssn_id ) => {
+ Nfs4RequestContent::DestroySession(ssn_id) => {
assert_eq!(ssn_id, &buf[4..]);
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
}
#[test]
fn test_nfs4_response_compound() {
- // Operations: SEQUENCE, PUTFH, CLOSE
+ // Operations: SEQUENCE, PUTFH, CLOSE
#[rustfmt::skip]
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x00, /*status*/
assert_eq!(status, 0);
assert_eq!(open_data, Some(res_open_data));
}
- _ => { panic!("Failure, {:?}", response); }
+ _ => {
+ panic!("Failure, {:?}", response);
+ }
}
}
assert_eq!(status, 0);
assert_eq!(wd, Some(wd_buf));
}
- _ => { panic!("Failure, {:?}", result); }
+ _ => {
+ panic!("Failure, {:?}", result);
+ }
}
}
assert_eq!(status, 0);
assert_eq!(ad, Some(ad_buf));
}
- _ => { panic!("Failure, {:?}", result); }
+ _ => {
+ panic!("Failure, {:?}", result);
+ }
}
}
assert_eq!(status, 0);
assert_eq!(fh, Some(fh_buf));
}
- _ => { panic!("Failure, {:?}", result); }
+ _ => {
+ panic!("Failure, {:?}", result);
+ }
}
}
assert_eq!(status, 0);
assert_eq!(attrs, Some(attrs_buf));
}
- _ => { panic!("Failure, {:?}", result); }
+ _ => {
+ panic!("Failure, {:?}", result);
+ }
}
}
assert_eq!(status, 0);
assert_eq!(rd, Some(res_rd));
}
- _ => { panic!("Failure!"); }
+ _ => {
+ panic!("Failure!");
+ }
}
}
Nfs4ResponseContent::SetClientId(status) => {
assert_eq!(status, 0);
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x2a, /*opcode*/
0x00, 0x00, 0x00, 0x00, /*status*/
- // exchange_id
- 0xe0, 0x14, 0x82, 0x00, 0x00, 0x00, 0x02, 0xd2,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x01, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x98, 0x3b, 0xa3, 0x1e,
- 0xd7, 0xa9, 0x11, 0xe8, 0x00, 0x00, 0x00, 0x10,
- 0x98, 0x3b, 0xa3, 0x1e, 0xd7, 0xa9, 0x11, 0xe8,
- 0xbc, 0x0c, 0x00, 0x0c, 0x29, 0xe9, 0x13, 0x93,
- 0x00, 0x00, 0x00, 0x10, 0x84, 0x8b, 0x93, 0x12,
- 0xd7, 0xa9, 0x11, 0xe8, 0xbc, 0x0c, 0x00, 0x0c,
- 0x29, 0xe9, 0x13, 0x93, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x0c, 0x6e, 0x65, 0x74, 0x61,
- 0x70, 0x70, 0x2e, 0x63, 0x6f, 0x6d, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x24, 0x4e, 0x65, 0x74, 0x41,
- 0x70, 0x70, 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61,
- 0x73, 0x65, 0x20, 0x56, 0x6f, 0x6f, 0x64, 0x6f,
- 0x6f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x5f,
- 0x5f, 0x39, 0x2e, 0x36, 0x2e, 0x30, 0x00, 0x00,
- 0x26, 0x0d, 0xcf, 0x5b, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
+ // exchange_id
+ 0xe0, 0x14, 0x82, 0x00, 0x00, 0x00, 0x02, 0xd2, 0x00, 0x00, 0x00, 0x01, 0x00, 0x06,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98, 0x3b, 0xa3, 0x1e, 0xd7, 0xa9, 0x11, 0xe8,
+ 0x00, 0x00, 0x00, 0x10, 0x98, 0x3b, 0xa3, 0x1e, 0xd7, 0xa9, 0x11, 0xe8, 0xbc, 0x0c,
+ 0x00, 0x0c, 0x29, 0xe9, 0x13, 0x93, 0x00, 0x00, 0x00, 0x10, 0x84, 0x8b, 0x93, 0x12,
+ 0xd7, 0xa9, 0x11, 0xe8, 0xbc, 0x0c, 0x00, 0x0c, 0x29, 0xe9, 0x13, 0x93, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c, 0x6e, 0x65, 0x74, 0x61, 0x70, 0x70, 0x2e, 0x63,
+ 0x6f, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x4e, 0x65, 0x74, 0x41, 0x70, 0x70,
+ 0x20, 0x52, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x56, 0x6f, 0x6f, 0x64, 0x6f,
+ 0x6f, 0x72, 0x61, 0x6e, 0x67, 0x65, 0x72, 0x5f, 0x5f, 0x39, 0x2e, 0x36, 0x2e, 0x30,
+ 0x00, 0x00, 0x26, 0x0d, 0xcf, 0x5b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
];
let (_, xchangeid) = nfs4_parse_res_exchangeid(&buf[8..]).unwrap();
assert_eq!(status, 0);
assert_eq!(xchngid_data, Some(xchangeid));
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x2b, /*opcode*/
0x00, 0x00, 0x00, 0x00, /*status*/
- // create_session
- 0x00, 0x00, 0x02, 0xd2, 0xe0, 0x14, 0x82, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x02,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x18, 0x00,
- 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x02, 0x80,
- 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x40,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ // create_session
+ 0x00, 0x00, 0x02, 0xd2, 0xe0, 0x14, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x04, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, 0x18, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x02, 0x80, 0x00, 0x00,
+ 0x00, 0x08, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
];
let (_, create_ssn) = nfs4_parse_res_create_session(&buf[8..]).unwrap();
let (_, response) = nfs4_res_create_session(&buf[4..]).unwrap();
match response {
- Nfs4ResponseContent::CreateSession( status, create_ssn_data) => {
+ Nfs4ResponseContent::CreateSession(status, create_ssn_data) => {
assert_eq!(status, 0);
assert_eq!(create_ssn_data, Some(create_ssn));
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
let buf: &[u8] = &[
0x00, 0x00, 0x00, 0x32, /*opcode*/
0x00, 0x00, 0x00, 0x00, /*status*/
- // layoutget
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x03, 0x82, 0x14, 0xe0, 0x5b, 0x00, 0x89, 0xd9,
- 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x58, 0x01, 0x01, 0x00, 0x00,
- 0x00, 0xf2, 0xfa, 0x80, 0x00, 0x00, 0x00, 0x00,
- 0x20, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x30, 0x01, 0x03, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x84, 0x72, 0x00, 0x00, 0x23, 0xa6, 0xc0, 0x12,
- 0x00, 0xf2, 0xfa, 0x80, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
- 0x00, 0xf2, 0xfa, 0x80, 0x00, 0x00, 0x00, 0x00,
- 0x20, 0x00, 0x00, 0x00,
+ // layoutget
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x82, 0x14, 0xe0, 0x5b, 0x00,
+ 0x89, 0xd9, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
+ 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x58, 0x01, 0x01, 0x00, 0x00,
+ 0x00, 0xf2, 0xfa, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x30, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x72, 0x00, 0x00, 0x23, 0xa6, 0xc0, 0x12,
+ 0x00, 0xf2, 0xfa, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01,
+ 0x00, 0x00, 0x00, 0xf2, 0xfa, 0x80, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
];
let (_, stateid) = nfs4_parse_stateid(&buf[12..28]).unwrap();
let (_, response) = nfs4_res_layoutget(&buf[4..]).unwrap();
match response {
- Nfs4ResponseContent::LayoutGet( status, lyg ) => {
+ Nfs4ResponseContent::LayoutGet(status, lyg) => {
assert_eq!(status, 0);
assert_eq!(lyg, Some(lyg_data));
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
0x00, 0x00, 0x00, 0x2f, /*opcode*/
0x00, 0x00, 0x00, 0x00, /*status*/
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x2c, // getdevinfo
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
- 0x00, 0x00, 0x00, 0x03, 0x74, 0x63, 0x70, 0x00,
- 0x00, 0x00, 0x00, 0x10, 0x31, 0x39, 0x32, 0x2e,
- 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e, 0x36, 0x31,
- 0x2e, 0x38, 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00,
+ 0x00, 0x01, 0x00, 0x00, 0x00, 0x03, 0x74, 0x63, 0x70, 0x00, 0x00, 0x00, 0x00, 0x10,
+ 0x31, 0x39, 0x32, 0x2e, 0x31, 0x36, 0x38, 0x2e, 0x30, 0x2e, 0x36, 0x31, 0x2e, 0x38,
+ 0x2e, 0x31, 0x00, 0x00, 0x00, 0x00,
];
let (_, getdevinfo) = nfs4_parse_res_getdevinfo(&buf[8..]).unwrap();
assert_eq!(status, 0);
assert_eq!(getdevinfo_data, Some(getdevinfo))
}
- _ => { panic!("Failure"); }
+ _ => {
+ panic!("Failure");
+ }
}
}
}
//! Nom parsers for NFS
-#[derive(Debug,PartialEq, Eq)]
+#[derive(Debug, PartialEq, Eq)]
pub struct NfsReplyRead<'a> {
pub status: u32,
pub attr_follows: u32,
- pub attr_blob: &'a[u8],
+ pub attr_blob: &'a [u8],
pub count: u32,
pub eof: bool,
pub data_len: u32,
- pub data: &'a[u8], // likely partial
+ pub data: &'a [u8], // likely partial
}
use crate::common::nom7::bits;
use nom7::bits::streaming::take as take_bits;
use nom7::bytes::streaming::take;
-use nom7::combinator::{cond, verify, rest};
+use nom7::combinator::{cond, rest, verify};
+use nom7::error::{make_error, ErrorKind};
use nom7::multi::length_data;
-use nom7::number::streaming::{be_u32};
+use nom7::number::streaming::be_u32;
use nom7::sequence::tuple;
-use nom7::error::{make_error, ErrorKind};
-use nom7::{IResult, Err};
+use nom7::{Err, IResult};
pub const RPC_MAX_MACHINE_SIZE: u32 = 256; // Linux kernel defines 64.
pub const RPC_MAX_CREDS_SIZE: u32 = 4096; // Linux kernel defines 400.
}
pub fn parse_rpc_packet_header(i: &[u8]) -> IResult<&[u8], RpcPacketHeader> {
- let (i, fraghdr) = verify(parse_bits, |v: &(u8,u32)| v.1 >= 24)(i)?;
+ let (i, fraghdr) = verify(parse_bits, |v: &(u8, u32)| v.1 >= 24)(i)?;
let (i, xid) = be_u32(i)?;
let (i, msgtype) = verify(be_u32, |&v| v <= 1)(i)?;
let hdr = RpcPacketHeader {
return Err(Err::Error(make_error(i, ErrorKind::LengthValue)));
}
- let data_size : u32 = (rec_size - consumed) as u32;
+ let data_size: u32 = (rec_size - consumed) as u32;
let (i, prog_data) = if !complete {
rest(i)?
} else {
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 as usize - consumed) as u32;
let (i, prog_data) = if !complete {
rest(i)?
} else {
let (i, verifier_len) = verify(be_u32, |&size| size < RPC_MAX_VERIFIER_SIZE)(i)?;
let (i, verifier) = take(verifier_len as usize)(i)?;
- let data_size : u32 = i.len() as u32;
+ let data_size: u32 = i.len() as u32;
let (i, prog_data) = rest(i)?;
let packet = RpcPacket {
hdr,
let (i, reply_state) = verify(be_u32, |&v| v <= 1)(i)?;
let (i, accept_state) = be_u32(i)?;
- let data_size : u32 = i.len() as u32;
+ let data_size: u32 = i.len() as u32;
let (i, prog_data) = rest(i)?;
let packet = RpcReplyPacket {
hdr,
fn test_partial_input_too_short() {
let buf: &[u8] = &[
0x80, 0x00, 0x00, 0x9c, // flags
- 0x8e, 0x28, 0x02, 0x7e // xid
+ 0x8e, 0x28, 0x02, 0x7e, // xid
];
let r = parse_rpc_request_partial(buf);
match r {
- Err(Incomplete(s)) => { assert_eq!(s, Needed::new(4)); },
- _ => { panic!("failed {:?}",r); }
+ Err(Incomplete(s)) => {
+ assert_eq!(s, Needed::new(4));
+ }
+ _ => {
+ panic!("failed {:?}", r);
+ }
}
}
#[test]
];
let expected = RpcRequestPacketPartial {
hdr: RpcPacketHeader {
- frag_is_last: true,
- frag_len: 156,
- xid: 2384986750,
- msgtype: 1
- },
+ frag_is_last: true,
+ frag_len: 156,
+ xid: 2384986750,
+ msgtype: 1,
+ },
rpcver: 2,
program: 3,
progver: 4,
- procedure: 5
+ procedure: 5,
};
let r = parse_rpc_request_partial(buf);
match r {
Ok((rem, hdr)) => {
assert_eq!(rem.len(), 0);
assert_eq!(hdr, expected);
- },
- _ => { panic!("failed {:?}",r); }
+ }
+ _ => {
+ panic!("failed {:?}", r);
+ }
}
}
}
*/
/* RFC 1813, section '3. Server Procedures' */
-pub const NFSPROC3_NULL: u32 = 0;
-pub const NFSPROC3_GETATTR: u32 = 1;
-pub const NFSPROC3_SETATTR: u32 = 2;
-pub const NFSPROC3_LOOKUP: u32 = 3;
-pub const NFSPROC3_ACCESS: u32 = 4;
-pub const NFSPROC3_READLINK: u32 = 5;
-pub const NFSPROC3_READ: u32 = 6;
-pub const NFSPROC3_WRITE: u32 = 7;
-pub const NFSPROC3_CREATE: u32 = 8;
-pub const NFSPROC3_MKDIR: u32 = 9;
-pub const NFSPROC3_SYMLINK: u32 = 10;
-pub const NFSPROC3_MKNOD: u32 = 11;
-pub const NFSPROC3_REMOVE: u32 = 12;
-pub const NFSPROC3_RMDIR: u32 = 13;
-pub const NFSPROC3_RENAME: u32 = 14;
-pub const NFSPROC3_LINK: u32 = 15;
-pub const NFSPROC3_READDIR: u32 = 16;
+pub const NFSPROC3_NULL: u32 = 0;
+pub const NFSPROC3_GETATTR: u32 = 1;
+pub const NFSPROC3_SETATTR: u32 = 2;
+pub const NFSPROC3_LOOKUP: u32 = 3;
+pub const NFSPROC3_ACCESS: u32 = 4;
+pub const NFSPROC3_READLINK: u32 = 5;
+pub const NFSPROC3_READ: u32 = 6;
+pub const NFSPROC3_WRITE: u32 = 7;
+pub const NFSPROC3_CREATE: u32 = 8;
+pub const NFSPROC3_MKDIR: u32 = 9;
+pub const NFSPROC3_SYMLINK: u32 = 10;
+pub const NFSPROC3_MKNOD: u32 = 11;
+pub const NFSPROC3_REMOVE: u32 = 12;
+pub const NFSPROC3_RMDIR: u32 = 13;
+pub const NFSPROC3_RENAME: u32 = 14;
+pub const NFSPROC3_LINK: u32 = 15;
+pub const NFSPROC3_READDIR: u32 = 16;
pub const NFSPROC3_READDIRPLUS: u32 = 17;
-pub const NFSPROC3_FSSTAT: u32 = 18;
-pub const NFSPROC3_FSINFO: u32 = 19;
-pub const NFSPROC3_PATHCONF: u32 = 20;
-pub const NFSPROC3_COMMIT: u32 = 21;
+pub const NFSPROC3_FSSTAT: u32 = 18;
+pub const NFSPROC3_FSINFO: u32 = 19;
+pub const NFSPROC3_PATHCONF: u32 = 20;
+pub const NFSPROC3_COMMIT: u32 = 21;
pub fn nfs3_procedure_string(procedure: u32) -> String {
match procedure {
- NFSPROC3_NULL => "NULL",
- NFSPROC3_GETATTR => "GETATTR",
- NFSPROC3_SETATTR => "SETATTR",
- NFSPROC3_LOOKUP => "LOOKUP",
- NFSPROC3_ACCESS => "ACCESS",
- NFSPROC3_READLINK => "READLINK",
- NFSPROC3_READ => "READ",
- NFSPROC3_WRITE => "WRITE",
- NFSPROC3_CREATE => "CREATE",
- NFSPROC3_MKDIR => "MKDIR",
- NFSPROC3_SYMLINK => "SYMLINK",
- NFSPROC3_MKNOD => "MKNOD",
- NFSPROC3_REMOVE => "REMOVE",
- NFSPROC3_RMDIR => "RMDIR",
- NFSPROC3_RENAME => "RENAME",
- NFSPROC3_LINK => "LINK",
- NFSPROC3_READDIR => "READDIR",
- NFSPROC3_READDIRPLUS => "READDIRPLUS",
- NFSPROC3_FSSTAT => "FSSTAT",
- NFSPROC3_FSINFO => "FSINFO",
- NFSPROC3_PATHCONF => "PATHCONF",
- NFSPROC3_COMMIT => "COMMIT",
+ NFSPROC3_NULL => "NULL",
+ NFSPROC3_GETATTR => "GETATTR",
+ NFSPROC3_SETATTR => "SETATTR",
+ NFSPROC3_LOOKUP => "LOOKUP",
+ NFSPROC3_ACCESS => "ACCESS",
+ NFSPROC3_READLINK => "READLINK",
+ NFSPROC3_READ => "READ",
+ NFSPROC3_WRITE => "WRITE",
+ NFSPROC3_CREATE => "CREATE",
+ NFSPROC3_MKDIR => "MKDIR",
+ NFSPROC3_SYMLINK => "SYMLINK",
+ NFSPROC3_MKNOD => "MKNOD",
+ NFSPROC3_REMOVE => "REMOVE",
+ NFSPROC3_RMDIR => "RMDIR",
+ NFSPROC3_RENAME => "RENAME",
+ NFSPROC3_LINK => "LINK",
+ NFSPROC3_READDIR => "READDIR",
+ NFSPROC3_READDIRPLUS => "READDIRPLUS",
+ NFSPROC3_FSSTAT => "FSSTAT",
+ NFSPROC3_FSINFO => "FSINFO",
+ NFSPROC3_PATHCONF => "PATHCONF",
+ NFSPROC3_COMMIT => "COMMIT",
_ => {
return (procedure).to_string();
}
- }.to_string()
+ }
+ .to_string()
}
/* RFC 1813, section '2.6 Defined Error Numbers' */
-pub const NFS3_OK: u32 = 0;
-pub const NFS3ERR_PERM: u32 = 1;
-pub const NFS3ERR_NOENT: u32 = 2;
-pub const NFS3ERR_IO: u32 = 5;
-pub const NFS3ERR_NXIO: u32 = 6;
-pub const NFS3ERR_ACCES: u32 = 13;
-pub const NFS3ERR_EXIST: u32 = 17;
-pub const NFS3ERR_XDEV: u32 = 18;
-pub const NFS3ERR_NODEV: u32 = 19;
-pub const NFS3ERR_NOTDIR: u32 = 20;
-pub const NFS3ERR_ISDIR: u32 = 21;
-pub const NFS3ERR_INVAL: u32 = 22;
-pub const NFS3ERR_FBIG: u32 = 27;
-pub const NFS3ERR_NOSPC: u32 = 28;
-pub const NFS3ERR_ROFS: u32 = 30;
-pub const NFS3ERR_MLINK: u32 = 31;
-pub const NFS3ERR_NAMETOOLONG: u32 = 63;
-pub const NFS3ERR_NOTEMPTY: u32 = 66;
-pub const NFS3ERR_DQUOT: u32 = 69;
-pub const NFS3ERR_STALE: u32 = 70;
-pub const NFS3ERR_REMOTE: u32 = 71;
-pub const NFS3ERR_BADHANDLE: u32 = 10001;
-pub const NFS3ERR_NOT_SYNC: u32 = 10002;
-pub const NFS3ERR_BAD_COOKIE: u32 = 10003;
-pub const NFS3ERR_NOTSUPP: u32 = 10004;
-pub const NFS3ERR_TOOSMALL: u32 = 10005;
-pub const NFS3ERR_SERVERFAULT: u32 = 10006;
-pub const NFS3ERR_BADTYPE: u32 = 10007;
-pub const NFS3ERR_JUKEBOX: u32 = 10008;
+pub const NFS3_OK: u32 = 0;
+pub const NFS3ERR_PERM: u32 = 1;
+pub const NFS3ERR_NOENT: u32 = 2;
+pub const NFS3ERR_IO: u32 = 5;
+pub const NFS3ERR_NXIO: u32 = 6;
+pub const NFS3ERR_ACCES: u32 = 13;
+pub const NFS3ERR_EXIST: u32 = 17;
+pub const NFS3ERR_XDEV: u32 = 18;
+pub const NFS3ERR_NODEV: u32 = 19;
+pub const NFS3ERR_NOTDIR: u32 = 20;
+pub const NFS3ERR_ISDIR: u32 = 21;
+pub const NFS3ERR_INVAL: u32 = 22;
+pub const NFS3ERR_FBIG: u32 = 27;
+pub const NFS3ERR_NOSPC: u32 = 28;
+pub const NFS3ERR_ROFS: u32 = 30;
+pub const NFS3ERR_MLINK: u32 = 31;
+pub const NFS3ERR_NAMETOOLONG: u32 = 63;
+pub const NFS3ERR_NOTEMPTY: u32 = 66;
+pub const NFS3ERR_DQUOT: u32 = 69;
+pub const NFS3ERR_STALE: u32 = 70;
+pub const NFS3ERR_REMOTE: u32 = 71;
+pub const NFS3ERR_BADHANDLE: u32 = 10001;
+pub const NFS3ERR_NOT_SYNC: u32 = 10002;
+pub const NFS3ERR_BAD_COOKIE: u32 = 10003;
+pub const NFS3ERR_NOTSUPP: u32 = 10004;
+pub const NFS3ERR_TOOSMALL: u32 = 10005;
+pub const NFS3ERR_SERVERFAULT: u32 = 10006;
+pub const NFS3ERR_BADTYPE: u32 = 10007;
+pub const NFS3ERR_JUKEBOX: u32 = 10008;
pub fn nfs3_status_string(status: u32) -> String {
match status {
- NFS3_OK => "OK",
- NFS3ERR_PERM => "ERR_PERM",
- NFS3ERR_NOENT => "ERR_NOENT",
- NFS3ERR_IO => "ERR_IO",
- NFS3ERR_NXIO => "ERR_NXIO",
- NFS3ERR_ACCES => "ERR_ACCES",
- NFS3ERR_EXIST => "ERR_EXIST",
- NFS3ERR_XDEV => "ERR_XDEV",
- NFS3ERR_NODEV => "ERR_NODEV",
- NFS3ERR_NOTDIR => "ERR_NOTDIR",
- NFS3ERR_ISDIR => "ERR_ISDIR",
- NFS3ERR_INVAL => "ERR_INVAL",
- NFS3ERR_FBIG => "ERR_FBIG",
- NFS3ERR_NOSPC => "ERR_NOSPC",
- NFS3ERR_ROFS => "ERR_ROFS",
- NFS3ERR_MLINK => "ERR_MLINK",
+ NFS3_OK => "OK",
+ NFS3ERR_PERM => "ERR_PERM",
+ NFS3ERR_NOENT => "ERR_NOENT",
+ NFS3ERR_IO => "ERR_IO",
+ NFS3ERR_NXIO => "ERR_NXIO",
+ NFS3ERR_ACCES => "ERR_ACCES",
+ NFS3ERR_EXIST => "ERR_EXIST",
+ NFS3ERR_XDEV => "ERR_XDEV",
+ NFS3ERR_NODEV => "ERR_NODEV",
+ NFS3ERR_NOTDIR => "ERR_NOTDIR",
+ NFS3ERR_ISDIR => "ERR_ISDIR",
+ NFS3ERR_INVAL => "ERR_INVAL",
+ NFS3ERR_FBIG => "ERR_FBIG",
+ NFS3ERR_NOSPC => "ERR_NOSPC",
+ NFS3ERR_ROFS => "ERR_ROFS",
+ NFS3ERR_MLINK => "ERR_MLINK",
NFS3ERR_NAMETOOLONG => "ERR_NAMETOOLONG",
- NFS3ERR_NOTEMPTY => "ERR_NOTEMPTY",
- NFS3ERR_DQUOT => "ERR_DQUOT",
- NFS3ERR_STALE => "ERR_STALE",
- NFS3ERR_REMOTE => "ERR_REMOTE",
- NFS3ERR_BADHANDLE => "ERR_BADHANDLE",
- NFS3ERR_NOT_SYNC => "ERR_NOT_SYNC",
- NFS3ERR_BAD_COOKIE => "ERR_BAD_COOKIE",
- NFS3ERR_NOTSUPP => "ERR_NOTSUPP",
- NFS3ERR_TOOSMALL => "ERR_TOOSMALL",
+ NFS3ERR_NOTEMPTY => "ERR_NOTEMPTY",
+ NFS3ERR_DQUOT => "ERR_DQUOT",
+ NFS3ERR_STALE => "ERR_STALE",
+ NFS3ERR_REMOTE => "ERR_REMOTE",
+ NFS3ERR_BADHANDLE => "ERR_BADHANDLE",
+ NFS3ERR_NOT_SYNC => "ERR_NOT_SYNC",
+ NFS3ERR_BAD_COOKIE => "ERR_BAD_COOKIE",
+ NFS3ERR_NOTSUPP => "ERR_NOTSUPP",
+ NFS3ERR_TOOSMALL => "ERR_TOOSMALL",
NFS3ERR_SERVERFAULT => "ERR_SERVERFAULT",
- NFS3ERR_BADTYPE => "ERR_BADTYPE",
- NFS3ERR_JUKEBOX => "ERR_JUKEBOX",
+ NFS3ERR_BADTYPE => "ERR_BADTYPE",
+ NFS3ERR_JUKEBOX => "ERR_JUKEBOX",
_ => {
return (status).to_string();
- },
- }.to_string()
+ }
+ }
+ .to_string()
}
-pub const RPCMSG_ACCEPTED: u32 = 0;
-pub const RPCMSG_DENIED: u32 = 1;
+pub const RPCMSG_ACCEPTED: u32 = 0;
+pub const RPCMSG_DENIED: u32 = 1;
pub fn rpc_status_string(status: u32) -> String {
match status {
RPCMSG_ACCEPTED => "ACCEPTED",
- RPCMSG_DENIED => "DENIED",
+ RPCMSG_DENIED => "DENIED",
_ => {
return (status).to_string();
- },
- }.to_string()
+ }
+ }
+ .to_string()
}
/* http://www.iana.org/assignments/rpc-authentication-numbers/rpc-authentication-numbers.xhtml */
/* RFC 1057 Section 7.2 */
/* RFC 2203 Section 3 */
-pub const RPCAUTH_NULL: u32 = 0;
-pub const RPCAUTH_UNIX: u32 = 1;
-pub const RPCAUTH_SHORT: u32 = 2;
-pub const RPCAUTH_DH: u32 = 3;
-pub const RPCAUTH_KERB: u32 = 4;
-pub const RPCAUTH_RSA: u32 = 5;
-pub const RPCAUTH_GSS: u32 = 6;
+pub const RPCAUTH_NULL: u32 = 0;
+pub const RPCAUTH_UNIX: u32 = 1;
+pub const RPCAUTH_SHORT: u32 = 2;
+pub const RPCAUTH_DH: u32 = 3;
+pub const RPCAUTH_KERB: u32 = 4;
+pub const RPCAUTH_RSA: u32 = 5;
+pub const RPCAUTH_GSS: u32 = 6;
pub fn rpc_auth_type_string(auth_type: u32) -> String {
match auth_type {
- RPCAUTH_NULL => "NULL",
- RPCAUTH_UNIX => "UNIX",
- RPCAUTH_SHORT => "SHORT",
- RPCAUTH_DH => "DH",
- RPCAUTH_KERB => "KERB",
- RPCAUTH_RSA => "RSA",
- RPCAUTH_GSS => "GSS",
+ RPCAUTH_NULL => "NULL",
+ RPCAUTH_UNIX => "UNIX",
+ RPCAUTH_SHORT => "SHORT",
+ RPCAUTH_DH => "DH",
+ RPCAUTH_KERB => "KERB",
+ RPCAUTH_RSA => "RSA",
+ RPCAUTH_GSS => "GSS",
_ => {
return (auth_type).to_string();
- },
- }.to_string()
+ }
+ }
+ .to_string()
}
pub fn rpc_auth_type_known(auth_type: u32) -> i8 {
return -1;
}
-
-pub const NFSPROC4_NULL: u32 = 0;
-pub const NFSPROC4_COMPOUND: u32 = 1;
+pub const NFSPROC4_NULL: u32 = 0;
+pub const NFSPROC4_COMPOUND: u32 = 1;
/* ops */
-pub const NFSPROC4_ACCESS: u32 = 3;
-pub const NFSPROC4_CLOSE: u32 = 4;
-pub const NFSPROC4_COMMIT: u32 = 5;
-pub const NFSPROC4_CREATE: u32 = 6;
-pub const NFSPROC4_DELEGPURGE: u32 = 7;
-pub const NFSPROC4_DELEGRETURN: u32 = 8;
-pub const NFSPROC4_GETATTR: u32 = 9;
-pub const NFSPROC4_GETFH: u32 = 10;
-pub const NFSPROC4_LINK: u32 = 11;
-pub const NFSPROC4_LOCK: u32 = 12;
-pub const NFSPROC4_LOCKT: u32 = 13;
-pub const NFSPROC4_LOCKU: u32 = 14;
-pub const NFSPROC4_LOOKUP: u32 = 15;
-pub const NFSPROC4_LOOKUPP: u32 = 16;
-pub const NFSPROC4_NVERIFY: u32 = 17;
-pub const NFSPROC4_OPEN: u32 = 18;
-pub const NFSPROC4_OPENATTR: u32 = 19;
-pub const NFSPROC4_OPEN_CONFIRM: u32 = 20;
-pub const NFSPROC4_OPEN_DOWNGRADE: u32 = 21;
-pub const NFSPROC4_PUTFH: u32 = 22;
-pub const NFSPROC4_PUTPUBFH: u32 = 23;
-pub const NFSPROC4_PUTROOTFH: u32 = 24;
-pub const NFSPROC4_READ: u32 = 25;
-pub const NFSPROC4_READDIR: u32 = 26;
-pub const NFSPROC4_READLINK: u32 = 27;
-pub const NFSPROC4_REMOVE: u32 = 28;
-pub const NFSPROC4_RENAME: u32 = 29;
-pub const NFSPROC4_RENEW: u32 = 30;
-pub const NFSPROC4_RESTOREFH: u32 = 31;
-pub const NFSPROC4_SAVEFH: u32 = 32;
-pub const NFSPROC4_SECINFO: u32 = 33;
-pub const NFSPROC4_SETATTR: u32 = 34;
-pub const NFSPROC4_SETCLIENTID: u32 = 35;
+pub const NFSPROC4_ACCESS: u32 = 3;
+pub const NFSPROC4_CLOSE: u32 = 4;
+pub const NFSPROC4_COMMIT: u32 = 5;
+pub const NFSPROC4_CREATE: u32 = 6;
+pub const NFSPROC4_DELEGPURGE: u32 = 7;
+pub const NFSPROC4_DELEGRETURN: u32 = 8;
+pub const NFSPROC4_GETATTR: u32 = 9;
+pub const NFSPROC4_GETFH: u32 = 10;
+pub const NFSPROC4_LINK: u32 = 11;
+pub const NFSPROC4_LOCK: u32 = 12;
+pub const NFSPROC4_LOCKT: u32 = 13;
+pub const NFSPROC4_LOCKU: u32 = 14;
+pub const NFSPROC4_LOOKUP: u32 = 15;
+pub const NFSPROC4_LOOKUPP: u32 = 16;
+pub const NFSPROC4_NVERIFY: u32 = 17;
+pub const NFSPROC4_OPEN: u32 = 18;
+pub const NFSPROC4_OPENATTR: u32 = 19;
+pub const NFSPROC4_OPEN_CONFIRM: u32 = 20;
+pub const NFSPROC4_OPEN_DOWNGRADE: u32 = 21;
+pub const NFSPROC4_PUTFH: u32 = 22;
+pub const NFSPROC4_PUTPUBFH: u32 = 23;
+pub const NFSPROC4_PUTROOTFH: u32 = 24;
+pub const NFSPROC4_READ: u32 = 25;
+pub const NFSPROC4_READDIR: u32 = 26;
+pub const NFSPROC4_READLINK: u32 = 27;
+pub const NFSPROC4_REMOVE: u32 = 28;
+pub const NFSPROC4_RENAME: u32 = 29;
+pub const NFSPROC4_RENEW: u32 = 30;
+pub const NFSPROC4_RESTOREFH: u32 = 31;
+pub const NFSPROC4_SAVEFH: u32 = 32;
+pub const NFSPROC4_SECINFO: u32 = 33;
+pub const NFSPROC4_SETATTR: u32 = 34;
+pub const NFSPROC4_SETCLIENTID: u32 = 35;
pub const NFSPROC4_SETCLIENTID_CONFIRM: u32 = 36;
-pub const NFSPROC4_VERIFY: u32 = 37;
-pub const NFSPROC4_WRITE: u32 = 38;
-pub const NFSPROC4_RELEASE_LOCKOWNER: u32 = 39;
-pub const NFSPROC4_EXCHANGE_ID: u32 = 42;
-pub const NFSPROC4_CREATE_SESSION: u32 = 43;
-pub const NFSPROC4_DESTROY_SESSION: u32 = 44;
-pub const NFSPROC4_GETDEVINFO: u32 = 47;
-pub const NFSPROC4_LAYOUTGET: u32 = 50;
-pub const NFSPROC4_LAYOUTRETURN: u32 = 51;
-pub const NFSPROC4_SECINFO_NO_NAME: u32 = 52;
-pub const NFSPROC4_SEQUENCE: u32 = 53;
-pub const NFSPROC4_DESTROY_CLIENTID: u32 = 57;
-pub const NFSPROC4_RECLAIM_COMPLETE: u32 = 58;
-
-pub const NFSPROC4_ILLEGAL: u32 = 10044;
+pub const NFSPROC4_VERIFY: u32 = 37;
+pub const NFSPROC4_WRITE: u32 = 38;
+pub const NFSPROC4_RELEASE_LOCKOWNER: u32 = 39;
+pub const NFSPROC4_EXCHANGE_ID: u32 = 42;
+pub const NFSPROC4_CREATE_SESSION: u32 = 43;
+pub const NFSPROC4_DESTROY_SESSION: u32 = 44;
+pub const NFSPROC4_GETDEVINFO: u32 = 47;
+pub const NFSPROC4_LAYOUTGET: u32 = 50;
+pub const NFSPROC4_LAYOUTRETURN: u32 = 51;
+pub const NFSPROC4_SECINFO_NO_NAME: u32 = 52;
+pub const NFSPROC4_SEQUENCE: u32 = 53;
+pub const NFSPROC4_DESTROY_CLIENTID: u32 = 57;
+pub const NFSPROC4_RECLAIM_COMPLETE: u32 = 58;
+pub const NFSPROC4_ILLEGAL: u32 = 10044;
pub fn nfs4_procedure_string(procedure: u32) -> String {
match procedure {
- NFSPROC4_COMPOUND => "COMPOUND",
- NFSPROC4_NULL => "NULL",
+ NFSPROC4_COMPOUND => "COMPOUND",
+ NFSPROC4_NULL => "NULL",
// ops
- NFSPROC4_ACCESS => "ACCESS",
- NFSPROC4_CLOSE => "CLOSE",
- NFSPROC4_COMMIT => "COMMIT",
- NFSPROC4_CREATE => "CREATE",
- NFSPROC4_DELEGPURGE => "DELEGPURGE",
- NFSPROC4_DELEGRETURN => "DELEGRETURN",
- NFSPROC4_GETATTR => "GETATTR",
- NFSPROC4_GETFH => "GETFH",
- NFSPROC4_LINK => "LINK",
- NFSPROC4_LOCK => "LOCK",
- NFSPROC4_LOCKT => "LOCKT",
- NFSPROC4_LOCKU => "LOCKU",
- NFSPROC4_LOOKUP => "LOOKUP",
- NFSPROC4_LOOKUPP => "LOOKUPP",
- NFSPROC4_NVERIFY => "NVERIFY",
- NFSPROC4_OPEN => "OPEN",
- NFSPROC4_OPENATTR => "OPENATTR",
- NFSPROC4_OPEN_CONFIRM => "OPEN_CONFIRM",
- NFSPROC4_OPEN_DOWNGRADE => "OPEN_DOWNGRADE",
- NFSPROC4_PUTFH => "PUTFH",
- NFSPROC4_PUTPUBFH => "PUTPUBFH",
- NFSPROC4_PUTROOTFH => "PUTROOTFH",
- NFSPROC4_READ => "READ",
- NFSPROC4_READDIR => "READDIR",
- NFSPROC4_READLINK => "READLINK",
- NFSPROC4_REMOVE => "REMOVE",
- NFSPROC4_RENAME => "RENAME",
- NFSPROC4_RENEW => "RENEW",
- NFSPROC4_RESTOREFH => "RESTOREFH",
- NFSPROC4_SAVEFH => "SAVEFH",
- NFSPROC4_SECINFO => "SECINFO",
- NFSPROC4_SETATTR => "SETATTR",
- NFSPROC4_SETCLIENTID => "SETCLIENTID",
- NFSPROC4_SETCLIENTID_CONFIRM => "SETCLIENTID_CONFIRM",
- NFSPROC4_VERIFY => "VERIFY",
- NFSPROC4_WRITE => "WRITE",
- NFSPROC4_RELEASE_LOCKOWNER => "RELEASE_LOCKOWNER",
- NFSPROC4_ILLEGAL => "ILLEGAL",
+ NFSPROC4_ACCESS => "ACCESS",
+ NFSPROC4_CLOSE => "CLOSE",
+ NFSPROC4_COMMIT => "COMMIT",
+ NFSPROC4_CREATE => "CREATE",
+ NFSPROC4_DELEGPURGE => "DELEGPURGE",
+ NFSPROC4_DELEGRETURN => "DELEGRETURN",
+ NFSPROC4_GETATTR => "GETATTR",
+ NFSPROC4_GETFH => "GETFH",
+ NFSPROC4_LINK => "LINK",
+ NFSPROC4_LOCK => "LOCK",
+ NFSPROC4_LOCKT => "LOCKT",
+ NFSPROC4_LOCKU => "LOCKU",
+ NFSPROC4_LOOKUP => "LOOKUP",
+ NFSPROC4_LOOKUPP => "LOOKUPP",
+ NFSPROC4_NVERIFY => "NVERIFY",
+ NFSPROC4_OPEN => "OPEN",
+ NFSPROC4_OPENATTR => "OPENATTR",
+ NFSPROC4_OPEN_CONFIRM => "OPEN_CONFIRM",
+ NFSPROC4_OPEN_DOWNGRADE => "OPEN_DOWNGRADE",
+ NFSPROC4_PUTFH => "PUTFH",
+ NFSPROC4_PUTPUBFH => "PUTPUBFH",
+ NFSPROC4_PUTROOTFH => "PUTROOTFH",
+ NFSPROC4_READ => "READ",
+ NFSPROC4_READDIR => "READDIR",
+ NFSPROC4_READLINK => "READLINK",
+ NFSPROC4_REMOVE => "REMOVE",
+ NFSPROC4_RENAME => "RENAME",
+ NFSPROC4_RENEW => "RENEW",
+ NFSPROC4_RESTOREFH => "RESTOREFH",
+ NFSPROC4_SAVEFH => "SAVEFH",
+ NFSPROC4_SECINFO => "SECINFO",
+ NFSPROC4_SETATTR => "SETATTR",
+ NFSPROC4_SETCLIENTID => "SETCLIENTID",
+ NFSPROC4_SETCLIENTID_CONFIRM => "SETCLIENTID_CONFIRM",
+ NFSPROC4_VERIFY => "VERIFY",
+ NFSPROC4_WRITE => "WRITE",
+ NFSPROC4_RELEASE_LOCKOWNER => "RELEASE_LOCKOWNER",
+ NFSPROC4_ILLEGAL => "ILLEGAL",
_ => {
return (procedure).to_string();
}
- }.to_string()
+ }
+ .to_string()
}
-pub const NFS4_OK: u32 = 0;
-
+pub const NFS4_OK: u32 = 0;