diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2021-03-03 10:23:55 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-03 10:25:58 -0800 |
commit | a9441aea2780da8c93da1c73da860219f98438de (patch) | |
tree | 8b12915756f5bfb926218214cd7bc0b3281605fd /pkg/sentry/socket/netstack/provider.go | |
parent | b8a5420f49a2afd622ec08b5019e1bf537f7da82 (diff) |
[op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.
Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
returns it and not unix.Stat_t.
Updates #214
PiperOrigin-RevId: 360701387
Diffstat (limited to 'pkg/sentry/socket/netstack/provider.go')
-rw-r--r-- | pkg/sentry/socket/netstack/provider.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/pkg/sentry/socket/netstack/provider.go b/pkg/sentry/socket/netstack/provider.go index 2515dda80..8605ad507 100644 --- a/pkg/sentry/socket/netstack/provider.go +++ b/pkg/sentry/socket/netstack/provider.go @@ -15,8 +15,7 @@ package netstack import ( - "syscall" - + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/sentry/fs" @@ -48,18 +47,18 @@ type provider struct { func getTransportProtocol(ctx context.Context, stype linux.SockType, protocol int) (tcpip.TransportProtocolNumber, bool, *syserr.Error) { switch stype { case linux.SOCK_STREAM: - if protocol != 0 && protocol != syscall.IPPROTO_TCP { + if protocol != 0 && protocol != unix.IPPROTO_TCP { return 0, true, syserr.ErrInvalidArgument } return tcp.ProtocolNumber, true, nil case linux.SOCK_DGRAM: switch protocol { - case 0, syscall.IPPROTO_UDP: + case 0, unix.IPPROTO_UDP: return udp.ProtocolNumber, true, nil - case syscall.IPPROTO_ICMP: + case unix.IPPROTO_ICMP: return header.ICMPv4ProtocolNumber, true, nil - case syscall.IPPROTO_ICMPV6: + case unix.IPPROTO_ICMPV6: return header.ICMPv6ProtocolNumber, true, nil } @@ -71,18 +70,18 @@ func getTransportProtocol(ctx context.Context, stype linux.SockType, protocol in } switch protocol { - case syscall.IPPROTO_ICMP: + case unix.IPPROTO_ICMP: return header.ICMPv4ProtocolNumber, true, nil - case syscall.IPPROTO_ICMPV6: + case unix.IPPROTO_ICMPV6: return header.ICMPv6ProtocolNumber, true, nil - case syscall.IPPROTO_UDP: + case unix.IPPROTO_UDP: return header.UDPProtocolNumber, true, nil - case syscall.IPPROTO_TCP: + case unix.IPPROTO_TCP: return header.TCPProtocolNumber, true, nil // IPPROTO_RAW signifies that the raw socket isn't assigned to // a transport protocol. Users will be able to write packets' // IP headers and won't receive anything. - case syscall.IPPROTO_RAW: + case unix.IPPROTO_RAW: return tcpip.TransportProtocolNumber(0), false, nil } } |