MCPcopy Index your code
hub / github.com/google/gvisor / GetSockOpt

Method GetSockOpt

pkg/sentry/socket/netstack/netstack.go:627–682  ·  view source on GitHub ↗

GetSockOpt implements the linux syscall getsockopt(2) for sockets backed by tcpip.Endpoint.

(t *kernel.Task, level, name int, outPtr hostarch.Addr, outLen int)

Source from the content-addressed store, hash-verified

625// GetSockOpt implements the linux syscall getsockopt(2) for sockets backed by
626// tcpip.Endpoint.
627func (s *sock) GetSockOpt(t *kernel.Task, level, name int, outPtr hostarch.Addr, outLen int) (marshal.Marshallable, *syserr.Error) {
628 // TODO(b/78348848): Unlike other socket options, SO_TIMESTAMP is
629 // implemented specifically for netstack.Socket rather than
630 // commonEndpoint. commonEndpoint should be extended to support socket
631 // options where the implementation is not shared, as unix sockets need
632 // their own support for SO_TIMESTAMP.
633 if level == linux.SOL_SOCKET && name == linux.SO_TIMESTAMP {
634 if outLen < sizeOfInt32 {
635 return nil, syserr.ErrInvalidArgument
636 }
637 val := primitive.Int32(0)
638 s.readMu.Lock()
639 defer s.readMu.Unlock()
640 if s.sockOptTimestamp {
641 val = 1
642 }
643 return &val, nil
644 }
645 if level == linux.SOL_TCP && name == linux.TCP_INQ {
646 if outLen < sizeOfInt32 {
647 return nil, syserr.ErrInvalidArgument
648 }
649 val := primitive.Int32(0)
650 s.readMu.Lock()
651 defer s.readMu.Unlock()
652 if s.sockOptInq {
653 val = 1
654 }
655 return &val, nil
656 }
657
658 switch level {
659 case linux.SOL_SOCKET:
660 return GetSockOptSocket(t, s, s.Endpoint, s.family, s.skType, name, outLen)
661
662 case linux.SOL_TCP:
663 return s.getSockOptTCP(t, s.Endpoint, name, outLen)
664
665 case linux.SOL_IPV6:
666 return s.getSockOptIPv6(t, s.Endpoint, name, outPtr, outLen)
667
668 case linux.SOL_IP:
669 return s.getSockOptIP(t, s.Endpoint, name, outPtr, outLen, s.family)
670
671 case linux.SOL_ICMPV6:
672 return s.getSockOptICMPv6(t, s.Endpoint, name, outLen)
673
674 case linux.SOL_PACKET:
675 return s.getSockOptPacket(t, s.Endpoint, name, outPtr, outLen)
676 case linux.SOL_UDP, linux.SOL_RAW:
677 // Not supported.
678 }
679
680 return nil, syserr.ErrProtocolNotAvailable
681
682}
683
684// SetSockOpt implements the linux syscall setsockopt(2) for sockets backed by

Callers

nothing calls this directly

Calls 9

getSockOptTCPMethod · 0.95
getSockOptIPv6Method · 0.95
getSockOptIPMethod · 0.95
getSockOptICMPv6Method · 0.95
getSockOptPacketMethod · 0.95
Int32TypeAlias · 0.92
GetSockOptSocketFunction · 0.85
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected