Skip to content

Commit

Permalink
Forward reuse address and port in udp protocol at lib virtual net
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjjo committed Dec 10, 2024
1 parent a09ad41 commit 81ccd9d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/virtual-net/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,24 @@ impl VirtualNetworking for LocalNetworking {
&self,
addr: SocketAddr,
_reuse_port: bool,
_reuse_addr: bool,
reuse_addr: bool,
) -> Result<Box<dyn VirtualUdpSocket + Sync>> {
use socket2::{Socket, Domain, Type};

if let Some(ruleset) = self.ruleset.as_ref() {
if !ruleset.allows_socket(addr, Direction::Inbound) {
tracing::warn!(%addr, "bind_udp blocked by firewall rule");
return Err(NetworkError::PermissionDenied);
}
}

let socket = mio::net::UdpSocket::bind(addr).map_err(io_err_into_net_error)?;
let std_sock = Socket::new(Domain::IPV4, Type::DGRAM, None).map_err(io_err_into_net_error)?;
std_sock.set_reuse_address(reuse_addr).map_err(io_err_into_net_error)?;
//std_sock.set_reuse_port(reuse_port).map_err(io_err_into_net_error)?;

std_sock.bind(&addr.into()).map_err(io_err_into_net_error)?;

let socket = mio::net::UdpSocket::from_std(std_sock.into());

#[allow(unused_mut)]
let mut ret = LocalUdpSocket {
Expand Down

0 comments on commit 81ccd9d

Please sign in to comment.