switch to smoltcp dev version

to support IpProtocol with Hash trait
This commit is contained in:
ssrlive 2023-03-25 00:24:02 +08:00 committed by B. Blechschmidt
parent 4eddcfd02b
commit bfa1bbc462
4 changed files with 13 additions and 14 deletions

View file

@ -12,7 +12,7 @@ env_logger = "0.10"
hashlink = "0.8"
log = "0.4"
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"
[dev-dependencies]

View file

@ -168,7 +168,7 @@ pub struct HttpManager {
impl ConnectionManager for HttpManager {
fn handles_connection(&self, connection: &Connection) -> bool {
connection.proto == IpProtocol::Tcp.into()
connection.proto == IpProtocol::Tcp
}
fn new_connection(
@ -176,7 +176,7 @@ impl ConnectionManager for HttpManager {
connection: &Connection,
manager: Rc<dyn ConnectionManager>,
) -> Option<Box<dyn TcpProxy>> {
if connection.proto != IpProtocol::Tcp.into() {
if connection.proto != IpProtocol::Tcp {
return None;
}
Some(Box::new(HttpConnection::new(connection, manager)))

View file

@ -299,7 +299,7 @@ pub struct Socks5Manager {
impl ConnectionManager for Socks5Manager {
fn handles_connection(&self, connection: &Connection) -> bool {
connection.proto == IpProtocol::Tcp.into()
connection.proto == IpProtocol::Tcp
}
fn new_connection(
@ -307,7 +307,7 @@ impl ConnectionManager for Socks5Manager {
connection: &Connection,
manager: Rc<dyn ConnectionManager>,
) -> Option<Box<dyn TcpProxy>> {
if connection.proto != IpProtocol::Tcp.into() {
if connection.proto != IpProtocol::Tcp {
return None;
}
Some(Box::new(SocksConnection::new(connection, manager)))

View file

@ -82,7 +82,7 @@ impl Display for Destination {
pub(crate) struct Connection {
pub(crate) src: SocketAddr,
pub(crate) dst: Destination,
pub(crate) proto: u8,
pub(crate) proto: IpProtocol,
}
impl Connection {
@ -126,11 +126,11 @@ pub(crate) type IncomingDataEvent<'a> = DataEvent<'a, IncomingDirection>;
pub(crate) type OutgoingDataEvent<'a> = DataEvent<'a, OutgoingDirection>;
fn get_transport_info(
proto: u8,
proto: IpProtocol,
transport_offset: usize,
packet: &[u8],
) -> Option<((u16, u16), bool, usize, usize)> {
if proto == IpProtocol::Udp.into() {
if proto == IpProtocol::Udp {
match UdpPacket::new_checked(packet) {
Ok(result) => Some((
(result.src_port(), result.dst_port()),
@ -140,7 +140,7 @@ fn get_transport_info(
)),
Err(_) => None,
}
} else if proto == IpProtocol::Tcp.into() {
} else if proto == IpProtocol::Tcp {
match TcpPacket::new_checked(packet) {
Ok(result) => Some((
(result.src_port(), result.dst_port()),
@ -157,7 +157,7 @@ fn get_transport_info(
fn connection_tuple(frame: &[u8]) -> Option<(Connection, bool, usize, usize)> {
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();
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) {
Ok(packet) => {
// TODO: Support extension headers.
let proto: u8 = packet.next_header().into();
let proto = packet.next_header();
let mut a: [u8; 16] = Default::default();
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);
if cm.is_none() {
return Ok(());
@ -484,8 +484,7 @@ impl<'a> TunToProxy<'a> {
// The connection handler builds up the connection or encapsulates the data.
// Therefore, we now expect it to write data to the server.
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 {
let payload = &frame[_payload_offset.._payload_offset + _payload_size];
if let Some(response) = virtual_dns.receive_query(payload) {