2018-09-10 15:08:59 -04:00
|
|
|
package internet_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"syscall"
|
|
|
|
"testing"
|
|
|
|
|
2021-02-16 15:31:50 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v4/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/net"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/testing/servers/tcp"
|
|
|
|
. "github.com/v2fly/v2ray-core/v4/transport/internet"
|
2018-09-10 15:08:59 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSockOptMark(t *testing.T) {
|
2018-09-17 10:27:41 -04:00
|
|
|
t.Skip("requires CAP_NET_ADMIN")
|
|
|
|
|
2018-09-10 15:08:59 -04:00
|
|
|
tcpServer := tcp.Server{
|
|
|
|
MsgProcessor: func(b []byte) []byte {
|
|
|
|
return b
|
|
|
|
},
|
|
|
|
}
|
|
|
|
dest, err := tcpServer.Start()
|
|
|
|
common.Must(err)
|
|
|
|
defer tcpServer.Close()
|
|
|
|
|
|
|
|
const mark = 1
|
2018-11-21 10:58:37 -05:00
|
|
|
dialer := DefaultSystemDialer{}
|
2018-11-21 11:15:41 -05:00
|
|
|
conn, err := dialer.Dial(context.Background(), nil, dest, &SocketConfig{Mark: mark})
|
2018-09-10 15:08:59 -04:00
|
|
|
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 {
|
2018-10-14 02:02:23 -04:00
|
|
|
t.Fatal("unexpected connection mark", m, " want ", mark)
|
2018-09-10 15:08:59 -04:00
|
|
|
}
|
|
|
|
})
|
|
|
|
common.Must(err)
|
|
|
|
}
|