From 947221eda045689db870a34e0c9057a337f2196e Mon Sep 17 00:00:00 2001 From: Tiramisu Mokka Date: Thu, 12 Jul 2018 16:50:31 +0200 Subject: [PATCH] nfs: add support for v4.2 operations and error codes (#7397) * nfs: add support for v4.2 operations and error codes NFSv4.2 (rfc7862) is a published standard since Nov. 2016 and supported by various nfs servers and clients. This change is adding operation and status codes defined by v4.2 spec. * packetbeat: add basic test for NFSv4.2 operations This is a basic test to verify NFsv4.2 support. Due to lack of server and client that supports full set of v4.2 operations, only one operation is added. * packetbeat: add test case for NFSv4.2 CLONE operation Signed-off-by: Tigran Mkrtchyan --- packetbeat/protos/nfs/nfs4.go | 41 +++++++++++++++++- packetbeat/protos/nfs/nfs_status.go | 8 ++++ .../tests/system/pcaps/nfsv42_clone.pcap | Bin 0 -> 580 bytes .../system/pcaps/nfsv42_layoutstats.pcap | Bin 0 -> 744 bytes packetbeat/tests/system/test_0061_nfs.py | 33 ++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 packetbeat/tests/system/pcaps/nfsv42_clone.pcap create mode 100644 packetbeat/tests/system/pcaps/nfsv42_layoutstats.pcap diff --git a/packetbeat/protos/nfs/nfs4.go b/packetbeat/protos/nfs/nfs4.go index 24f76670ff6..a9b829e6462 100644 --- a/packetbeat/protos/nfs/nfs4.go +++ b/packetbeat/protos/nfs/nfs4.go @@ -76,6 +76,19 @@ const ( opWantDelegation = 56 opDestroyClientid = 57 opReclaimComplete = 58 + opAllocate = 59 + opCopy = 60 + opCopyNotify = 61 + opDeallocate = 62 + opIoAdvise = 63 + opLayoutError = 64 + opLayoutStats = 65 + opOffloadCancel = 66 + opOffloadStatus = 67 + opReadPlus = 68 + opSeek = 69 + opWriteSame = 70 + opClone = 71 opIllegal = 10044 ) @@ -136,6 +149,19 @@ var nfsOpnum4 = map[int]string{ 56: "WANT_DELEGATION", 57: "DESTROY_CLIENTID", 58: "RECLAIM_COMPLETE", + 59: "ALLOCATE", + 60: "COPY", + 61: "COPY_NOTIFY", + 62: "DEALLOCATE", + 63: "IO_ADVISE", + 64: "LAYOUTERROR", + 65: "LAYOUTSTATS", + 66: "OFFLOAD_CANCEL", + 67: "OFFLOAD_STATUS", + 68: "READ_PLUS", + 69: "SEEK", + 70: "WRITE_SAME", + 71: "CLONE", 10044: "ILLEGAL", } @@ -261,7 +287,20 @@ func (nfs *nfs) findV4MainOpcode(xdr *xdr) string { opSetSsv, opTestStateid, opWantDelegation, - opWrite: + opWrite, + opAllocate, + opCopy, + opCopyNotify, + opDeallocate, + opIoAdvise, + opLayoutError, + opLayoutStats, + opOffloadCancel, + opOffloadStatus, + opReadPlus, + opSeek, + opWriteSame, + opClone: found = true default: diff --git a/packetbeat/protos/nfs/nfs_status.go b/packetbeat/protos/nfs/nfs_status.go index 1d3dc593a7f..bf4e7de5c15 100644 --- a/packetbeat/protos/nfs/nfs_status.go +++ b/packetbeat/protos/nfs/nfs_status.go @@ -126,4 +126,12 @@ var nfsStatus = map[int]string{ 10084: "NFSERR_DIRDELEG_UNAVAIL", 10085: "NFSERR_REJECT_DELEG", 10086: "NFSERR_RETURNCONFLICT", + 10087: "NFS4ERR_DELEG_REVOKED", + 10088: "NFS4ERR_PARTNER_NOTSUPP", + 10089: "NFS4ERR_PARTNER_NO_AUTH", + 10090: "NFS4ERR_UNION_NOTSUPP", + 10091: "NFS4ERR_OFFLOAD_DENIED", + 10092: "NFS4ERR_WRONG_LFS", + 10093: "NFS4ERR_BADLABEL", + 10094: "NFS4ERR_OFFLOAD_NO_REQS", } diff --git a/packetbeat/tests/system/pcaps/nfsv42_clone.pcap b/packetbeat/tests/system/pcaps/nfsv42_clone.pcap new file mode 100644 index 0000000000000000000000000000000000000000..2ebea37a37a4659a141f95115da8f6ae112323fd GIT binary patch literal 580 zcmca|c+)~A1{MYw`2U}Qff3006Kojm-OS7o2IPP+1CM6@dTAhe<;x=u23H0~4>=|W z1_!oT3I|p&hybxB(=!f6`CnW2HOt=K)gZyx({uu85+euK5}w>#rAZWuRg7 zL+%E3WrVa8f(d4c0ZAD~1~$emi)wGrYi#@ilV@V!V5oaI_c)NR0K_=e&GF)3sE4R? z2kC{`3350H!1&A%E+)AEEW`;ULGG4d0QwFT%4IFg4BLPLAPfm#5rO%4t(JpAnPEli z9#AM7vw=bw6w(}wOwT|eEdOiUC15CD%b5fTWl#u%Lb`#0p#U1nFo%K6g#vXED1#M9 fn}XOdS7Qk|IiNHMg8(R0KtKUZBKW|NP!|CJtBqxO literal 0 HcmV?d00001 diff --git a/packetbeat/tests/system/pcaps/nfsv42_layoutstats.pcap b/packetbeat/tests/system/pcaps/nfsv42_layoutstats.pcap new file mode 100644 index 0000000000000000000000000000000000000000..04eaa4e97a08fbd7a4d0ff48d82a5094e1f24e9d GIT binary patch literal 744 zcmca|c+)~A1{MYcU}0bcat?~=Mz<_tXW(LD0AmIQp7|ek#;9>sc%*SKxH2&Qk)H3s z;J`L#N%P8`SDRPvpTJzr!I*0i&ggpRb610enqJd#1_nk(4z4n>=|3-eA6eeOz<8v9 zoA(jaCME{Pw#7g;$ZC*xPfMq*+^B4_4EJrXGNc@KaAd?AUHXB$kP;44l9fSlk zkqD5RkO9bFSAdwgB)I@2E@o(KsAp(qsb^>jq)m+V42?|nOe{fC1l6`lMNC~AN<6D(G5%)z*MmTlsXz17!sf<13eUh l=BwKP2@n9sIEaCW84wSYa^SJf59EU|2!LW92tfMPZ2$l&Z>0bL literal 0 HcmV?d00001 diff --git a/packetbeat/tests/system/test_0061_nfs.py b/packetbeat/tests/system/test_0061_nfs.py index 8cc2a4bbd03..60e49ce60e3 100644 --- a/packetbeat/tests/system/test_0061_nfs.py +++ b/packetbeat/tests/system/test_0061_nfs.py @@ -73,3 +73,36 @@ def test_first_class_op(self): o = objs[0] assert o["nfs.opcode"] == "CLOSE" + + def test_first_class_op_v42(self): + """ + Should correctly detect first-class nfs v4.2 opration in a middle of + compound call + """ + self.render_config_template( + nfs_ports=[2049], + ) + self.run_packetbeat(pcap="nfsv42_layoutstats.pcap") + + objs = self.read_output() + assert len(objs) == 1 + o = objs[0] + + assert o["nfs.opcode"] == "LAYOUTSTATS" + + def test_clone_notsupp_v42(self): + """ + Should correctly detect first-class nfs v4.2 opration in a middle of + compound call and corresponding error code + """ + self.render_config_template( + nfs_ports=[2049], + ) + self.run_packetbeat(pcap="nfsv42_clone.pcap") + + objs = self.read_output() + assert len(objs) == 1 + o = objs[0] + + assert o["nfs.opcode"] == "CLONE" + assert o["nfs.status"] == "NFSERR_NOTSUPP"