Skip to content

Commit

Permalink
fix(deps): update rust crate smoltcp to 0.12 (#1785)
Browse files Browse the repository at this point in the history
* fix(deps): update rust crate smoltcp to 0.12

* fix(shadowsocks-service): compatible with smoltcp v0.12

* fix(ci): service msrv 1.80, rust msrv 1.80, lib msrv 1.75

* chore(shadowsocks-service): smoltcp v0.12 uses libcore Ipv4Addr, Ipv6Addr

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: zonyitoo <[email protected]>
  • Loading branch information
renovate[bot] and zonyitoo authored Nov 28, 2024
1 parent 707b8bc commit 1adb52d
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 24 deletions.
54 changes: 50 additions & 4 deletions .github/workflows/build-msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ env:
RUST_LOG: "trace"

jobs:
buid-test-check:
shadowsocks-rust:
strategy:
matrix:
platform:
Expand All @@ -28,12 +28,58 @@ jobs:
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.75
rustup default 1.75
rustup override set 1.75
rustup toolchain install 1.80
rustup default 1.80
rustup override set 1.80
- name: Build with All Features Enabled (Unix)
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: cargo build --verbose --features "full-extra local-flow-stat utility-url-outline"
- name: Build with All Features Enabled (Windows)
if: ${{ runner.os == 'Windows' }}
run: cargo build --verbose --features "full-extra local-flow-stat utility-url-outline winservice"

shadowsocks-service:
strategy:
matrix:
platform:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- if: ${{ runner.os == 'Windows' }}
uses: ilammy/setup-nasm@v1
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.80
rustup default 1.80
rustup override set 1.80
- name: Build with All Features Enabled
run: cargo build --manifest-path crates/shadowsocks-service/Cargo.toml --verbose --features "full dns-over-tls dns-over-https dns-over-h3 local-dns local-flow-stat local-http-rustls local-tun local-fake-dns local-online-config stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra security-replay-attack-detect"

shadowsocks:
strategy:
matrix:
platform:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- if: ${{ runner.os == 'Windows' }}
uses: ilammy/setup-nasm@v1
- name: Install Rust
run: |
rustup set profile minimal
rustup toolchain install 1.75
rustup default 1.75
rustup override set 1.75
- name: Build with All Features Enabled
run: cargo build --manifest-path crates/shadowsocks/Cargo.toml --verbose --features "stream-cipher aead-cipher-extra aead-cipher-2022 aead-cipher-2022-extra security-replay-attack-detect"
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ documentation = "https://docs.rs/shadowsocks-rust"
keywords = ["shadowsocks", "proxy", "socks", "socks5", "firewall"]
license = "MIT"
edition = "2021"
rust-version = "1.75"
rust-version = "1.80"

[badges]
maintenance = { status = "passively-maintained" }
Expand Down
4 changes: 2 additions & 2 deletions crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ documentation = "https://docs.rs/shadowsocks-service"
keywords = ["shadowsocks", "proxy", "socks", "socks5", "firewall"]
license = "MIT"
edition = "2021"
rust-version = "1.75"
rust-version = "1.80"

[badges]
maintenance = { status = "passively-maintained" }
Expand Down Expand Up @@ -199,7 +199,7 @@ tun2 = { version = "4.0", optional = true, default-features = false, features =
"async",
] }
etherparse = { version = "0.16", optional = true }
smoltcp = { version = "0.11", optional = true, default-features = false, features = [
smoltcp = { version = "0.12", optional = true, default-features = false, features = [
"std",
"log",
"medium-ip",
Expand Down
10 changes: 5 additions & 5 deletions crates/shadowsocks-service/src/local/tun/ip_packet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! IP packet encapsulation

use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use std::net::IpAddr;

use smoltcp::wire::{IpProtocol, IpVersion, Ipv4Packet, Ipv6Packet};

Expand All @@ -21,15 +21,15 @@ impl<T: AsRef<[u8]> + Copy> IpPacket<T> {

pub fn src_addr(&self) -> IpAddr {
match *self {
IpPacket::Ipv4(ref packet) => IpAddr::from(Ipv4Addr::from(packet.src_addr())),
IpPacket::Ipv6(ref packet) => IpAddr::from(Ipv6Addr::from(packet.src_addr())),
IpPacket::Ipv4(ref packet) => IpAddr::from(packet.src_addr()),
IpPacket::Ipv6(ref packet) => IpAddr::from(packet.src_addr()),
}
}

pub fn dst_addr(&self) -> IpAddr {
match *self {
IpPacket::Ipv4(ref packet) => IpAddr::from(Ipv4Addr::from(packet.dst_addr())),
IpPacket::Ipv6(ref packet) => IpAddr::from(Ipv6Addr::from(packet.dst_addr())),
IpPacket::Ipv4(ref packet) => IpAddr::from(packet.dst_addr()),
IpPacket::Ipv6(ref packet) => IpAddr::from(packet.dst_addr()),
}
}

Expand Down
11 changes: 6 additions & 5 deletions crates/shadowsocks-service/src/local/tun/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::{
use log::{debug, error, trace};
use shadowsocks::{net::TcpSocketOpts, relay::socks5::Address};
use smoltcp::{
iface::{Config as InterfaceConfig, Interface, SocketHandle, SocketSet},
iface::{Config as InterfaceConfig, Interface, PollResult, SocketHandle, SocketSet},
phy::{DeviceCapabilities, Medium},
socket::tcp::{Socket as TcpSocket, SocketBuffer as TcpSocketBuffer, State as TcpState},
storage::RingBuffer,
Expand Down Expand Up @@ -324,9 +324,7 @@ impl TcpTun {
}

let before_poll = SmolInstant::now();
let updated_sockets = iface.poll(before_poll, device, &mut socket_set);

if updated_sockets {
if let PollResult::SocketStateChanged = iface.poll(before_poll, device, &mut socket_set) {
trace!("VirtDevice::poll costed {}", SmolInstant::now() - before_poll);
}

Expand Down Expand Up @@ -357,7 +355,10 @@ impl TcpTun {
}

// SHUT_WR
if matches!(control.send_state, TcpSocketState::Close) && socket.send_queue() == 0 && control.send_buffer.is_empty() {
if matches!(control.send_state, TcpSocketState::Close)
&& socket.send_queue() == 0
&& control.send_buffer.is_empty()
{
trace!("closing TCP Write Half, {:?}", socket.state());

// Close the socket. Set to FIN state
Expand Down
10 changes: 5 additions & 5 deletions crates/shadowsocks-service/src/local/tun/virt_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Device for VirtTunDevice {
}

fn transmit(&mut self, _timestamp: Instant) -> Option<Self::TxToken<'_>> {
return Some(VirtTxToken(self));
Some(VirtTxToken(self))
}

fn capabilities(&self) -> DeviceCapabilities {
Expand All @@ -86,17 +86,17 @@ pub struct VirtRxToken<'a> {
}

impl phy::RxToken for VirtRxToken<'_> {
fn consume<R, F>(mut self, f: F) -> R
fn consume<R, F>(self, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
F: FnOnce(&[u8]) -> R,
{
f(&mut self.buffer[..])
f(&self.buffer)
}
}

pub struct VirtTxToken<'a>(&'a mut VirtTunDevice);

impl<'a> phy::TxToken for VirtTxToken<'a> {
impl phy::TxToken for VirtTxToken<'_> {
fn consume<R, F>(self, len: usize, f: F) -> R
where
F: FnOnce(&mut [u8]) -> R,
Expand Down

0 comments on commit 1adb52d

Please sign in to comment.