Skip to content

Commit

Permalink
Add NFSv4 error support
Browse files Browse the repository at this point in the history
Support NFSv4 errors, and update "nfs-v4" test case to include NFSv4 NULL procedure.
  • Loading branch information
sikarash committed Feb 15, 2024
1 parent 893e7b1 commit ab18945
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 29 deletions.
124 changes: 124 additions & 0 deletions nfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,3 +416,127 @@ struct nfsv3_pathconf {
nd_uint32_t pc_caseinsensitive;
nd_uint32_t pc_casepreserving;
};

/*
* nfs definitions as per the Version 4 specs
*/

#define NFSV4PROC_NULL 0
#define NFSV4PROC_COMPOUND 1

/* RFC 7530 NFSv4 */
#define NFS4_OK 0
#define NFS4ERR_PERM 1
#define NFS4ERR_NOENT 2
#define NFS4ERR_IO 5
#define NFS4ERR_NXIO 6
#define NFS4ERR_ACCESS 13
#define NFS4ERR_EXIST 17
#define NFS4ERR_XDEV 18
#define NFS4ERR_NOTDIR 20
#define NFS4ERR_ISDIR 21
#define NFS4ERR_INVAL 22
#define NFS4ERR_FBIG 27
#define NFS4ERR_NOSPC 28
#define NFS4ERR_ROFS 30
#define NFS4ERR_MLINK 31
#define NFS4ERR_NAMETOOLONG 63
#define NFS4ERR_NOTEMPTY 66
#define NFS4ERR_DQUOT 69
#define NFS4ERR_STALE 70
#define NFS4ERR_BADHANDLE 10001
#define NFS4ERR_BAD_COOKIE 10003
#define NFS4ERR_NOTSUPP 10004
#define NFS4ERR_TOOSMALL 10005
#define NFS4ERR_SERVERFAULT 10006
#define NFS4ERR_BADTYPE 10007
#define NFS4ERR_DELAY 10008
#define NFS4ERR_SAME 10009
#define NFS4ERR_DENIED 10010
#define NFS4ERR_EXPIRED 10011
#define NFS4ERR_LOCKED 10012
#define NFS4ERR_GRACE 10013
#define NFS4ERR_FHEXPIRED 10014
#define NFS4ERR_SHARE_DENIED 10015
#define NFS4ERR_WRONGSEC 10016
#define NFS4ERR_CLID_INUSE 10017
#define NFS4ERR_RESOURCE 10018
#define NFS4ERR_MOVED 10019
#define NFS4ERR_NOFILEHANDLE 10020
#define NFS4ERR_MINOR_VERS_MISMATCH 10021
#define NFS4ERR_STALE_CLIENTID 10022
#define NFS4ERR_STALE_STATEID 10023
#define NFS4ERR_OLD_STATEID 10024
#define NFS4ERR_BAD_STATEID 10025
#define NFS4ERR_BAD_SEQID 10026
#define NFS4ERR_NOT_SAME 10027
#define NFS4ERR_LOCK_RANGE 10028
#define NFS4ERR_SYMLINK 10029
#define NFS4ERR_RESTOREFH 10030
#define NFS4ERR_LEASE_MOVED 10031
#define NFS4ERR_ATTRNOTSUPP 10032
#define NFS4ERR_NO_GRACE 10033
#define NFS4ERR_RECLAIM_BAD 10034
#define NFS4ERR_RECLAIM_CONFLICT 10035
#define NFS4ERR_BADXDR 10036
#define NFS4ERR_LOCKS_HELD 10037
#define NFS4ERR_OPENMODE 10038
#define NFS4ERR_BADOWNER 10039
#define NFS4ERR_BADCHAR 10040
#define NFS4ERR_BADNAME 10041
#define NFS4ERR_BAD_RANGE 10042
#define NFS4ERR_LOCK_NOTSUPP 10043
#define NFS4ERR_OP_ILLEGAL 10044
#define NFS4ERR_DEADLOCK 10045
#define NFS4ERR_FILE_OPEN 10046
#define NFS4ERR_ADMIN_REVOKED 10047
#define NFS4ERR_CB_PATH_DOWN 10048

/* RFC 8881 NFSv4.1 */
#define NFS4ERR_BADIOMODE 10049
#define NFS4ERR_BADLAYOUT 10050
#define NFS4ERR_BAD_SESSION_DIGEST 10051
#define NFS4ERR_BADSESSION 10052
#define NFS4ERR_BADSLOT 10053
#define NFS4ERR_COMPLETE_ALREADY 10054
#define NFS4ERR_CONN_NOT_BOUND_TO_SESSION 10055
#define NFS4ERR_DELEG_ALREADY_WANTED 10056
#define NFS4ERR_BACK_CHAN_BUSY 10057
#define NFS4ERR_LAYOUTTRYLATER 10058
#define NFS4ERR_LAYOUTUNAVAILABLE 10059
#define NFS4ERR_NOMATCHING_LAYOUT 10060
#define NFS4ERR_RECALLCONFLICT 10061
#define NFS4ERR_UNKNOWN_LAYOUTTYPE 10062
#define NFS4ERR_SEQ_MISORDERED 10063
#define NFS4ERR_SEQUENCE_POS 10064
#define NFS4ERR_REQ_TOO_BIG 10065
#define NFS4ERR_REP_TOO_BIG 10066
#define NFS4ERR_REP_TOO_BIG_TO_CACHE 10067
#define NFS4ERR_RETRY_UNCACHED_REP 10068
#define NFS4ERR_UNSAFE_COMPOUND 10069
#define NFS4ERR_TOO_MANY_OPS 10070
#define NFS4ERR_OP_NOT_IN_SESSION 10071
#define NFS4ERR_HASH_ALG_UNSUPP 10072
#define NFS4ERR_CLIENTID_BUSY 10074
#define NFS4ERR_PNFS_IO_HOLE 10075
#define NFS4ERR_SEQ_FALSE_RETRY 10076
#define NFS4ERR_BAD_HIGH_SLOT 10077
#define NFS4ERR_DEADSESSION 10078
#define NFS4ERR_ENCR_ALG_UNSUPP 10079
#define NFS4ERR_PNFS_NO_LAYOUT 10080
#define NFS4ERR_NOT_ONLY_OP 10081
#define NFS4ERR_WRONG_CRED 10082
#define NFS4ERR_WRONG_TYPE 10083
#define NFS4ERR_DIRDELEG_UNAVAIL 10084
#define NFS4ERR_REJECT_DELEG 10085
#define NFS4ERR_RETURNCONFLICT 10086
#define NFS4ERR_DELEG_REVOKED 10087

/* RFC 7862 NFSv4.2 */
#define NFS4ERR_PARTNER_NOTSUPP 10088
#define NFS4ERR_PARTNER_NO_AUTH 10089
#define NFS4ERR_UNION_NOTSUPP 10090
#define NFS4ERR_OFFLOAD_DENIED 10091
#define NFS4ERR_WRONG_LFS 10092
#define NFS4ERR_BADLABEL 10093
#define NFS4ERR_OFFLOAD_NO_REQS 10094
177 changes: 154 additions & 23 deletions print-nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,133 @@ static int xid_map_find(netdissect_options *, const struct sunrpc_msg *, const u
static void interp_reply(netdissect_options *, const struct sunrpc_msg *, uint32_t, uint32_t, int);
static const uint32_t *parse_post_op_attr(netdissect_options *, const uint32_t *, int);

/*
* NFS Version 4 Procedures.
*/
static const struct tok nfsv4proc_str[] = {
{ NFSV4PROC_NULL, "null" },
{ NFSV4PROC_COMPOUND, "compound" },
{ 0, NULL }
};

static const struct tok status2strv4[] = {
/* RFC 7530 NFSv4 */
{ NFS4_OK, "NFS4_OK" },
{ NFS4ERR_PERM, "NFS4ERR_PERM" },
{ NFS4ERR_NOENT, "NFS4ERR_NOENT" },
{ NFS4ERR_IO, "NFS4ERR_IO" },
{ NFS4ERR_NXIO, "NFS4ERR_NXIO" },
{ NFS4ERR_ACCESS, "NFS4ERR_ACCESS" },
{ NFS4ERR_EXIST, "NFS4ERR_EXIST" },
{ NFS4ERR_XDEV, "NFS4ERR_XDEV" },
{ NFS4ERR_NOTDIR, "NFS4ERR_NOTDIR" },
{ NFS4ERR_ISDIR, "NFS4ERR_ISDIR" },
{ NFS4ERR_INVAL, "NFS4ERR_INVAL" },
{ NFS4ERR_FBIG, "NFS4ERR_FBIG" },
{ NFS4ERR_NOSPC, "NFS4ERR_NOSPC" },
{ NFS4ERR_ROFS, "NFS4ERR_ROFS" },
{ NFS4ERR_MLINK, "NFS4ERR_MLINK" },
{ NFS4ERR_NAMETOOLONG, "NFS4ERR_NAMETOOLONG" },
{ NFS4ERR_NOTEMPTY, "NFS4ERR_NOTEMPTY" },
{ NFS4ERR_DQUOT, "NFS4ERR_DQUOT" },
{ NFS4ERR_STALE, "NFS4ERR_STALE" },
{ NFS4ERR_BADHANDLE, "NFS4ERR_BADHANDLE" },
{ NFS4ERR_BAD_COOKIE, "NFS4ERR_BAD_COOKIE" },
{ NFS4ERR_NOTSUPP, "NFS4ERR_NOTSUPP" },
{ NFS4ERR_TOOSMALL, "NFS4ERR_TOOSMALL" },
{ NFS4ERR_SERVERFAULT, "NFS4ERR_SERVERFAULT" },
{ NFS4ERR_BADTYPE, "NFS4ERR_BADTYPE" },
{ NFS4ERR_DELAY, "NFS4ERR_DELAY" },
{ NFS4ERR_SAME, "NFS4ERR_SAME" },
{ NFS4ERR_DENIED, "NFS4ERR_DENIED" },
{ NFS4ERR_EXPIRED, "NFS4ERR_EXPIRED" },
{ NFS4ERR_LOCKED, "NFS4ERR_LOCKED" },
{ NFS4ERR_GRACE, "NFS4ERR_GRACE" },
{ NFS4ERR_FHEXPIRED, "NFS4ERR_FHEXPIRED" },
{ NFS4ERR_SHARE_DENIED, "NFS4ERR_SHARE_DENIED" },
{ NFS4ERR_WRONGSEC, "NFS4ERR_WRONGSEC" },
{ NFS4ERR_CLID_INUSE, "NFS4ERR_CLID_INUSE" },
{ NFS4ERR_RESOURCE, "NFS4ERR_RESOURCE" },
{ NFS4ERR_MOVED, "NFS4ERR_MOVED" },
{ NFS4ERR_NOFILEHANDLE, "NFS4ERR_NOFILEHANDLE" },
{ NFS4ERR_MINOR_VERS_MISMATCH, "NFS4ERR_MINOR_VERS_MISMATCH" },
{ NFS4ERR_STALE_CLIENTID, "NFS4ERR_STALE_CLIENTID" },
{ NFS4ERR_STALE_STATEID, "NFS4ERR_STALE_STATEID" },
{ NFS4ERR_OLD_STATEID, "NFS4ERR_OLD_STATEID" },
{ NFS4ERR_BAD_STATEID, "NFS4ERR_BAD_STATEID" },
{ NFS4ERR_BAD_SEQID, "NFS4ERR_BAD_SEQID" },
{ NFS4ERR_NOT_SAME, "NFS4ERR_NOT_SAME" },
{ NFS4ERR_LOCK_RANGE, "NFS4ERR_LOCK_RANGE" },
{ NFS4ERR_SYMLINK, "NFS4ERR_SYMLINK" },
{ NFS4ERR_RESTOREFH, "NFS4ERR_RESTOREFH" },
{ NFS4ERR_LEASE_MOVED, "NFS4ERR_LEASE_MOVED" },
{ NFS4ERR_ATTRNOTSUPP, "NFS4ERR_ATTRNOTSUPP" },
{ NFS4ERR_NO_GRACE, "NFS4ERR_NO_GRACE" },
{ NFS4ERR_RECLAIM_BAD, "NFS4ERR_RECLAIM_BAD" },
{ NFS4ERR_RECLAIM_CONFLICT, "NFS4ERR_RECLAIM_CONFLICT" },
{ NFS4ERR_BADXDR, "NFS4ERR_BADXDR" },
{ NFS4ERR_LOCKS_HELD, "NFS4ERR_LOCKS_HELD" },
{ NFS4ERR_OPENMODE, "NFS4ERR_OPENMODE" },
{ NFS4ERR_BADOWNER, "NFS4ERR_BADOWNER" },
{ NFS4ERR_BADCHAR, "NFS4ERR_BADCHAR" },
{ NFS4ERR_BADNAME, "NFS4ERR_BADNAME" },
{ NFS4ERR_BAD_RANGE, "NFS4ERR_BAD_RANGE" },
{ NFS4ERR_LOCK_NOTSUPP, "NFS4ERR_LOCK_NOTSUPP" },
{ NFS4ERR_OP_ILLEGAL, "NFS4ERR_OP_ILLEGAL" },
{ NFS4ERR_DEADLOCK, "NFS4ERR_DEADLOCK" },
{ NFS4ERR_FILE_OPEN, "NFS4ERR_FILE_OPEN" },
{ NFS4ERR_ADMIN_REVOKED, "NFS4ERR_ADMIN_REVOKED" },
{ NFS4ERR_CB_PATH_DOWN, "NFS4ERR_CB_PATH_DOWN" },
/* RFC 8881 NFSv4.1 */
{ NFS4ERR_BADIOMODE, "NFS4ERR_BADIOMODE" },
{ NFS4ERR_BADLAYOUT, "NFS4ERR_BADLAYOUT" },
{ NFS4ERR_BAD_SESSION_DIGEST, "NFS4ERR_BAD_SESSION_DIGEST" },
{ NFS4ERR_BADSESSION, "NFS4ERR_BADSESSION" },
{ NFS4ERR_BADSLOT, "NFS4ERR_BADSLOT" },
{ NFS4ERR_COMPLETE_ALREADY, "NFS4ERR_COMPLETE_ALREADY" },
{ NFS4ERR_CONN_NOT_BOUND_TO_SESSION, "NFS4ERR_CONN_NOT_BOUND_TO_SESSION" },
{ NFS4ERR_DELEG_ALREADY_WANTED, "NFS4ERR_DELEG_ALREADY_WANTED" },
{ NFS4ERR_BACK_CHAN_BUSY, "NFS4ERR_BACK_CHAN_BUSY" },
{ NFS4ERR_LAYOUTTRYLATER, "NFS4ERR_LAYOUTTRYLATER" },
{ NFS4ERR_LAYOUTUNAVAILABLE, "NFS4ERR_LAYOUTUNAVAILABLE" },
{ NFS4ERR_NOMATCHING_LAYOUT, "NFS4ERR_NOMATCHING_LAYOUT" },
{ NFS4ERR_RECALLCONFLICT, "NFS4ERR_RECALLCONFLICT" },
{ NFS4ERR_UNKNOWN_LAYOUTTYPE, "NFS4ERR_UNKNOWN_LAYOUTTYPE" },
{ NFS4ERR_SEQ_MISORDERED, "NFS4ERR_SEQ_MISORDERED" },
{ NFS4ERR_SEQUENCE_POS, "NFS4ERR_SEQUENCE_POS" },
{ NFS4ERR_REQ_TOO_BIG, "NFS4ERR_REQ_TOO_BIG" },
{ NFS4ERR_REP_TOO_BIG, "NFS4ERR_REP_TOO_BIG" },
{ NFS4ERR_REP_TOO_BIG_TO_CACHE, "NFS4ERR_REP_TOO_BIG_TO_CACHE" },
{ NFS4ERR_RETRY_UNCACHED_REP, "NFS4ERR_RETRY_UNCACHED_REP" },
{ NFS4ERR_UNSAFE_COMPOUND, "NFS4ERR_UNSAFE_COMPOUND" },
{ NFS4ERR_TOO_MANY_OPS, "NFS4ERR_TOO_MANY_OPS" },
{ NFS4ERR_OP_NOT_IN_SESSION, "NFS4ERR_OP_NOT_IN_SESSION" },
{ NFS4ERR_HASH_ALG_UNSUPP, "NFS4ERR_HASH_ALG_UNSUPP" },
{ NFS4ERR_CLIENTID_BUSY, "NFS4ERR_CLIENTID_BUSY" },
{ NFS4ERR_PNFS_IO_HOLE, "NFS4ERR_PNFS_IO_HOLE" },
{ NFS4ERR_SEQ_FALSE_RETRY, "NFS4ERR_SEQ_FALSE_RETRY" },
{ NFS4ERR_BAD_HIGH_SLOT, "NFS4ERR_BAD_HIGH_SLOT" },
{ NFS4ERR_DEADSESSION, "NFS4ERR_DEADSESSION" },
{ NFS4ERR_ENCR_ALG_UNSUPP, "NFS4ERR_ENCR_ALG_UNSUPP" },
{ NFS4ERR_PNFS_NO_LAYOUT, "NFS4ERR_PNFS_NO_LAYOUT" },
{ NFS4ERR_NOT_ONLY_OP, "NFS4ERR_NOT_ONLY_OP" },
{ NFS4ERR_WRONG_CRED, "NFS4ERR_WRONG_CRED" },
{ NFS4ERR_WRONG_TYPE, "NFS4ERR_WRONG_TYPE" },
{ NFS4ERR_DIRDELEG_UNAVAIL, "NFS4ERR_DIRDELEG_UNAVAIL" },
{ NFS4ERR_REJECT_DELEG, "NFS4ERR_REJECT_DELEG" },
{ NFS4ERR_RETURNCONFLICT, "NFS4ERR_RETURNCONFLICT" },
{ NFS4ERR_DELEG_REVOKED, "NFS4ERR_DELEG_REVOKED" },
/* RFC 7862 NFSv4.2 */
{ NFS4ERR_PARTNER_NOTSUPP, "NFS4ERR_PARTNER_NOTSUPP" },
{ NFS4ERR_PARTNER_NO_AUTH, "NFS4ERR_PARTNER_NO_AUTH" },
{ NFS4ERR_UNION_NOTSUPP, "NFS4ERR_UNION_NOTSUPP" },
{ NFS4ERR_OFFLOAD_DENIED, "NFS4ERR_OFFLOAD_DENIED" },
{ NFS4ERR_WRONG_LFS, "NFS4ERR_WRONG_LFS" },
{ NFS4ERR_BADLABEL, "NFS4ERR_BADLABEL" },
{ NFS4ERR_OFFLOAD_NO_REQS, "NFS4ERR_OFFLOAD_NO_REQS" },
{ 0, NULL }
};

/*
* Mapping of old NFS Version 2 RPC numbers to generic numbers.
*/
Expand Down Expand Up @@ -572,15 +699,7 @@ nfsreq_noaddr_print(netdissect_options *ndo,
proc = GET_BE_U_4(&rp->rm_call.cb_proc);

if (GET_BE_U_4(&rp->rm_call.cb_vers) == NFS_VER4) {
ND_PRINT(" v4");
switch (proc) {
case 0:
ND_PRINT(" null");
break;
case 1:
ND_PRINT(" compound");
break;
}
ND_PRINT(" v4 %s", tok2str(nfsv4proc_str, "proc-%u", proc));
return;
}

Expand Down Expand Up @@ -1131,6 +1250,24 @@ parsestatus(netdissect_options *ndo,
return (dp + 1);
}

static const uint32_t *
parsestatusv4(netdissect_options *ndo,
const uint32_t *dp, u_int *er, int *nfserrp)
{
u_int errnum;

errnum = GET_BE_U_4(dp);
if (er)
*er = errnum;
if (errnum != NFS4_OK) {
if (!ndo->ndo_qflag)
ND_PRINT(" ERROR: %s",
tok2str(status2strv4, "unk %u", errnum));
*nfserrp = 1;
}
return (dp + 1);
}

static const uint32_t *
parsefattr(netdissect_options *ndo,
const uint32_t *dp, int verbose, int v3)
Expand Down Expand Up @@ -1553,21 +1690,15 @@ interp_reply(netdissect_options *ndo,
int nfserr = 0;

if (vers == NFS_VER4) {
ND_PRINT(" v4");
switch (proc) {
case 0:
ND_PRINT(" null");
break;
case 1:
ND_PRINT(" compound");
break;
ND_PRINT(" v4 %s", tok2str(nfsv4proc_str, "proc-%u", proc));
if (proc == NFSV4PROC_COMPOUND) {
dp = parserep(ndo, rp, length, &nfserr);
if (dp == NULL)
goto trunc;
dp = parsestatusv4(ndo, dp, &er, &nfserr);
if (dp == NULL)
goto trunc;
}
dp = parserep(ndo, rp, length, &nfserr);
if (dp == NULL)
goto trunc;
dp = parsestatus(ndo, dp, &er, &nfserr);
if (dp == NULL)
goto trunc;
return;
}

Expand Down
12 changes: 6 additions & 6 deletions tests/nfs-v4.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 08:48:53.854625 IP 192.168.200.177.671 > 192.168.200.1.2049: Flags [P.], seq 1022539785:1022539969, ack 556520858, win 1592, options [nop,nop,TS val 1549792688 ecr 1201363416], length 184: NFS request xid 1209063269 180 v4 compound
2 08:48:53.855103 IP 192.168.200.1.2049 > 192.168.200.177.671: Flags [P.], seq 1:173, ack 184, win 1064, options [nop,nop,TS val 1201382193 ecr 1549792688], length 172: NFS reply xid 1209063269 reply ok 168 v4 compound
3 08:48:53.855178 IP 192.168.200.177.671 > 192.168.200.1.2049: Flags [.], ack 173, win 1615, options [nop,nop,TS val 1549792689 ecr 1201382193], length 0
4 08:48:53.855490 IP 192.168.200.177.671 > 192.168.200.1.2049: Flags [P.], seq 184:376, ack 173, win 1615, options [nop,nop,TS val 1549792689 ecr 1201382193], length 192: NFS request xid 1225840485 188 v4 compound
5 08:48:53.855747 IP 192.168.200.1.2049 > 192.168.200.177.671: Flags [P.], seq 173:273, ack 376, win 1078, options [nop,nop,TS val 1201382194 ecr 1549792689], length 100: NFS reply xid 1225840485 reply ok 96 v4 compound ERROR: No such file or directory
6 08:48:53.896607 IP 192.168.200.177.671 > 192.168.200.1.2049: Flags [.], ack 273, win 1615, options [nop,nop,TS val 1549792730 ecr 1201382194], length 0
1 06:39:25.778133 IP 192.168.200.198.857 > 192.168.200.1.2049: Flags [P.], seq 3806116338:3806116382, ack 3240065782, win 229, options [nop,nop,TS val 190691472 ecr 193176172], length 44: NFS request xid 1710309038 40 v4 null
2 06:39:25.778431 IP 192.168.200.1.2049 > 192.168.200.198.857: Flags [P.], seq 1:29, ack 44, win 227, options [nop,nop,TS val 193176172 ecr 190691472], length 28: NFS reply xid 1710309038 reply ok 24 v4 null
3 06:39:25.778791 IP 192.168.200.198.857 > 192.168.200.1.2049: Flags [P.], seq 44:284, ack 29, win 229, options [nop,nop,TS val 190691473 ecr 193176172], length 240: NFS request xid 1727086254 236 v4 compound
4 06:39:25.778965 IP 192.168.200.1.2049 > 192.168.200.198.857: Flags [P.], seq 29:133, ack 284, win 235, options [nop,nop,TS val 193176173 ecr 190691473], length 104: NFS reply xid 1727086254 reply ok 100 v4 compound
5 06:39:35.254619 IP 192.168.200.198.857 > 192.168.200.1.2049: Flags [P.], seq 3584:3776, ack 3801, win 371, options [nop,nop,TS val 190700949 ecr 193185649], length 192: NFS request xid 2079407790 188 v4 compound
6 06:39:35.254792 IP 192.168.200.1.2049 > 192.168.200.198.857: Flags [P.], seq 3801:3901, ack 3776, win 411, options [nop,nop,TS val 193185649 ecr 190700949], length 100: NFS reply xid 2079407790 reply ok 96 v4 compound ERROR: NFS4ERR_NOENT
Binary file modified tests/nfs-v4.pcap
Binary file not shown.

0 comments on commit ab18945

Please sign in to comment.