fix tproxy udp "unable to get destination" in IPv6 environment

pull/2531/head
lucifer9 5 years ago committed by kslr
parent 30b5f521c4
commit d055c0497d

@ -3,6 +3,7 @@ package internet
import (
"net"
"syscall"
"golang.org/x/sys/unix"
)
@ -99,10 +100,12 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
}
if config.ReceiveOriginalDestAddress && isUDPSocket(network) {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_IPV6, unix.IPV6_RECVORIGDSTADDR, 1); err != nil {
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR, 1); err != nil {
return err
}
}
}
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
return newError("failed to set SO_REUSEPORT").Base(err).AtWarning()

@ -5,6 +5,7 @@ package udp
import (
"syscall"
"golang.org/x/sys/unix"
"v2ray.com/core/common/net"
)
@ -18,7 +19,7 @@ func RetrieveOriginalDest(oob []byte) net.Destination {
ip := net.IPAddress(msg.Data[4:8])
port := net.PortFromBytes(msg.Data[2:4])
return net.UDPDestination(ip, port)
} else if msg.Header.Level == syscall.SOL_IPV6 && msg.Header.Type == syscall.IP_RECVORIGDSTADDR {
} else if msg.Header.Level == syscall.SOL_IPV6 && msg.Header.Type == unix.IPV6_RECVORIGDSTADDR {
ip := net.IPAddress(msg.Data[8:24])
port := net.PortFromBytes(msg.Data[2:4])
return net.UDPDestination(ip, port)

Loading…
Cancel
Save