mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-21 22:39:08 +00:00
renaming
This commit is contained in:
parent
49dca1b535
commit
2211ec6d7a
1 changed files with 17 additions and 18 deletions
|
@ -581,23 +581,23 @@ impl<'a> TunToProxy<'a> {
|
||||||
}
|
}
|
||||||
let (info, _first_packet, payload_offset, payload_size) = result?;
|
let (info, _first_packet, payload_offset, payload_size) = result?;
|
||||||
let origin_dst = SocketAddr::try_from(&info.dst)?;
|
let origin_dst = SocketAddr::try_from(&info.dst)?;
|
||||||
let connection_info = self.preprocess_origin_connection_info(info)?;
|
let info = self.preprocess_origin_connection_info(info)?;
|
||||||
|
|
||||||
let manager = self.get_connection_manager().ok_or("get connection manager")?;
|
let manager = self.get_connection_manager().ok_or("get connection manager")?;
|
||||||
|
|
||||||
if connection_info.protocol == IpProtocol::Tcp {
|
if info.protocol == IpProtocol::Tcp {
|
||||||
if _first_packet {
|
if _first_packet {
|
||||||
let tcp_proxy_handler = manager.new_tcp_proxy(&connection_info, false)?;
|
let tcp_proxy_handler = manager.new_tcp_proxy(&info, false)?;
|
||||||
let server = manager.get_server_addr();
|
let server = manager.get_server_addr();
|
||||||
let state = self.create_new_tcp_connection_state(server, origin_dst, tcp_proxy_handler, false)?;
|
let state = self.create_new_tcp_connection_state(server, origin_dst, tcp_proxy_handler, false)?;
|
||||||
self.connection_map.insert(connection_info.clone(), state);
|
self.connection_map.insert(info.clone(), state);
|
||||||
|
|
||||||
log::info!("Connect done {} ({})", connection_info, origin_dst);
|
log::info!("Connect done {} ({})", info, origin_dst);
|
||||||
} else if !self.connection_map.contains_key(&connection_info) {
|
} else if !self.connection_map.contains_key(&info) {
|
||||||
// log::debug!("Drop middle session {} ({})", connection_info, origin_dst);
|
// log::debug!("Drop middle session {} ({})", info, origin_dst);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
} else {
|
} else {
|
||||||
// log::trace!("Subsequent packet {} ({})", connection_info, origin_dst);
|
// log::trace!("Subsequent packet {} ({})", info, origin_dst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject the packet to advance the remote proxy server smoltcp socket state
|
// Inject the packet to advance the remote proxy server smoltcp socket state
|
||||||
|
@ -609,29 +609,28 @@ impl<'a> TunToProxy<'a> {
|
||||||
self.expect_smoltcp_send()?;
|
self.expect_smoltcp_send()?;
|
||||||
|
|
||||||
// Read from the smoltcp socket and push the data to the connection handler.
|
// Read from the smoltcp socket and push the data to the connection handler.
|
||||||
self.tunsocket_read_and_forward(&connection_info)?;
|
self.tunsocket_read_and_forward(&info)?;
|
||||||
|
|
||||||
// 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(&connection_info)?;
|
self.write_to_server(&info)?;
|
||||||
} else if connection_info.protocol == IpProtocol::Udp {
|
} else if info.protocol == IpProtocol::Udp {
|
||||||
let port = connection_info.dst.port();
|
let port = info.dst.port();
|
||||||
let payload = &frame[payload_offset..payload_offset + payload_size];
|
let payload = &frame[payload_offset..payload_offset + payload_size];
|
||||||
if let (Some(virtual_dns), true) = (&mut self.options.virtual_dns, port == DNS_PORT) {
|
if let (Some(virtual_dns), true) = (&mut self.options.virtual_dns, port == DNS_PORT) {
|
||||||
log::info!("DNS query via virtual DNS {} ({})", connection_info, origin_dst);
|
log::info!("DNS query via virtual DNS {} ({})", info, origin_dst);
|
||||||
let response = virtual_dns.receive_query(payload)?;
|
let response = virtual_dns.receive_query(payload)?;
|
||||||
self.send_udp_packet_to_client(origin_dst, connection_info.src, response.as_slice())?;
|
self.send_udp_packet_to_client(origin_dst, info.src, response.as_slice())?;
|
||||||
} else {
|
} else {
|
||||||
// Another UDP packet
|
// Another UDP packet
|
||||||
if self.options.dns_over_tcp && origin_dst.port() == DNS_PORT {
|
if self.options.dns_over_tcp && origin_dst.port() == DNS_PORT {
|
||||||
let info = &connection_info;
|
self.process_incoming_udp_packets_dns_over_tcp(&manager, &info, origin_dst, payload)?;
|
||||||
self.process_incoming_udp_packets_dns_over_tcp(&manager, info, origin_dst, payload)?;
|
|
||||||
} else {
|
} else {
|
||||||
self.process_incoming_udp_packets(&manager, &connection_info, origin_dst, payload)?;
|
self.process_incoming_udp_packets(&manager, &info, origin_dst, payload)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log::warn!("Unsupported protocol: {} ({})", connection_info, origin_dst);
|
log::warn!("Unsupported protocol: {} ({})", info, origin_dst);
|
||||||
}
|
}
|
||||||
Ok::<(), Error>(())
|
Ok::<(), Error>(())
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue