Skip to content

Commit d618659

Browse files
committed
minor edit
1 parent 81890d3 commit d618659

File tree

6 files changed

+61
-26
lines changed

6 files changed

+61
-26
lines changed

doc/book/src/lua/map_config.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ out_auto_route = {
147147
}
148148
```
149149

150+
ip 拨号是建立一个虚拟网卡,一般为 tun. 这个一般可以用于配合 tcp/ip stack (smoltcp) 进行全局路由使用,详情
151+
见 local.lua 中的对应示例,以及 [这里](https://github.com/e1732a364fed/ruci/blob/tokio/doc/notes.md#tun模式的一些实测信息)
152+
153+
150154
### OptDialer
151155
in
152156

doc/notes.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ ruci chain 模式中,
192192

193193
在ruci 中, 你可以: dial 一个由 host1 解析得的ip, 然后 tls 里的 sni 写 host2, 然后 ws/grpc 的请求 url 中 写 host3
194194

195-
## tun 模式的一些实测信息
195+
## tun模式的一些实测信息
196196

197197
tun 是用 如下配置启用
198198

@@ -208,13 +208,41 @@ tun 是用 如下配置启用
208208

209209
详见 local.lua 中对应示例
210210

211-
windows 上需要 wintun.dll. 可用ruci-cmd `ruci-cmd utils wintun` 来自动下载 wintun.zip
211+
windows 上需要 wintun.dll. 可用ruci-cmd `ruci-cmd utils wintun` 来自动下载 wintun.zip,wintun.zip 中还有子文件夹,
212+
一般要进入 amd64 文件夹中,解压出里面的 wintun.dll
212213

213214
在windows上, 可以在控制面板中找到所建立的虚拟网卡
214215

215216

216217
实测, 在 windows 上, 就算不配置任何路由, 系统也会识别到它建立的虚拟网卡, 并向其发送一些信息;在 linux 和 macos 上, 也会收到少量信息(即会在log中显示一些输出)
217218

219+
在 linux/macOS 上,运行要用 sudo , 在 windows 上,要用管理员权限运行程序,这样ruci-cmd 才能启动虚拟网卡。
220+
221+
222+
在 in_auto_route 的 ` original_dev_name = "en0"` 项 和 `sockopt``bind_to_device = "en0"` 项中,均要填写网卡名称信息
223+
224+
在 linux/macOS 上用 ifconfig 查看, 在 windows 上用 ipconfig 查看。
225+
226+
windows 上,根据系统语言不同,网卡名称也不同,比如 "ETHERNET" 在中文系统中为 "以太网"
227+
228+
## smoltcp/lwip 与 tun
229+
230+
smoltcp 和 lwip 是两种 tcp/ip stack 的实现
231+
232+
lwip 无法在 windows 上编译。
233+
234+
二者均需要使用 tun 包 或 tun2 包来作为底层tun device.
235+
236+
一开始,先有 tun包,后来作者不维护了,又出现了tun2包,但是到了 24年年底,
237+
tun2包的作者又开始维护 tun 包,因此 此时 tun 包就更新了。
238+
239+
tun 包在 windows 平台使用 wintun, 而在 其它平台使用 系统调用。
240+
241+
经测试发现,windows 上的 wintun 性能很强,而在其它平台则用起来很卡顿,也许是平台问题,
242+
也许是tun 包的 异步实现代码的问题。
243+
244+
smoltcp 的实现 在实践中比 lwip 实现快一些。因此 ruci-cmd 只采用了 smoltcp 的网络栈。
245+
218246

219247
# lib note
220248

@@ -357,6 +385,9 @@ quinn (代码在 rucimp/src/map/quinn):全没问题
357385

358386
而且 s2n-quic 在 windows 无法编译通过
359387

388+
389+
390+
360391
## 编译运行问题
361392

362393
tproxy,tun 要使用 管理员权限 运行

rucimp/src/map/tcp_ip_stack_smoltcp/device.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ impl SmoltcpDevice {
488488
network: Network::UDP,
489489
};
490490

491-
let ac = super::udp2::new(sa, sh, read_rx, self.udp_write_data_tx.clone());
491+
let ac = super::udp::new(sa, sh, read_rx, self.udp_write_data_tx.clone());
492492

493493
//debug!("smoltcp got new udp connection {dst_ipe} {src_ipe}");
494494

@@ -510,14 +510,14 @@ impl SmoltcpDevice {
510510

511511
/// check timeout udp and remove from device's SocketSet
512512
pub fn udp_health_check(&mut self) {
513-
debug!("udp_health_check");
513+
// debug!("udp_health_check");
514514
let mut udp_src_to_remove = Vec::new();
515515

516516
{
517517
let m = self.udp_read_data_tx_map.lock();
518518

519519
for (src, sender) in m.iter() {
520-
debug!("checking udp for {:?}", src);
520+
// debug!("checking udp for {:?}", src);
521521
if sender.is_closed() {
522522
//debug!("udp_health_check got a closed");
523523
udp_src_to_remove.push(src.to_owned());
@@ -545,12 +545,12 @@ impl SmoltcpDevice {
545545

546546
let so: &mut smoltcp::socket::tcp::Socket = self.tcp_sockets.get_mut(h);
547547

548-
debug!(
549-
"checking {h}, {:?}, {:?} {}",
550-
so.local_endpoint(),
551-
so.remote_endpoint(),
552-
so.state()
553-
);
548+
// debug!(
549+
// "checking {h}, {:?}, {:?} {}",
550+
// so.local_endpoint(),
551+
// so.remote_endpoint(),
552+
// so.state()
553+
// );
554554
if !so.can_recv() {
555555
debug!("cant recv {h}");
556556
}
@@ -572,13 +572,13 @@ impl SmoltcpDevice {
572572
let tcp_stream_read_data_sender = m.get(&h).unwrap();
573573

574574
if tcp_stream_read_data_sender.is_closed() {
575-
debug!("{h}, will delete tcp because sender closed");
575+
// debug!("{h}, will delete tcp because sender closed");
576576
tcp_handles_to_remove.push(h);
577577
tcp_src_to_remove.push(src);
578578
} else {
579-
if !so.can_recv() {
580-
debug!("{h}, has src but cant recv, {}", so.state());
581-
}
579+
// if !so.can_recv() {
580+
// debug!("{h}, has src but cant recv, {}", so.state());
581+
// }
582582

583583
while so.can_recv() && tcp_stream_read_data_sender.capacity() > 0 {
584584
let mut buffer = BytesMut::with_capacity(so.recv_queue());
@@ -602,16 +602,16 @@ impl SmoltcpDevice {
602602
break;
603603
}
604604
} else {
605-
debug!("tcp_read_data_tx so.recv_slice failed");
605+
// debug!("tcp_read_data_tx so.recv_slice failed");
606606
so.close();
607607
break;
608608
}
609609
}
610610
if so.state() == State::CloseWait && so.send_queue() == 0 {
611-
debug!(
612-
"{h}, so.state() == State::CloseWait
613-
&& so.send_queue() == 0"
614-
);
611+
// debug!(
612+
// "{h}, so.state() == State::CloseWait
613+
// && so.send_queue() == 0"
614+
// );
615615
let _ =
616616
tcp_stream_read_data_sender.try_send(BytesMut::with_capacity(0));
617617
//这里将令 TcpStream 的 read端 收到一个 0字节,表示EOF

rucimp/src/map/tcp_ip_stack_smoltcp/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Defines a [`Map`] called [`Stack`] using user level tcp/ip stack based on `smolt
44
pub mod device;
55
pub mod ip_packet;
66
pub mod tcp;
7-
pub mod udp2;
7+
pub mod udp;
88

99
use std::time::Duration;
1010

rucimp/src/map/tcp_ip_stack_smoltcp/tcp.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ impl AsyncRead for TcpReadHalf {
9696
let dst_buffer = buf.initialize_unfilled();
9797
let len = dst_buffer.len().min(me.buf.len());
9898

99-
debug!("smoltcp tcp read got len {len}");
99+
// debug!("smoltcp tcp read got len {len}");
100100
let _ = &dst_buffer[..len].copy_from_slice(&me.buf.as_ref()[..len]);
101101
me.buf.advance(len);
102102
buf.set_filled(buf.filled().len() + len);
103103
Poll::Ready(Ok(()))
104104
} else if let Some(data) = ready!(me.rx.poll_recv(cx)) {
105-
debug!("smoltcp tcp poll ready, got data {}", data.len());
105+
// debug!("smoltcp tcp poll ready, got data {}", data.len());
106106
if data.is_empty() {
107107
return Poll::Ready(Ok(()));
108108
}
@@ -137,7 +137,7 @@ impl AsyncWrite for TcpWriteHalf {
137137
}
138138

139139
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
140-
debug!("smoltcp tcp shutdown called");
140+
// debug!("smoltcp tcp shutdown called");
141141
self.poll_write(cx, &[]).map(|ret| ret.map(|_| ()))
142142
}
143143
}
@@ -150,7 +150,7 @@ impl AsyncRead for TcpStream {
150150
) -> Poll<std::io::Result<()>> {
151151
let me = self.get_mut();
152152
if me.is_closed {
153-
debug!("smoltcp read got is closed");
153+
// debug!("smoltcp read got is closed");
154154
return Poll::Ready(Ok(()));
155155
}
156156
Pin::new(&mut me.r).poll_read(cx, buf)
@@ -171,7 +171,7 @@ impl AsyncWrite for TcpStream {
171171
Pin::new(&mut me.w).poll_flush(cx)
172172
}
173173
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>> {
174-
debug!("smoltcp tcpstream shutdown called");
174+
// debug!("smoltcp tcpstream shutdown called");
175175
let me = self.get_mut();
176176
me.is_closed = true;
177177
me.r.rx.close();
File renamed without changes.

0 commit comments

Comments
 (0)