|
| 1 | +# NFSv3 TCP Server Demo |
| 2 | + |
| 3 | +This demo shows how to create a simple NFSv3 server that listens on a TCP socket and decodes incoming NFSv3 packets. |
| 4 | + |
| 5 | +## What it does |
| 6 | + |
| 7 | +1. Starts a TCP server on `127.0.0.1:2049` (default NFS port) |
| 8 | +2. Accepts incoming connections |
| 9 | +3. Receives TCP data and prints it in hexadecimal format |
| 10 | +4. Decodes RPC record marking (RM) frames |
| 11 | +5. Decodes RPC call messages |
| 12 | +6. Decodes NFSv3 procedure calls |
| 13 | +7. Pretty-prints all decoded information to the console |
| 14 | + |
| 15 | +## Running the demo |
| 16 | + |
| 17 | +```bash |
| 18 | +# Build the project first |
| 19 | +npm run build |
| 20 | + |
| 21 | +# Run the demo |
| 22 | +node lib/nfs/v3/__demos__/tcp-server.js |
| 23 | +``` |
| 24 | + |
| 25 | +Or run directly with ts-node: |
| 26 | + |
| 27 | +```bash |
| 28 | +npx ts-node src/nfs/v3/__demos__/tcp-server.ts |
| 29 | +``` |
| 30 | + |
| 31 | +## Testing the server |
| 32 | + |
| 33 | +You can test the server using various methods: |
| 34 | + |
| 35 | +### Using the included test client |
| 36 | + |
| 37 | +First, start the server in one terminal: |
| 38 | + |
| 39 | +```bash |
| 40 | +npx ts-node src/nfs/v3/__demos__/tcp-server.ts |
| 41 | +``` |
| 42 | + |
| 43 | +Then, in another terminal, run the test client: |
| 44 | + |
| 45 | +```bash |
| 46 | +npx ts-node src/nfs/v3/__demos__/tcp-client.ts |
| 47 | +``` |
| 48 | + |
| 49 | +The test client will send a GETATTR request to the server, and you'll see the decoded output in the server terminal. |
| 50 | + |
| 51 | +### Using a real NFS client |
| 52 | + |
| 53 | +```bash |
| 54 | +# Mount the NFS server (will likely fail since we only decode, not respond) |
| 55 | +mount -t nfs -o vers=3,tcp 127.0.0.1:/ /mnt/test |
| 56 | +``` |
| 57 | + |
| 58 | +### Using netcat to send raw data |
| 59 | + |
| 60 | +```bash |
| 61 | +# Send raw bytes to test the decoder |
| 62 | +echo -n "80000028000000010000000200000003000000010000000000000000000000000000000000000008010203040506" | xxd -r -p | nc 127.0.0.1 2049 |
| 63 | +``` |
| 64 | + |
| 65 | +## Output Example |
| 66 | + |
| 67 | +When a client connects and sends data, you'll see output like: |
| 68 | + |
| 69 | +``` |
| 70 | +13:53 $ npx ts-node src/nfs/v3/__demos__/tcp-server.ts |
| 71 | +NFSv3 TCP Server listening on 127.0.0.1:2049 |
| 72 | +Waiting for connections... |
| 73 | +
|
| 74 | +[2025-10-08T11:53:14.082Z] Client connected from 127.0.0.1:59751 |
| 75 | +
|
| 76 | +================================================================================ |
| 77 | +[2025-10-08T11:53:14.084Z] Received 56 bytes |
| 78 | +HEX: 80000034000030390000000000000002000186a3000000030000000100000000000000000000000000000000000000080102030405060708 |
| 79 | +-------------------------------------------------------------------------------- |
| 80 | +
|
| 81 | +RPC Record (52 bytes): |
| 82 | +HEX: 000030390000000000000002000186a3000000030000000100000000000000000000000000000000000000080102030405060708 |
| 83 | +
|
| 84 | +RPC Message: |
| 85 | +RpcCallMessage { |
| 86 | + xid: 12345, |
| 87 | + rpcvers: 2, |
| 88 | + prog: 100003, |
| 89 | + vers: 3, |
| 90 | + proc: 1, |
| 91 | + cred: RpcOpaqueAuth { |
| 92 | + flavor: 0, |
| 93 | + body: Reader { uint8: Uint8Array(0) [], view: [DataView], x: 0, end: 0 } |
| 94 | + }, |
| 95 | + verf: RpcOpaqueAuth { |
| 96 | + flavor: 0, |
| 97 | + body: Reader { uint8: Uint8Array(0) [], view: [DataView], x: 0, end: 0 } |
| 98 | + }, |
| 99 | + params: Reader { |
| 100 | + uint8: Uint8Array(16384) [ |
| 101 | + 128, 0, 0, 52, 0, 0, 48, 57, 0, 0, 0, 0, |
| 102 | + 0, 0, 0, 2, 0, 1, 134, 163, 0, 0, 0, 3, |
| 103 | + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, |
| 104 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, |
| 105 | + 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, |
| 106 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 107 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 108 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
| 109 | + 0, 0, 0, 0, |
| 110 | + ... 16284 more items |
| 111 | + ], |
| 112 | + view: DataView { |
| 113 | + byteLength: 16384, |
| 114 | + byteOffset: 0, |
| 115 | + buffer: [ArrayBuffer] |
| 116 | + }, |
| 117 | + x: 44, |
| 118 | + end: 56 |
| 119 | + } |
| 120 | +} |
| 121 | +
|
| 122 | +NFS Procedure: GETATTR |
| 123 | +
|
| 124 | +NFS Message: |
| 125 | +Nfsv3GetattrRequest { |
| 126 | + object: Nfsv3Fh { |
| 127 | + data: Reader { uint8: [Uint8Array], view: [DataView], x: 0, end: 8 } |
| 128 | + } |
| 129 | +} |
| 130 | +================================================================================ |
| 131 | +
|
| 132 | +[2025-10-08T11:53:14.183Z] Client disconnected |
| 133 | +``` |
| 134 | + |
| 135 | +## Stopping the server |
| 136 | + |
| 137 | +Press `Ctrl+C` to gracefully shut down the server. |
0 commit comments