# ndp — RFC 4861 IPv6 Neighbor Discovery & Router Advertisements (`ndp`)

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

- **Full Protocol Name:** IPv6 Neighbor Discovery Protocol
- **Keyword:** `ndp`
- **OSI Layer & Transport:** Layer 3 · ICMPv6 NextHdr 58 (Hop Limit 255)
- **Host Endpoint Rule:** IPv6-Only
- **Standards:** RFC 4861
- **Wireshark Display Filter:** `icmpv6.type >= 133 && icmpv6.type <= 137`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv6 -> IPv6 NDP (ICMPv6 NextHdr 58 (Hop Limit 255))`

## Overview

IPv6 threw ARP in the bin and replaced it with ICMPv6 Neighbor Discovery at Hop Limit `255`. `ndp` builds `neighborsolicit`, `neighboradvert`, and rogue `routeradvert` frames to test switch RA Guard.

IPv6 Neighbor Discovery Protocol (`ndp`) replaces IPv4 ARP, ICMP Router Discovery, and ICMP Redirect with five ICMPv6 message types (`133..137`) carried over IPv6 Next Header `58`. Per RFC 4861, routers and hosts validate that incoming NDP packets arrive with **IPv6 Hop Limit `255`** so off-link spoofing attempts are dropped immediately.

FrameAssembly defaults `ndp` Hop Limit (`ttl`) to `255`, encodes Source and Target Link-Layer Address options (`slla` Type 1, `tlla` Type 2) padded to 8-octet boundaries, and computes the full IPv6 pseudo-header checksum automatically.

## Minimal Quickstart (`ndp_quickstart.frasm`)

```frameassembly
host host_v6   { ip 2001:db8:cafe::25 mac 00:1b:21:aa:00:25 }
host router_v6 { ip 2001:db8:cafe::1  mac 00:1c:73:bb:00:01 }

compile {
    host_v6 -> router_v6 ndp neighborsolicit target 2001:db8:cafe::1 slla 00:1b:21:aa:00:25 wait 1ms
    host_v6 <- router_v6 ndp neighboradvert target 2001:db8:cafe::1 tlla 00:1c:73:bb:00:01
}
```

### Automatic Wire Calculations

- Enforces IPv6 Hop Limit `255` (`ttl 255`) by default in accordance with RFC 4861 §6.1.2 / §7.1.1.
- Encodes exact ICMPv6 message bodies for `routersolicit` (`133`), `routeradvert` (`134`, `routerlifetime 1800`), `neighborsolicit` (`135`), `neighboradvert` (`136`, Solicited + Override flags set), and `redirect` (`137`).
- Appends 8-byte RFC 4861 Option TLV 1 (`slla`) or TLV 2 (`tlla`) when link-layer MACs are provided and computes the IPv6 pseudo-header checksum.

## Practical Lab Example: IPv6 SLAAC Router Discovery Followed by Neighbor Solicitation & Advertisement (`ndp_slaac_discovery.frasm`)

Models a dual-interface IPv6 leaf node soliciting an upstream router (`routersolicit` -> `routeradvert`) before resolving next-hop MAC reachability (`neighborsolicit` -> `neighboradvert`).

```frameassembly
host leaf_node { ip fe80::1b21:ff:feaa:10 mac 00:1b:21:aa:00:10 }
host core_rtr  { ip fe80::1c73:ff:febb:01 mac 00:1c:73:bb:00:01 }

compile {
    // 1. Host sends Router Solicitation with Source Link-Layer Address (SLLA)
    leaf_node -> core_rtr ndp routersolicit slla 00:1b:21:aa:00:10 vlan 100 wait 2ms
    // 2. Router replies with Router Advertisement (30-minute router lifetime)
    core_rtr -> leaf_node ndp routeradvert routerlifetime 1800 slla 00:1c:73:bb:00:01 vlan 100 wait 5ms
    // 3. Neighbor Solicitation & Solicited+Override Neighbor Advertisement
    leaf_node -> core_rtr ndp neighborsolicit target fe80::1c73:ff:febb:01 slla 00:1b:21:aa:00:10 vlan 100 wait 1ms
    leaf_node <- core_rtr ndp neighboradvert target fe80::1c73:ff:febb:01 tlla 00:1c:73:bb:00:01 vlan 100
}
```

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

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

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

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

## All `ndp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host ndp [routersolicit | routeradvert | neighborsolicit | neighboradvert | redirect] [target <ipv6>] [slla <mac>] [tlla <mac>] [routerlifetime <0..65535>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `routersolicit \| routeradvert \| neighborsolicit \| neighboradvert \| redirect` | NDP message selector | `neighborsolicit (Type 135)` | Selects ICMPv6 Type `133` (`routersolicit`), `134` (`routeradvert`), `135` (`neighborsolicit`), `136` (`neighboradvert`), or `137` (`redirect`). |
| `target <ipv6>` | 128-bit IPv6 address literal | `Destination host IPv6 address` | Populates the 16-byte Target Address field in Neighbor Solicitation, Neighbor Advertisement, and Redirect messages. |
| `slla <mac> \| tlla <mac>` | 48-bit MAC address | `Omitted unless set` | Appends 8-byte NDP Option Type `1` (Source Link-Layer Address, `slla`) or Option Type `2` (Target Link-Layer Address, `tlla`). |
| `routerlifetime <0..65535>` | Whole number (0..65535) (seconds) | `1800` | Sets the 16-bit Router Lifetime in `routeradvert` (`0` indicates the router is not a default gateway). |

## Cross-Layer Options Valid with `ndp`

| 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 255, 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 ndp

- **Avoid:** `host v4_a { ip 10.0.0.1 }
v4_a -> v4_b ndp neighborsolicit`
- **Valid v3.2.2 Syntax:** `host v6_a { ip 2001:db8::1 }
v6_a -> v6_b ndp neighborsolicit`

NDP runs over ICMPv6, so both hosts on an `ndp` line must have IPv6 addresses. Use `arp` for IPv4 MAC resolution.

### Strict Alphanumeric Message Names

- **Avoid:** `v6_a -> v6_b ndp neighbor_solicit router_lifetime 900`
- **Valid v3.2.2 Syntax:** `v6_a -> v6_b ndp routeradvert routerlifetime 900`

Spell NDP sub-keywords without underscores: `routersolicit`, `routeradvert`, `neighborsolicit`, `neighboradvert`, `routerlifetime`.
