summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/socket
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-11-13 07:00:09 +0000
committergVisor bot <gvisor-bot@google.com>2020-11-13 07:00:09 +0000
commitf560fd07ef27eef3027f03e93e2c958375d60dd7 (patch)
tree38c9c19a5948edaa06ab43454fb38a96d9f9531d /pkg/sentry/socket
parentf942d232b2c93d40a7af7007a8490c51d663e7f5 (diff)
parent5bb64ce1b8c42fcd96e44a5be05e17f34a83f840 (diff)
Merge release-20201030.0-83-g5bb64ce1b (automated)
Diffstat (limited to 'pkg/sentry/socket')
-rw-r--r--pkg/sentry/socket/netstack/netstack.go15
-rw-r--r--pkg/sentry/socket/unix/transport/transport_state_autogen.go3
-rw-r--r--pkg/sentry/socket/unix/transport/unix.go11
-rw-r--r--pkg/sentry/socket/unix/unix.go3
-rw-r--r--pkg/sentry/socket/unix/unix_state_autogen.go3
5 files changed, 26 insertions, 9 deletions
diff --git a/pkg/sentry/socket/netstack/netstack.go b/pkg/sentry/socket/netstack/netstack.go
index 86c634715..7d0ae15ca 100644
--- a/pkg/sentry/socket/netstack/netstack.go
+++ b/pkg/sentry/socket/netstack/netstack.go
@@ -262,6 +262,9 @@ type commonEndpoint interface {
// LastError implements tcpip.Endpoint.LastError.
LastError() *tcpip.Error
+
+ // SocketOptions implements tcpip.Endpoint.SocketOptions.
+ SocketOptions() *tcpip.SocketOptions
}
// LINT.IfChange
@@ -1163,13 +1166,8 @@ func getSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, fam
return nil, syserr.ErrInvalidArgument
}
- v, err := ep.GetSockOptBool(tcpip.BroadcastOption)
- if err != nil {
- return nil, syserr.TranslateNetstackError(err)
- }
-
- vP := primitive.Int32(boolToInt32(v))
- return &vP, nil
+ v := primitive.Int32(boolToInt32(ep.SocketOptions().GetBroadcast()))
+ return &v, nil
case linux.SO_KEEPALIVE:
if outLen < sizeOfInt32 {
@@ -1916,7 +1914,8 @@ func setSockOptSocket(t *kernel.Task, s socket.SocketOps, ep commonEndpoint, nam
}
v := usermem.ByteOrder.Uint32(optVal)
- return syserr.TranslateNetstackError(ep.SetSockOptBool(tcpip.BroadcastOption, v != 0))
+ ep.SocketOptions().SetBroadcast(v != 0)
+ return nil
case linux.SO_PASSCRED:
if len(optVal) < sizeOfInt32 {
diff --git a/pkg/sentry/socket/unix/transport/transport_state_autogen.go b/pkg/sentry/socket/unix/transport/transport_state_autogen.go
index 4ec849a7f..e20168bb3 100644
--- a/pkg/sentry/socket/unix/transport/transport_state_autogen.go
+++ b/pkg/sentry/socket/unix/transport/transport_state_autogen.go
@@ -334,6 +334,7 @@ func (e *baseEndpoint) StateFields() []string {
"connected",
"path",
"linger",
+ "ops",
}
}
@@ -347,6 +348,7 @@ func (e *baseEndpoint) StateSave(stateSinkObject state.Sink) {
stateSinkObject.Save(3, &e.connected)
stateSinkObject.Save(4, &e.path)
stateSinkObject.Save(5, &e.linger)
+ stateSinkObject.Save(6, &e.ops)
}
func (e *baseEndpoint) afterLoad() {}
@@ -358,6 +360,7 @@ func (e *baseEndpoint) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(3, &e.connected)
stateSourceObject.Load(4, &e.path)
stateSourceObject.Load(5, &e.linger)
+ stateSourceObject.Load(6, &e.ops)
}
func init() {
diff --git a/pkg/sentry/socket/unix/transport/unix.go b/pkg/sentry/socket/unix/transport/unix.go
index b648273a4..18a50e9f8 100644
--- a/pkg/sentry/socket/unix/transport/unix.go
+++ b/pkg/sentry/socket/unix/transport/unix.go
@@ -205,6 +205,9 @@ type Endpoint interface {
// LastError implements tcpip.Endpoint.LastError.
LastError() *tcpip.Error
+
+ // SocketOptions implements tcpip.Endpoint.SocketOptions.
+ SocketOptions() *tcpip.SocketOptions
}
// A Credentialer is a socket or endpoint that supports the SO_PASSCRED socket
@@ -757,6 +760,8 @@ type baseEndpoint struct {
// linger is used for SO_LINGER socket option.
linger tcpip.LingerOption
+
+ ops tcpip.SocketOptions
}
// EventRegister implements waiter.Waitable.EventRegister.
@@ -865,7 +870,6 @@ func (e *baseEndpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error {
func (e *baseEndpoint) SetSockOptBool(opt tcpip.SockOptBool, v bool) *tcpip.Error {
switch opt {
- case tcpip.BroadcastOption:
case tcpip.PasscredOption:
e.setPasscred(v)
case tcpip.ReuseAddressOption:
@@ -980,6 +984,11 @@ func (*baseEndpoint) LastError() *tcpip.Error {
return nil
}
+// SocketOptions implements Endpoint.SocketOptions.
+func (e *baseEndpoint) SocketOptions() *tcpip.SocketOptions {
+ return &e.ops
+}
+
// Shutdown closes the read and/or write end of the endpoint connection to its
// peer.
func (e *baseEndpoint) Shutdown(flags tcpip.ShutdownFlags) *syserr.Error {
diff --git a/pkg/sentry/socket/unix/unix.go b/pkg/sentry/socket/unix/unix.go
index b32bb7ba8..3e520d2ee 100644
--- a/pkg/sentry/socket/unix/unix.go
+++ b/pkg/sentry/socket/unix/unix.go
@@ -115,6 +115,9 @@ type socketOpsCommon struct {
// bound, they cannot be modified.
abstractName string
abstractNamespace *kernel.AbstractSocketNamespace
+
+ // ops is used to get socket level options.
+ ops tcpip.SocketOptions
}
func (s *socketOpsCommon) isPacket() bool {
diff --git a/pkg/sentry/socket/unix/unix_state_autogen.go b/pkg/sentry/socket/unix/unix_state_autogen.go
index fba990d9a..9e9055b79 100644
--- a/pkg/sentry/socket/unix/unix_state_autogen.go
+++ b/pkg/sentry/socket/unix/unix_state_autogen.go
@@ -87,6 +87,7 @@ func (s *socketOpsCommon) StateFields() []string {
"stype",
"abstractName",
"abstractNamespace",
+ "ops",
}
}
@@ -99,6 +100,7 @@ func (s *socketOpsCommon) StateSave(stateSinkObject state.Sink) {
stateSinkObject.Save(2, &s.stype)
stateSinkObject.Save(3, &s.abstractName)
stateSinkObject.Save(4, &s.abstractNamespace)
+ stateSinkObject.Save(5, &s.ops)
}
func (s *socketOpsCommon) afterLoad() {}
@@ -109,6 +111,7 @@ func (s *socketOpsCommon) StateLoad(stateSourceObject state.Source) {
stateSourceObject.Load(2, &s.stype)
stateSourceObject.Load(3, &s.abstractName)
stateSourceObject.Load(4, &s.abstractNamespace)
+ stateSourceObject.Load(5, &s.ops)
}
func (s *SocketVFS2) StateTypeName() string {