Skip to content

Commit 079c1a9

Browse files
committed
Merge pull request #9551 from amysaq2023:support-external-stack
PiperOrigin-RevId: 677933413
2 parents 48b7308 + 56f2530 commit 079c1a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2811
-8
lines changed

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ test:race --@io_bazel_rules_go//go/config:race --@io_bazel_rules_go//go/config:p
2929
build --@io_bazel_rules_go//go/config:pure
3030
test --@io_bazel_rules_go//go/config:pure
3131

32+
# Set bazel_rule as non-pure when cgo is used.
33+
build:plugin-tldk --@io_bazel_rules_go//go/config:pure=false --define=plugin_tldk=true --define=network_plugins=true
34+
3235
# By default, exclude nogo targets from building. They will still be included
3336
# by default for all tests.
3437
build --build_tag_filters=-nogo

.buildkite/pipeline.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ steps:
8787
label: ":world_map: Build runsc and pkg (AMD64)"
8888
commands:
8989
- "make build TARGETS=//pkg/..."
90-
- "make build TARGETS=//runsc/..."
90+
- "make build TARGETS='--build_tag_filters=-network_plugins //runsc/...'"
9191
agents:
9292
arch: "amd64"
9393

@@ -96,7 +96,7 @@ steps:
9696
label: ":world_map: Build runsc and pkg (ARM64)"
9797
commands:
9898
- "make build TARGETS=//pkg/..."
99-
- "make build TARGETS=//runsc/..."
99+
- "make build TARGETS='--build_tag_filters=-network_plugins //runsc/...'"
100100
agents:
101101
arch: "arm64"
102102

@@ -105,7 +105,7 @@ steps:
105105
<<: *source_test_continuous
106106
label: ":world_map: Build everything"
107107
commands:
108-
- "make build TARGETS=//..."
108+
- "make build TARGETS='--build_tag_filters=-network_plugins //...'"
109109

110110
# Check that the Go branch builds. This is not technically required, as this build is maintained
111111
# as a GitHub action in order to preserve this maintaince across forks. However, providing the

BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ go_path(
139139

140140
# Packages that are not dependencies of the above.
141141
"//pkg/sentry/kernel/memevent",
142+
"//pkg/sentry/socket/plugin/stack",
142143
"//pkg/tcpip/adapters/gonet",
143144
"//pkg/tcpip/faketime",
144145
"//pkg/tcpip/link/channel",

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ nogo-tests:
221221
#
222222
# FIXME(gvisor.dev/issue/10045): Need to fix broken tests.
223223
unit-tests: ## Local package unit tests in pkg/..., tools/.., etc.
224-
@$(call test,--test_tag_filters=-nogo$(COMMA)-requires-kvm -- //:all pkg/... tools/... runsc/... vdso/... test/trace/... -//pkg/metric:metric_test -//pkg/coretag:coretag_test -//runsc/config:config_test -//tools/tracereplay:tracereplay_test -//test/trace:trace_test)
224+
@$(call test,--test_tag_filters=-nogo$(COMMA)-requires-kvm --build_tag_filters=-network_plugins -- //:all pkg/... tools/... runsc/... vdso/... test/trace/... -//pkg/metric:metric_test -//pkg/coretag:coretag_test -//runsc/config:config_test -//tools/tracereplay:tracereplay_test -//test/trace:trace_test)
225225
.PHONY: unit-tests
226226

227227
# See unit-tests: this includes runsc/container.

WORKSPACE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ http_archive(
5252
# Allow for patching of the go_sdk.
5353
"//tools:rules_go_sdk.patch",
5454
"//tools:rules_go_facts.patch",
55+
"//tools:rules_cgo.patch",
5556
],
5657
sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
5758
urls = [
@@ -3351,3 +3352,9 @@ go_repository(
33513352
sum = "h1:uImZAk6qLkC6F9ju6mZ5SPBqTyK8xjZKwSmwnCg4bxg=",
33523353
version = "v2.3.3",
33533354
)
3355+
3356+
new_local_repository(
3357+
name = "libpluginstack",
3358+
path = "tools/plugin-stack",
3359+
build_file = "tools/plugin-stack/plugin-stack.BUILD",
3360+
)

pkg/abi/linux/netdevice.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ type IFConf struct {
8585
Ptr uint64
8686
}
8787

88+
// SizeOfIFConf is the binary size of an IFConf struct (16 bytes).
89+
var SizeOfIFConf = (*IFConf)(nil).SizeBytes()
90+
8891
// EthtoolCmd is a marshallable type to be able to easily copyin the
8992
// the command for an SIOCETHTOOL ioctl.
9093
//

pkg/sentry/socket/plugin/BUILD

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
load("//tools:defs.bzl", "go_library")
2+
3+
package(
4+
default_applicable_licenses = ["//:license"],
5+
licenses = ["notice"],
6+
)
7+
8+
go_library(
9+
name = "plugin",
10+
srcs = [
11+
"config.go",
12+
"plugin.go",
13+
],
14+
visibility = ["//visibility:public"],
15+
deps = [
16+
"//pkg/seccomp",
17+
"//pkg/sentry/inet",
18+
"//pkg/waiter",
19+
"@org_golang_x_sys//unix:go_default_library",
20+
],
21+
)

pkg/sentry/socket/plugin/cgo/BUILD

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
load("//tools:defs.bzl", "go_library")
2+
3+
package(
4+
default_applicable_licenses = ["//:license"],
5+
licenses = ["notice"],
6+
)
7+
8+
config_setting(
9+
name = "network_plugins",
10+
values = {"define": "network_plugins=true"},
11+
)
12+
13+
go_library(
14+
name = "cgo",
15+
srcs = [
16+
"cgo.go",
17+
"nocgo_stub_unsafe.go",
18+
"socket_unsafe.go",
19+
"stack_unsafe.go",
20+
"util_unsafe.go",
21+
],
22+
bazel_cdeps = [
23+
"@libpluginstack//:libpluginstack",
24+
],
25+
bazel_cgo = select({
26+
":network_plugins": True,
27+
"//conditions:default": False,
28+
}),
29+
bazel_clinkopts = [
30+
"-L external/libpluginstack",
31+
],
32+
bazel_copts = [
33+
"-march=native",
34+
"-I external/libpluginstack/lib/libtle_glue",
35+
],
36+
visibility = ["//visibility:public"],
37+
deps = [
38+
"//pkg/abi/linux",
39+
"//pkg/abi/linux/errno",
40+
],
41+
)

pkg/sentry/socket/plugin/cgo/cgo.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2024 The gVisor Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package cgo provides interfaces definition to interact with third-party
16+
// network stack. It also implements CGO wrappers to handle Golang arguments
17+
// to CGO and CGO return values to Golang.
18+
//
19+
// Third-party external network stack will implement interfaces defined in this
20+
// package in order to be used by gVisor.
21+
package cgo
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
// Copyright 2024 The gVisor Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build !network_plugins
16+
// +build !network_plugins
17+
18+
package cgo
19+
20+
import (
21+
"syscall"
22+
"unsafe"
23+
)
24+
25+
// GetPtr is a non-cgo stub function.
26+
func GetPtr(bs []byte) unsafe.Pointer {
27+
panic("unimplemented")
28+
}
29+
30+
// EpollCreate is a non-cgo stub function.
31+
func EpollCreate() int {
32+
panic("unimplemented")
33+
}
34+
35+
// EpollCtl is a non-cgo stub function.
36+
func EpollCtl(epfd int32, op int, handle, events uint32) {
37+
panic("unimplemented")
38+
}
39+
40+
// EpollWait is a non-cgo stub function.
41+
func EpollWait(epfd int32, events []syscall.EpollEvent, n int, us int) int {
42+
panic("unimplemented")
43+
}
44+
45+
// Socket is a non-cgo stub function.
46+
func Socket(domain, skType, protocol int) int64 {
47+
panic("unimplemented")
48+
}
49+
50+
// Bind is a non-cgo stub function.
51+
func Bind(handle uint32, sa []byte) int64 {
52+
panic("unimplemented")
53+
}
54+
55+
// Listen is a non-cgo stub function.
56+
func Listen(handle uint32, backlog int) int64 {
57+
panic("unimplemented")
58+
}
59+
60+
// Accept is a non-cgo stub function.
61+
func Accept(handle uint32, addrPtr *byte, lenPtr *uint32) int64 {
62+
panic("unimplemented")
63+
}
64+
65+
// Ioctl is a non-cgo stub function.
66+
func Ioctl(handle uint32, cmd uint32, buf []byte) int64 {
67+
panic("unimplemented")
68+
}
69+
70+
// Connect is a non-cgo stub function.
71+
func Connect(handle uint32, addr []byte) int64 {
72+
panic("unimplemented")
73+
}
74+
75+
// Getsockopt is a non-cgo stub function.
76+
func Getsockopt(handle uint32, l int, n int, val []byte, s int) (int64, int) {
77+
panic("unimplemented")
78+
}
79+
80+
// Setsockopt is a non-cgo stub function.
81+
func Setsockopt(handle uint32, l int, n int, val []byte) int64 {
82+
panic("unimplemented")
83+
}
84+
85+
// Shutdown is a non-cgo stub function.
86+
func Shutdown(handle uint32, how int) int64 {
87+
panic("unimplemented")
88+
}
89+
90+
// Close is a non-cgo stub function.
91+
func Close(handle uint32) {
92+
panic("unimplemented")
93+
}
94+
95+
// Getsockname is a non-cgo stub function.
96+
func Getsockname(handle uint32, addr []byte, addrlen *uint32) int64 {
97+
panic("unimplemented")
98+
}
99+
100+
// GetPeername is a non-cgo stub function.
101+
func GetPeername(handle uint32, addr []byte, addrlen *uint32) int64 {
102+
panic("unimplemented")
103+
}
104+
105+
// Readiness is a non-cgo stub function.
106+
func Readiness(handle uint32, mask uint64) int64 {
107+
panic("unimplemented")
108+
}
109+
110+
// Read is a non-cgo stub function.
111+
func Read(handle uint32, buf uintptr, count int) int64 {
112+
panic("unimplemented")
113+
}
114+
115+
// Readv is a non-cgo stub function.
116+
func Readv(handle uint32, iovs []syscall.Iovec) int64 {
117+
panic("unimplemented")
118+
}
119+
120+
// Recvfrom is a non-cgo stub function.
121+
func Recvfrom(handle uint32, buf, addr []byte, flags int) (int64, int) {
122+
panic("unimplemented")
123+
}
124+
125+
// Recvmsg is a non-cgo stub function.
126+
func Recvmsg(handle uint32, iovs []syscall.Iovec, addr, control []byte, flags int) (int64, int, int, int) {
127+
panic("unimplemented")
128+
}
129+
130+
// Write is a non-cgo stub function.
131+
func Write(handle uint32, buf uintptr, count int) int64 {
132+
panic("unimplemented")
133+
}
134+
135+
// Writev is a non-cgo stub function.
136+
func Writev(handle uint32, iovs []syscall.Iovec) int64 {
137+
panic("unimplemented")
138+
}
139+
140+
// Sendto is a non-cgo stub function.
141+
func Sendto(handle uint32, buf uintptr, count int, flags int, addr []byte) int64 {
142+
panic("unimplemented")
143+
}
144+
145+
// Sendmsg is a non-cgo stub function.
146+
func Sendmsg(handle uint32, iovs []syscall.Iovec, addr []byte, flags int) int64 {
147+
panic("unimplemented")
148+
}
149+
150+
// InitStack is a non-cgo stub function.
151+
func InitStack(initStr string, fds []int) error {
152+
panic("unimplemented")
153+
}
154+
155+
// PreInitStack is a non-cgo stub function.
156+
func PreInitStack(pid int) (string, []int, error) {
157+
panic("unimplemented")
158+
}

0 commit comments

Comments
 (0)