mirror of
https://github.com/dndx/phantun.git
synced 2025-01-19 06:19:30 +08:00
fix(phantun) better UDP error handling
When UDP send fails, print a proper error message and close the connection, instead of `panic`ing.
This commit is contained in:
parent
e3e50f8a9e
commit
5a6ebf52ea
@ -139,7 +139,11 @@ async fn main() {
|
|||||||
match res {
|
match res {
|
||||||
Some(size) => {
|
Some(size) => {
|
||||||
if size > 0 {
|
if size > 0 {
|
||||||
udp_sock.send(&buf_tcp[..size]).await.unwrap();
|
if let Err(e) = udp_sock.send(&buf_tcp[..size]).await {
|
||||||
|
connections.write().await.remove(&addr);
|
||||||
|
error!("Unable to send UDP packet to {}: {}, closing connection", e, addr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
|
@ -3,7 +3,7 @@ extern crate dndx_fork_tokio_tun as tokio_tun;
|
|||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
use fake_tcp::packet::MAX_PACKET_LEN;
|
use fake_tcp::packet::MAX_PACKET_LEN;
|
||||||
use fake_tcp::Stack;
|
use fake_tcp::Stack;
|
||||||
use log::info;
|
use log::{error, info};
|
||||||
use std::net::SocketAddrV4;
|
use std::net::SocketAddrV4;
|
||||||
use tokio::net::UdpSocket;
|
use tokio::net::UdpSocket;
|
||||||
use tokio::time::{self, Duration};
|
use tokio::time::{self, Duration};
|
||||||
@ -90,7 +90,10 @@ async fn main() {
|
|||||||
match res {
|
match res {
|
||||||
Some(size) => {
|
Some(size) => {
|
||||||
if size > 0 {
|
if size > 0 {
|
||||||
udp_sock.send(&buf_tcp[..size]).await.unwrap();
|
if let Err(e) = udp_sock.send(&buf_tcp[..size]).await {
|
||||||
|
error!("Unable to send UDP packet to {}: {}, closing connection", e, remote_addr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => { return; },
|
None => { return; },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user