Skip to content

Commit

Permalink
fix(shadowsocks): IpStackCapability check IPv4-mapped-IPv6 properly
Browse files Browse the repository at this point in the history
- ref #1543
  • Loading branch information
zonyitoo committed Jun 16, 2024
1 parent 5ba8b7d commit 765c9e5
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/shadowsocks/src/net/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ static IP_STACK_CAPABILITIES: Lazy<IpStackCapabilities> = Lazy::new(|| {
// Check IPv4
if let Ok(_) = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)) {

Check warning on line 153 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy ubuntu-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:153:12 | 153 | if let Ok(_) = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)) { | -------^^^^^--------------------------------------------------------------- help: try: `if Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `#[warn(clippy::redundant_pattern_matching)]` on by default

Check warning on line 153 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy macos-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:153:12 | 153 | if let Ok(_) = Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)) { | -------^^^^^--------------------------------------------------------------- help: try: `if Socket::new(Domain::IPV4, Type::STREAM, Some(Protocol::TCP)).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `#[warn(clippy::redundant_pattern_matching)]` on by default
caps.support_ipv4 = true;
debug!("IpStackCapability support_ipv4=true");
}

// Check IPv6 (::1)
Expand All @@ -160,16 +161,18 @@ static IP_STACK_CAPABILITIES: Lazy<IpStackCapabilities> = Lazy::new(|| {
let local_host = SockAddr::from(SocketAddr::new(Ipv6Addr::LOCALHOST.into(), 0));
if let Ok(..) = ipv6_socket.bind(&local_host) {

Check warning on line 162 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy ubuntu-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:162:20 | 162 | if let Ok(..) = ipv6_socket.bind(&local_host) { | -------^^^^^^-------------------------------- help: try: `if ipv6_socket.bind(&local_host).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

Check warning on line 162 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy macos-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:162:20 | 162 | if let Ok(..) = ipv6_socket.bind(&local_host) { | -------^^^^^^-------------------------------- help: try: `if ipv6_socket.bind(&local_host).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
caps.support_ipv6 = true;
debug!("IpStackCapability support_ipv6=true");
}
}
}

// Check IPv4-mapped-IPv6 (127.0.0.1)
if let Ok(ipv6_socket) = Socket::new(Domain::IPV6, Type::STREAM, Some(Protocol::TCP)) {
if let Ok(..) = ipv6_socket.set_only_v6(false) {

Check warning on line 171 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy ubuntu-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:171:16 | 171 | if let Ok(..) = ipv6_socket.set_only_v6(false) { | -------^^^^^^--------------------------------- help: try: `if ipv6_socket.set_only_v6(false).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

Check warning on line 171 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy macos-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:171:16 | 171 | if let Ok(..) = ipv6_socket.set_only_v6(false) { | -------^^^^^^--------------------------------- help: try: `if ipv6_socket.set_only_v6(false).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
let local_host = SockAddr::from(SocketAddr::new(Ipv4Addr::LOCALHOST.into(), 0));
let local_host = SockAddr::from(SocketAddr::new(Ipv4Addr::LOCALHOST.to_ipv6_mapped().into(), 0));
if let Ok(..) = ipv6_socket.bind(&local_host) {

Check warning on line 173 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy ubuntu-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:173:20 | 173 | if let Ok(..) = ipv6_socket.bind(&local_host) { | -------^^^^^^-------------------------------- help: try: `if ipv6_socket.bind(&local_host).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching

Check warning on line 173 in crates/shadowsocks/src/net/sys/mod.rs

View workflow job for this annotation

GitHub Actions / clippy macos-latest

redundant pattern matching, consider using `is_ok()`

warning: redundant pattern matching, consider using `is_ok()` --> crates/shadowsocks/src/net/sys/mod.rs:173:20 | 173 | if let Ok(..) = ipv6_socket.bind(&local_host) { | -------^^^^^^-------------------------------- help: try: `if ipv6_socket.bind(&local_host).is_ok()` | = note: this will change drop order of the result, as well as all temporaries = note: add `#[allow(clippy::redundant_pattern_matching)]` if this is important = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
caps.support_ipv4_mapped_ipv6 = true;
debug!("IpStackCapability support_ipv4_mapped_ipv6=true");
}
}
}
Expand Down

0 comments on commit 765c9e5

Please sign in to comment.