mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Marshallable socket opitons.
Socket option values are now required to implement marshal.Marshallable. Co-authored-by: Rahat Mahmood <rahat@google.com> PiperOrigin-RevId: 322831612
This commit is contained in:
committed by
gVisor bot
co-authored by
Rahat Mahmood
parent
384369e01e
commit
6f7f739967
@@ -51,6 +51,8 @@ go_library(
|
||||
"//pkg/tcpip/transport/udp",
|
||||
"//pkg/usermem",
|
||||
"//pkg/waiter",
|
||||
"//tools/go_marshal/marshal",
|
||||
"//tools/go_marshal/primitive",
|
||||
"@org_golang_x_sys//unix:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,8 @@ import (
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/usermem"
|
||||
"gvisor.dev/gvisor/pkg/waiter"
|
||||
"gvisor.dev/gvisor/tools/go_marshal/marshal"
|
||||
"gvisor.dev/gvisor/tools/go_marshal/primitive"
|
||||
)
|
||||
|
||||
// SocketVFS2 encapsulates all the state needed to represent a network stack
|
||||
@@ -200,7 +202,7 @@ func (s *SocketVFS2) Ioctl(ctx context.Context, uio usermem.IO, args arch.Syscal
|
||||
|
||||
// GetSockOpt implements the linux syscall getsockopt(2) for sockets backed by
|
||||
// tcpip.Endpoint.
|
||||
func (s *SocketVFS2) GetSockOpt(t *kernel.Task, level, name int, outPtr usermem.Addr, outLen int) (interface{}, *syserr.Error) {
|
||||
func (s *SocketVFS2) GetSockOpt(t *kernel.Task, level, name int, outPtr usermem.Addr, outLen int) (marshal.Marshallable, *syserr.Error) {
|
||||
// TODO(b/78348848): Unlike other socket options, SO_TIMESTAMP is
|
||||
// implemented specifically for netstack.SocketVFS2 rather than
|
||||
// commonEndpoint. commonEndpoint should be extended to support socket
|
||||
@@ -210,25 +212,25 @@ func (s *SocketVFS2) GetSockOpt(t *kernel.Task, level, name int, outPtr usermem.
|
||||
if outLen < sizeOfInt32 {
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
val := int32(0)
|
||||
val := primitive.Int32(0)
|
||||
s.readMu.Lock()
|
||||
defer s.readMu.Unlock()
|
||||
if s.sockOptTimestamp {
|
||||
val = 1
|
||||
}
|
||||
return val, nil
|
||||
return &val, nil
|
||||
}
|
||||
if level == linux.SOL_TCP && name == linux.TCP_INQ {
|
||||
if outLen < sizeOfInt32 {
|
||||
return nil, syserr.ErrInvalidArgument
|
||||
}
|
||||
val := int32(0)
|
||||
val := primitive.Int32(0)
|
||||
s.readMu.Lock()
|
||||
defer s.readMu.Unlock()
|
||||
if s.sockOptInq {
|
||||
val = 1
|
||||
}
|
||||
return val, nil
|
||||
return &val, nil
|
||||
}
|
||||
|
||||
if s.skType == linux.SOCK_RAW && level == linux.IPPROTO_IP {
|
||||
@@ -246,7 +248,7 @@ func (s *SocketVFS2) GetSockOpt(t *kernel.Task, level, name int, outPtr usermem.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return info, nil
|
||||
return &info, nil
|
||||
|
||||
case linux.IPT_SO_GET_ENTRIES:
|
||||
if outLen < linux.SizeOfIPTGetEntries {
|
||||
@@ -261,7 +263,7 @@ func (s *SocketVFS2) GetSockOpt(t *kernel.Task, level, name int, outPtr usermem.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return entries, nil
|
||||
return &entries, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user