rustbgpd-wire
BGP message codec for Rust. Encode and decode OPEN, UPDATE, KEEPALIVE, NOTIFICATION, and ROUTE-REFRESH messages per RFC 4271, with extensions for MP-BGP, EVPN, FlowSpec, Add-Path, Extended Messages, and more.
This crate is the wire-protocol foundation of rustbgpd but is designed for standalone use in any Rust project that needs to parse or build BGP messages — monitors, analyzers, test harnesses, MRT readers, etc.
Supported RFCs
| RFC | Feature |
|---|---|
| 1997 | Standard communities (4-byte) |
| 2545 | IPv6 link-local next-hop in MP_REACH_NLRI (32-byte form) |
| 2918 | Route Refresh capability |
| 4271 | BGP-4 core: OPEN, UPDATE, NOTIFICATION, KEEPALIVE |
| 4360 | Extended communities (route target, route origin, 4-byte AS) |
| 4456 | Route reflector: ORIGINATOR_ID, CLUSTER_LIST |
| 4486 | NOTIFICATION subcodes |
| 4724 | Graceful restart capability |
| 4760 | MP-BGP: MP_REACH_NLRI / MP_UNREACH_NLRI |
| 5492 | BGP capabilities |
| 6793 | 4-octet AS numbers |
| 7313 | Enhanced Route Refresh (BoRR / EoRR markers) |
| 7432 | EVPN: Types 1–4 (EAD, MAC/IP, IMET, Ethernet Segment) |
| 7674 | Clarification of MP_REACH_NLRI next-hop encoding |
| 7911 | Add-Path: path ID in NLRI encode/decode |
| 8092 | Large communities (3× u32) |
| 8203 | Admin shutdown communication |
| 8365 | EVPN over VXLAN encapsulation |
| 8538 | Notification GR (N-bit) |
| 8654 | Extended messages (up to 65535 bytes) |
| 8950 | Extended next hop (IPv4 NLRI over IPv6 NH) |
| 8955/8956 | FlowSpec: 13 component types, numeric/bitmask operators; §6.1-compliant NEXT_HOP validation (the irrelevant-next-hop case is accepted, not rejected) |
| 9012 | Tunnel Encapsulation attribute |
| 9135 | EVPN integrated routing for IRB |
| 9136 | EVPN Type 5: IP Prefix advertisement |
| 9494 | Long-lived graceful restart capability |
Usage
Parse an UPDATE from raw bytes:
use Bytes;
use ;
let raw = from;
let update = decode?;
let parsed = update.parse?;
for route in &parsed.announced
for attr in &parsed.attributes
Build and encode an OPEN message:
use ;
let open = OpenMessage ;
let msg = Open;
let bytes = encode_message;
Key types
Message— top-level enum:Open,Update,Keepalive,Notification,RouteRefreshUpdateMessage/ParsedUpdate— raw wire form and parsed routes + attributesPathAttribute— 18+ attribute types includingAsPath,NextHop,Communities,MpReachNlri,LargeCommunitiesPrefix—V4(Ipv4Prefix)/V6(Ipv6Prefix)enumCapability— OPEN capabilities: multi-protocol, 4-octet AS, Add-Path, graceful restart, etc.FlowSpecRule/FlowSpecComponent— FlowSpec NLRI with all 13 match typesEvpnRoute/EvpnRouteKey— typed EVPN routes (Types 1–5) with full payloads (RFC 7432, RFC 9136)DecodeError/EncodeError— structured error types viathiserror
Fuzz tested
Three fuzz targets exercise the decode paths continuously in CI:
decode_message— full BGP message framingdecode_update— UPDATE parsing with Add-Path and MP-BGP variantsdecode_flowspec— FlowSpec NLRI component decoding
License
MIT OR Apache-2.0