mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-24 15:56:03 +00:00
switch to smoltcp dev version
to support IpProtocol with Hash trait
This commit is contained in:
parent
4eddcfd02b
commit
bfa1bbc462
4 changed files with 13 additions and 14 deletions
|
@ -12,7 +12,7 @@ env_logger = "0.10"
|
||||||
hashlink = "0.8"
|
hashlink = "0.8"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
mio = { version = "0.8", features = ["os-poll", "net", "os-ext"] }
|
mio = { version = "0.8", features = ["os-poll", "net", "os-ext"] }
|
||||||
smoltcp = { version = "0.9", features = ["std"] }
|
smoltcp = { version = "0.9", git = "https://github.com/smoltcp-rs/smoltcp.git", features = ["std"] }
|
||||||
url = "2.3"
|
url = "2.3"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
@ -168,7 +168,7 @@ pub struct HttpManager {
|
||||||
|
|
||||||
impl ConnectionManager for HttpManager {
|
impl ConnectionManager for HttpManager {
|
||||||
fn handles_connection(&self, connection: &Connection) -> bool {
|
fn handles_connection(&self, connection: &Connection) -> bool {
|
||||||
connection.proto == IpProtocol::Tcp.into()
|
connection.proto == IpProtocol::Tcp
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_connection(
|
fn new_connection(
|
||||||
|
@ -176,7 +176,7 @@ impl ConnectionManager for HttpManager {
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
manager: Rc<dyn ConnectionManager>,
|
manager: Rc<dyn ConnectionManager>,
|
||||||
) -> Option<Box<dyn TcpProxy>> {
|
) -> Option<Box<dyn TcpProxy>> {
|
||||||
if connection.proto != IpProtocol::Tcp.into() {
|
if connection.proto != IpProtocol::Tcp {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Box::new(HttpConnection::new(connection, manager)))
|
Some(Box::new(HttpConnection::new(connection, manager)))
|
||||||
|
|
|
@ -299,7 +299,7 @@ pub struct Socks5Manager {
|
||||||
|
|
||||||
impl ConnectionManager for Socks5Manager {
|
impl ConnectionManager for Socks5Manager {
|
||||||
fn handles_connection(&self, connection: &Connection) -> bool {
|
fn handles_connection(&self, connection: &Connection) -> bool {
|
||||||
connection.proto == IpProtocol::Tcp.into()
|
connection.proto == IpProtocol::Tcp
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_connection(
|
fn new_connection(
|
||||||
|
@ -307,7 +307,7 @@ impl ConnectionManager for Socks5Manager {
|
||||||
connection: &Connection,
|
connection: &Connection,
|
||||||
manager: Rc<dyn ConnectionManager>,
|
manager: Rc<dyn ConnectionManager>,
|
||||||
) -> Option<Box<dyn TcpProxy>> {
|
) -> Option<Box<dyn TcpProxy>> {
|
||||||
if connection.proto != IpProtocol::Tcp.into() {
|
if connection.proto != IpProtocol::Tcp {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
Some(Box::new(SocksConnection::new(connection, manager)))
|
Some(Box::new(SocksConnection::new(connection, manager)))
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl Display for Destination {
|
||||||
pub(crate) struct Connection {
|
pub(crate) struct Connection {
|
||||||
pub(crate) src: SocketAddr,
|
pub(crate) src: SocketAddr,
|
||||||
pub(crate) dst: Destination,
|
pub(crate) dst: Destination,
|
||||||
pub(crate) proto: u8,
|
pub(crate) proto: IpProtocol,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
|
@ -126,11 +126,11 @@ pub(crate) type IncomingDataEvent<'a> = DataEvent<'a, IncomingDirection>;
|
||||||
pub(crate) type OutgoingDataEvent<'a> = DataEvent<'a, OutgoingDirection>;
|
pub(crate) type OutgoingDataEvent<'a> = DataEvent<'a, OutgoingDirection>;
|
||||||
|
|
||||||
fn get_transport_info(
|
fn get_transport_info(
|
||||||
proto: u8,
|
proto: IpProtocol,
|
||||||
transport_offset: usize,
|
transport_offset: usize,
|
||||||
packet: &[u8],
|
packet: &[u8],
|
||||||
) -> Option<((u16, u16), bool, usize, usize)> {
|
) -> Option<((u16, u16), bool, usize, usize)> {
|
||||||
if proto == IpProtocol::Udp.into() {
|
if proto == IpProtocol::Udp {
|
||||||
match UdpPacket::new_checked(packet) {
|
match UdpPacket::new_checked(packet) {
|
||||||
Ok(result) => Some((
|
Ok(result) => Some((
|
||||||
(result.src_port(), result.dst_port()),
|
(result.src_port(), result.dst_port()),
|
||||||
|
@ -140,7 +140,7 @@ fn get_transport_info(
|
||||||
)),
|
)),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
} else if proto == IpProtocol::Tcp.into() {
|
} else if proto == IpProtocol::Tcp {
|
||||||
match TcpPacket::new_checked(packet) {
|
match TcpPacket::new_checked(packet) {
|
||||||
Ok(result) => Some((
|
Ok(result) => Some((
|
||||||
(result.src_port(), result.dst_port()),
|
(result.src_port(), result.dst_port()),
|
||||||
|
@ -157,7 +157,7 @@ fn get_transport_info(
|
||||||
|
|
||||||
fn connection_tuple(frame: &[u8]) -> Option<(Connection, bool, usize, usize)> {
|
fn connection_tuple(frame: &[u8]) -> Option<(Connection, bool, usize, usize)> {
|
||||||
if let Ok(packet) = Ipv4Packet::new_checked(frame) {
|
if let Ok(packet) = Ipv4Packet::new_checked(frame) {
|
||||||
let proto: u8 = packet.next_header().into();
|
let proto = packet.next_header();
|
||||||
|
|
||||||
let mut a: [u8; 4] = Default::default();
|
let mut a: [u8; 4] = Default::default();
|
||||||
a.copy_from_slice(packet.src_addr().as_bytes());
|
a.copy_from_slice(packet.src_addr().as_bytes());
|
||||||
|
@ -184,7 +184,7 @@ fn connection_tuple(frame: &[u8]) -> Option<(Connection, bool, usize, usize)> {
|
||||||
match Ipv6Packet::new_checked(frame) {
|
match Ipv6Packet::new_checked(frame) {
|
||||||
Ok(packet) => {
|
Ok(packet) => {
|
||||||
// TODO: Support extension headers.
|
// TODO: Support extension headers.
|
||||||
let proto: u8 = packet.next_header().into();
|
let proto = packet.next_header();
|
||||||
|
|
||||||
let mut a: [u8; 16] = Default::default();
|
let mut a: [u8; 16] = Default::default();
|
||||||
a.copy_from_slice(packet.src_addr().as_bytes());
|
a.copy_from_slice(packet.src_addr().as_bytes());
|
||||||
|
@ -419,7 +419,7 @@ impl<'a> TunToProxy<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if resolved_conn.proto == IpProtocol::Tcp.into() {
|
if resolved_conn.proto == IpProtocol::Tcp {
|
||||||
let cm = self.get_connection_manager(&resolved_conn);
|
let cm = self.get_connection_manager(&resolved_conn);
|
||||||
if cm.is_none() {
|
if cm.is_none() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -484,8 +484,7 @@ impl<'a> TunToProxy<'a> {
|
||||||
// The connection handler builds up the connection or encapsulates the data.
|
// The connection handler builds up the connection or encapsulates the data.
|
||||||
// Therefore, we now expect it to write data to the server.
|
// Therefore, we now expect it to write data to the server.
|
||||||
self.write_to_server(&resolved_conn);
|
self.write_to_server(&resolved_conn);
|
||||||
} else if resolved_conn.proto == IpProtocol::Udp.into() && resolved_conn.dst.port == 53
|
} else if resolved_conn.proto == IpProtocol::Udp && resolved_conn.dst.port == 53 {
|
||||||
{
|
|
||||||
if let Some(virtual_dns) = &mut self.options.virtdns {
|
if let Some(virtual_dns) = &mut self.options.virtdns {
|
||||||
let payload = &frame[_payload_offset.._payload_offset + _payload_size];
|
let payload = &frame[_payload_offset.._payload_offset + _payload_size];
|
||||||
if let Some(response) = virtual_dns.receive_query(payload) {
|
if let Some(response) = virtual_dns.receive_query(payload) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue