# iscsi — Port 3260 48-Byte BHS Login, SCSI Read/Write & NOPs (`iscsi`)

> **FrameAssembly v3.3.0** · Protocol 95 of 81 · Canonical URL: https://frameassembly-lang.dev/docs/protocols/iscsi

- **Full Protocol Name:** Internet Small Computer Systems Interface Block SAN
- **Keyword:** `iscsi`
- **OSI Layer & Transport:** Layer 7 · TCP 3260
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 7143, RFC 3720, SAM-5
- **Wireshark Display Filter:** `iscsi`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> TCP 3260 -> iSCSI (RFC 7143)`

## Overview

Every iSCSI PDU starts with a strict 48-byte Basic Header Segment on TCP `3260` — `iscsi` builds IQN `login` key-value pairs, `lun`-addressed SCSI commands, `itt`/`cmdsn`/`statsn` counters, and `nop` keepalives.

Internet Small Computer Systems Interface (`iscsi`, RFC 7143 / RFC 3720) transports block-level SCSI commands, NVMe/hypervisor datastore I/O, and cluster shared volumes across IP storage networks on **TCP port `3260`**. Every iSCSI Protocol Data Unit begins with a **48-byte Basic Header Segment (BHS)** containing a 6-bit `Opcode` (plus `I` Immediate bit), `Flags` (`Final` `0x80`, `Read`/`Write`, `Transit`/`Continue`), 24-bit `DataSegmentLength` (padded to 4-byte boundaries), 64-bit `LUN`, `Initiator Task Tag (itt)`, `CmdSN`, `ExpStatSN` / `StatSN`, and 16-byte SCSI Command Descriptor Blocks (CDBs) or `key=value ` Login/Text operational parameters.

FrameAssembly packs exact 48-byte BHS frames + 4-byte padded `InitiatorName` / `TargetName` IQN text segments over stateful 4-tuple TCP (`3260`).

## Minimal Quickstart (`iscsi_quickstart.frasm`)

```frameassembly
host esxi_host  { ip 10.70.20.11 }
host san_target { ip 10.70.20.50 }

compile {
    esxi_host -> san_target tcp syn srcport 51320 dstport 3260 win 65535 mss 8960 wait 1ms
    esxi_host <- san_target tcp syn ack win 65535 mss 8960 wait 1ms
    esxi_host -> san_target tcp ack wait 1ms
    esxi_host -> san_target iscsi login initiator "iqn.2026-01.corp.vm:esxi01" target "iqn.2026-01.corp.san:datastore01" itt 1 cmdsn 1 wait 2ms
    esxi_host <- san_target iscsi response opcode 0x23 itt 1 statsn 1 status 0
}
```

### Automatic Wire Calculations

- Defaults to stateful TCP port `3260` (`psh ack`, automatic `seq`/`acknum` progression across 48-byte BHS + padded data segments).
- Formats null-delimited `InitiatorName=<iqn>` and `TargetName=<iqn>` operational key-value pairs on `login` (`0x03`), writing unpadded `DataSegmentLength` into BHS bytes 5..7 while zero-padding the wire segment to 4-byte alignment.
- Populates 10-byte SCSI `READ(10)` (`0x28`) and `WRITE(10)` (`0x2a`) CDBs inside `SCSI Command` (`0x01`) BHS headers using `lun` and `offset` LBA.

## Practical Lab Example: Storage VLAN 200 iSCSI Session Login, SCSI READ(10) Data-In & NOP-Out Ping (`iscsi_san_read_cycle.frasm`)

Establishes an iSCSI Full Feature Phase session over VLAN `200`, executes a SCSI `READ` on `LUN 1` (`offset 4096`), returns `SCSI Data-In` (`0x25`) with status completion, and exchanges `NOP-Out` / `NOP-In` keepalives.

```frameassembly
host hv_node01 { ip 172.18.200.11 mac 00:25:b5:01:00:11 }
host flash_san { ip 172.18.200.80 mac 00:25:b5:02:00:80 }

compile {
    hv_node01 -> flash_san tcp syn srcport 54320 dstport 3260 vlan 200 pcp 4 df wait 1ms
    hv_node01 <- flash_san tcp syn ack vlan 200 pcp 4 df wait 1ms
    hv_node01 -> flash_san tcp ack vlan 200 pcp 4 df wait 1ms
    // 1. iSCSI Login Request (0x03) -> Login Response (0x23, StatusClass=0 Success)
    hv_node01 -> flash_san iscsi login initiator "iqn.2026-01.internal.hv:node01" target "iqn.2026-01.internal.san:lun-db01" itt 0x1001 cmdsn 1 vlan 200 pcp 4 wait 2ms
    hv_node01 <- flash_san iscsi response opcode 0x23 itt 0x1001 statsn 1 status 0 vlan 200 pcp 4 wait 2ms
    // 2. SCSI READ(10) Command on LUN 1 at LBA 4096 -> Data-In (0x25) + SCSI Response (0x21)
    hv_node01 -> flash_san iscsi read lun 1 itt 0x1002 cmdsn 2 statsn 1 offset 4096 vlan 200 pcp 4 wait 1ms
    hv_node01 <- flash_san iscsi data opcode 0x25 lun 1 itt 0x1002 statsn 2 payload "BLOCK-SECTOR-4096-DATA" vlan 200 pcp 4 wait 1ms
    hv_node01 <- flash_san iscsi response lun 1 itt 0x1002 statsn 3 status 0 vlan 200 pcp 4 wait 10ms
    // 3. iSCSI NOP-Out (0x00) -> NOP-In (0x20) storage fabric liveness check
    hv_node01 -> flash_san iscsi nop itt 0x1003 cmdsn 3 statsn 3 vlan 200 pcp 4 wait 1ms
    hv_node01 <- flash_san iscsi response opcode 0x20 itt 0x1003 statsn 4 vlan 200 pcp 4
}
```

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

# 2. Compile .frasm -> classic .pcap, nanosecond .pcapng, or pipe via '-'
frameassembly iscsi_san_read_cycle.frasm iscsi_san_read_cycle.pcap
frameassembly iscsi_san_read_cycle.frasm iscsi_san_read_cycle.pcapng

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

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

## All `iscsi` Keywords & Header Options

Packet line pattern: `src_host -> dst_host iscsi [login | logout | read | write | nop | response | data | text | cmd "<text>"] [opcode <0..63>] [initiator "<text>"] [target "<text>"] [lun <0..65535>] [itt <number>] [cmdsn <number>] [statsn <number>] [status <0..255>] [flags <0..255>] [offset <number>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `login \| logout \| read \| write \| nop \| response \| data \| text \| cmd "<text>"` | iSCSI BHS PDU type shorthand | `nop (0x00)` | Selects `0x00` NOP-Out, `0x01` SCSI Command (`read`/`write`), `0x03` Login Request, `0x04` Text Request, `0x05` SCSI Data-Out, `0x06` Logout, `0x21` SCSI Response, `0x23` Login Response, or `0x25` SCSI Data-In. |
| `opcode <0..63>` | 6-bit RFC 7143 BHS Opcode override | `Derived from command keyword` | Explicitly sets byte 0 (`0x20` NOP-In, `0x21` SCSI Resp, `0x23` Login Resp, `0x24` Text Resp, `0x25` Data-In, `0x31` R2T). |
| `initiator "<text>" \| target "<text>"` | iSCSI Qualified Name (IQN / EUI) strings | `"iqn.2026-01.com.example:initiator" / "...:target"` | Appends `InitiatorName="<text>" ` and `TargetName="<text>" ` key-value pairs in Login/Text DataSegments. |
| `lun <0..65535>` | 16-bit single-level Logical Unit Number | `0` | Writes the big-endian LUN in bytes 8..15 of the 48-byte BHS. |
| `itt <number> \| cmdsn <number> \| statsn <number>` | 32-bit Initiator Task Tag, Command SeqNum, and Status SeqNum | `itt 1, cmdsn 1, statsn 1` | Populates BHS bytes 16..19 (`ITT`) and 24..31 (`CmdSN` / `ExpStatSN` / `StatSN`). |
| `status <0..255> \| flags <0..255> \| offset <number>` | 8-bit SCSI Status (`0x00` Good, `0x02` Check Cond), BHS Flags, and 32-bit LBA/Buffer Offset | `status 0, flags 0x80 (Final), offset 0` | Sets BHS byte 1 (`flags`), byte 3 (`status`), and CDB LBA or Data-In/Out `Buffer Offset`. |

## Cross-Layer Options Valid with `iscsi`

| 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). |
| `comment "<text>"` | Quoted UTF-8 annotation | `Omitted` | Attaches an Enhanced Packet Block `opt_comment` annotation when compiling to `.pcapng` (Wireshark `pkt_comment` filter). |
| `payload "<text>" \| hexpayload "<hex>"` | Quoted text or hex bytes (choose one) | `Omitted` | Appends or overrides raw payload bytes (`"deadbeef"`, `"de:ad:be:ef"`, or `"\x01\x02"`) and updates packet lengths and checksums. |
| `srcmac <mac> \| dstmac <mac> \| ethertype <0..65535>` | Colon/hyphen/Cisco MAC · EtherType 0..65535 (e.g. 0x0800) | `Host MAC / RFC multicast MAC / auto EtherType` | Overrides the 14-byte Ethernet II source MAC, destination MAC, or standalone Layer 2 16-bit EtherType. |
| `fcs \| badfcs` | Ethernet CRC-32 trailer flags (choose one) | `Omitted` | `fcs` appends a valid IEEE 802.3 4-byte CRC-32 Frame Check Sequence trailer; `badfcs` XOR-corrupts the CRC-32 for NIC/tap negative tests. |
| `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>]` | Repeatable label stack (0..1048575, exp/tc 0..7, bos 0..1, ttl 0..255) | `Unlabeled (auto bos=0 on outer labels, bos=1 on bottom)` | Prepends one or more 32-bit MPLS label shims (`0x8847`, e.g. `mpls 16000 mpls 24010`) ahead of Layer 2 EoMPLS or Layer 3 payloads. |
| `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>] [routeralert] [badipchecksum]` | IPv4 ID, DF/MF flags, offset 0..8191, Router Alert & checksum fault | `ipid 1, flags 0, fragoffset 0, valid RFC 1071 checksum` | Sets IPv4 Identification/fragmentation, injects RFC 2113 Router Alert (`20 04 00 00`), or corrupts the 16-bit IPv4 header checksum (`badipchecksum`). |
| `flowlabel <0..1048575>` | 20-bit IPv6 Flow Label (0..1048575) | `0` | Sets the 20-bit IPv6 Flow Label for ECMP routing tests (valid on IPv6 endpoint pairs only). |
| `srcport <0..65535> \| dstport <0..65535>` | Port number 0..65535 | `srcport 49152 (remembered), TCP 3260` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |
| `transport sctp` | Optional SCTP association transport (IP Proto 132) | `TCP (TCP 3260)` | Carries this Layer 7 PDU inside a stateful RFC 9260 SCTP `DATA` chunk with automatic Verification Tag, TSN tracking, and CRC-32c. |
| `badchecksum` | L4/ICMP/SCTP checksum fault injection flag | `Valid RFC checksum / CRC-32c` | Deliberately corrupts the TCP, SCTP CRC-32c, ICMP, or ICMPv6 checksum for negative IDS/firewall testing. |
| `seq <number> \| acknum <number> \| win\|window <0..65535> \| urgent <0..65535> \| syn \| ack \| psh \| fin \| rst \| urg \| ece \| cwr` | TCP sequence/ack numbers, window, flags, SACK, TCP-MD5 & TFO options | `psh ack, win 65535, automatic TCP seq/acknum` | Overrides automatic TCP sequence tracking, flags, or RFC 7323/2018/2385/7413 options (`mss`, `wscale`, `sackperm`, `sackblock`, `tsval`, `tsecr`, `tcpmd5`, `tfo`). |

## Common Mistakes & Quick Fixes

### Match Initiator Task Tag (itt) Across Command, Data, and Response PDUs

- **Valid v3.3.0 Syntax:** `h -> s iscsi read lun 1 itt 0x42
h <- s iscsi response lun 1 itt 0x42 status 0`

Wireshark’s `iscsi` dissector uses the 32-bit `Initiator Task Tag (itt)` to link a SCSI Command (`0x01`) with its Data-In/Out and Response PDUs and compute SAN I/O latency.

### Target-to-Initiator Opcodes Set Bit 0x20

- **Valid v3.3.0 Syntax:** `h <- s iscsi response opcode 0x23 itt 1 statsn 1 status 0`

In RFC 7143, initiator-to-target opcodes occupy `0x00..0x1f` (`0x03` Login Req) while target-to-initiator opcodes add `0x20` (`0x20` NOP-In, `0x21` SCSI Resp, `0x23` Login Resp, `0x25` Data-In).
