MCPcopy
hub / github.com/google/gvisor / GetSockOptSocket

Function GetSockOptSocket

pkg/sentry/socket/netstack/netstack.go:995–1179  ·  view source on GitHub ↗

GetSockOptSocket handles linux getsockopt(2) when level is SOL_SOCKET.

(t *kernel.Task, s socket.Socket, ep commonEndpoint, family int, _ linux.SockType, name, outLen int)

Source from the content-addressed store, hash-verified

993
994// GetSockOptSocket handles linux getsockopt(2) when level is SOL_SOCKET.
995func GetSockOptSocket(t *kernel.Task, s socket.Socket, ep commonEndpoint, family int, _ linux.SockType, name, outLen int) (marshal.Marshallable, *syserr.Error) {
996 // TODO(b/124056281): Stop rejecting short optLen values in getsockopt.
997 switch name {
998 case linux.SO_ERROR:
999 if outLen < sizeOfInt32 {
1000 return nil, syserr.ErrInvalidArgument
1001 }
1002
1003 // Get the last error and convert it.
1004 err := ep.SocketOptions().GetLastError()
1005 if err == nil {
1006 optP := primitive.Int32(0)
1007 return &optP, nil
1008 }
1009
1010 optP := primitive.Int32(syserr.TranslateNetstackError(err).ToLinux())
1011 return &optP, nil
1012
1013 case linux.SO_PEERCRED:
1014 if family != linux.AF_UNIX || outLen < unix.SizeofUcred {
1015 return nil, syserr.ErrInvalidArgument
1016 }
1017 return s.GetPeerCreds(t)
1018
1019 case linux.SO_PASSCRED:
1020 if outLen < sizeOfInt32 {
1021 return nil, syserr.ErrInvalidArgument
1022 }
1023
1024 v := primitive.Int32(boolToInt32(ep.SocketOptions().GetPassCred()))
1025 return &v, nil
1026
1027 case linux.SO_SNDBUF:
1028 if outLen < sizeOfInt32 {
1029 return nil, syserr.ErrInvalidArgument
1030 }
1031
1032 size := ep.SocketOptions().GetSendBufferSize()
1033
1034 if size > math.MaxInt32 {
1035 size = math.MaxInt32
1036 }
1037
1038 sizeP := primitive.Int32(size)
1039 return &sizeP, nil
1040
1041 case linux.SO_RCVBUF:
1042 if outLen < sizeOfInt32 {
1043 return nil, syserr.ErrInvalidArgument
1044 }
1045
1046 size := ep.SocketOptions().GetReceiveBufferSize()
1047
1048 if size > math.MaxInt32 {
1049 size = math.MaxInt32
1050 }
1051
1052 sizeP := primitive.Int32(size)

Callers 2

GetSockOptMethod · 0.92
GetSockOptMethod · 0.85

Calls 15

Int32TypeAlias · 0.92
TranslateNetstackErrorFunction · 0.92
ByteSliceTypeAlias · 0.92
NsecToTimevalFunction · 0.92
boolToInt32Function · 0.85
getSockOptSocketCustomFunction · 0.85
GetLastErrorMethod · 0.80
GetPassCredMethod · 0.80
GetSendBufferSizeMethod · 0.80
GetReceiveBufferSizeMethod · 0.80
GetReuseAddressMethod · 0.80
GetReusePortMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…