1
0

filtering packet source

This commit is contained in:
EAimTY 2023-02-03 00:48:23 +09:00
parent 9806c62fe7
commit 2eeaec66d4
2 changed files with 34 additions and 26 deletions

View File

@ -284,7 +284,8 @@ impl Connection {
async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) { async fn handle_uni_stream(self, recv: RecvStream, _reg: Register) {
let res = match self.model.accept_uni_stream(recv).await { let res = match self.model.accept_uni_stream(recv).await {
Err(err) => Err(Error::from(err)), Err(err) => Err(Error::from(err)),
Ok(Task::Packet(pkt)) => match pkt.accept().await { Ok(Task::Packet(pkt)) => match self.udp_relay_mode {
UdpRelayMode::Quic => match pkt.accept().await {
Ok(Some((pkt, addr, assoc_id))) => { Ok(Some((pkt, addr, assoc_id))) => {
let addr = match addr { let addr = match addr {
Address::None => unreachable!(), Address::None => unreachable!(),
@ -298,6 +299,8 @@ impl Connection {
Ok(None) => Ok(()), Ok(None) => Ok(()),
Err(err) => Err(Error::from(err)), Err(err) => Err(Error::from(err)),
}, },
UdpRelayMode::Native => Err(Error::WrongPacketSource),
},
_ => unreachable!(), _ => unreachable!(),
}; };
@ -322,7 +325,8 @@ impl Connection {
async fn handle_datagram(self, dg: Bytes) { async fn handle_datagram(self, dg: Bytes) {
let res = match self.model.accept_datagram(dg) { let res = match self.model.accept_datagram(dg) {
Err(err) => Err(Error::from(err)), Err(err) => Err(Error::from(err)),
Ok(Task::Packet(pkt)) => match pkt.accept().await { Ok(Task::Packet(pkt)) => match self.udp_relay_mode {
UdpRelayMode::Native => match pkt.accept().await {
Ok(Some((pkt, addr, assoc_id))) => { Ok(Some((pkt, addr, assoc_id))) => {
let addr = match addr { let addr = match addr {
Address::None => unreachable!(), Address::None => unreachable!(),
@ -336,6 +340,8 @@ impl Connection {
Ok(None) => Ok(()), Ok(None) => Ok(()),
Err(err) => Err(Error::from(err)), Err(err) => Err(Error::from(err)),
}, },
UdpRelayMode::Quic => Err(Error::WrongPacketSource),
},
_ => unreachable!(), _ => unreachable!(),
}; };

View File

@ -20,6 +20,8 @@ pub enum Error {
Timeout, Timeout,
#[error("cannot resolve the server name")] #[error("cannot resolve the server name")]
DnsResolve, DnsResolve,
#[error("received packet from an unexpected source")]
WrongPacketSource,
#[error("invalid socks5 authentication")] #[error("invalid socks5 authentication")]
InvalidSocks5Auth, InvalidSocks5Auth,
} }