diff options
Diffstat (limited to 'pkg/sentry/socket/control')
-rw-r--r-- | pkg/sentry/socket/control/BUILD | 42 | ||||
-rw-r--r-- | pkg/sentry/socket/control/control_state_autogen.go | 60 | ||||
-rw-r--r-- | pkg/sentry/socket/control/control_test.go | 59 |
3 files changed, 60 insertions, 101 deletions
diff --git a/pkg/sentry/socket/control/BUILD b/pkg/sentry/socket/control/BUILD deleted file mode 100644 index 0e0e82365..000000000 --- a/pkg/sentry/socket/control/BUILD +++ /dev/null @@ -1,42 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "control", - srcs = [ - "control.go", - "control_vfs2.go", - ], - imports = [ - "gvisor.dev/gvisor/pkg/sentry/fs", - ], - visibility = ["//pkg/sentry:internal"], - deps = [ - "//pkg/abi/linux", - "//pkg/binary", - "//pkg/context", - "//pkg/hostarch", - "//pkg/sentry/fs", - "//pkg/sentry/kernel", - "//pkg/sentry/kernel/auth", - "//pkg/sentry/socket", - "//pkg/sentry/socket/unix/transport", - "//pkg/sentry/vfs", - "//pkg/syserror", - ], -) - -go_test( - name = "control_test", - size = "small", - srcs = ["control_test.go"], - library = ":control", - deps = [ - "//pkg/abi/linux", - "//pkg/binary", - "//pkg/hostarch", - "//pkg/sentry/socket", - "@com_github_google_go_cmp//cmp:go_default_library", - ], -) diff --git a/pkg/sentry/socket/control/control_state_autogen.go b/pkg/sentry/socket/control/control_state_autogen.go new file mode 100644 index 000000000..412025601 --- /dev/null +++ b/pkg/sentry/socket/control/control_state_autogen.go @@ -0,0 +1,60 @@ +// automatically generated by stateify. + +package control + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (fs *RightsFiles) StateTypeName() string { + return "pkg/sentry/socket/control.RightsFiles" +} + +func (fs *RightsFiles) StateFields() []string { + return nil +} + +func (c *scmCredentials) StateTypeName() string { + return "pkg/sentry/socket/control.scmCredentials" +} + +func (c *scmCredentials) StateFields() []string { + return []string{ + "t", + "kuid", + "kgid", + } +} + +func (c *scmCredentials) beforeSave() {} + +// +checklocksignore +func (c *scmCredentials) StateSave(stateSinkObject state.Sink) { + c.beforeSave() + stateSinkObject.Save(0, &c.t) + stateSinkObject.Save(1, &c.kuid) + stateSinkObject.Save(2, &c.kgid) +} + +func (c *scmCredentials) afterLoad() {} + +// +checklocksignore +func (c *scmCredentials) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &c.t) + stateSourceObject.Load(1, &c.kuid) + stateSourceObject.Load(2, &c.kgid) +} + +func (fs *RightsFilesVFS2) StateTypeName() string { + return "pkg/sentry/socket/control.RightsFilesVFS2" +} + +func (fs *RightsFilesVFS2) StateFields() []string { + return nil +} + +func init() { + state.Register((*RightsFiles)(nil)) + state.Register((*scmCredentials)(nil)) + state.Register((*RightsFilesVFS2)(nil)) +} diff --git a/pkg/sentry/socket/control/control_test.go b/pkg/sentry/socket/control/control_test.go deleted file mode 100644 index 7e28a0cef..000000000 --- a/pkg/sentry/socket/control/control_test.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2020 The gVisor Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package control provides internal representations of socket control -// messages. -package control - -import ( - "testing" - - "github.com/google/go-cmp/cmp" - "gvisor.dev/gvisor/pkg/abi/linux" - "gvisor.dev/gvisor/pkg/binary" - "gvisor.dev/gvisor/pkg/hostarch" - "gvisor.dev/gvisor/pkg/sentry/socket" -) - -func TestParse(t *testing.T) { - // Craft the control message to parse. - length := linux.SizeOfControlMessageHeader + linux.SizeOfTimeval - hdr := linux.ControlMessageHeader{ - Length: uint64(length), - Level: linux.SOL_SOCKET, - Type: linux.SO_TIMESTAMP, - } - buf := make([]byte, 0, length) - buf = binary.Marshal(buf, hostarch.ByteOrder, &hdr) - ts := linux.Timeval{ - Sec: 2401, - Usec: 343, - } - buf = binary.Marshal(buf, hostarch.ByteOrder, &ts) - - cmsg, err := Parse(nil, nil, buf, 8 /* width */) - if err != nil { - t.Fatalf("Parse(_, _, %+v, _): %v", cmsg, err) - } - - want := socket.ControlMessages{ - IP: socket.IPControlMessages{ - HasTimestamp: true, - Timestamp: ts.ToNsecCapped(), - }, - } - if diff := cmp.Diff(want, cmsg); diff != "" { - t.Errorf("unexpected message parsed, (-want, +got):\n%s", diff) - } -} |