dndx / phantun

Transforms UDP stream into (fake) TCP streams that can go through Layer 3 & Layer 4 (NAPT) firewalls/NATs.
Apache License 2.0
1.71k stars 137 forks source link

phantun_aarch64-unknown-linux-musl-v0.6.0 Run an error on OpenWRT #86

Closed CTCD closed 2 years ago

CTCD commented 2 years ago

Run this code 1: RUST_LOG=info ./phantun_client -4 -l 127.0.0.1:10086 -r 13.250.8.233:80 INFO client > Remote address is: 13.250.8.233:80 INFO client > 2 cores available thread 'main' panicked at 'called Result::unwrap() on an Err value: EBADF', phantun/src/bin/client.rs:162:10 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace

Run this code 2: RUST_BACKTRACE=1 ./phantun_client -4 -l 127.0.0.1:10086 -r 13.250.8.233:80 thread 'main' panicked at 'called Result::unwrap() on an Err value: EBADF', phantun/src/bin/client.rs:162:10 stack backtrace: 0: rust_begin_unwind at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14 2: core::result::unwrap_failed at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/result.rs:1814:5 3: client::main::{{closure}} 4: std::thread::local::LocalKey::with 5: tokio::park::thread::CachedParkThread::block_on 6: tokio::runtime::scheduler::multi_thread::MultiThread::block_on 7: tokio::runtime::Runtime::block_on 8: client::main note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

Run this code 3: RUST_BACKTRACE=full ./phantun_client -4 -l 127.0.0.1:10086 -r 13.250.8.233:80 thread 'main' panicked at 'called Result::unwrap() on an Err value: EBADF', phantun/src/bin/client.rs:162:10 stack backtrace: 0: 0x5431c0 - std::backtrace_rs::backtrace::libunwind::trace::hc7f0777a5f98ea61 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x5431c0 - std::backtrace_rs::backtrace::trace_unsynchronized::h16d5d28ebad2ef9c at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x5431c0 - std::sys_common::backtrace::_print_fmt::he5d66cd5b0c387ae at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:66:5 3: 0x5431c0 - ::fmt::h2986bd11e6976a92 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:45:22 4: 0x5756e8 - core::fmt::write::h4001b417f200fba8 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/fmt/mod.rs:1198:17 5: 0x53e598 - std::io::Write::write_fmt::h9c94ed5e50af2aea at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/io/mod.rs:1672:15 6: 0x5448a8 - std::sys_common::backtrace::_print::hecdf21887b334bab at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:48:5 7: 0x5448a8 - std::sys_common::backtrace::print::hc1db74787194746c at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:35:9 8: 0x5448a8 - std::panicking::default_hook::{{closure}}::h16cd2a13dc4430bc at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:295:22 9: 0x544518 - std::panicking::default_hook::h760d3cc45a923e5c at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:314:9 10: 0x544f18 - std::panicking::rust_panic_with_hook::h7f7e8e586ddcd9ff at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:698:17 11: 0x544cf4 - std::panicking::begin_panic_handler::{{closure}}::h044659f762aeb6c9 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:588:13 12: 0x5436a4 - std::sys_common::backtrace::__rust_end_short_backtrace::h37aac26d6fb4cc8d at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/sys_common/backtrace.rs:138:18 13: 0x544a40 - rust_begin_unwind at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5 14: 0x4094f8 - core::panicking::panic_fmt::ha2e05dc1b43eec3c at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14 15: 0x40959c - core::result::unwrap_failed::hd730db48eca41c86 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/result.rs:1814:5 16: 0x43024c - client::main::{{closure}}::h12005f424d8eb8ba 17: 0x41e164 - std::thread::local::LocalKey::with::h3e788c5fef3896e2 18: 0x410c9c - tokio::park::thread::CachedParkThread::block_on::hd1cc49d6437ef028 19: 0x425f04 - tokio::runtime::scheduler::multi_thread::MultiThread::block_on::h623e058925af9056 20: 0x41d048 - tokio::runtime::Runtime::block_on::h2089b0b88b7274e9 21: 0x4172fc - client::main::hb35e5799adbaa71f 22: 0x410f5c - std::sys_common::backtrace::__rust_begin_short_backtrace::ha521dbc240a65474 23: 0x4124d4 - std::rt::lang_start::{{closure}}::h3a8d0e501e1c6868 24: 0x5397d8 - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::he7927d6f7463b77d at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:280:13 25: 0x5397d8 - std::panicking::try::do_call::hea7f200984950f46 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492:40 26: 0x5397d8 - std::panicking::try::h51f13112c87eb59c at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456:19 27: 0x5397d8 - std::panic::catch_unwind::h40c6239a2b758910 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137:14 28: 0x5397d8 - std::rt::lang_start_internal::{{closure}}::h4f86d114f42648ea at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/rt.rs:128:48 29: 0x5397d8 - std::panicking::try::do_call::h24ce8fc293e75eba at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:492:40 30: 0x5397d8 - std::panicking::try::h2e226ea1f7c1452e at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:456:19 31: 0x5397d8 - std::panic::catch_unwind::hbef768fbff75704a at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panic.rs:137:14 32: 0x5397d8 - std::rt::lang_start_internal::h42774ad8c239ed70 at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/rt.rs:128:20 33: 0x4173e0 - main

Hostname | OpenWrt -- | -- Model | Xiaomi Redmi Router AX6S Architecture | ARMv8 Processor rev 4 Target Platform | mediatek/mt7622 Firmware Version | OpenWrt 22.03.2 r19803-9a599fee93 / LuCI openwrt-22.03 branch git-22.288.45147-96ec0cd Kernel Version | 5.10.146
dndx commented 2 years ago

Did you run Phantun with root? You can also run it with strace to see which syscall actually failed.

CTCD commented 2 years ago

你和吗?您也可以使用它来查看哪个系统调用实际上失败了。root``strace

Yes, run Phantun with root

strace ./phantun_client -4 -l 127.0.0.1:10086 -r 13.250.8.233:80 execve("./phantun_client", ["./phantun_client", "-4", "-l", "127.0.0.1:10086", "-r", "13.250.8.233:80"], 0x7ff5e9ca98 / 14 vars /) = 0 mmap(NULL, 592, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8e249000 set_tid_address(0x653db8) = 4638 ppoll([{fd=0, events=0}, {fd=1, events=0}, {fd=2, events=0}], 3, {tv_sec=0, tv_nsec=0}, NULL, 8) = 0 (Timeout) rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x571258}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0 rt_sigaction(SIGSEGV, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0 rt_sigprocmask(SIG_UNBLOCK, [RT_1 RT_2], NULL, 8) = 0 rt_sigaction(SIGSEGV, {sa_handler=0x546cc0, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0x571258}, NULL, 8) = 0 rt_sigaction(SIGBUS, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0 rt_sigaction(SIGBUS, {sa_handler=0x546cc0, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK|SA_SIGINFO, sa_restorer=0x571258}, NULL, 8) = 0 sigaltstack(NULL, {ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=0}) = 0 mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_STACK, -1, 0) = 0x7f8e245000 mprotect(0x7f8e245000, 4096, PROT_NONE) = 0 sigaltstack({ss_sp=0x7f8e246000, ss_flags=0, ss_size=12288}, NULL) = 0 brk(NULL) = 0x1d732000 brk(0x1d733000) = 0x1d733000 rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 openat(AT_FDCWD, "/proc/self/cgroup", O_RDONLY|O_LARGEFILE|O_CLOEXEC) = 3 fcntl(3, F_SETFD, FD_CLOEXEC) = 0 brk(0x1d736000) = 0x1d736000 read(3, "0::/services/dropbear/instance1\n", 8192) = 32 read(3, "", 8192) = 0 close(3) = 0 sched_getaffinity(0, 128, [0, 1]) = 8 epoll_create1(EPOLL_CLOEXEC) = 3 eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK) = 4 epoll_ctl(3, EPOLL_CTL_ADD, 4, {events=EPOLLIN|EPOLLRDHUP|EPOLLET, data={u32=2147483648, u64=2147483648}}) = 0 fcntl(3, F_DUPFD_CLOEXEC, 3) = 5 fcntl(5, F_SETFD, FD_CLOEXEC) = 0 brk(0x1d73b000) = 0x1d73b000 socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0, [6, 7]) = 0 fcntl(6, F_DUPFD_CLOEXEC, 0) = 8 fcntl(8, F_SETFD, FD_CLOEXEC) = 0 epoll_ctl(5, EPOLL_CTL_ADD, 8, {events=EPOLLIN|EPOLLRDHUP|EPOLLET, data={u32=0, u64=0}}) = 0 brk(0x1d73d000) = 0x1d73d000 getrandom("\x43\xe1\x77\x3a\x6c\x14\xe6\x2f\x89\xa2\x64\x62\x5e\x3a\x1a\x31", 16, GRND_INSECURE) = 16 brk(0x1d73e000) = 0x1d73e000 rt_sigprocmask(SIG_UNBLOCK, [RT_1 RT_2], NULL, 8) = 0 mmap(NULL, 2109440, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8e042000 mprotect(0x7f8e044000, 2101248, PROT_READ|PROT_WRITE) = 0 rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 8) = 0 clone(child_stack=0x7f8e244980, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID|0x400000, parent_tid=[4639], tls=0x7f8e244a90, child_tidptr=0x653db8) = 4639 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 mmap(NULL, 2109440, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8de3f000 mprotect(0x7f8de41000, 2101248, PROT_READ|PROT_WRITE) = 0 rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1 RT_2], [], 8) = 0 clone(child_stack=0x7f8e041980, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID|0x400000, parent_tid=[4640], tls=0x7f8e041a90, child_tidptr=0x653db8) = 4640 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 futex(0x7f8e041b90, FUTEX_WAKE_PRIVATE, 1) = 1 ioctl(2, TIOCGWINSZ, {ws_row=30, ws_col=120, ws_xpixel=640, ws_ypixel=480}) = 0 brk(0x1d73f000) = 0x1d73f000 brk(0x1d741000) = 0x1d741000 brk(0x1d742000) = 0x1d742000 brk(0x1d743000) = 0x1d743000 sched_getaffinity(0, 128, [0, 1]) = 8 openat(AT_FDCWD, "/dev/net/tun", O_RDWR|O_NONBLOCK|O_LARGEFILE) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/dev/net/tun", O_RDWR|O_NONBLOCK|O_LARGEFILE) = -1 ENOENT (No such file or directory) ioctl(-1, TUNSETIFF, 0x7fd386e9c0) = -1 EBADF (Bad file descriptor) write(2, "thread '", 8thread ') = 8 write(2, "main", 4main) = 4 write(2, "' panicked at '", 15' panicked at ') = 15 write(2, "called Result::unwrap() on an "..., 50called Result::unwrap() on an Err value: EBADF) = 50 write(2, "', ", 3', ) = 3 write(2, "phantun/src/bin/client.rs", 25phantun/src/bin/client.rs) = 25 write(2, ":", 1:) = 1 write(2, "162", 3162) = 3 write(2, ":", 1:) = 1 write(2, "10", 210) = 2 write(2, "\n", 1 ) = 1 write(2, "note: run with RUST_BACKTRACE=1"..., 78note: run withRUST_BACKTRACE=1` environment variable to display a backtrace ) = 78 write(4, "\1\0\0\0\0\0\0\0", 8) = 8 futex(0x7f8e244b90, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x7f8e041b90, FUTEX_WAKE_PRIVATE, 1) = 1 futex(0x7f8e2491e0, FUTEX_WAIT_PRIVATE, 1, NULL) = -1 EAGAIN (Resource temporarily unavailable) futex(0x7f8e2449f0, FUTEX_WAIT_PRIVATE, 1, NULL) = -1 EAGAIN (Resource temporarily unavailable) munmap(0x7f8e042000, 2109440) = 0 munmap(0x7f8de3f000, 2109440) = 0 sigaltstack({ss_sp=NULL, ss_flags=SS_DISABLE, ss_size=12288}, NULL) = 0 munmap(0x7f8e245000, 16384) = 0 exit_group(101) = ? +++ exited with 101 +++

dndx commented 2 years ago
openat(AT_FDCWD, "/dev/net/tun", O_RDWR|O_NONBLOCK|O_LARGEFILE) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/dev/net/tun", O_RDWR|O_NONBLOCK|O_LARGEFILE) = -1 ENOENT (No such file or directory)

It appears your system lacks Tun/Tap support. Maybe the Kernel does not have the modules built.

To confirm:

$ ls -l /dev/net/tun
crw-rw-rw- 1 root root 10, 200 Oct 25 16:03 /dev/net/tun
CTCD commented 2 years ago

ls -l /dev/net/tun

How to solve it?

dndx commented 2 years ago

No idea. Maybe you can ask the firmware author instead.