add support for RESPONSE-ORIGIN and OTHER-ADDRESS attributes
This commit is contained in:
		
							
								
								
									
										32
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										32
									
								
								src/lib.rs
									
									
									
									
									
								
							@@ -31,6 +31,8 @@ const ATTR_UNKNOWN_ATTRIBUTES: u16 = 0x000a;
 | 
				
			|||||||
const ATTR_REALM: u16 = 0x0014;
 | 
					const ATTR_REALM: u16 = 0x0014;
 | 
				
			||||||
const ATTR_NONCE: u16 = 0x0015;
 | 
					const ATTR_NONCE: u16 = 0x0015;
 | 
				
			||||||
const ATTR_ALTERNATE_SERVER: u16 = 0x8023;
 | 
					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 SOFTWARE: [u8; 8] = *b"tailnode";
 | 
				
			||||||
const BINDING_REQUEST: [u8; 2] = [0x00, 0x01];
 | 
					const BINDING_REQUEST: [u8; 2] = [0x00, 0x01];
 | 
				
			||||||
@@ -149,6 +151,8 @@ pub enum StunAttribute {
 | 
				
			|||||||
    UnknownAttributes(Vec<u16>),
 | 
					    UnknownAttributes(Vec<u16>),
 | 
				
			||||||
    Software(String),
 | 
					    Software(String),
 | 
				
			||||||
    AlternateServer(AddrPort),
 | 
					    AlternateServer(AddrPort),
 | 
				
			||||||
 | 
					    ResponseOrigin(AddrPort),
 | 
				
			||||||
 | 
					    OtherAddress(AddrPort),
 | 
				
			||||||
    Unknown((u16, Vec<u8>)),
 | 
					    Unknown((u16, Vec<u8>)),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -223,8 +227,26 @@ impl fmt::Display for StunAttribute {
 | 
				
			|||||||
                    a.port
 | 
					                    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)) => {
 | 
					            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)?;
 | 
					            let (_residual, addr) = parse_stun_address(attr_data)?;
 | 
				
			||||||
            StunAttribute::AlternateServer(addr)
 | 
					            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 => {
 | 
					        t => {
 | 
				
			||||||
            warn!("Unknown STUN attribute type {t}");
 | 
					            warn!("Unknown STUN attribute type {t}");
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user