# arp — Broadcast ARP Requests, Replies & GARP Failovers (`arp`)

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

- **Full Protocol Name:** Address Resolution Protocol & Gratuitous ARP
- **Keyword:** `arp`
- **OSI Layer & Transport:** Layer 2 · EtherType 0x0806
- **Host Endpoint Rule:** MAC-Only or IP
- **Standards:** RFC 826, RFC 5227
- **Wireshark Display Filter:** `arp`
- **Wire Encapsulation:** `Ethernet II -> ARP / GARP (EtherType 0x0806)`

## Overview

Every network outage eventually gets blamed on DNS or ARP — with `a -> b arp` you can script broadcast Who-Has queries, `a <- b arp reply` answers, and `arp gratuitous` VIP takeovers in three lines flat.

Address Resolution Protocol (`arp`) maps IPv4 layer-3 addresses to 48-bit Ethernet MAC addresses inside a 28-byte ARP payload carried directly over Ethernet II (`0x0806`). FrameAssembly synthesizes standard broadcast Who-Has requests (`request`), unicast `is-at` replies (`reply`), and broadcast Gratuitous ARP announcements (`gratuitous` / `garp`) used during VRRP/HSRP failovers and duplicate-IP detection.

Because `arp` is a native Layer 2 protocol, endpoints may declare both `ip` and `mac` or operate as pure MAC-only hosts with explicit `senderip`/`targetip` (`spa`/`tpa`) fields—making it straightforward to craft Dynamic ARP Inspection (DAI) positive and negative test cases.

## Minimal Quickstart (`arp_quickstart.frasm`)

```frameassembly
host client  { ip 10.0.10.25 mac 00:1b:21:aa:00:25 }
host gateway { ip 10.0.10.1  mac 00:1b:21:aa:00:01 }

compile {
    client -> gateway arp
}
```

### Automatic Wire Calculations

- Sets Ethernet II EtherType to `0x0806` and broadcasts `request` frames to destination MAC `ff:ff:ff:ff:ff:ff` unless `dstmac` is overridden.
- Populates Hardware Type `1` (Ethernet), Protocol Type `0x0800` (IPv4), `hlen=6`, `plen=4`, and `opcode=1` (`request`).
- Fills `sendermac` (`sha`) and `senderip` (`spa`) from the source host, sets `targetmac` (`tha`) to `00:00:00:00:00:00` on requests, and sets `targetip` (`tpa`) from the destination host.
- Pads the Ethernet frame cleanly when needed and switches `reply` frames to unicast peer MACs automatically.

## Practical Lab Example: VLAN-Tagged ARP Resolution Followed by Gratuitous ARP VIP Takeover (`arp_garp_failover.frasm`)

Simulates a workstation resolving its default gateway on VLAN 10, followed by a standby router broadcasting an RFC 5227 Gratuitous ARP announcement during a virtual IP takeover.

```frameassembly
host workstation { ip 10.10.10.50 mac 00:1b:21:10:00:50 }
host rtr_active  { ip 10.10.10.1  mac 00:00:5e:00:01:01 }
host rtr_standby { ip 10.10.10.2  mac 00:1b:21:10:00:02 }

compile {
    // 1. Broadcast ARP Who-Has on VLAN 10
    workstation -> rtr_active arp request vlan 10 pcp 3 wait 1ms
    // 2. Unicast ARP Is-At reply from active gateway
    workstation <- rtr_active arp reply vlan 10 wait 5ms
    // 3. Standby router takes over VIP 10.10.10.1 and broadcasts GARP
    rtr_standby -> workstation arp gratuitous sendermac 00:00:5e:00:01:01 senderip 10.10.10.1 vlan 10
}
```

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

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

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

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

## All `arp` Keywords & Header Options

Packet line pattern: `src_host -> dst_host arp [request | reply | gratuitous | garp] [sendermac|sha <mac>] [senderip|spa <ipv4>] [targetmac|tha <mac>] [targetip|tpa <ipv4>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `request \| reply \| gratuitous \| garp` | Operation mode flag | `request` | Selects Opcode `1` broadcast Who-Has (`request`), Opcode `2` unicast Is-At (`reply`), or broadcast Gratuitous ARP (`gratuitous`/`garp` with `tpa = spa` and `ff:ff:ff:ff:ff:ff`). |
| `sendermac <mac> \| sha <mac>` | 48-bit MAC (colon, hyphen, or Cisco dot) | `Source host MAC` | Sets the 6-byte ARP Sender Hardware Address (`sha`) independently of the outer Ethernet II `srcmac`. |
| `senderip <ipv4> \| spa <ipv4>` | IPv4 literal | `Source host IPv4 (or 0.0.0.0 on MAC-only host)` | Sets the 4-byte ARP Sender Protocol Address (`spa`). |
| `targetmac <mac> \| tha <mac>` | 48-bit MAC (colon, hyphen, or Cisco dot) | `00:00:00:00:00:00 on request; peer MAC on reply` | Sets the 6-byte ARP Target Hardware Address (`tha`). |
| `targetip <ipv4> \| tpa <ipv4>` | IPv4 literal | `Destination host IPv4 (or senderip on garp)` | Sets the 4-byte ARP Target Protocol Address (`tpa`). |

## Cross-Layer Options Valid with `arp`

| 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. |

## Common Mistakes & Quick Fixes

### Use ndp for Native IPv6 Neighbor Solicitation

- **Avoid:** `host6_a -> host6_b arp senderip 2001:db8::1`
- **Valid v3.2.2 Syntax:** `host6_a -> host6_b ndp neighborsolicit target 2001:db8::2`

ARP `senderip`/`targetip` (`spa`/`tpa`) are 32-bit IPv4 fields per RFC 826. For IPv6 link-layer address resolution with SLLA/TLLA options and Hop Limit 255, use `ndp`.

### Zero Underscores in Sub-Keywords

- **Avoid:** `a -> b arp sender_ip 10.0.0.1 target_ip 10.0.0.2`
- **Valid v3.2.2 Syntax:** `a -> b arp senderip 10.0.0.1 targetip 10.0.0.2`

All FrameAssembly v3.2.0 built-in modifiers are lowercase alphanumeric (`senderip`/`spa`, `sendermac`/`sha`, `targetip`/`tpa`, `targetmac`/`tha`).
