# rip — RIPv2 (UDP 520) & IPv6 RIPng (UDP 521) Route Updates (`rip`)

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

- **Full Protocol Name:** Routing Information Protocol — RIPv2 & Dual-Stack RIPng
- **Keyword:** `rip`
- **OSI Layer & Transport:** Layer 3 · UDP 520 (RIPv2) / UDP 521 (RIPng)
- **Host Endpoint Rule:** Dual-Stack Morphing (v4/v6)
- **Standards:** RFC 2453, RFC 2080
- **Wireshark Display Filter:** `rip || ripng`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> RIPv2 / RIPng (UDP 520 (RIPv2) / UDP 521 (RIPng))`

## Overview

Every textbook swears RIP died in 1998, right up until you inherit a branch router running it. `rip` builds RIPv2 (`520`) over IPv4 and RIPng (`521`) over IPv6, right up to `metric 16` poison reverse.

Routing Information Protocol (`rip`) is a distance-vector routing protocol limited to a maximum hop count of `15` (`metric 16` = infinity / route poison). In FrameAssembly v3.2.0, `rip` morphs automatically by address family: between IPv4 hosts, it emits **RIPv2** (RFC 2453, **UDP `520 -> 520`**, 20-byte Route Table Entry with Route Tag, Subnet Mask, Next Hop, and 32-bit Metric); between IPv6 hosts, it emits **RIPng** (RFC 2080, **UDP `521 -> 521`**, Version `1`, 20-byte IPv6 Prefix RTE).

Both `request` (`command 1`) and `response`/`reply` (`command 2`) messages compile cleanly with zero boilerplate.

## Minimal Quickstart (`rip_quickstart.frasm`)

```frameassembly
host branch_rtr { ip 10.10.0.1 }
host edge_rtr   { ip 10.10.0.2 }

compile {
    branch_rtr -> edge_rtr rip request wait 2ms
    branch_rtr <- edge_rtr rip response prefix 10.200.0.0 metric 2 tag 100
}
```

### Automatic Wire Calculations

- Selects RIPv2 on UDP `520 -> 520` over IPv4 hosts or RIPng on UDP `521 -> 521` over IPv6 hosts.
- Populates Address Family Identifier `2` (`AF_INET`), `255.255.255.0` default mask, Route Tag, Next Hop, and Metric in RIPv2—or 128-bit IPv6 prefix + prefix-length + 8-bit metric in RIPng.
- Derives RFC multicast Ethernet MACs automatically when sending to `224.0.0.9` (RIPv2) or `ff02::9` (RIPng).

## Practical Lab Example: RIPv2 Multicast Update, Route Poisoning (Metric 16), and IPv6 RIPng (`rip_v2_ripng.frasm`)

Shows a branch router advertising `10.50.10.0` (`metric 2`), subsequently poisoning the route (`metric 16`) upon link loss, and advertising an IPv6 prefix over RIPng (`ff02::9`).

```frameassembly
host rtr_branch { ip 172.16.10.2 }
host rip_mcast  { ip 224.0.0.9 }
host rtr6_a     { ip fe80::10:1 }
host ripng_all  { ip ff02::9 }

compile {
    // 1. Periodic RIPv2 multicast advertisement (metric 2, route tag 65010)
    rtr_branch -> rip_mcast rip response prefix 10.50.10.0 nexthop 0.0.0.0 metric 2 tag 65010 ttl 2 wait 10ms
    // 2. Triggered route-poison update (metric 16 = infinity / unreachable)
    rtr_branch -> rip_mcast rip response prefix 10.50.10.0 nexthop 0.0.0.0 metric 16 tag 65010 ttl 2 wait 5ms
    // 3. IPv6 RIPng advertisement on UDP 521 -> 521 to ff02::9
    rtr6_a -> ripng_all rip response prefix 2001:db8:50:: metric 1 tag 100 ttl 255
}
```

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

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

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

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

## All `rip` Keywords & Header Options

Packet line pattern: `src_host -> dst_host rip [request | response | reply] [prefix <ip>] [metric <1..16>] [nexthop <ip>] [tag <0..65535>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `request \| response \| reply \| command <1\|2>` | RIP Command selector | `response (Command 2)` | Selects Command `1` (`request`) or Command `2` (`response` / `reply`). |
| `prefix <ip>` | IPv4 or IPv6 address literal (no /CIDR slash) | `10.0.0.0 (v4) / 2001:db8:: (v6)` | Sets the advertised destination network address in the Route Table Entry. |
| `metric <1..16>` | Hop count integer (1..16) | `1` | Sets the route hop-count metric (`1..15` reachable hops, `16` infinity / unreachable). |
| `nexthop <ip>` | IPv4 address literal | `0.0.0.0 (advertising router)` | Sets the immediate Next Hop IP in RIPv2 (`0.0.0.0` means use the UDP packet source IP). |
| `tag <0..65535>` | Whole number (0..65535) | `0` | Sets the 16-bit external Route Tag (often carrying redistributed BGP ASN). |

## Cross-Layer Options Valid with `rip`

| 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 520 (RIPv2) / UDP 521 (RIPng)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### Pass Plain IP Literals to rip prefix (No /24 Suffix)

- **Avoid:** `r1 -> r2 rip response prefix "10.50.10.0/24"`
- **Valid v3.2.2 Syntax:** `r1 -> r2 rip response prefix 10.50.10.0 metric 2`

Unlike `bgp update prefix "10.20.0.0/16"`, `rip prefix <ip>` expects an unquoted IPv4 or IPv6 address literal (`10.50.10.0` or `2001:db8:50::`).

### Valid Hop-Count Metric Bounds (1..16)

- **Avoid:** `r1 -> r2 rip response metric 255`
- **Valid v3.2.2 Syntax:** `r1 -> r2 rip response metric 16`

Per RFC 2453, RIP metrics range from `1` to `16` (`16` = infinity).
