Add support for ipv6
This commit is contained in:
parent
49a35cc8fe
commit
208089b257
16
src/lib.rs
16
src/lib.rs
@ -2,7 +2,7 @@ use axum::extract::State;
|
|||||||
use axum::{http::StatusCode, Json};
|
use axum::{http::StatusCode, Json};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{Ipv4Addr, SocketAddrV4};
|
use std::net::{IpAddr, SocketAddr};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use tokio::io::{self, AsyncWriteExt};
|
use tokio::io::{self, AsyncWriteExt};
|
||||||
use tokio::net::{TcpListener, TcpStream};
|
use tokio::net::{TcpListener, TcpStream};
|
||||||
@ -20,12 +20,12 @@ enum Command {
|
|||||||
New {
|
New {
|
||||||
incoming_port: u16,
|
incoming_port: u16,
|
||||||
destination_port: u16,
|
destination_port: u16,
|
||||||
destination_ip: Ipv4Addr,
|
destination_ip: IpAddr,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
},
|
},
|
||||||
Modify {
|
Modify {
|
||||||
destination_port: u16,
|
destination_port: u16,
|
||||||
destination_ip: Ipv4Addr,
|
destination_ip: IpAddr,
|
||||||
id: Uuid,
|
id: Uuid,
|
||||||
},
|
},
|
||||||
Delete {
|
Delete {
|
||||||
@ -53,7 +53,7 @@ impl GlobalState {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct ProxyState {
|
struct ProxyState {
|
||||||
destination: SocketAddrV4,
|
destination: SocketAddr,
|
||||||
control: Sender<ProxyControlMessage>,
|
control: Sender<ProxyControlMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ pub async fn process_command(
|
|||||||
destination_ip,
|
destination_ip,
|
||||||
id,
|
id,
|
||||||
} => {
|
} => {
|
||||||
let addr = SocketAddrV4::new(destination_ip, destination_port);
|
let addr = SocketAddr::new(destination_ip, destination_port);
|
||||||
let (tx, rx) = watch::channel(ProxyControlMessage::Open { destination: addr });
|
let (tx, rx) = watch::channel(ProxyControlMessage::Open { destination: addr });
|
||||||
state.proxies.lock().unwrap().insert(
|
state.proxies.lock().unwrap().insert(
|
||||||
id,
|
id,
|
||||||
@ -117,7 +117,7 @@ pub async fn process_command(
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ProxyControlMessage {
|
enum ProxyControlMessage {
|
||||||
Open { destination: SocketAddrV4 }, // Reroute { new: SocketAddr },
|
Open { destination: SocketAddr },
|
||||||
Close,
|
Close,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +221,7 @@ async fn transfer(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::net::Ipv4Addr;
|
use std::net::{IpAddr, Ipv4Addr};
|
||||||
|
|
||||||
use crate::{Command, ProxyCommand};
|
use crate::{Command, ProxyCommand};
|
||||||
use uuid::uuid;
|
use uuid::uuid;
|
||||||
@ -232,7 +232,7 @@ mod tests {
|
|||||||
command: Command::New {
|
command: Command::New {
|
||||||
incoming_port: 5555,
|
incoming_port: 5555,
|
||||||
destination_port: 6666,
|
destination_port: 6666,
|
||||||
destination_ip: Ipv4Addr::new(127, 0, 0, 1),
|
destination_ip: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
||||||
id: uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"),
|
id: uuid!("67e55044-10b1-426f-9247-bb680e5fe0c8"),
|
||||||
},
|
},
|
||||||
signature: [0u8; 32],
|
signature: [0u8; 32],
|
||||||
|
Loading…
Reference in New Issue
Block a user