Silence the error log message for SO_RCVLOWAT option.

Removed the unimplemented syscall message for SO_RCVLOWAT option and added a
test for {g,s}etsockopt.

PiperOrigin-RevId: 438145815
This commit is contained in:
Nayana Bidari
2022-03-29 15:48:33 -07:00
committed by gVisor bot
parent e40dd291c4
commit 007a91a911
4 changed files with 67 additions and 1 deletions
+19
View File
@@ -1064,6 +1064,14 @@ func getSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, fam
vP := primitive.Int32(boolToInt32(v))
return &vP, nil
case linux.SO_RCVLOWAT:
if outLen < sizeOfInt32 {
return nil, syserr.ErrInvalidArgument
}
v := primitive.Int32(ep.SocketOptions().GetRcvlowat())
return &v, nil
default:
socket.GetSockOptEmitUnimplementedEvent(t, name)
}
@@ -2002,6 +2010,17 @@ func setSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, nam
var v tcpip.SocketDetachFilterOption
return syserr.TranslateNetstackError(ep.SetSockOpt(&v))
// TODO(b/226603727): Add support for SO_RCVLOWAT option. For now, only
// the unsupported syscall message is removed.
case linux.SO_RCVLOWAT:
if len(optVal) < sizeOfInt32 {
return syserr.ErrInvalidArgument
}
v := hostarch.ByteOrder.Uint32(optVal)
ep.SocketOptions().SetRcvlowat(int32(v))
return nil
default:
socket.SetSockOptEmitUnimplementedEvent(t, name)
}
-1
View File
@@ -583,7 +583,6 @@ func emitUnimplementedEvent(t *kernel.Task, name int) {
linux.SO_PEEK_OFF,
linux.SO_PRIORITY,
linux.SO_RCVBUF,
linux.SO_RCVLOWAT,
linux.SO_RCVTIMEO,
linux.SO_REUSEADDR,
linux.SO_REUSEPORT,
+18
View File
@@ -245,6 +245,10 @@ type SocketOptions struct {
// linger determines the amount of time the socket should linger before
// close. We currently implement this option for TCP socket only.
linger LingerOption
// rcvlowat specifies the minimum number of bytes which should be
// received to indicate the socket as readable.
rcvlowat int32
}
// InitHandler initializes the handler. This must be called before using the
@@ -702,3 +706,17 @@ func (so *SocketOptions) SetReceiveBufferSize(receiveBufferSize int64, notify bo
}
so.receiveBufferSize.Store(receiveBufferSize)
}
// GetRcvlowat gets value for SO_RCVLOWAT option.
func (so *SocketOptions) GetRcvlowat() int32 {
// TODO(b/226603727): Return so.rcvlowat after adding complete support
// for SO_RCVLOWAT option. For now, return the default value of 1.
defaultRcvlowat := int32(1)
return defaultRcvlowat
}
// SetRcvlowat sets value for SO_RCVLOWAT option.
func (so *SocketOptions) SetRcvlowat(rcvlowat int32) Error {
atomic.StoreInt32(&so.rcvlowat, rcvlowat)
return nil
}
@@ -968,5 +968,35 @@ TEST_P(AllSocketPairTest, GetSocketRcvbufOption) {
EXPECT_EQ(opt, minRcvBufSizeLinux);
}
}
TEST_P(AllSocketPairTest, GetSetSocketRcvlowatOption) {
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
int opt = 0;
socklen_t opt_len = sizeof(opt);
constexpr int defaultSz = 1;
ASSERT_THAT(
getsockopt(sockets->first_fd(), SOL_SOCKET, SO_RCVLOWAT, &opt, &opt_len),
SyscallSucceeds());
ASSERT_EQ(opt_len, sizeof(opt));
EXPECT_EQ(opt, defaultSz);
int rcvlowatSz = 100;
ASSERT_THAT(setsockopt(sockets->first_fd(), SOL_SOCKET, SO_RCVLOWAT,
&rcvlowatSz, sizeof(rcvlowatSz)),
SyscallSucceeds());
ASSERT_THAT(
getsockopt(sockets->first_fd(), SOL_SOCKET, SO_RCVLOWAT, &opt, &opt_len),
SyscallSucceeds());
ASSERT_EQ(opt_len, sizeof(opt));
if (IsRunningOnGvisor()) {
// TODO(b/226603727): Add support for setting SO_RCVLOWAT option in gVisor.
EXPECT_EQ(opt, defaultSz);
} else {
EXPECT_EQ(opt, rcvlowatSz);
}
}
} // namespace testing
} // namespace gvisor