Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

feat: enable SO_REUSEPORT #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions boringtun/src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,8 @@ impl Device {
// Then open new sockets and bind to the port
let udp_sock4 = socket2::Socket::new(Domain::IPV4, Type::DGRAM, Some(Protocol::UDP))?;
udp_sock4.set_reuse_address(true)?;
// SO_REUSEPORT is not really needed here, as long as the wildcard address is used in the bind
udp_sock4.set_reuse_port(true)?;
udp_sock4.bind(&SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port).into())?;
udp_sock4.set_nonblocking(true)?;

Expand All @@ -438,6 +440,8 @@ impl Device {

let udp_sock6 = socket2::Socket::new(Domain::IPV6, Type::DGRAM, Some(Protocol::UDP))?;
udp_sock6.set_reuse_address(true)?;
// SO_REUSEPORT is not really needed here, as long as the wildcard address is used in the bind
udp_sock6.set_reuse_port(true)?;
udp_sock6.bind(&SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, port, 0, 0).into())?;
udp_sock6.set_nonblocking(true)?;

Expand Down
2 changes: 2 additions & 0 deletions boringtun/src/device/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl Peer {
let udp_conn =
socket2::Socket::new(Domain::for_address(addr), Type::STREAM, Some(Protocol::UDP))?;
udp_conn.set_reuse_address(true)?;
// SO_REUSEPORT is not really needed here, as long as the wildcard address is used in the bind
udp_conn.set_reuse_port(true)?;
let bind_addr = if addr.is_ipv4() {
SocketAddrV4::new(Ipv4Addr::UNSPECIFIED, port).into()
} else {
Expand Down