Skip to content
sahlbergPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unfs4 - a minimal NFSv4.0 client
================================

The sibling of usmb2: the same API shape, the same feature flags and the
same tiny TCP hooks, but for NFS instead of SMB2. It aims at minimal code
and data size for retro targets.

Why NFSv4.0
-----------
NFSv3 needs three protocols (portmapper, MOUNT and NFS). NFSv4 is one
program on TCP port 2049, and the export is reached with PUTROOTFH and
LOOKUPs. NFSv4.1 would need EXCHANGE_ID, CREATE_SESSION and a SEQUENCE in
every request; NFSv4.0 lets us keep no state at all.

How it stays stateless
----------------------
* Credentials are AUTH_SYS with a fixed uid and gid. No authentication.
* Every request is one COMPOUND that starts from the export: PUTFH, a
  LOOKUP per path component, then the operation.
* A "file handle" is the NFS filehandle (XDR opaque, up to UNFS4_MAX_FH
  bytes). Opening a file is LOOKUP and GETFH; closing it is free().
* READ and WRITE use the anonymous stateid, so there is no OPEN, no
  SETCLIENTID and no lease to renew. WRITE is FILE_SYNC, so no COMMIT.
* Only creating a regular file needs an OPEN (UNFS4_FEATURE_CREATE):
  SETCLIENTID, then SETCLIENTID_CONFIRM + OPEN in one request, then
  GETFH + OPEN_CONFIRM + CLOSE. Nothing stays open afterwards.

Server requirements
-------------------
* NFSv4.0 enabled (cat /proc/fs/nfsd/versions on Linux shows +4.0).
* With the sockets API the client uses an ordinary port above 1023, so a
  Linux export needs the "insecure" option.
* The Windows NFS server only does 4.1 and will not work.

Features
--------
See unfs4.h. unfs4_open() with O_CREAT creates the file, it does not
truncate an existing one. unfs4_rename() replaces an existing target.
readdir does not return "." and "..".

Testing
-------
  make
  ./unfs4-test <server-ip> <export> [file-to-cat]

It lists the export, then works in a scratch directory unfs4-test.<pid>.
Passes against Linux knfsd (localhost:/data and nfs-server-1:/home/nfsshare).

unfs4-cat-host runs unfs4 on usmb2's tiny TCP/IP stack, with
UNFS4_FEATURE_TINY_TCP and UNFS4_FEATURE_REASSEMBLY as Neutrino builds it,
on raw sockets. It needs CAP_NET_RAW and the kernel's RSTs for the
connection dropped, which a pasta namespace gives without root; the
gateway address reaches the host:

  make unfs4-cat-host USMB2_DIR=../usmb2
  pasta --config-net -- sh -c '
    nft add table ip f
    nft add chain ip f out "{ type filter hook output priority 0; }"
    nft add rule ip f out tcp dport 2049 tcp flags rst drop
    ./unfs4-cat-host <gateway-ip> <export> <dir> <file> > out'

It lists <dir> and reads <file> 2048 bytes at a time. Passes against
Linux knfsd with a 1 MB file.

  make size
shows the code size of the client with no features and with all of them.

Licence
-------
BSD 2-Clause, see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages