From 6985ed6614fac526db3340e2947d6f795db491cb Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Fri, 14 Feb 2025 18:06:41 -0800 Subject: [PATCH] add support for RESPONSE-ORIGIN and OTHER-ADDRESS attributes --- src/lib.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b805c02..edbc093 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,8 @@ const ATTR_UNKNOWN_ATTRIBUTES: u16 = 0x000a; const ATTR_REALM: u16 = 0x0014; const ATTR_NONCE: u16 = 0x0015; const ATTR_ALTERNATE_SERVER: u16 = 0x8023; +const ATTR_RESPONSE_ORIGIN: u16 = 0x802b; +const ATTR_OTHER_ADDRESS: u16 = 0x802c; const SOFTWARE: [u8; 8] = *b"tailnode"; const BINDING_REQUEST: [u8; 2] = [0x00, 0x01]; @@ -149,6 +151,8 @@ pub enum StunAttribute { UnknownAttributes(Vec), Software(String), AlternateServer(AddrPort), + ResponseOrigin(AddrPort), + OtherAddress(AddrPort), Unknown((u16, Vec)), } @@ -223,8 +227,26 @@ impl fmt::Display for StunAttribute { a.port ) } + StunAttribute::ResponseOrigin(a) => { + write!( + f, + " ResponseOrigin ({}) {}:{}", + addr_family(&a.address), + a.address, + a.port + ) + }, + StunAttribute::OtherAddress(a) => { + write!( + f, + " OtherAddress ({}) {}:{}", + addr_family(&a.address), + a.address, + a.port + ) + }, StunAttribute::Unknown((attr_type, data)) => { - write!(f, " Unknown ({}) {:?}", attr_type, data) + write!(f, " Unknown ({:04x}) {:?}", attr_type, data) } } } @@ -488,6 +510,14 @@ where let (_residual, addr) = parse_stun_address(attr_data)?; StunAttribute::AlternateServer(addr) } + ATTR_RESPONSE_ORIGIN => { + let (_residual, addr) = parse_stun_address(attr_data)?; + StunAttribute::ResponseOrigin(addr) + } + ATTR_OTHER_ADDRESS => { + let (_residual, addr) = parse_stun_address(attr_data)?; + StunAttribute::OtherAddress(addr) + } t => { warn!("Unknown STUN attribute type {t}");