mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
tcpip: ensure fdbased/mmap_stub.go uses a stateify-recognized suffix
Our Bazel build infrastructure explicitly recognizes some suffixes that can
appear at the end of filenames (tools/bazeldefs/tags.bzl). It uses these tags
to group files passed to go_stateify (tools/defs.bzl:go_library() =>
calculate_sets()).
Each invocation of go_stateify infers build tags from its input files. Before
this CL, all Go files in pkg/tcpip/link/fdbased (except for fdbased_unsafe.go)
are grouped together to generate fdbased_state_autogen.go, so go_stateify
infers builds tags "!linux !amd64,!arm64" (from mmap_stub.go) and "linux ..."
(from most other files); these contradictory build tags mean that
fdbased_state_autogen.go is never actually compiled, preventing its types from
being registered. After this CL, mmap_nonlinux.go independently generates
fdbased_nonlinux_state_autogen.go.
Fixing this causes fdbased_state_autogen.go to be included for the first time,
exposing a second problem:
```
pkg/tcpip/link/fdbased/endpoint_test.go:80:6: context already declared through import of package context ("context")
.../pkg/tcpip/link/fdbased/fdbased_state_autogen.go:12:2: other declaration of context
```
(Apparently Go imports are a pessimal hybrid of "shared between files in a
package" and "not shared between files in a package".) To fix this, rename the
test type to testContext.
PiperOrigin-RevId: 663522480
This commit is contained in:
@@ -11,7 +11,7 @@ go_library(
|
||||
"endpoint.go",
|
||||
"endpoint_unsafe.go",
|
||||
"mmap.go",
|
||||
"mmap_stub.go",
|
||||
"mmap_nonlinux.go",
|
||||
"mmap_unsafe.go",
|
||||
"packet_dispatchers.go",
|
||||
"processors.go",
|
||||
|
||||
@@ -77,7 +77,7 @@ func checkPacketInfoEqual(t *testing.T, got, want packetInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
type context struct {
|
||||
type testContext struct {
|
||||
t *testing.T
|
||||
readFDs []int
|
||||
writeFDs []int
|
||||
@@ -86,7 +86,7 @@ type context struct {
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func newContext(t *testing.T, opt *Options) *context {
|
||||
func newContext(t *testing.T, opt *Options) *testContext {
|
||||
firstFDPair, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_SEQPACKET, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Socketpair failed: %v", err)
|
||||
@@ -107,7 +107,7 @@ func newContext(t *testing.T, opt *Options) *context {
|
||||
t.Fatalf("Failed to create FD endpoint: %v", err)
|
||||
}
|
||||
|
||||
c := &context{
|
||||
c := &testContext{
|
||||
t: t,
|
||||
readFDs: []int{firstFDPair[0], secondFDPair[0]},
|
||||
writeFDs: opt.FDs,
|
||||
@@ -121,7 +121,7 @@ func newContext(t *testing.T, opt *Options) *context {
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *context) cleanup() {
|
||||
func (c *testContext) cleanup() {
|
||||
for _, fd := range c.readFDs {
|
||||
unix.Close(fd)
|
||||
}
|
||||
@@ -132,12 +132,12 @@ func (c *context) cleanup() {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *context) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
|
||||
func (c *testContext) DeliverNetworkPacket(protocol tcpip.NetworkProtocolNumber, pkt *stack.PacketBuffer) {
|
||||
pkt.IncRef()
|
||||
c.ch <- packetInfo{protocol, pkt}
|
||||
}
|
||||
|
||||
func (c *context) DeliverLinkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
|
||||
func (c *testContext) DeliverLinkPacket(tcpip.NetworkProtocolNumber, *stack.PacketBuffer) {
|
||||
c.t.Fatal("DeliverLinkPacket not implemented")
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ archs = [
|
||||
|
||||
oses = [
|
||||
"_linux",
|
||||
"_nonlinux",
|
||||
]
|
||||
|
||||
generic = [
|
||||
|
||||
Reference in New Issue
Block a user