diff options
author | Yuchen Wu <[email protected]> | 2024-07-02 16:30:20 -0700 |
---|---|---|
committer | Yuchen Wu <[email protected]> | 2024-07-12 11:24:29 -0700 |
commit | 2ff09e727d3a896bbb5193e0b34345d9bfcc595e (patch) | |
tree | 347636c260755e85a6eb1e8e9d96abb870889ab3 | |
parent | 09b5e03fb180dbf1742938538ebccf0d95586b79 (diff) | |
download | pingora-2ff09e727d3a896bbb5193e0b34345d9bfcc595e.tar.gz pingora-2ff09e727d3a896bbb5193e0b34345d9bfcc595e.zip |
Ignore 0.0.0.0 when checking fd mismatch
Avoid false positive since 0.0.0.0 in some systems is mapped
to other IPs.
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-core/src/protocols/mod.rs | 9 |
2 files changed, 10 insertions, 1 deletions
@@ -1 +1 @@ -940539c7d0bff45d8182d4eb6c40d099b20ed44e
\ No newline at end of file +05356d8d19882e125b57f2b855ec744bec733d40
\ No newline at end of file diff --git a/pingora-core/src/protocols/mod.rs b/pingora-core/src/protocols/mod.rs index 0699ac5..32695e1 100644 --- a/pingora-core/src/protocols/mod.rs +++ b/pingora-core/src/protocols/mod.rs @@ -29,6 +29,7 @@ pub use ssl::ALPN; use async_trait::async_trait; use std::fmt::Debug; +use std::net::{IpAddr, Ipv4Addr}; use std::sync::Arc; /// Define how a protocol should shutdown its connection. @@ -256,6 +257,14 @@ impl ConnFdReusable for InetSocketAddr { let fd = fd.as_raw_fd(); match getpeername::<SockaddrStorage>(fd) { Ok(peer) => { + const ZERO: IpAddr = IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)); + if self.ip() == ZERO { + // https://www.rfc-editor.org/rfc/rfc1122.html#section-3.2.1.3 + // 0.0.0.0 should only be used as source IP not destination + // However in some systems this destination IP is mapped to 127.0.0.1. + // We just skip this check here to avoid false positive mismatch. + return true; + } let addr = SockaddrStorage::from(*self); if addr == peer { debug!("Inet FD to: {addr} is reusable"); |