mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Move SO_ERROR and SO_OOBINLINE option to socketops.
SO_OOBINLINE option is set/get as boolean value, which is the same as linux. As we currently do not support disabling this option, we always return it as true. PiperOrigin-RevId: 347413905
This commit is contained in:
committed by
gVisor bot
parent
08d36b6c63
commit
ab593661ef
@@ -965,7 +965,7 @@ func getSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, fam
|
||||
}
|
||||
|
||||
// Get the last error and convert it.
|
||||
err := ep.LastError()
|
||||
err := ep.SocketOptions().GetLastError()
|
||||
if err == nil {
|
||||
optP := primitive.Int32(0)
|
||||
return &optP, nil
|
||||
@@ -1127,13 +1127,8 @@ func getSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, fam
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
|
||||
var v tcpip.OutOfBandInlineOption
|
||||
if err := ep.GetSockOpt(&v); err != nil {
|
||||
return nil, syserr.TranslateNetstackError(err)
|
||||
}
|
||||
|
||||
vP := primitive.Int32(v)
|
||||
return &vP, nil
|
||||
v := primitive.Int32(boolToInt32(ep.SocketOptions().GetOutOfBandInline()))
|
||||
return &v, nil
|
||||
|
||||
case linux.SO_NO_CHECK:
|
||||
if outLen < sizeOfInt32 {
|
||||
@@ -1880,8 +1875,8 @@ func setSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, nam
|
||||
socket.SetSockOptEmitUnimplementedEvent(t, name)
|
||||
}
|
||||
|
||||
opt := tcpip.OutOfBandInlineOption(v)
|
||||
return syserr.TranslateNetstackError(ep.SetSockOpt(&opt))
|
||||
ep.SocketOptions().SetOutOfBandInline(v != 0)
|
||||
return nil
|
||||
|
||||
case linux.SO_NO_CHECK:
|
||||
if len(optVal) < sizeOfInt32 {
|
||||
|
||||
@@ -37,6 +37,9 @@ type SocketOptionsHandler interface {
|
||||
|
||||
// OnCorkOptionSet is invoked when TCP_CORK is set for an endpoint.
|
||||
OnCorkOptionSet(v bool)
|
||||
|
||||
// LastError is invoked when SO_ERROR is read for an endpoint.
|
||||
LastError() *Error
|
||||
}
|
||||
|
||||
// DefaultSocketOptionsHandler is an embeddable type that implements no-op
|
||||
@@ -60,6 +63,11 @@ func (*DefaultSocketOptionsHandler) OnDelayOptionSet(bool) {}
|
||||
// OnCorkOptionSet implements SocketOptionsHandler.OnCorkOptionSet.
|
||||
func (*DefaultSocketOptionsHandler) OnCorkOptionSet(bool) {}
|
||||
|
||||
// LastError implements SocketOptionsHandler.LastError.
|
||||
func (*DefaultSocketOptionsHandler) LastError() *Error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SocketOptions contains all the variables which store values for SOL_SOCKET,
|
||||
// SOL_IP, SOL_IPV6 and SOL_TCP level options.
|
||||
//
|
||||
@@ -316,3 +324,17 @@ func (so *SocketOptions) GetReceiveOriginalDstAddress() bool {
|
||||
func (so *SocketOptions) SetReceiveOriginalDstAddress(v bool) {
|
||||
storeAtomicBool(&so.receiveOriginalDstAddress, v)
|
||||
}
|
||||
|
||||
// GetLastError gets value for SO_ERROR option.
|
||||
func (so *SocketOptions) GetLastError() *Error {
|
||||
return so.handler.LastError()
|
||||
}
|
||||
|
||||
// GetOutOfBandInline gets value for SO_OOBINLINE option.
|
||||
func (*SocketOptions) GetOutOfBandInline() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// SetOutOfBandInline sets value for SO_OOBINLINE option. We currently do not
|
||||
// support disabling this option.
|
||||
func (*SocketOptions) SetOutOfBandInline(bool) {}
|
||||
|
||||
@@ -1096,14 +1096,6 @@ type RemoveMembershipOption MembershipOption
|
||||
|
||||
func (*RemoveMembershipOption) isSettableSocketOption() {}
|
||||
|
||||
// OutOfBandInlineOption is used by SetSockOpt/GetSockOpt to specify whether
|
||||
// TCP out-of-band data is delivered along with the normal in-band data.
|
||||
type OutOfBandInlineOption int
|
||||
|
||||
func (*OutOfBandInlineOption) isGettableSocketOption() {}
|
||||
|
||||
func (*OutOfBandInlineOption) isSettableSocketOption() {}
|
||||
|
||||
// SocketDetachFilterOption is used by SetSockOpt to detach a previously attached
|
||||
// classic BPF filter on a given endpoint.
|
||||
type SocketDetachFilterOption int
|
||||
|
||||
@@ -1838,9 +1838,6 @@ func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error {
|
||||
e.keepalive.Unlock()
|
||||
e.notifyProtocolGoroutine(notifyKeepaliveChanged)
|
||||
|
||||
case *tcpip.OutOfBandInlineOption:
|
||||
// We don't currently support disabling this option.
|
||||
|
||||
case *tcpip.TCPUserTimeoutOption:
|
||||
e.LockUser()
|
||||
e.userTimeout = time.Duration(*v)
|
||||
@@ -2046,10 +2043,6 @@ func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) *tcpip.Error {
|
||||
*o = tcpip.TCPUserTimeoutOption(e.userTimeout)
|
||||
e.UnlockUser()
|
||||
|
||||
case *tcpip.OutOfBandInlineOption:
|
||||
// We don't currently support disabling this option.
|
||||
*o = 1
|
||||
|
||||
case *tcpip.CongestionControlOption:
|
||||
e.LockUser()
|
||||
*o = e.cc
|
||||
|
||||
@@ -853,5 +853,21 @@ TEST_P(AllSocketPairTest, SetAndGetBooleanSocketOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(AllSocketPairTest, GetSocketOutOfBandInlineOption) {
|
||||
// We do not support disabling this option. It is always enabled.
|
||||
SKIP_IF(!IsRunningOnGvisor());
|
||||
|
||||
auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
|
||||
int enable = -1;
|
||||
socklen_t enableLen = sizeof(enable);
|
||||
|
||||
int want = 1;
|
||||
ASSERT_THAT(getsockopt(sockets->first_fd(), SOL_SOCKET, SO_OOBINLINE, &enable,
|
||||
&enableLen),
|
||||
SyscallSucceeds());
|
||||
ASSERT_EQ(enableLen, sizeof(enable));
|
||||
EXPECT_EQ(enable, want);
|
||||
}
|
||||
|
||||
} // namespace testing
|
||||
} // namespace gvisor
|
||||
|
||||
Reference in New Issue
Block a user