mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-23 08:05:10 +00:00
UDP socket should set different IP_TRANSPARENT and IPV6_TRANSPARENT
This commit is contained in:
@@ -101,7 +101,7 @@ fn create_redir_listener(addr: &SocketAddr) -> io::Result<TcpListener> {
|
||||
let socket = Socket::new(domain, Type::stream(), Some(Protocol::tcp()))?;
|
||||
|
||||
// For Linux 2.4+ TPROXY
|
||||
// Sockets have to set IP_TRANSPARENT for retrieving original destination by getsockname()
|
||||
// Sockets have to set IP_TRANSPARENT, IPV6_TRANSPARENT for retrieving original destination by getsockname()
|
||||
unsafe {
|
||||
let fd = socket.as_raw_fd();
|
||||
|
||||
|
||||
@@ -103,14 +103,23 @@ fn set_socket_before_bind(addr: &SocketAddr, socket: &Socket) -> io::Result<()>
|
||||
|
||||
let enable: libc::c_int = 1;
|
||||
unsafe {
|
||||
// 1. Set IP_TRANSPARENT to allow binding to non-local addresses
|
||||
let ret = libc::setsockopt(
|
||||
fd,
|
||||
libc::SOL_IP,
|
||||
libc::IP_TRANSPARENT,
|
||||
&enable as *const _ as *const _,
|
||||
mem::size_of_val(&enable) as libc::socklen_t,
|
||||
);
|
||||
// 1. Set IP_TRANSPARENT, IPV6_TRANSPARENT to allow binding to non-local addresses
|
||||
let ret = match *addr {
|
||||
SocketAddr::V4(..) => libc::setsockopt(
|
||||
fd,
|
||||
libc::SOL_IP,
|
||||
libc::IP_TRANSPARENT,
|
||||
&enable as *const _ as *const _,
|
||||
mem::size_of_val(&enable) as libc::socklen_t,
|
||||
),
|
||||
SocketAddr::V6(..) => libc::setsockopt(
|
||||
fd,
|
||||
libc::SOL_IPV6,
|
||||
libc::IPV6_TRANSPARENT,
|
||||
&enable as *const _ as *const _,
|
||||
mem::size_of_val(&enable) as libc::socklen_t,
|
||||
),
|
||||
};
|
||||
if ret != 0 {
|
||||
return Err(Error::last_os_error());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user