github.com/xraypb/Xray-core@v1.8.1/transport/internet/sockopt_linux_test.go (about) 1 package internet_test 2 3 import ( 4 "context" 5 "syscall" 6 "testing" 7 8 "github.com/xraypb/Xray-core/common" 9 "github.com/xraypb/Xray-core/common/net" 10 "github.com/xraypb/Xray-core/testing/servers/tcp" 11 . "github.com/xraypb/Xray-core/transport/internet" 12 ) 13 14 func TestSockOptMark(t *testing.T) { 15 t.Skip("requires CAP_NET_ADMIN") 16 17 tcpServer := tcp.Server{ 18 MsgProcessor: func(b []byte) []byte { 19 return b 20 }, 21 } 22 dest, err := tcpServer.Start() 23 common.Must(err) 24 defer tcpServer.Close() 25 26 const mark = 1 27 dialer := DefaultSystemDialer{} 28 conn, err := dialer.Dial(context.Background(), nil, dest, &SocketConfig{Mark: mark}) 29 common.Must(err) 30 defer conn.Close() 31 32 rawConn, err := conn.(*net.TCPConn).SyscallConn() 33 common.Must(err) 34 err = rawConn.Control(func(fd uintptr) { 35 m, err := syscall.GetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_MARK) 36 common.Must(err) 37 if mark != m { 38 t.Fatal("unexpected connection mark", m, " want ", mark) 39 } 40 }) 41 common.Must(err) 42 }