2016-08-15 15:33:32 -04:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package udp_test
|
|
|
|
|
|
|
|
import (
|
2016-08-16 03:01:58 -04:00
|
|
|
"os"
|
2016-08-15 15:33:32 -04:00
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/v2ray/v2ray-core/common/alloc"
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
|
|
"github.com/v2ray/v2ray-core/proxy"
|
|
|
|
"github.com/v2ray/v2ray-core/testing/assert"
|
2016-08-15 17:11:01 -04:00
|
|
|
"github.com/v2ray/v2ray-core/transport/internet/internal"
|
2016-08-15 15:33:32 -04:00
|
|
|
. "github.com/v2ray/v2ray-core/transport/internet/udp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestHubSocksOption(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
2016-08-16 03:01:58 -04:00
|
|
|
if os.Geteuid() != 0 {
|
|
|
|
// This test case requires root permission.
|
|
|
|
return
|
|
|
|
}
|
2016-08-15 15:33:32 -04:00
|
|
|
|
|
|
|
hub, err := ListenUDP(v2net.LocalHostIP, v2net.Port(0), ListenOption{
|
|
|
|
Callback: func(*alloc.Buffer, *proxy.SessionInfo) {},
|
|
|
|
ReceiveOriginalDest: true,
|
|
|
|
})
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
conn := hub.Connection()
|
|
|
|
|
2016-08-16 02:37:38 -04:00
|
|
|
fd, err := internal.GetSysFd(conn)
|
2016-08-15 15:33:32 -04:00
|
|
|
assert.Error(err).IsNil()
|
|
|
|
|
|
|
|
v, err := syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Int(v).Equals(1)
|
|
|
|
|
|
|
|
v, err = syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Int(v).Equals(1)
|
|
|
|
}
|