move sockopt test back to its own file

pull/1269/head
Darien Raymond 6 years ago
parent 3b7c4f5ac6
commit c8a12bc35d
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

@ -0,0 +1,48 @@
package internet_test
import (
"context"
"syscall"
"testing"
"v2ray.com/core/common"
"v2ray.com/core/common/net"
"v2ray.com/core/testing/servers/tcp"
. "v2ray.com/core/transport/internet"
)
func TestSockOptMark(t *testing.T) {
t.Skip("requires CAP_NET_ADMIN")
tcpServer := tcp.Server{
MsgProcessor: func(b []byte) []byte {
return b
},
}
dest, err := tcpServer.Start()
common.Must(err)
defer tcpServer.Close()
const mark = 1
ctx := context.Background()
ctx = ContextWithStreamSettings(ctx, &MemoryStreamConfig{
SocketSettings: &SocketConfig{
Mark: mark,
},
})
dialer := DefaultSystemDialer{}
conn, err := dialer.Dial(ctx, nil, dest)
common.Must(err)
defer conn.Close()
rawConn, err := conn.(*net.TCPConn).SyscallConn()
common.Must(err)
err = rawConn.Control(func(fd uintptr) {
m, err := syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK)
common.Must(err)
if mark != m {
t.Fatal("unexpected conneciton mark", m, " want ", mark)
}
})
common.Must(err)
}

@ -2,13 +2,11 @@ package internet_test
import (
"context"
"syscall"
"testing"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/compare"
"v2ray.com/core/common/net"
"v2ray.com/core/testing/servers/tcp"
. "v2ray.com/core/transport/internet"
)
@ -43,39 +41,3 @@ func TestTCPFastOpen(t *testing.T) {
t.Fatal(err)
}
}
func TestSockOptMark(t *testing.T) {
t.Skip("requires CAP_NET_ADMIN")
tcpServer := tcp.Server{
MsgProcessor: func(b []byte) []byte {
return b
},
}
dest, err := tcpServer.Start()
common.Must(err)
defer tcpServer.Close()
const mark = 1
ctx := context.Background()
ctx = ContextWithStreamSettings(ctx, &MemoryStreamConfig{
SocketSettings: &SocketConfig{
Mark: mark,
},
})
dialer := DefaultSystemDialer{}
conn, err := dialer.Dial(ctx, nil, dest)
common.Must(err)
defer conn.Close()
rawConn, err := conn.(*net.TCPConn).SyscallConn()
common.Must(err)
err = rawConn.Control(func(fd uintptr) {
m, err := syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK)
common.Must(err)
if mark != m {
t.Fatal("unexpected conneciton mark", m, " want ", mark)
}
})
common.Must(err)
}

@ -8,21 +8,18 @@ import (
)
const (
// For incoming connections.
TCP_FASTOPEN = 23
// For out-going connections.
TCP_FASTOPEN_CONNECT = 30
TCP_FASTOPEN = 0x105
)
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
if strings.HasPrefix(network, "tcp") {
switch config.Tfo {
case SocketConfig_Enable:
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 1); err != nil {
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 1); err != nil {
return err
}
case SocketConfig_Disable:
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 0); err != nil {
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, 0); err != nil {
return err
}
}

Loading…
Cancel
Save