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"
|
|
|
|
|
2016-12-09 05:35:27 -05:00
|
|
|
"v2ray.com/core/common/buf"
|
2016-08-20 14:55:45 -04:00
|
|
|
v2net "v2ray.com/core/common/net"
|
|
|
|
"v2ray.com/core/testing/assert"
|
|
|
|
"v2ray.com/core/transport/internet/internal"
|
|
|
|
. "v2ray.com/core/transport/internet/udp"
|
2016-08-15 15:33:32 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
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{
|
2017-01-26 14:55:01 -05:00
|
|
|
Callback: func(*buf.Buffer, v2net.Destination, v2net.Destination) {},
|
2016-08-15 15:33:32 -04:00
|
|
|
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()
|
|
|
|
|
2016-11-27 11:01:44 -05:00
|
|
|
val, err := syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_TRANSPARENT)
|
2016-08-15 15:33:32 -04:00
|
|
|
assert.Error(err).IsNil()
|
2016-11-27 11:01:44 -05:00
|
|
|
assert.Int(val).Equals(1)
|
2016-08-15 15:33:32 -04:00
|
|
|
|
2016-11-27 11:01:44 -05:00
|
|
|
val, err = syscall.GetsockoptInt(fd, syscall.SOL_IP, syscall.IP_RECVORIGDSTADDR)
|
2016-08-15 15:33:32 -04:00
|
|
|
assert.Error(err).IsNil()
|
2016-11-27 11:01:44 -05:00
|
|
|
assert.Int(val).Equals(1)
|
2016-08-15 15:33:32 -04:00
|
|
|
}
|