chore: linux ipv6 REDIRECT (#311)
This commit is contained in:
parent
861357234f
commit
fcd5580875
1 changed files with 17 additions and 0 deletions
|
@ -29,6 +29,9 @@ func parserPacket(conn net.Conn) (socks5.Addr, error) {
|
||||||
|
|
||||||
rc.Control(func(fd uintptr) {
|
rc.Control(func(fd uintptr) {
|
||||||
addr, err = getorigdst(fd)
|
addr, err = getorigdst(fd)
|
||||||
|
if err != nil {
|
||||||
|
addr, err = getorigdst6(fd)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return addr, err
|
return addr, err
|
||||||
|
@ -49,3 +52,17 @@ func getorigdst(fd uintptr) (socks5.Addr, error) {
|
||||||
addr[1+net.IPv4len], addr[1+net.IPv4len+1] = port[0], port[1]
|
addr[1+net.IPv4len], addr[1+net.IPv4len+1] = port[0], port[1]
|
||||||
return addr, nil
|
return addr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getorigdst6(fd uintptr) (socks5.Addr, error) {
|
||||||
|
raw := syscall.RawSockaddrInet6{}
|
||||||
|
siz := uint32(unsafe.Sizeof(raw))
|
||||||
|
if err := socketcall(GETSOCKOPT, fd, syscall.IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, uintptr(unsafe.Pointer(&raw)), uintptr(unsafe.Pointer(&siz)), 0); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
addr := make([]byte, 1+net.IPv6len+2)
|
||||||
|
addr[0] = socks5.AtypIPv6
|
||||||
|
copy(addr[1:1+net.IPv6len], raw.Addr[:])
|
||||||
|
port := (*[2]byte)(unsafe.Pointer(&raw.Port)) // big-endian
|
||||||
|
addr[1+net.IPv6len], addr[1+net.IPv6len+1] = port[0], port[1]
|
||||||
|
return addr, nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue