update for smoltcp

This commit is contained in:
ssrlive 2023-04-10 09:58:17 +08:00
parent 44122f3c68
commit 3fc112fc2c
2 changed files with 18 additions and 9 deletions

5
.cargo/config.toml Normal file
View file

@ -0,0 +1,5 @@
[registries.cratees-io]
protocol = "sparse"
[build]
target = ["x86_64-unknown-linux-gnu"]

View file

@ -132,8 +132,8 @@ fn get_transport_info(
transport_offset: usize,
packet: &[u8],
) -> Option<((u16, u16), bool, usize, usize)> {
if proto == IpProtocol::Udp {
match UdpPacket::new_checked(packet) {
match proto {
IpProtocol::Udp => match UdpPacket::new_checked(packet) {
Ok(result) => Some((
(result.src_port(), result.dst_port()),
false,
@ -141,9 +141,8 @@ fn get_transport_info(
packet.len() - 8,
)),
Err(_) => None,
}
} else if proto == IpProtocol::Tcp {
match TcpPacket::new_checked(packet) {
},
IpProtocol::Tcp => match TcpPacket::new_checked(packet) {
Ok(result) => Some((
(result.src_port(), result.dst_port()),
result.syn() && !result.ack(),
@ -151,9 +150,8 @@ fn get_transport_info(
packet.len(),
)),
Err(_) => None,
}
} else {
None
},
_ => None,
}
}
@ -271,7 +269,13 @@ impl<'a> TunToProxy<'a> {
Interest::READABLE,
)?;
let config = Config::new();
let config = match tun.capabilities().medium {
Medium::Ethernet => Config::new(
smoltcp::wire::EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x01]).into(),
),
Medium::Ip => Config::new(smoltcp::wire::HardwareAddress::Ip),
Medium::Ieee802154 => todo!(),
};
let mut virt = VirtualTunDevice::new(tun.capabilities());
let gateway4: Ipv4Addr = Ipv4Addr::from_str("0.0.0.1")?;
let gateway6: Ipv6Addr = Ipv6Addr::from_str("::1")?;