mirror of
https://github.com/tun2proxy/tun2proxy.git
synced 2025-04-22 06:49:08 +00:00
IpProtocol values
This commit is contained in:
parent
4af656039e
commit
6fe44f8055
3 changed files with 12 additions and 9 deletions
|
@ -4,6 +4,7 @@ use crate::tun2proxy::{
|
|||
OutgoingDataEvent, OutgoingDirection, TcpProxy,
|
||||
};
|
||||
use base64::Engine;
|
||||
use smoltcp::wire::IpProtocol;
|
||||
use std::collections::VecDeque;
|
||||
use std::net::SocketAddr;
|
||||
use std::rc::Rc;
|
||||
|
@ -170,7 +171,7 @@ pub struct HttpManager {
|
|||
|
||||
impl ConnectionManager for HttpManager {
|
||||
fn handles_connection(&self, connection: &Connection) -> bool {
|
||||
connection.proto == smoltcp::wire::IpProtocol::Tcp.into()
|
||||
connection.proto == IpProtocol::Tcp.into()
|
||||
}
|
||||
|
||||
fn new_connection(
|
||||
|
@ -178,7 +179,7 @@ impl ConnectionManager for HttpManager {
|
|||
connection: &Connection,
|
||||
manager: Rc<dyn ConnectionManager>,
|
||||
) -> Option<Box<dyn TcpProxy>> {
|
||||
if connection.proto != smoltcp::wire::IpProtocol::Tcp.into() {
|
||||
if connection.proto != IpProtocol::Tcp.into() {
|
||||
return None;
|
||||
}
|
||||
Some(Box::new(HttpConnection::new(connection, manager)))
|
||||
|
|
|
@ -3,6 +3,7 @@ use crate::tun2proxy::{
|
|||
Connection, ConnectionManager, Credentials, DestinationHost, IncomingDataEvent,
|
||||
IncomingDirection, OutgoingDataEvent, OutgoingDirection, TcpProxy,
|
||||
};
|
||||
use smoltcp::wire::IpProtocol;
|
||||
use std::collections::VecDeque;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::rc::Rc;
|
||||
|
@ -297,7 +298,7 @@ pub struct Socks5Manager {
|
|||
|
||||
impl ConnectionManager for Socks5Manager {
|
||||
fn handles_connection(&self, connection: &Connection) -> bool {
|
||||
connection.proto == smoltcp::wire::IpProtocol::Tcp.into()
|
||||
connection.proto == IpProtocol::Tcp.into()
|
||||
}
|
||||
|
||||
fn new_connection(
|
||||
|
@ -305,7 +306,7 @@ impl ConnectionManager for Socks5Manager {
|
|||
connection: &Connection,
|
||||
manager: Rc<dyn ConnectionManager>,
|
||||
) -> Option<Box<dyn TcpProxy>> {
|
||||
if connection.proto != smoltcp::wire::IpProtocol::Tcp.into() {
|
||||
if connection.proto != IpProtocol::Tcp.into() {
|
||||
return None;
|
||||
}
|
||||
Some(Box::new(SocksConnection::new(connection, manager)))
|
||||
|
|
|
@ -10,7 +10,8 @@ use smoltcp::phy::{Device, Medium, RxToken, TunTapInterface, TxToken};
|
|||
use smoltcp::socket::tcp;
|
||||
use smoltcp::time::Instant;
|
||||
use smoltcp::wire::{
|
||||
IpAddress, IpCidr, Ipv4Address, Ipv4Packet, Ipv6Address, Ipv6Packet, TcpPacket, UdpPacket,
|
||||
IpAddress, IpCidr, IpProtocol, Ipv4Address, Ipv4Packet, Ipv6Address, Ipv6Packet, TcpPacket,
|
||||
UdpPacket,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::From;
|
||||
|
@ -115,7 +116,7 @@ fn get_transport_info(
|
|||
transport_offset: usize,
|
||||
packet: &[u8],
|
||||
) -> Option<((u16, u16), bool, usize, usize)> {
|
||||
if proto == smoltcp::wire::IpProtocol::Udp.into() {
|
||||
if proto == IpProtocol::Udp.into() {
|
||||
match UdpPacket::new_checked(packet) {
|
||||
Ok(result) => Some((
|
||||
(result.src_port(), result.dst_port()),
|
||||
|
@ -125,7 +126,7 @@ fn get_transport_info(
|
|||
)),
|
||||
Err(_) => None,
|
||||
}
|
||||
} else if proto == smoltcp::wire::IpProtocol::Tcp.into() {
|
||||
} else if proto == IpProtocol::Tcp.into() {
|
||||
match TcpPacket::new_checked(packet) {
|
||||
Ok(result) => Some((
|
||||
(result.src_port(), result.dst_port()),
|
||||
|
@ -380,7 +381,7 @@ impl<'a> TunToProxy<'a> {
|
|||
if let Some((connection, first_packet, _payload_offset, _payload_size)) =
|
||||
connection_tuple(frame)
|
||||
{
|
||||
if connection.proto == smoltcp::wire::IpProtocol::Tcp.into() {
|
||||
if connection.proto == IpProtocol::Tcp.into() {
|
||||
let cm = self.get_connection_manager(&connection);
|
||||
if cm.is_none() {
|
||||
return;
|
||||
|
@ -447,7 +448,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(&connection);
|
||||
} else if connection.proto == smoltcp::wire::IpProtocol::Udp.into() {
|
||||
} else if connection.proto == IpProtocol::Udp.into() {
|
||||
// UDP is not yet supported
|
||||
/*if _payload_offset > frame.len() || _payload_offset + _payload_offset > frame.len() {
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue