# quic — RFC 9000 Encrypted UDP 443 Handshakes & Connection IDs (`quic`)

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

- **Full Protocol Name:** QUIC v1 & v2 Encrypted UDP Transport
- **Keyword:** `quic`
- **OSI Layer & Transport:** Layer 7 · UDP 443
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 9000, RFC 9369
- **Wireshark Display Filter:** `quic`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 443 -> QUIC (HTTP/3)`

## Overview

Half of enterprise firewall policy is "block UDP `443` so browsers fall back to TLS over TCP where we can inspect it" — `quic initial` lets you test whether that policy actually works.

QUIC (`quic`, RFC 9000 / RFC 9369) is the encrypted transport underlying **HTTP/3** on **UDP port `443`**. Enterprise firewalls frequently block or inspect UDP `443` differently from TCP `443` (forcing browsers back to TLS-over-TCP when UDP `443` is dropped), while security sensors inspect QUIC Long Headers (`initial`, `zerortt`, `handshake`, `retry`) and Connection IDs (`dcid`, `scid`).

FrameAssembly encodes both RFC 9000 **Long Header** packets (including Version `1` `0x00000001` or QUIC v2 `0x6b3343cf`, 8-byte Destination/Source Connection IDs, Retry/Initial `token`, and 2-byte RFC 9000 §16 variable-length Length integers) and **1-RTT Short Header** (`short`) data packets.

## Minimal Quickstart (`quic_quickstart.frasm`)

```frameassembly
host browser { ip 10.20.4.15 }
host cdn_vip { ip 198.51.100.44 }

compile {
    browser -> cdn_vip quic initial version 1 dcid 0x1122334455667788 scid 0xaabbccddeeff0011 pktnum 1 wait 2ms
    browser <- cdn_vip quic handshake version 1 dcid 0xaabbccddeeff0011 scid 0x1122334455667788 pktnum 1
}
```

### Automatic Wire Calculations

- Defaults to UDP destination port `443`, QUIC v1 (`version 1` `0x00000001`), and sets the mandatory Fixed Bit (`0x40`) in byte 0.
- Encodes 8-byte `dcid` and `scid` Connection IDs plus RFC 9000 variable-length integer payload lengths automatically on Long Header packets.
- Emits compact 1-RTT Short Header frames (`0x40` + 8-byte `dcid` + `pktnum`) when `short` is selected.

## Practical Lab Example: QUIC v1 Retry Token Challenge, Handshake & 1-RTT Connection Migration (`quic_connection_migration.frasm`)

Shows a server challenging an initial client packet with `retry`, completing the QUIC handshake, and maintaining the same `dcid` across a NAT source-port rebind on `short` packets.

```frameassembly
host mobile_app { ip 198.51.100.70 }
host edge_pop   { ip 203.0.113.44 }

compile {
    // 1. Initial attempt -> Server sends stateless Retry token
    mobile_app -> edge_pop quic initial srcport 51443 dcid 0x0102030405060708 scid 0x1111222233334444 pktnum 0 wait 2ms
    mobile_app <- edge_pop quic retry dcid 0x1111222233334444 scid 0x9999888877776666 token "addr-verified-tok" wait 2ms
    // 2. Client resends Initial with token + Handshake completion
    mobile_app -> edge_pop quic initial dcid 0x9999888877776666 scid 0x1111222233334444 token "addr-verified-tok" pktnum 1 wait 2ms
    mobile_app <- edge_pop quic handshake dcid 0x1111222233334444 scid 0x9999888877776666 pktnum 1 wait 3ms
    // 3. 1-RTT Short Header packets (client migrates from srcport 51443 -> 60222 keeping dcid)
    mobile_app -> edge_pop quic short dcid 0x9999888877776666 pktnum 2 payload "h3-stream-frame-1" wait 5ms
    mobile_app -> edge_pop quic short srcport 60222 dstport 443 dcid 0x9999888877776666 pktnum 3 payload "h3-migrated-port"
}
```

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

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

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

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

## All `quic` Keywords & Header Options

Packet line pattern: `src_host -> dst_host quic [initial | zerortt | handshake | retry | short] [version <number>] [dcid <hex_or_num>] [scid <hex_or_num>] [token "<text>"] [pktnum <number>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `initial \| zerortt \| handshake \| retry \| short` | QUIC packet header type | `initial` | Selects Long Header (`initial`, `zerortt`, `handshake`, `retry`) or 1-RTT Short Header (`short`). |
| `version <number>` | `1` (RFC 9000 QUIC v1) or `0x6b3343cf` (RFC 9369 QUIC v2) | `1 (0x00000001)` | Sets the 32-bit Version field in Long Header packets. |
| `dcid <hex_or_num> \| scid <hex_or_num>` | 64-bit Connection IDs (e.g. 0x1122334455667788) | `Deterministic 8-byte IDs` | Sets the 8-byte Destination Connection ID (`dcid`) and Source Connection ID (`scid`, Long Header only). |
| `token "<text>"` | Quoted Retry / address-validation token | `Empty (length 0)` | Populates the Token field on `initial` and `retry` packets. |
| `pktnum <number>` | Packet Number | `1` | Sets the packet number field in `initial`, `zerortt`, `handshake`, and `short` frames. |

## Cross-Layer Options Valid with `quic`

| 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), UDP 443` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### 0-RTT Is Spelled zerortt (Letters Before Digits Pattern)

- **Avoid:** `browser -> cdn_vip quic 0rtt dcid 0x1234`
- **Valid v3.2.2 Syntax:** `browser -> cdn_vip quic zerortt dcid 0x1234`

Spell 0-RTT early-data packets as `zerortt` with no hyphen.

### QUIC Runs Over UDP 443 (Do Not Add TCP Flags Like syn or ack)

- **Avoid:** `browser -> cdn_vip quic initial syn`
- **Valid v3.2.2 Syntax:** `browser -> cdn_vip quic initial pktnum 1`

QUIC handles reliability inside UDP datagrams rather than TCP, so TCP flags (`syn`, `ack`, `fin`) are rejected.
