pub struct ExtendedCommunity(/* private fields */);Expand description
RFC 4360 Extended Community — 8-byte value stored as u64.
Wire layout: type (1) + sub-type (1) + value (6). Bit 6 of the type byte: 0 = transitive, 1 = non-transitive.
Implementations§
Source§impl ExtendedCommunity
impl ExtendedCommunity
Sourcepub fn is_transitive(self) -> bool
pub fn is_transitive(self) -> bool
Transitive if bit 6 of the type byte is 0.
Sourcepub fn value_bytes(self) -> [u8; 6]
pub fn value_bytes(self) -> [u8; 6]
Bytes 2-7 of the community value.
Sourcepub fn route_target(self) -> Option<(u32, u32)>
pub fn route_target(self) -> Option<(u32, u32)>
Decode as Route Target (sub-type 0x02).
Returns (global_admin, local_admin) as raw u32 values. The
interpretation of global_admin depends on the type byte:
- Type 0x00 (2-octet AS specific): global = ASN (fits u16), local = u32
- Type 0x01 (IPv4 address specific): global = IPv4 addr as u32, local = u16
- Type 0x02 (4-octet AS specific): global = ASN (u32), local = u16
Callers that need to distinguish these encodings (e.g. for display as
RT:192.0.2.1:100 vs RT:65001:100) must also check type_byte().
Sourcepub fn route_origin(self) -> Option<(u32, u32)>
pub fn route_origin(self) -> Option<(u32, u32)>
Decode as Route Origin (sub-type 0x03).
Same layout as route_target() — returns raw
(global_admin, local_admin) with the same type-byte-dependent
interpretation. Check type_byte() to distinguish
2-octet AS, IPv4-address, and 4-octet AS encodings.
Sourcepub fn as_bgp_encapsulation(self) -> Option<u16>
pub fn as_bgp_encapsulation(self) -> Option<u16>
Decode as BGP Encapsulation Extended Community (RFC 9012 §4.1, encoded per the widely-deployed RFC 5512 layout: 4-byte reserved + 2-byte Tunnel Type). Type 0x03, subtype 0x0C.
Returns the Tunnel Type code. For VXLAN-EVPN (RFC 8365), the value is 8. Other common values: 7 = NVGRE, 11 = MPLS-over-GRE.
The reserved bytes are intentionally not validated here: RFC 5512
specifies MUST-zero on send, ignored on receive. FRR, GoBGP, Cisco,
and Juniper all emit zeros in practice; rejecting non-zero reserves
would break interop in the rare case an unknown implementation
re-purposes those bytes. Consumers should treat the returned
tunnel_type as the semantic signal.
Sourcepub fn bgp_encapsulation(tunnel_type: u16) -> Self
pub fn bgp_encapsulation(tunnel_type: u16) -> Self
Construct a BGP Encapsulation Extended Community (RFC 9012 §4.1).
Writes 4 bytes of reserved zero followed by the 16-bit tunnel type.
Sourcepub fn as_mac_mobility(self) -> Option<(bool, u32)>
pub fn as_mac_mobility(self) -> Option<(bool, u32)>
Decode as MAC Mobility Extended Community (RFC 7432 §7.7). Type 0x06, subtype 0x00.
Returns (sticky, sequence_number). The sticky bit (bit 0 of the
flags byte) marks the MAC as non-movable; receivers must not displace
a sticky MAC with a higher-sequence non-sticky advertisement.
Sourcepub fn mac_mobility(sticky: bool, sequence: u32) -> Self
pub fn mac_mobility(sticky: bool, sequence: u32) -> Self
Construct a MAC Mobility Extended Community (RFC 7432 §7.7).
Sourcepub fn as_esi_label(self) -> Option<(bool, u32)>
pub fn as_esi_label(self) -> Option<(bool, u32)>
Decode as ESI Label Extended Community (RFC 7432 §7.5). Type 0x06, subtype 0x01.
Returns (single_active, label). The single-active flag (bit 0 of
the flags byte) signals single-active multi-homing mode.
Sourcepub fn esi_label(single_active: bool, label: u32) -> Self
pub fn esi_label(single_active: bool, label: u32) -> Self
Construct an ESI Label Extended Community (RFC 7432 §7.5).
label is a 24-bit MPLS label or VXLAN VNI; high 8 bits are masked.
Sourcepub fn as_es_import_rt(self) -> Option<[u8; 6]>
pub fn as_es_import_rt(self) -> Option<[u8; 6]>
Decode as ES-Import Route Target Extended Community (RFC 7432 §7.6). Type 0x06, subtype 0x02.
Returns the 6-byte MAC address that serves as the import target for Type 4 ES routes.
Sourcepub fn es_import_rt(mac: [u8; 6]) -> Self
pub fn es_import_rt(mac: [u8; 6]) -> Self
Construct an ES-Import Route Target Extended Community.
Sourcepub fn as_router_mac(self) -> Option<[u8; 6]>
pub fn as_router_mac(self) -> Option<[u8; 6]>
Decode as Router MAC Extended Community (RFC 9135 §4.1). Type 0x06, subtype 0x03.
Returns the 6-byte router MAC used for symmetric IRB.
Sourcepub fn router_mac(mac: [u8; 6]) -> Self
pub fn router_mac(mac: [u8; 6]) -> Self
Construct a Router MAC Extended Community (RFC 9135 §4.1).
Sourcepub fn as_default_gateway(self) -> bool
pub fn as_default_gateway(self) -> bool
Decode as Default Gateway Extended Community (RFC 4761 §3.2.5 / RFC 7432). Type 0x03, subtype 0x0D. This is a flag-only community: presence is the signal and the 6-byte value field must be all zeros. Malformed advertisements with non-zero value bytes are treated as non-matches rather than silently accepted — downstream policy and validation consumers treat this accessor as semantic truth.
Sourcepub fn default_gateway() -> Self
pub fn default_gateway() -> Self
Construct a Default Gateway Extended Community.
Source§impl ExtendedCommunity
impl ExtendedCommunity
Sourcepub fn as_flowspec_action(&self) -> Option<FlowSpecAction>
pub fn as_flowspec_action(&self) -> Option<FlowSpecAction>
Try to decode this extended community as a FlowSpec action.
Sourcepub fn from_flowspec_action(action: &FlowSpecAction) -> Self
pub fn from_flowspec_action(action: &FlowSpecAction) -> Self
Create an extended community from a FlowSpec action.
Trait Implementations§
Source§impl Clone for ExtendedCommunity
impl Clone for ExtendedCommunity
Source§fn clone(&self) -> ExtendedCommunity
fn clone(&self) -> ExtendedCommunity
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more