realityone / akarin Goto Github PK
View Code? Open in Web Editor NEWLightweight and stateless IP tunnel.
License: Apache License 2.0
Lightweight and stateless IP tunnel.
License: Apache License 2.0
你好,我正在尝试写一个 tun2ssh 的项目,大概就是 转发 TAP
的数据包至 TUN
设备,然后把 TUN
设备中的 TCP/UDP
数据包 通过 SSH
通道放在远程服务器执行,并传回。
项目目标旨在提高易用性,减少配置。争取做到 一行命令解决所有问题:
tun2ssh --ssh_host "20.202.20.20" --ssh_name "root" --ssh_password "impasswd!"
tun2ssh --ssh_host "20.202.20.20" --ssh_name "root" --ssh_pri_key "~/.ssh/my_pri_key"
由于刚开始,对 TAP/TUN
这块还不太熟悉,如果您代码这块可以很好工作起来,那将会极大地加速 tun2ssh
项目的开发进度。
目前看起来, 数据包(IPv4/IPv6/TCP/UDP)这方面好像还没有支持完善。
非常希望得到你的帮助。
建议 IP 数据包转发时,直接采用 SSH 协议,这样就把加密相关都交给了 SSH.
运行定制过的 SSH server: https://docs.rs/thrussh/0.16.2/thrussh/server/trait.Handler.html
Lines:
akarin/src/tun/macos/device.rs
Lines 85 to 109 in 4f37744
修正数据包发送不完整的 BUG.
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
if !buf.len() > 0 {
return Ok(0);
};
let mut data = Vec::with_capacity(buf.len() + IP_HEADER_LEN);
match buf[0] >> 4 {
IPV4 => data.extend_from_slice(&IPV4_HEADER),
IPV6 => data.extend_from_slice(&IPV6_HEADER),
_ => {}
};
// Fix
data.extend_from_slice(&buf);
match self.tun.write(&data) {
Ok(len) => Ok(if len > IP_HEADER_LEN { len - IP_HEADER_LEN } else { 0 }),
Err(e) => Err(e),
}
}
Lines:
akarin/src/tun/macos/device.rs
Lines 79 to 81 in 4f37744
和 write
方法保持一致,剔除 macOS extra header
.
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
match self.tun.read(buf) {
Ok(size) => {
if size > IP_HEADER_LEN {
unsafe {
let buf_copy: &mut [u8] = ::std::mem::transmute_copy(&buf);
let mut idx = IP_HEADER_LEN;
while idx < buf.len() {
buf[idx-IP_HEADER_LEN] = buf_copy[idx];
idx += 1;
}
::std::mem::forget(buf_copy);
}
Ok(size-IP_HEADER_LEN)
} else {
Ok(size)
}
},
Err(e) => Err(e)
}
}
如果你希望对 IP 包的 抵达地址 进行区域判断的话(比如国内IP不转发),可以看下这个:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.