mirror of
https://github.com/dndx/phantun.git
synced 2025-10-16 02:35:35 +08:00
Compare commits
9 Commits
v0.8.0
...
dependabot
Author | SHA1 | Date | |
---|---|---|---|
|
2dcbd45d34 | ||
|
7f7da10b1b | ||
|
9d74a6bfeb | ||
|
9bdfd76819 | ||
|
d1c18c64f3 | ||
|
b42ed82147 | ||
|
7c3864a3ed | ||
|
6a39e9e9d0 | ||
|
cedee0c699 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -64,7 +64,7 @@ jobs:
|
|||||||
- mipsel-unknown-linux-musl
|
- mipsel-unknown-linux-musl
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: actions-rs/toolchain@v1
|
- uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
|
111
Cargo.lock
generated
111
Cargo.lock
generated
@@ -2,21 +2,6 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "addr2line"
|
|
||||||
version = "0.24.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1"
|
|
||||||
dependencies = [
|
|
||||||
"gimli",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "adler2"
|
|
||||||
version = "2.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "aho-corasick"
|
name = "aho-corasick"
|
||||||
version = "1.1.3"
|
version = "1.1.3"
|
||||||
@@ -82,21 +67,6 @@ version = "1.5.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "backtrace"
|
|
||||||
version = "0.3.75"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6806a6321ec58106fea15becdad98371e28d92ccbc7c8f1b3b6dd724fe8f1002"
|
|
||||||
dependencies = [
|
|
||||||
"addr2line",
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
"miniz_oxide",
|
|
||||||
"object",
|
|
||||||
"rustc-demangle",
|
|
||||||
"windows-targets 0.52.6",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.9.3"
|
version = "2.9.3"
|
||||||
@@ -253,7 +223,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fake-tcp"
|
name = "fake-tcp"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"flume",
|
"flume",
|
||||||
@@ -332,12 +302,6 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "gimli"
|
|
||||||
version = "0.31.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "glob"
|
name = "glob"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
@@ -368,17 +332,6 @@ version = "0.2.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fc6d6206008e25125b1f97fbe5d309eb7b85141cf9199d52dbd3729a1584dd16"
|
checksum = "fc6d6206008e25125b1f97fbe5d309eb7b85141cf9199d52dbd3729a1584dd16"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "io-uring"
|
|
||||||
version = "0.7.10"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "046fa2d4d00aea763528b4950358d0ead425372445dc8ff86312b3c69ff7727b"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags",
|
|
||||||
"cfg-if",
|
|
||||||
"libc",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ipnetwork"
|
name = "ipnetwork"
|
||||||
version = "0.20.0"
|
version = "0.20.0"
|
||||||
@@ -452,15 +405,6 @@ dependencies = [
|
|||||||
"autocfg",
|
"autocfg",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "miniz_oxide"
|
|
||||||
version = "0.8.9"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316"
|
|
||||||
dependencies = [
|
|
||||||
"adler2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mio"
|
name = "mio"
|
||||||
version = "1.0.4"
|
version = "1.0.4"
|
||||||
@@ -539,15 +483,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "object"
|
|
||||||
version = "0.36.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "62948e14d923ea95ea2c7c86c71013138b66525b86bdc08d2dcc262bdb497b87"
|
|
||||||
dependencies = [
|
|
||||||
"memchr",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "once_cell"
|
name = "once_cell"
|
||||||
version = "1.21.3"
|
version = "1.21.3"
|
||||||
@@ -585,7 +520,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "phantun"
|
name = "phantun"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"fake-tcp",
|
"fake-tcp",
|
||||||
@@ -829,12 +764,6 @@ version = "0.8.5"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "rustc-demangle"
|
|
||||||
version = "0.1.26"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "56f7d92ca342cea22a06f2121d944b4fd82af56988c270852495420f961d4ace"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
@@ -870,12 +799,6 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "slab"
|
|
||||||
version = "0.4.11"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7a2ae44ef20feb57a68b23d846850f861394c2e02dc425a50098ae8c90267589"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "smallvec"
|
name = "smallvec"
|
||||||
version = "1.15.1"
|
version = "1.15.1"
|
||||||
@@ -949,29 +872,26 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.47.1"
|
version = "1.48.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
|
checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"backtrace",
|
|
||||||
"bytes",
|
"bytes",
|
||||||
"io-uring",
|
|
||||||
"libc",
|
"libc",
|
||||||
"mio",
|
"mio",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"pin-project-lite",
|
"pin-project-lite",
|
||||||
"signal-hook-registry",
|
"signal-hook-registry",
|
||||||
"slab",
|
|
||||||
"socket2",
|
"socket2",
|
||||||
"tokio-macros",
|
"tokio-macros",
|
||||||
"windows-sys 0.59.0",
|
"windows-sys 0.61.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tokio-macros"
|
name = "tokio-macros"
|
||||||
version = "2.5.0"
|
version = "2.6.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8"
|
checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@@ -1124,6 +1044,12 @@ version = "0.1.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-link"
|
||||||
|
version = "0.2.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-sys"
|
name = "windows-sys"
|
||||||
version = "0.59.0"
|
version = "0.59.0"
|
||||||
@@ -1142,6 +1068,15 @@ dependencies = [
|
|||||||
"windows-targets 0.53.3",
|
"windows-targets 0.53.3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.61.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-link 0.2.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "windows-targets"
|
name = "windows-targets"
|
||||||
version = "0.52.6"
|
version = "0.52.6"
|
||||||
@@ -1164,7 +1099,7 @@ version = "0.53.3"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
|
checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"windows-link",
|
"windows-link 0.1.3",
|
||||||
"windows_aarch64_gnullvm 0.53.0",
|
"windows_aarch64_gnullvm 0.53.0",
|
||||||
"windows_aarch64_msvc 0.53.0",
|
"windows_aarch64_msvc 0.53.0",
|
||||||
"windows_i686_gnu 0.53.0",
|
"windows_i686_gnu 0.53.0",
|
||||||
|
12
README.md
12
README.md
@@ -5,8 +5,7 @@ A lightweight and fast UDP to TCP obfuscator.
|
|||||||

|

|
||||||

|

|
||||||
|
|
||||||
Table of Contents
|
# Table of Contents
|
||||||
=================
|
|
||||||
|
|
||||||
* [Phantun](#phantun)
|
* [Phantun](#phantun)
|
||||||
* [Latest release](#latest-release)
|
* [Latest release](#latest-release)
|
||||||
@@ -35,7 +34,14 @@ Table of Contents
|
|||||||
|
|
||||||
# Latest release
|
# Latest release
|
||||||
|
|
||||||
[v0.7.0](https://github.com/dndx/phantun/releases/tag/v0.7.0)
|
[v0.8.1](https://github.com/dndx/phantun/releases/tag/v0.8.1)
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>MIPS architecture support for Phantun</summary>
|
||||||
|
|
||||||
|
[Rust only provides Tier 3 supports for MIPS based platforms](https://github.com/rust-lang/compiler-team/issues/648)
|
||||||
|
since 2023. Phantun's MIPS build are therefore built using nightly Rust toolchain and provided on a best effort basis only.
|
||||||
|
</details>
|
||||||
|
|
||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
|
@@ -25,6 +25,10 @@ FROM debian:latest
|
|||||||
COPY --from=builder /usr/local/bin/phantun-server /usr/local/bin/
|
COPY --from=builder /usr/local/bin/phantun-server /usr/local/bin/
|
||||||
COPY --from=builder /usr/local/bin/phantun-client /usr/local/bin/
|
COPY --from=builder /usr/local/bin/phantun-client /usr/local/bin/
|
||||||
COPY docker/phantun.sh /usr/local/bin/
|
COPY docker/phantun.sh /usr/local/bin/
|
||||||
|
RUN apt-get update && apt-get install -y \
|
||||||
|
iproute2 \
|
||||||
|
iptables \
|
||||||
|
procps
|
||||||
|
|
||||||
ENV USE_IPTABLES_NFT_BACKEND=0
|
ENV USE_IPTABLES_NFT_BACKEND=0
|
||||||
ENV RUST_LOG=INFO
|
ENV RUST_LOG=INFO
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
|
||||||
# alias settings must be global, and must be defined before the function being called with the alias
|
# alias settings must be global, and must be defined before the function being called with the alias
|
||||||
if [ "$USE_IPTABLES_NFT_BACKEND" = 1 ]; then
|
if [ "$USE_IPTABLES_NFT_BACKEND" = 1 ]; then
|
||||||
@@ -70,17 +70,17 @@ _is_ipv4_only() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_get_tun_from_args() {
|
_get_tun_from_args() {
|
||||||
local tun=$(echo "$@" | awk -F '--tun' '{print $2}' | awk '{print $1}')
|
local tun=$(echo "$@" | awk -F '--tun ' '{print $2}' | awk '{print $1}')
|
||||||
echo ${tun:=tun0}
|
echo ${tun:=tun0}
|
||||||
}
|
}
|
||||||
|
|
||||||
_get_peer_from_args() {
|
_get_peer_from_args() {
|
||||||
local peer=$(echo "$@" | awk -F '--tun-peer' '{print $2}' | awk '{print $1}')
|
local peer=$(echo "$@" | awk -F '--tun-peer ' '{print $2}' | awk '{print $1}')
|
||||||
_is_server_mode "$1" && echo ${peer:=192.168.201.2} || echo ${peer:=192.168.200.2}
|
_is_server_mode "$1" && echo ${peer:=192.168.201.2} || echo ${peer:=192.168.200.2}
|
||||||
}
|
}
|
||||||
|
|
||||||
_get_peer6_from_args() {
|
_get_peer6_from_args() {
|
||||||
local peer=$(echo "$@" | awk -F '--tun-peer6' '{print $2}' | awk '{print $1}')
|
local peer=$(echo "$@" | awk -F '--tun-peer6 ' '{print $2}' | awk '{print $1}')
|
||||||
_is_server_mode "$1" && echo ${peer:=fcc9::2} || echo ${peer:=fcc8::2}
|
_is_server_mode "$1" && echo ${peer:=fcc9::2} || echo ${peer:=fcc8::2}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fake-tcp"
|
name = "fake-tcp"
|
||||||
version = "0.7.0"
|
version = "0.7.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Datong Sun <dndx@idndx.com>"]
|
authors = ["Datong Sun <dndx@idndx.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
@@ -5,7 +5,7 @@ packet oriented tunneling with minimum overhead.
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright 2021 Datong Sun <dndx@idndx.com>
|
Copyright 2021-2025 Datong Sun <dndx@idndx.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
|
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "phantun"
|
name = "phantun"
|
||||||
version = "0.8.0"
|
version = "0.8.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
authors = ["Datong Sun <dndx@idndx.com>"]
|
authors = ["Datong Sun <dndx@idndx.com>"]
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
@@ -4,7 +4,7 @@ Client/Server crate, see [Phantun Project README.md](https://github.com/dndx/pha
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright 2021 Datong Sun <dndx@idndx.com>
|
Copyright 2021-2025 Datong Sun <dndx@idndx.com>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
|
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
|
||||||
|
@@ -10,8 +10,12 @@ use neli::{
|
|||||||
types::RtBuffer,
|
types::RtBuffer,
|
||||||
utils::Groups,
|
utils::Groups,
|
||||||
};
|
};
|
||||||
use nix::sys::socket::{CmsgIterator, ControlMessageOwned, SockaddrLike as _};
|
use nix::sys::socket::{
|
||||||
|
CmsgIterator, ControlMessageOwned, MsgFlags, SockaddrLike, SockaddrStorage, cmsg_space,
|
||||||
|
};
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
|
||||||
|
use std::os::unix::io::AsRawFd;
|
||||||
|
use tokio::io::Interest;
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
|
|
||||||
pub fn new_udp_reuseport(local_addr: SocketAddr) -> UdpSocket {
|
pub fn new_udp_reuseport(local_addr: SocketAddr) -> UdpSocket {
|
||||||
@@ -49,26 +53,26 @@ pub fn new_udp_reuseport(local_addr: SocketAddr) -> UdpSocket {
|
|||||||
udp_sock.try_into().unwrap()
|
udp_sock.try_into().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Similiar to `UdpSocket::recv_from()`, but returns a 3rd value `IPAddr`
|
||||||
|
/// which corresponds to where the UDP datagram was destined to, this is useful
|
||||||
|
/// for disambigous when socket can receive on multiple IP address
|
||||||
|
/// or interfaces.
|
||||||
pub async fn udp_recv_pktinfo(
|
pub async fn udp_recv_pktinfo(
|
||||||
sock: &UdpSocket,
|
sock: &UdpSocket,
|
||||||
buf: &mut [u8],
|
buf: &mut [u8],
|
||||||
) -> std::io::Result<(usize, std::net::SocketAddr, std::net::IpAddr)> {
|
) -> std::io::Result<(usize, SocketAddr, IpAddr)> {
|
||||||
use std::os::unix::io::AsRawFd;
|
|
||||||
use tokio::io::Interest;
|
|
||||||
use nix::sys::socket::cmsg_space;
|
|
||||||
|
|
||||||
sock.async_io(Interest::READABLE, || {
|
sock.async_io(Interest::READABLE, || {
|
||||||
let control_buffer_size = std::cmp::max(
|
const CONTROL_MESSAGE_BUFFER_SIZE: usize = max_usize(
|
||||||
cmsg_space::<nix::libc::in_pktinfo>(),
|
cmsg_space::<nix::libc::in_pktinfo>(),
|
||||||
cmsg_space::<nix::libc::in6_pktinfo>(),
|
cmsg_space::<nix::libc::in6_pktinfo>(),
|
||||||
);
|
);
|
||||||
let mut control_buffer = vec![0u8; control_buffer_size];
|
let mut control_message_buffer = [0u8; CONTROL_MESSAGE_BUFFER_SIZE];
|
||||||
let iov = &mut [std::io::IoSliceMut::new(buf)];
|
let iov = &mut [std::io::IoSliceMut::new(buf)];
|
||||||
let res = nix::sys::socket::recvmsg::<nix::sys::socket::SockaddrStorage>(
|
let res = nix::sys::socket::recvmsg::<SockaddrStorage>(
|
||||||
sock.as_raw_fd(),
|
sock.as_raw_fd(),
|
||||||
iov,
|
iov,
|
||||||
Some(&mut control_buffer),
|
Some(&mut control_message_buffer),
|
||||||
nix::sys::socket::MsgFlags::empty(),
|
MsgFlags::empty(),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let src_addr = res.address.expect("missing source address");
|
let src_addr = res.address.expect("missing source address");
|
||||||
@@ -104,6 +108,7 @@ fn dst_addr_from_cmsgs(cmsgs: CmsgIterator) -> Option<IpAddr> {
|
|||||||
return Some(Ipv6Addr::from(pktinfo.ipi6_addr.s6_addr).into());
|
return Some(Ipv6Addr::from(pktinfo.ipi6_addr.s6_addr).into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,3 +149,7 @@ pub fn assign_ipv6_address(device_name: &str, local: Ipv6Addr, peer: Ipv6Addr) {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
rtnl.send(&nl_header).unwrap();
|
rtnl.send(&nl_header).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fn max_usize(a: usize, b: usize) -> usize {
|
||||||
|
if a > b { a } else { b }
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user