# mld — IPv6 Multicast Listener Discovery (ICMPv6 130–132) (`mld`)

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

- **Full Protocol Name:** Multicast Listener Discovery v1 & v2 (IPv6)
- **Keyword:** `mld`
- **OSI Layer & Transport:** Layer 3 · ICMPv6 NextHdr 58 (Hop Limit 1)
- **Host Endpoint Rule:** IPv6-Only
- **Standards:** RFC 2710, RFC 3810
- **Wireshark Display Filter:** `icmpv6.type >= 130 && icmpv6.type <= 132`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv6 -> IPv6 MLD (ICMPv6 NextHdr 58 (Hop Limit 1))`

## Overview

What `igmp` does for IPv4, `mld` does for IPv6 (`ff02::/16 -> 33:33:xx:xx:xx:xx` Ethernet MACs at Hop Limit `1`), making it easy to check whether your leaf switches actually snoop IPv6 multicast.

Multicast Listener Discovery (`mld`) is the IPv6 counterpart to IGMP, carried inside ICMPv6 (`Next Header 58`) with a link-local **Hop Limit of `1`**. IPv6 nodes use MLD not only for streaming multicast applications, but also to join solicited-node multicast groups (`ff02::1:ffxx:xxxx`) required by IPv6 Neighbor Discovery.

FrameAssembly constructs 24-byte MLD messages (`query` Type `130`, `report` Type `131`, and `done` Type `132`) with automatic RFC 2464 `33:33:xx:xx:xx:xx` multicast Ethernet MAC derivation and IPv6 pseudo-header checksums.

## Minimal Quickstart (`mld_quickstart.frasm`)

```frameassembly
host rtr_v6  { ip fe80::1 }
host node_v6 { ip fe80::25 }

compile {
    rtr_v6 -> node_v6 mld query maxrespdelay 10000 wait 3ms
    node_v6 -> rtr_v6 mld report multicastaddr ff02::1:ff00:25
}
```

### Automatic Wire Calculations

- Sets IPv6 Next Header to `58` (ICMPv6) and defaults Hop Limit (`ttl`) to `1` per RFC 2710.
- Encodes ICMPv6 Type `130` (`query`), `131` (`report`), or `132` (`done`), 16-bit `Maximum Response Delay` (milliseconds), and 128-bit `Multicast Address`.
- Derives RFC 2464 `33:33:xx:xx:xx:xx` destination MACs automatically when sending to `ff00::/8` multicast hosts and computes the IPv6 pseudo-header checksum.

## Practical Lab Example: Link-Local MLD General Query, Solicited-Node Join, and Listener Done (`mld_snooping_ipv6.frasm`)

Simulates an IPv6 multicast router querying all link-local nodes (`ff02::1`), a subscriber reporting membership in `ff05::100`, and cleanly departing with `mld done`.

```frameassembly
host querier_v6 { ip fe80::1c73:1 }
host all_nodes  { ip ff02::1 }
host all_rtrs   { ip ff02::2 }
host listener   { ip fe80::1b21:50 }

compile {
    // 1. General MLD Query to ff02::1 (multicastaddr :: = all groups, 10000ms max delay)
    querier_v6 -> all_nodes mld query multicastaddr :: maxrespdelay 10000 vlan 200 wait 4ms
    // 2. Host joins site-local multicast stream ff05::100
    listener -> querier_v6 mld report multicastaddr ff05::100 maxrespdelay 0 vlan 200 wait 25ms
    // 3. Host sends MLD Done to all-routers multicast ff02::2 upon leaving
    listener -> all_rtrs mld done multicastaddr ff05::100 vlan 200
}
```

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

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

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

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

## All `mld` Keywords & Header Options

Packet line pattern: `src_host -> dst_host mld [query | report | done] [multicastaddr <ipv6>] [maxrespdelay <0..65535>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `query \| report \| done` | MLD message selector | `query (Type 130)` | Selects MLD Multicast Listener Query (`130`), Multicast Listener Report (`131`), or Multicast Listener Done (`132`). |
| `multicastaddr <ipv6>` | 128-bit IPv6 multicast address (or ::) | `:: (General Query)` | Sets the 16-byte Multicast Address field (`::` in General Queries, specific `ffxx::` group in Group-Specific Queries, Reports, and Done messages). |
| `maxrespdelay <0..65535>` | Whole number (0..65535) (milliseconds) | `10000 (10 seconds)` | Sets the Maximum Response Delay in milliseconds on MLD Queries (`0` on Reports and Done messages). |

## Cross-Layer Options Valid with `mld`

| 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 1, dscp 0, ecn 0` | Sets IPv4 TTL or IPv6 Hop Limit plus DiffServ (DSCP) and ECN QoS markings. |
| `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). |

## Common Mistakes & Quick Fixes

### IPv6 Endpoints Are Mandatory on mld

- **Avoid:** `host4_a -> host4_b mld query`
- **Valid v3.2.2 Syntax:** `host6_a -> host6_b mld query multicastaddr ::`

MLD runs inside ICMPv6, so both hosts must have IPv6 addresses. Use `igmp` for IPv4 multicast group management.

### Use multicastaddr (Not group) and maxrespdelay in Milliseconds

- **Avoid:** `node_v6 -> rtr_v6 mld report group ff05::100 maxresp 100`
- **Valid v3.2.2 Syntax:** `node_v6 -> rtr_v6 mld report multicastaddr ff05::100 maxrespdelay 1000`

MLD uses `multicastaddr <ipv6>` and millisecond-granularity `maxrespdelay <0..65535>`, whereas IPv4 `igmp` uses `group <ipv4>` and `1/10`s `maxresp <0..255>`.
