Git Product home page Git Product logo

akarin's People

Contributors

realityone avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

akarin's Issues

TAP/TUN 代码 可以正常工作吗?

你好,我正在尝试写一个 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)这方面好像还没有支持完善。

非常希望得到你的帮助。

[BUG] 数据包发送不完整

Lines:

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] & 0xF {
IPV4 => {
data.extend_from_slice(&IPV4_HEADER);
}
IPV6 => data.extend_from_slice(&IPV6_HEADER),
_ => {}
};
match self.tun.write(&data) {
Ok(len) => {
Ok(if len > IP_HEADER_LEN {
len - IP_HEADER_LEN
} else {
0
})
}
Err(e) => Err(e),
}
}

修正数据包发送不完整的 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:

fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
self.tun.read(buf)
}

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)
        }
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.