From ffbb885586832928c3b6335d22986c854079bb88 Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 1 Aug 2017 11:08:48 +0000 Subject: [PATCH] Remove IpEndpoint::accepts. Unclear purpose, one use, we don't need it. --- src/socket/udp.rs | 8 +++++--- src/wire/ip.rs | 8 -------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/socket/udp.rs b/src/socket/udp.rs index 7a47811..e60f3c7 100644 --- a/src/socket/udp.rs +++ b/src/socket/udp.rs @@ -188,12 +188,14 @@ impl<'a, 'b> UdpSocket<'a, 'b> { let packet = UdpPacket::new_checked(&payload[..ip_repr.payload_len()])?; let repr = UdpRepr::parse(&packet, &ip_repr.src_addr(), &ip_repr.dst_addr())?; - let endpoint = IpEndpoint { addr: ip_repr.src_addr(), port: repr.src_port }; - if !self.endpoint.accepts(&endpoint) { return Err(Error::Rejected) } + // Reject packets with a wrong destination. + if self.endpoint.port != repr.dst_port { return Err(Error::Rejected) } + if !self.endpoint.addr.is_unspecified() && + self.endpoint.addr != ip_repr.dst_addr() { return Err(Error::Rejected) } let packet_buf = self.rx_buffer.try_enqueue(|buf| buf.resize(repr.payload.len()))?; packet_buf.as_mut().copy_from_slice(repr.payload); - packet_buf.endpoint = endpoint; + packet_buf.endpoint = IpEndpoint { addr: ip_repr.src_addr(), port: repr.src_port }; net_trace!("[{}]{}:{}: receiving {} octets", self.debug_id, self.endpoint, packet_buf.endpoint, packet_buf.size); diff --git a/src/wire/ip.rs b/src/wire/ip.rs index a8c0c32..4e6fdfd 100644 --- a/src/wire/ip.rs +++ b/src/wire/ip.rs @@ -139,14 +139,6 @@ impl Endpoint { pub fn is_specified(&self) -> bool { !self.addr.is_unspecified() && self.port != 0 } - - /// Query whether `self` should accept packets from `other`. - /// - /// Returns `true` if `other` is a specified endpoint and `self` either - /// has an unspecified address, or the addresses are equal. - pub fn accepts(&self, other: &Endpoint) -> bool { - other.is_specified() && (self.addr == other.addr || self.addr.is_unspecified()) - } } impl fmt::Display for Endpoint {