# nfs — Port 2049 ONC RPC Record-Marking & NFSv4 COMPOUND (`nfs`)

> **FrameAssembly v3.2.2** · Protocol 68 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/nfs

- **Full Protocol Name:** Network File System over ONC RPC
- **Keyword:** `nfs`
- **OSI Layer & Transport:** Layer 7 · TCP 2049 (or UDP 2049 via transport udp)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 7530, RFC 8881, RFC 1813
- **Wireshark Display Filter:** `nfs || rpc`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 2049 (or UDP 2049 via transport udp) (transport tcp|udp) -> NFSv3 / v4`

## Overview

Verify storage-VLAN segmentation on port `2049`: over default TCP, FrameAssembly automatically prepends the 4-byte ONC RPC Record-Marking fragment header (`0x80000000 | len`) so Wireshark dissects NFSv4 `COMPOUND` calls cleanly.

Network File System (`nfs`, RFC 7530 / RFC 1813) mounts shared NAS volumes across Linux, VMware ESXi, and Kubernetes nodes on **port `2049`** (ONC RPC Program `100003`). Unlike legacy NFSv3 setups requiring separate portmapper ports, modern **NFSv4** (`vers 4`, default) consolidates mounting, locking, and file operations inside single `compound` RPC calls over **TCP port `2049`** (with `transport udp` available for UDP `2049` legacy tests).

FrameAssembly builds the ONC RPC v2 Call/Reply header (including the 4-byte Last-Fragment Record Marking header over TCP), XDR-padded UTF-8 `tag` and export `path` strings, and NFSv4 `PUTFH` / `LOOKUP` operations automatically.

## Minimal Quickstart (`nfs_quickstart.frasm`)

```frameassembly
host esxi_node { ip 10.40.10.21 }
host nas_filer { ip 10.40.10.100 }

compile {
    esxi_node -> nas_filer tcp syn srcport 892 dstport 2049 wait 1ms
    esxi_node <- nas_filer tcp syn ack wait 1ms
    esxi_node -> nas_filer tcp ack wait 1ms
    esxi_node -> nas_filer nfs vers 4 compound xid 0x55001122 tag "lookup-datastore" path "/vol/vmstore01"
}
```

### Automatic Wire Calculations

- Defaults to TCP destination port `2049` (`vers 4`, RPC Program `100003`) and prepends the 4-byte ONC RPC Record Marking header (`0x80000000 | length`) over TCP (omitting it cleanly when `transport udp` is selected).
- Aligns `tag` and `path` UTF-8 strings to 4-byte XDR boundaries per RFC 4506.
- Uses privileged client ports easily (`srcport 892`) when testing `root_squash` / `insecure` NFS export rules.

## Practical Lab Example: NFSv4 TCP 2049 Export Lookup + Legacy NFSv3 UDP Probe (`nfs_storage_audit.frasm`)

Opens TCP port 2049 from a privileged source port (`srcport 850`) to mount `/exports/backups`, then tests a legacy NFSv3 `NULL` ping over UDP 2049.

```frameassembly
host worker_01 { ip 172.16.40.25 }
host netapp_01 { ip 172.16.40.200 }

compile {
    // 1. Stateful NFSv4 COMPOUND over TCP 2049 from privileged port 850 (< 1024)
    worker_01 -> netapp_01 tcp syn srcport 850 dstport 2049 win 65535 mss 1460 wait 1ms
    worker_01 <- netapp_01 tcp syn ack win 65535 mss 1460 wait 1ms
    worker_01 -> netapp_01 tcp ack wait 1ms
    worker_01 -> netapp_01 nfs vers 4 compound xid 0x7001 tag "mount-backups" path "/exports/backups" wait 3ms
    // 2. Legacy NFSv3 NULL RPC check over UDP 2049
    worker_01 -> netapp_01 nfs vers 3 proc "NULL" xid 0x7002 transport udp
}
```

```bash
# 1. Eyeball relative timestamps, ports & wire lengths in your terminal
frameassembly show nfs_storage_audit.frasm

# 2. Compile .frasm -> classic .pcap (tcpdump/tcpreplay/Suricata) or nanosecond .pcapng
frameassembly nfs_storage_audit.frasm nfs_storage_audit.pcap
frameassembly nfs_storage_audit.frasm nfs_storage_audit.pcapng

# 3. Round-trip .pcap <-> .frasm whenever you want to scrub or tweak an existing capture
frameassembly reverse nfs_storage_audit.pcap nfs_storage_audit_edited.frasm

# 4. Verify dissected protocol fields in tshark
tshark -r nfs_storage_audit.pcap
```

## All `nfs` Keywords & Header Options

Packet line pattern: `src_host -> dst_host nfs [vers <3|4>] [compound | proc "<text>"] [tag "<text>"] [path "<text>"] [xid <hex_or_num>] [transport <tcp|udp>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `vers <3\|4>` | NFS protocol version (`4` default, or `3`) | `4` | Sets the ONC RPC Program Version (`4` or `3`) for Program `100003`. |
| `compound \| proc "<text>"` | `compound` or procedure name (`"NULL"`, `"GETATTR"`, `"LOOKUP"`, `"READ"`, `"WRITE"`) | `compound` | Selects RPC procedure `1` (`COMPOUND` on NFSv4) or named NFSv3/v4 procedure. |
| `tag "<text>" \| path "<text>"` | Quoted NFSv4 compound tag and export path | `tag "fa", path "/export"` | Encodes XDR length-prefixed `tag` and `LOOKUP` component path inside NFSv4 `COMPOUND`. |
| `xid <hex_or_num>` | 32-bit ONC RPC Transaction ID | `0x12345678` | Sets the 4-byte RPC `XID` matching RPC replies to calls. |
| `transport <tcp\|udp>` | `tcp` or `udp` | `tcp` | Switches between TCP `2049` (with 4-byte RPC record mark) and UDP `2049`. |

## Cross-Layer Options Valid with `nfs`

| Option | Range / Format | Default | Effect |
| --- | --- | --- | --- |
| `wait <number><ns\|us\|ms\|s\|m>` | Time gap (ns, us, ms, s, m) | `10ms` | Advances the packet timestamp clock after sending this packet and before the next packet (`wait 0ns` sends back-to-back). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"` or `"de:ad:be:ef"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType u16 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or 16-bit EtherType for this single packet. |
| `vlan <0..4095> [pcp <0..7>] [dei <0\|1>]` | VLAN ID 0..4095, PCP 0..7, DEI 0..1 | `Untagged` | Wraps the packet in an IEEE 802.1Q VLAN tag (`0x8100`) with optional 802.1p QoS priority. |
| `qinq <0..4095> [innervlan <0..4095>]` | Outer S-VLAN 0..4095, Inner C-VLAN 0..4095 | `Untagged (innervlan 1 when qinq is set)` | Double-tags the packet with outer IEEE 802.1ad S-Tag (`0x88a8`) plus inner IEEE 802.1Q C-Tag (`0x8100`). |
| `mpls <0..1048575> [label <0..1048575>] [exp\|tc <0..7>] [bos <0\|1>] [mplsttl <0..255>]` | Label 0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255 | `Unlabeled (at most 1 mpls tag per packet)` | Inserts a 32-bit MPLS label header (`0x8847`) ahead of the Layer 3 header. |
| `ttl <0..255> [dscp <0..63>] [ecn <0..3>]` | TTL/Hop Limit 0..255, DSCP 0..63, ECN 0..3 | `ttl 64, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `ipid <0..65535> [df] [mf] [fragoffset <0..8191>]` | IPv4 ID, DF/MF flags, fragment offset 0..8191 | `ipid 1, flags 0, fragoffset 0` | Sets IPv4 Identification, Do-Not-Fragment (`df`), More-Fragments (`mf`), and fragment offset (ignored over IPv6). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (ignored when running over IPv4 hosts). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 2049 (or UDP 2049 via transport udp)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport <tcp\|udp>` | `tcp` or `udp` (supported on 9 dual-L4 protocols) | `transport tcp` | Switches Layer 4 transport between TCP (`psh ack` + length framing where required) and UDP. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window size, flags & RFC 7323 options | `psh ack, win 65535, automatic TCP seq/acknum` | When using TCP (`transport tcp` or default TCP): overrides automatic TCP sequence tracking, flags, or `mss`/`wscale`/`sackperm`/`tsval`/`tsecr`. |

## Common Mistakes & Quick Fixes

### NFS Defaults to TCP (Unlike DNS/Syslog Which Default to UDP)

- **Valid v3.2.2 Syntax:** `worker_01 -> netapp_01 nfs vers 3 proc "NULL" transport udp`

`nfs` defaults to `transport tcp` on port `2049` because RFC 7530 NFSv4 mandates TCP; add `transport udp` explicitly when testing UDP.
