1
0

mark outbound UDP socket IPv6 only

This commit is contained in:
EAimTY 2023-02-04 16:41:56 +09:00
parent 41e9489f30
commit f4dfa75e4c

View File

@ -4,11 +4,12 @@ use crossbeam_utils::atomic::AtomicCell;
use parking_lot::Mutex; use parking_lot::Mutex;
use quinn::{Connecting, Connection as QuinnConnection, Endpoint, RecvStream, SendStream, VarInt}; use quinn::{Connecting, Connection as QuinnConnection, Endpoint, RecvStream, SendStream, VarInt};
use register_count::{Counter, Register}; use register_count::{Counter, Register};
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
use std::{ use std::{
collections::{hash_map::Entry, HashMap}, collections::{hash_map::Entry, HashMap},
future::Future, future::Future,
io::{Error as IoError, ErrorKind}, io::{Error as IoError, ErrorKind},
net::{Ipv4Addr, Ipv6Addr, SocketAddr}, net::{Ipv4Addr, Ipv6Addr, SocketAddr, UdpSocket as StdUdpSocket},
pin::Pin, pin::Pin,
sync::{ sync::{
atomic::{AtomicBool, AtomicUsize, Ordering}, atomic::{AtomicBool, AtomicUsize, Ordering},
@ -440,9 +441,13 @@ impl UdpSession {
let socket_v4 = let socket_v4 =
Arc::new(UdpSocket::bind(SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))).await?); Arc::new(UdpSocket::bind(SocketAddr::from((Ipv4Addr::UNSPECIFIED, 0))).await?);
let socket_v6 = if udp_relay_ipv6 { let socket_v6 = if udp_relay_ipv6 {
Some(Arc::new( let socket = Socket::new(Domain::IPV6, Type::DGRAM, Some(Protocol::UDP))?;
UdpSocket::bind(SocketAddr::from((Ipv6Addr::UNSPECIFIED, 0))).await?, socket.set_only_v6(true)?;
)) socket.bind(&SockAddr::from(SocketAddr::from((
Ipv6Addr::UNSPECIFIED,
0,
))))?;
Some(Arc::new(UdpSocket::from_std(StdUdpSocket::from(socket))?))
} else { } else {
None None
}; };