# radius — UDP 1812/1813 AAA Decisions & Accounting AVPs (`radius`)

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

- **Full Protocol Name:** Remote Authentication Dial-In User Service (Auth & Accounting)
- **Keyword:** `radius`
- **OSI Layer & Transport:** Layer 7 · UDP 1812 (Auth) / UDP 1813 (Accounting)
- **Host Endpoint Rule:** Dual-Stack IPv4/IPv6
- **Standards:** RFC 2865, RFC 2866
- **Wireshark Display Filter:** `radius`
- **Wire Encapsulation:** `Ethernet II -> [802.1Q / QinQ / MPLS] -> IPv4 / IPv6 -> UDP 1812 (Auth) / UDP 1813 (Accounting) -> RADIUS`

## Overview

Watch `accessrequest -> accesschallenge -> accessaccept` on UDP `1812` and switch seamlessly to UDP `1813` on `accountingrequest`, complete with `User-Name`, `NAS-IP-Address`, and `Framed-IP-Address` AVPs.

Remote Authentication Dial-In User Service (`radius`, RFC 2865 / RFC 2866) carries centralized Wi-Fi, 802.1X switch port, and VPN login requests between network access devices and AAA servers such as FreeRADIUS, Cisco ISE, or Aruba ClearPass. Authentication runs on **UDP port `1812`**, while session accounting runs on **UDP port `1813`**.

FrameAssembly automatically selects UDP `1812` or `1813` from the message type, builds the 20-byte RADIUS header (Code, Identifier, Length, and 16-byte Authenticator), and attaches standard Attribute-Value Pairs (AVPs) for `User-Name` (Type 1), `NAS-IP-Address` (Type 4), `Service-Type` (Type 6), and `Framed-IP-Address` (Type 8).

## Minimal Quickstart (`radius_quickstart.frasm`)

```frameassembly
host access_sw { ip 10.20.0.10 }
host ise_node  { ip 10.20.0.50 }

compile {
    access_sw -> ise_node radius accessrequest id 1 user "corp\\jdoe" nasip 10.20.0.10 servicetype 2 wait 3ms
    access_sw <- ise_node radius accessaccept id 1 framedip 10.20.15.42
}
```

### Automatic Wire Calculations

- Picks UDP destination port `1812` for `accessrequest`, `accessaccept`, `accessreject`, and `accesschallenge`, or UDP `1813` for `accountingrequest` and `accountingresponse`.
- Calculates the exact 16-bit RADIUS Length across the 20-byte header and all included AVP attributes, and reverses UDP ports automatically on `<-` replies.
- Formats standard RFC 2865 AVP TLVs (`User-Name`, `NAS-IP-Address`, `Service-Type`, `Framed-IP-Address`) so Wireshark decodes every attribute cleanly.

## Practical Lab Example: MFA Challenge, VPN IP Assignment & RADIUS Accounting Start (`radius_vpn_mfa_accounting.frasm`)

Walks through a VPN gateway sending an Access-Request, handling an MFA Access-Challenge, receiving an Access-Accept with an assigned client IP, and logging an Accounting-Request on UDP 1813.

```frameassembly
host vpn_gw    { ip 172.16.1.5 }
host radius_01 { ip 172.16.10.20 }

compile {
    // 1. Initial VPN login + MFA Access-Challenge on UDP 1812
    vpn_gw -> radius_01 radius accessrequest id 10 user "oncall.netops" nasip 172.16.1.5 servicetype 2 wait 2ms
    vpn_gw <- radius_01 radius accesschallenge id 10 wait 15ms
    // 2. Second factor approved -> Access-Accept assigns Framed-IP 10.250.0.25
    vpn_gw -> radius_01 radius accessrequest id 11 user "oncall.netops" nasip 172.16.1.5 servicetype 2 wait 2ms
    vpn_gw <- radius_01 radius accessaccept id 11 framedip 10.250.0.25 wait 5ms
    // 3. Session accounting record on UDP 1813
    vpn_gw -> radius_01 radius accountingrequest id 12 user "oncall.netops" nasip 172.16.1.5 framedip 10.250.0.25 wait 2ms
    vpn_gw <- radius_01 radius accountingresponse id 12
}
```

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

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

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

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

## All `radius` Keywords & Header Options

Packet line pattern: `src_host -> dst_host radius [accessrequest | accessaccept | accessreject | accesschallenge | accountingrequest | accountingresponse | code "<text>"] [id <0..255>] [user "<text>"] [nasip <ipv4>] [servicetype <number>] [framedip <ipv4>]`

| Keyword / Option | Accepted Value | Default | Effect on Packet |
| --- | --- | --- | --- |
| `accessrequest \| accessaccept \| accessreject \| accesschallenge \| accountingrequest \| accountingresponse` | RADIUS packet code keyword (or `code "<text>"`) | `accessrequest (Code 1, UDP 1812)` | Sets the 1-byte RADIUS Code (`1` Access-Request, `2` Access-Accept, `3` Access-Reject, `4` Accounting-Request, `5` Accounting-Response, `11` Access-Challenge) and selects UDP `1812` or `1813`. |
| `id <0..255>` | 1-byte identifier (0..255) | `1` | Sets the RADIUS Identifier byte used to match replies with pending requests. |
| `user "<text>"` | Quoted username text | `Omitted unless set` | Adds Attribute `1` (`User-Name`) to the RADIUS packet. |
| `nasip <ipv4>` | IPv4 address (e.g. 10.20.0.10) | `Omitted unless set` | Adds Attribute `4` (`NAS-IP-Address`) identifying the switch, WLC, or VPN concentrator. |
| `servicetype <number>` | Whole number (`1` Login, `2` Framed, `6` Administrative) | `Omitted unless set` | Adds Attribute `6` (`Service-Type`) as a 4-byte integer. |
| `framedip <ipv4>` | IPv4 address (e.g. 10.250.0.25) | `Omitted unless set` | Adds Attribute `8` (`Framed-IP-Address`) carrying the client’s assigned IPv4 address. |

## Cross-Layer Options Valid with `radius`

| 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 1812 (Auth) / UDP 1813 (Accounting)` | Overrides source or destination port and remembers the port pair automatically on `<-` replies. |

## Common Mistakes & Quick Fixes

### No Hyphens or Underscores in RADIUS Message Names

- **Avoid:** `access_sw -> ise_node radius access_request user "alice"`
- **Valid v3.2.2 Syntax:** `access_sw -> ise_node radius accessrequest user "alice"`

Write RADIUS packet types as single lowercase words: `accessrequest`, `accessaccept`, `accessreject`, `accesschallenge`, `accountingrequest`, and `accountingresponse`.

### Escape Backslashes in Domain Usernames

- **Avoid:** `access_sw -> ise_node radius accessrequest user "CORP\alice" (single slash)`
- **Valid v3.2.2 Syntax:** `access_sw -> ise_node radius accessrequest user "CORP\\alice"`

Inside double quotes, `\\` writes a single literal backslash (`CORP\alice`) on the wire so `	` or `
` are not interpreted as control characters.
