From 8c22b4470db43200d34e2489bfd98ded72104af2 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 3 Jan 2025 00:32:32 +0100 Subject: [PATCH] update smoltcp (#214) --- CHANGELOG.md | 2 + Cargo.lock | 113 ++++++++++++++++--------------- Cargo.toml | 6 +- src/messages.rs | 10 +-- src/network/tests.rs | 60 ++++++++-------- src/network/udp.rs | 13 ++-- src/network/virtual_device.rs | 6 +- src/packet_sources/wireguard.rs | 8 +-- wireguard-test-client/Cargo.toml | 2 +- 9 files changed, 109 insertions(+), 111 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea8f8791..e87f0ecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased: mitmproxy_rs next +- Add local redirect mode for Linux. +- Update dependencies. ## 11 December 2024: mitmproxy_rs 0.11.1 diff --git a/Cargo.lock b/Cargo.lock index 94dac377..164100a9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ checksum = "c7c24de15d275a1ecfd47a380fb4d5ec9bfe0933f309ed5e705b775596a3574d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -172,7 +172,7 @@ checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -288,7 +288,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -335,7 +335,7 @@ dependencies = [ "aya-log-parser", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -931,7 +931,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -960,7 +960,7 @@ dependencies = [ "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -1000,7 +1000,7 @@ checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -1018,7 +1018,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -1169,7 +1169,7 @@ checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -1253,7 +1253,7 @@ checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -1714,7 +1714,7 @@ checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -1794,9 +1794,9 @@ checksum = "fc6d6206008e25125b1f97fbe5d309eb7b85141cf9199d52dbd3729a1584dd16" [[package]] name = "internet-packet" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a91d3c77ac026a0277212049e3c4a53729149bfea6fc47f32af16f3a6f0a5941" +checksum = "b6cfb28f710b057e47c991776879091bd1c706318cc724ce65c932474cd95e95" dependencies = [ "internet-checksum", "smoltcp", @@ -1842,7 +1842,7 @@ dependencies = [ "socket2", "widestring", "windows-sys 0.48.0", - "winreg 0.50.0", + "winreg", ] [[package]] @@ -2127,7 +2127,6 @@ dependencies = [ "tokio-util", "tun", "windows 0.58.0", - "x25519-dalek", ] [[package]] @@ -2265,7 +2264,7 @@ checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2359,7 +2358,7 @@ checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2506,7 +2505,7 @@ dependencies = [ "proc-macro-error-attr2", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2538,7 +2537,7 @@ dependencies = [ "itertools 0.13.0", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2593,7 +2592,7 @@ checksum = "b2df2884957d2476731f987673befac5d521dff10abb0a7cbe12015bc7702fe9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2636,7 +2635,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2649,7 +2648,7 @@ dependencies = [ "proc-macro2", "pyo3-build-config", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2884,22 +2883,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9781016e935a97e8beecf0c933758c97a5520d32930e460142b4cd80c6338e" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.216" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46f859dbbf73865c6627ed570e78961cd3ac92407a2d117204c49232485da55e" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -2961,8 +2960,9 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "smoltcp" -version = "0.11.0" -source = "git+https://github.com/smoltcp-rs/smoltcp?rev=ef67e7b46cabf49783053cbf68d8671ed97ff8d4#ef67e7b46cabf49783053cbf68d8671ed97ff8d4" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dad095989c1533c1c266d9b1e8d70a1329dd3723c3edac6d03bbd67e7bf6f4bb" dependencies = [ "bitflags 1.3.2", "byteorder", @@ -3021,9 +3021,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.92" +version = "2.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ae51629bf965c5c098cc9e87908a3df5301051a9e087d6f9bef5c9771ed126" +checksum = "987bc0be1cdea8b10216bd06e2ca407d40b9543468fafd3ddfb02f36e77f71f3" dependencies = [ "proc-macro2", "quote", @@ -3044,7 +3044,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3080,12 +3080,13 @@ checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" [[package]] name = "tempfile" -version = "3.14.0" +version = "3.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cce251fcbc87fac86a866eeb0d6c2d536fc16d06f184bb61aeae11aa4cee0c" +checksum = "9a8a559c81686f576e8cd0290cd2a24a2a9ad80c98b3478856500fcbd7acd704" dependencies = [ "cfg-if", "fastrand", + "getrandom", "once_cell", "rustix", "windows-sys 0.59.0", @@ -3117,7 +3118,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3128,7 +3129,7 @@ checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3232,7 +3233,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3363,7 +3364,7 @@ checksum = "395ae124c09f9e6918a2310af6038fba074bcf474ac352496d5910dd59a2226d" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3539,7 +3540,7 @@ dependencies = [ "log", "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", "wasm-bindgen-shared", ] @@ -3561,7 +3562,7 @@ checksum = "30d7a95b763d3c45903ed6c81f156801839e5ee968bb07e534c44df0fcd330c2" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3722,7 +3723,7 @@ checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3733,7 +3734,7 @@ checksum = "2bbd5b46c938e506ecbce286b6628a02171d56153ba733b6c741fc627ec9579b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3744,7 +3745,7 @@ checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3755,7 +3756,7 @@ checksum = "053c4c462dc91d3b1504c6fe5a726dd15e216ba718e84a0e46a88fbe5ded3515" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -3962,13 +3963,13 @@ dependencies = [ ] [[package]] -name = "winreg" -version = "0.52.0" +name = "winreg2" +version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +checksum = "e25225e44ce2ac6b72befed6416b0857cf8663f9963dba572c39473062f0e625" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] @@ -3988,9 +3989,9 @@ checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" [[package]] name = "wintun-bindings" -version = "0.7.26" +version = "0.7.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "379a11db27bd8fb4d14ac1a445fc056234f9a3b60e38c8ce2a3d56110f62771b" +checksum = "8e35d3911efde5ee25586385204127ff6a3f251477dcdd3b222775aaa4d95977" dependencies = [ "blocking", "c2rust-bitfields", @@ -3999,7 +4000,7 @@ dependencies = [ "log", "thiserror 2.0.9", "windows-sys 0.59.0", - "winreg 0.52.0", + "winreg2", ] [[package]] @@ -4057,7 +4058,7 @@ checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", "synstructure", ] @@ -4079,7 +4080,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -4099,7 +4100,7 @@ checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", "synstructure", ] @@ -4120,7 +4121,7 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] [[package]] @@ -4142,5 +4143,5 @@ checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.92", + "syn 2.0.94", ] diff --git a/Cargo.toml b/Cargo.toml index 3fd2bb7a..82ea5f7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,24 +55,22 @@ anyhow = { version = "1.0.93", features = ["backtrace"] } log = "0.4.22" once_cell = "1" pretty-hex = "0.4.1" -smoltcp = "0.11" +smoltcp = "0.12" tokio = { version = "1.41.1", features = ["macros", "net", "rt-multi-thread", "sync", "time", "io-util", "process"] } boringtun = { version = "0.6", default-features = false } -x25519-dalek = "2.0.0" console-subscriber = { version = "0.4.1", optional = true } image = { version = "0.25.5", default-features = false, features = ["png", "tiff"] } prost = "0.13.3" tokio-util = { version = "0.7.12", features = ["codec"] } futures-util = { version = "0.3.31", features = ["sink"] } lru_time_cache = "0.11.11" -internet-packet = { version = "0.2.2", features = ["smoltcp"] } +internet-packet = { version = "0.2.3", features = ["smoltcp"] } data-encoding = "2.4.0" hickory-resolver = "0.24.1" socket2 = "0.5.8" [patch.crates-io] # tokio = { path = "../tokio/tokio" } -smoltcp = { git = 'https://github.com/smoltcp-rs/smoltcp', rev = 'ef67e7b46cabf49783053cbf68d8671ed97ff8d4' } boringtun = { git = 'https://github.com/cloudflare/boringtun', rev = 'e3252d9c4f4c8fc628995330f45369effd4660a1' } [target.'cfg(windows)'.dependencies.windows] diff --git a/src/messages.rs b/src/messages.rs index 4a5ed3bc..b302b58c 100755 --- a/src/messages.rs +++ b/src/messages.rs @@ -1,6 +1,6 @@ use std::fmt; use std::fmt::Formatter; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; +use std::net::{IpAddr, SocketAddr}; use anyhow::{anyhow, Result}; use internet_packet::{InternetPacket, TransportProtocol}; @@ -184,15 +184,15 @@ impl TryFrom> for SmolPacket { impl SmolPacket { pub fn src_ip(&self) -> IpAddr { match self { - SmolPacket::V4(packet) => IpAddr::V4(Ipv4Addr::from(packet.src_addr())), - SmolPacket::V6(packet) => IpAddr::V6(Ipv6Addr::from(packet.src_addr())), + SmolPacket::V4(packet) => IpAddr::V4(packet.src_addr()), + SmolPacket::V6(packet) => IpAddr::V6(packet.src_addr()), } } pub fn dst_ip(&self) -> IpAddr { match self { - SmolPacket::V4(packet) => IpAddr::V4(Ipv4Addr::from(packet.dst_addr())), - SmolPacket::V6(packet) => IpAddr::V6(Ipv6Addr::from(packet.dst_addr())), + SmolPacket::V4(packet) => IpAddr::V4(packet.dst_addr()), + SmolPacket::V6(packet) => IpAddr::V6(packet.dst_addr()), } } diff --git a/src/network/tests.rs b/src/network/tests.rs index 5dcd5525..f6d84f3c 100755 --- a/src/network/tests.rs +++ b/src/network/tests.rs @@ -1,4 +1,4 @@ -use std::net::{Ipv6Addr, SocketAddr}; +use std::net::SocketAddr; use super::task::NetworkTask; use crate::messages::{ @@ -6,6 +6,8 @@ use crate::messages::{ }; use crate::shutdown; use anyhow::{anyhow, Result}; +use core::net::Ipv4Addr; +use core::net::Ipv6Addr; use internet_packet::InternetPacket; use smoltcp::{phy::ChecksumCapabilities, wire::*}; use tokio::sync::watch; @@ -99,8 +101,8 @@ impl MockNetwork { #[allow(clippy::too_many_arguments)] fn build_ipv4_tcp_packet( - src_addr: Ipv4Address, - dst_addr: Ipv4Address, + src_addr: Ipv4Addr, + dst_addr: Ipv4Addr, src_port: u16, dst_port: u16, control: TcpControl, @@ -119,6 +121,7 @@ fn build_ipv4_tcp_packet( max_seg_size: Some(1380), sack_permitted: true, sack_ranges: [None, None, None], + timestamp: None, payload, }; @@ -147,8 +150,8 @@ fn build_ipv4_tcp_packet( #[allow(clippy::too_many_arguments)] fn build_ipv6_tcp_packet( - src_addr: Ipv6Address, - dst_addr: Ipv6Address, + src_addr: Ipv6Addr, + dst_addr: Ipv6Addr, src_port: u16, dst_port: u16, control: TcpControl, @@ -167,6 +170,7 @@ fn build_ipv6_tcp_packet( max_seg_size: Some(1380), sack_permitted: true, sack_ranges: [None, None, None], + timestamp: None, payload, }; @@ -194,8 +198,8 @@ fn build_ipv6_tcp_packet( } fn build_ipv4_udp_packet( - src_addr: Ipv4Address, - dst_addr: Ipv4Address, + src_addr: Ipv4Addr, + dst_addr: Ipv4Addr, src_port: u16, dst_port: u16, payload: &[u8], @@ -228,8 +232,8 @@ fn build_ipv4_udp_packet( } fn build_ipv6_udp_packet( - src_addr: Ipv6Address, - dst_addr: Ipv6Address, + src_addr: Ipv6Addr, + dst_addr: Ipv6Addr, src_port: u16, dst_port: u16, payload: &[u8], @@ -262,8 +266,8 @@ fn build_ipv6_udp_packet( } fn build_icmp4_echo_packet( - src_addr: Ipv4Address, - dst_addr: Ipv4Address, + src_addr: Ipv4Addr, + dst_addr: Ipv4Addr, ident: u16, seq_no: u16, data: &[u8], @@ -294,8 +298,8 @@ fn build_icmp4_echo_packet( } fn build_icmp6_echo_packet( - src_addr: Ipv6Address, - dst_addr: Ipv6Address, + src_addr: Ipv6Addr, + dst_addr: Ipv6Addr, ident: u16, seq_no: u16, data: &[u8], @@ -391,8 +395,8 @@ async fn udp_read_write( #[tokio::test] async fn ipv4_udp() -> Result<()> { init_logger(); - let src_addr = Ipv4Address([10, 0, 0, 1]); - let dst_addr = Ipv4Address([10, 0, 0, 42]); + let src_addr = "10.0.0.1".parse()?; + let dst_addr = "10.0.0.42".parse()?; let data = "hello world!".as_bytes(); let udp_ip_packet = build_ipv4_udp_packet(src_addr, dst_addr, 1234, 31337, data); @@ -409,19 +413,17 @@ async fn ipv4_udp() -> Result<()> { async fn ipv6_udp() -> Result<()> { init_logger(); - let src: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:01".parse()?; - let dst: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:02".parse()?; + let src_addr: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:01".parse()?; + let dst_addr: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:02".parse()?; - let src_addr = Ipv6Address::from(src); - let dst_addr = Ipv6Address::from(dst); let data = "hello world!".as_bytes(); let udp_ip_packet = build_ipv6_udp_packet(src_addr, dst_addr, 1234, 31337, data); udp_read_write( udp_ip_packet.into(), - SocketAddr::from((src, 1234)), - SocketAddr::from((dst, 31337)), + SocketAddr::from((src_addr, 1234)), + SocketAddr::from((dst_addr, 31337)), ) .await } @@ -432,8 +434,8 @@ async fn tcp_ipv4_connection() -> Result<()> { let mut mock = MockNetwork::init().await?; let mut seq = TcpSeqNumber(rand::random::()); - let src_addr = Ipv4Address([10, 0, 0, 1]); - let dst_addr = Ipv4Address([10, 0, 0, 42]); + let src_addr = "10.0.0.1".parse()?; + let dst_addr = "10.0.0.42".parse()?; let data = "hello world!".as_bytes(); // send TCP SYN @@ -609,8 +611,8 @@ async fn tcp_ipv6_connection() -> Result<()> { let mut mock = MockNetwork::init().await?; let mut seq = TcpSeqNumber(rand::random::()); - let src_addr = Ipv6Address(b"cafecafecafe0001".to_owned()); - let dst_addr = Ipv6Address(b"cafecafecafe0002".to_owned()); + let src_addr: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:01".parse()?; + let dst_addr: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:02".parse()?; let data = "hello world!".as_bytes(); // send TCP SYN @@ -785,8 +787,8 @@ async fn receive_icmp4_echo() -> Result<()> { init_logger(); let mut mock = MockNetwork::init().await?; - let src_addr = Ipv4Address([10, 0, 0, 1]); - let dst_addr = Ipv4Address([10, 0, 0, 42]); + let src_addr = "10.0.0.1".parse()?; + let dst_addr = "10.0.0.42".parse()?; let data = "hello world!".as_bytes(); let icmp_echo_ip_packet = build_icmp4_echo_packet(src_addr, dst_addr, 42, 31337, data); @@ -823,8 +825,8 @@ async fn receive_icmp6_echo() -> Result<()> { init_logger(); let mut mock = MockNetwork::init().await?; - let src_addr = Ipv6Address(b"cafecafecafe0001".to_owned()); - let dst_addr = Ipv6Address(b"cafecafecafe0002".to_owned()); + let src_addr: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:01".parse()?; + let dst_addr: Ipv6Addr = "ca:fe:ca:fe:ca:fe:00:02".parse()?; let data = "hello world!".as_bytes(); let icmp_echo_ip_packet = build_icmp6_echo_packet(src_addr, dst_addr, 42, 31337, data); diff --git a/src/network/udp.rs b/src/network/udp.rs index 1b85c600..74502a77 100644 --- a/src/network/udp.rs +++ b/src/network/udp.rs @@ -12,10 +12,7 @@ use crate::messages::{ use internet_packet::InternetPacket; use smoltcp::phy::ChecksumCapabilities; -use smoltcp::wire::{ - IpProtocol, IpRepr, Ipv4Address, Ipv4Packet, Ipv4Repr, Ipv6Address, Ipv6Packet, Ipv6Repr, - UdpRepr, -}; +use smoltcp::wire::{IpProtocol, IpRepr, Ipv4Packet, Ipv4Repr, Ipv6Packet, Ipv6Repr, UdpRepr}; #[derive(Default)] pub struct ConnectionState { @@ -217,15 +214,15 @@ impl From for SmolPacket { let ip_repr: IpRepr = match (src_addr, dst_addr) { (SocketAddr::V4(src_addr), SocketAddr::V4(dst_addr)) => IpRepr::Ipv4(Ipv4Repr { - src_addr: Ipv4Address::from(*src_addr.ip()), - dst_addr: Ipv4Address::from(*dst_addr.ip()), + src_addr: (*src_addr.ip()), + dst_addr: (*dst_addr.ip()), next_header: IpProtocol::Udp, payload_len: udp_repr.header_len() + payload.len(), hop_limit: 255, }), (SocketAddr::V6(src_addr), SocketAddr::V6(dst_addr)) => IpRepr::Ipv6(Ipv6Repr { - src_addr: Ipv6Address::from(*src_addr.ip()), - dst_addr: Ipv6Address::from(*dst_addr.ip()), + src_addr: (*src_addr.ip()), + dst_addr: (*dst_addr.ip()), next_header: IpProtocol::Udp, payload_len: udp_repr.header_len() + payload.len(), hop_limit: 255, diff --git a/src/network/virtual_device.rs b/src/network/virtual_device.rs index c87f1885..c0c451ed 100755 --- a/src/network/virtual_device.rs +++ b/src/network/virtual_device.rs @@ -99,10 +99,10 @@ pub struct VirtualRxToken { } impl RxToken for VirtualRxToken { - fn consume(mut self, f: F) -> R + fn consume(self, f: F) -> R where - F: FnOnce(&mut [u8]) -> R, + F: FnOnce(&[u8]) -> R, { - f(&mut self.buffer[..]) + f(&self.buffer[..]) } } diff --git a/src/packet_sources/wireguard.rs b/src/packet_sources/wireguard.rs index 5456d711..19fb5ef4 100755 --- a/src/packet_sources/wireguard.rs +++ b/src/packet_sources/wireguard.rs @@ -1,5 +1,5 @@ use std::collections::HashMap; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}; +use std::net::{IpAddr, SocketAddr}; use std::sync::Arc; use crate::messages::{ @@ -286,8 +286,7 @@ impl WireGuardTask { pretty_hex(&buf), ); - self.peers_by_ip - .insert(Ipv4Addr::from(packet.src_addr()).into(), peer); + self.peers_by_ip.insert(packet.src_addr().into(), peer); let event = NetworkEvent::ReceivePacket { packet: SmolPacket::from(packet), tunnel_info: TunnelInfo::WireGuard { @@ -318,8 +317,7 @@ impl WireGuardTask { pretty_hex(&buf), ); - self.peers_by_ip - .insert(Ipv6Addr::from(packet.src_addr()).into(), peer); + self.peers_by_ip.insert(packet.src_addr().into(), peer); let event = NetworkEvent::ReceivePacket { packet: SmolPacket::from(packet), tunnel_info: TunnelInfo::WireGuard { diff --git a/wireguard-test-client/Cargo.toml b/wireguard-test-client/Cargo.toml index 2e8a5787..e948ed5a 100644 --- a/wireguard-test-client/Cargo.toml +++ b/wireguard-test-client/Cargo.toml @@ -17,4 +17,4 @@ anyhow = "1.0.93" data-encoding = "2.6.0" boringtun = "0.6" hex = "0.4" -smoltcp = "0.11" +smoltcp = "0.12"