diff --git a/pkg/lisafs/client_file.go b/pkg/lisafs/client_file.go index 596d85afa..226a22390 100644 --- a/pkg/lisafs/client_file.go +++ b/pkg/lisafs/client_file.go @@ -573,7 +573,8 @@ func (f *ClientFD) RemoveXattr(ctx context.Context, name string) error { return err } -// ClientBoundSocketFD corresponds to a bound socket on the server. +// ClientBoundSocketFD corresponds to a bound socket on the server. It +// implements transport.BoundSocketFD. // // All fields are immutable. type ClientBoundSocketFD struct { @@ -587,19 +588,18 @@ type ClientBoundSocketFD struct { client *Client } -// Close closes the host and gofer-backed FDs associated to this bound socket. +// Close implements transport.BoundSocketFD.Close. func (f *ClientBoundSocketFD) Close(ctx context.Context) { _ = unix.Close(int(f.notificationFD)) f.client.CloseFD(ctx, f.fd, true /* flush */) } -// NotificationFD is a host FD that can be used to notify when new clients -// connect to the socket. +// NotificationFD implements transport.BoundSocketFD.NotificationFD. func (f *ClientBoundSocketFD) NotificationFD() int32 { return f.notificationFD } -// Listen makes a Listen RPC. +// Listen implements transport.BoundSocketFD.Listen. func (f *ClientBoundSocketFD) Listen(ctx context.Context, backlog int32) error { req := ListenReq{ FD: f.fd, @@ -612,7 +612,7 @@ func (f *ClientBoundSocketFD) Listen(ctx context.Context, backlog int32) error { return err } -// Accept makes an Accept RPC. +// Accept implements transport.BoundSocketFD.Accept. func (f *ClientBoundSocketFD) Accept(ctx context.Context) (int, error) { req := AcceptReq{ FD: f.fd, diff --git a/pkg/sentry/socket/unix/transport/BUILD b/pkg/sentry/socket/unix/transport/BUILD index c1319d0e3..b2f6d79e8 100644 --- a/pkg/sentry/socket/unix/transport/BUILD +++ b/pkg/sentry/socket/unix/transport/BUILD @@ -99,7 +99,6 @@ go_library( "//pkg/errors/linuxerr", "//pkg/fdnotifier", "//pkg/ilist", - "//pkg/lisafs", "//pkg/log", "//pkg/refs", "//pkg/refsvfs2", diff --git a/pkg/sentry/socket/unix/transport/connectioned.go b/pkg/sentry/socket/unix/transport/connectioned.go index ca8c7a61e..8807ae782 100644 --- a/pkg/sentry/socket/unix/transport/connectioned.go +++ b/pkg/sentry/socket/unix/transport/connectioned.go @@ -21,7 +21,6 @@ import ( "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/context" "gvisor.dev/gvisor/pkg/fdnotifier" - "gvisor.dev/gvisor/pkg/lisafs" "gvisor.dev/gvisor/pkg/sentry/uniqueid" "gvisor.dev/gvisor/pkg/syserr" "gvisor.dev/gvisor/pkg/tcpip" @@ -120,7 +119,7 @@ type connectionedEndpoint struct { // that may listen and accept incoming connections. // // boundSocketFD is protected by baseEndpoint.mu. - boundSocketFD *lisafs.ClientBoundSocketFD + boundSocketFD BoundSocketFD } var ( @@ -604,7 +603,7 @@ func (e *connectionedEndpoint) OnSetSendBufferSize(v int64) (newSz int64) { func (e *connectionedEndpoint) WakeupWriters() {} // SetBoundSocketFD implement HostBountEndpoint.SetBoundSocketFD. -func (e *connectionedEndpoint) SetBoundSocketFD(bsFD *lisafs.ClientBoundSocketFD) { +func (e *connectionedEndpoint) SetBoundSocketFD(bsFD BoundSocketFD) { e.Lock() defer e.Unlock() if e.boundSocketFD != nil { diff --git a/pkg/sentry/socket/unix/transport/unix.go b/pkg/sentry/socket/unix/transport/unix.go index cb22e7b1d..d6fd6b09e 100644 --- a/pkg/sentry/socket/unix/transport/unix.go +++ b/pkg/sentry/socket/unix/transport/unix.go @@ -18,7 +18,6 @@ package transport import ( "gvisor.dev/gvisor/pkg/abi/linux" "gvisor.dev/gvisor/pkg/context" - "gvisor.dev/gvisor/pkg/lisafs" "gvisor.dev/gvisor/pkg/log" "gvisor.dev/gvisor/pkg/syserr" "gvisor.dev/gvisor/pkg/tcpip" @@ -269,9 +268,26 @@ type BoundEndpoint interface { // on the host. type HostBoundEndpoint interface { // SetBoundSocketFD will be called on supporting endpoints after - // binding a socket on the host filesystem. Implementations should use - // delegate Listen and Accept calls to the ClientBoundSocketFD. - SetBoundSocketFD(*lisafs.ClientBoundSocketFD) + // binding a socket on the host filesystem. Implementations should + // delegate Listen and Accept calls to the BoundSocketFD. + SetBoundSocketFD(bsFD BoundSocketFD) +} + +// BoundSocketFD is an interface that wraps a socket FD that was bind(2)-ed. +// It allows to listen and accept on that socket. +type BoundSocketFD interface { + // Close closes the socket FD. + Close(ctx context.Context) + + // NotificationFD is a host FD that can be used to notify when new clients + // connect to the socket. + NotificationFD() int32 + + // Listen is analogous to listen(2). + Listen(ctx context.Context, backlog int32) error + + // Accept is analogous to accept(2). + Accept(ctx context.Context) (int, error) } // message represents a message passed over a Unix domain socket.