3 Commits

Author SHA1 Message Date
dependabot[bot]
850de2febe chore(deps): bump socket2 from 0.6.0 to 0.6.1
Bumps [socket2](https://github.com/rust-lang/socket2) from 0.6.0 to 0.6.1.
- [Release notes](https://github.com/rust-lang/socket2/releases)
- [Changelog](https://github.com/rust-lang/socket2/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/socket2/compare/v0.6.0...v0.6.1)

---
updated-dependencies:
- dependency-name: socket2
  dependency-version: 0.6.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-10-13 08:19:18 +00:00
Heng lu
7f7da10b1b fix(docker): fix parameter parsing and signal handling in phantun.sh (#235)
All checks were successful
Docker image build / build (push) Successful in 5m48s
Rust / build (push) Successful in 4m6s
- Fix awk delimiter parsing for --tun, --tun-peer, --tun-peer6 arguments
- Change shebang from sh to bash to fix signal trap handling
- Add missing dependencies (iproute2, iptables, procps) to Dockerfile
2025-10-06 09:29:18 -07:00
WGH
9d74a6bfeb style(phantun): calculate cmsg buffer size statically
Closes #178 and supersedes #225.
2025-10-06 09:25:21 -07:00
4 changed files with 22 additions and 16 deletions

10
Cargo.lock generated
View File

@@ -433,9 +433,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.28"
version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "memchr"
@@ -884,12 +884,12 @@ checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "socket2"
version = "0.6.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807"
checksum = "17129e116933cf371d018bb80ae557e889637989d8638274fb25622827b03881"
dependencies = [
"libc",
"windows-sys 0.59.0",
"windows-sys 0.60.2",
]
[[package]]

View File

@@ -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-client /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 RUST_LOG=INFO

View File

@@ -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
if [ "$USE_IPTABLES_NFT_BACKEND" = 1 ]; then
@@ -70,17 +70,17 @@ _is_ipv4_only() {
}
_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}
}
_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}
}
_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}
}

View File

@@ -62,13 +62,11 @@ pub async fn udp_recv_pktinfo(
buf: &mut [u8],
) -> std::io::Result<(usize, SocketAddr, IpAddr)> {
sock.async_io(Interest::READABLE, || {
// according to documented struct definition in RFC 3542,
// sizeof(in6_pktinfo) should always be larger than sizeof(in_pktinfo),
// this assert just double checks that. The goal is to avoid
// a heap allocation with Vec at runtime.
assert!(cmsg_space::<nix::libc::in6_pktinfo>() >= cmsg_space::<nix::libc::in_pktinfo>());
let mut control_message_buffer = [0u8; cmsg_space::<nix::libc::in6_pktinfo>()];
const CONTROL_MESSAGE_BUFFER_SIZE: usize = max_usize(
cmsg_space::<nix::libc::in_pktinfo>(),
cmsg_space::<nix::libc::in6_pktinfo>(),
);
let mut control_message_buffer = [0u8; CONTROL_MESSAGE_BUFFER_SIZE];
let iov = &mut [std::io::IoSliceMut::new(buf)];
let res = nix::sys::socket::recvmsg::<SockaddrStorage>(
sock.as_raw_fd(),
@@ -151,3 +149,7 @@ pub fn assign_ipv6_address(device_name: &str, local: Ipv6Addr, peer: Ipv6Addr) {
.unwrap();
rtnl.send(&nl_header).unwrap();
}
const fn max_usize(a: usize, b: usize) -> usize {
if a > b { a } else { b }
}