diff options
Diffstat (limited to 'pkg/tcpip/link/muxed')
-rw-r--r-- | pkg/tcpip/link/muxed/injectable.go | 12 | ||||
-rw-r--r-- | pkg/tcpip/link/muxed/injectable_test.go | 16 |
2 files changed, 27 insertions, 1 deletions
diff --git a/pkg/tcpip/link/muxed/injectable.go b/pkg/tcpip/link/muxed/injectable.go index 9d85bda60..29073afae 100644 --- a/pkg/tcpip/link/muxed/injectable.go +++ b/pkg/tcpip/link/muxed/injectable.go @@ -94,7 +94,17 @@ func (m *InjectableEndpoint) WritePacket(r *stack.Route, hdr buffer.Prependable, return tcpip.ErrNoRoute } -// NewInjectableEndpoint creates a new multi-fd-based injectable endpoint. +// WriteRawPacket writes outbound packets to the appropriate +// LinkInjectableEndpoint based on the dest address. +func (m *InjectableEndpoint) WriteRawPacket(dest tcpip.Address, packet []byte) *tcpip.Error { + endpoint, ok := m.routes[dest] + if !ok { + return tcpip.ErrNoRoute + } + return endpoint.WriteRawPacket(dest, packet) +} + +// NewInjectableEndpoint creates a new multi-endpoint injectable endpoint. func NewInjectableEndpoint(routes map[tcpip.Address]stack.InjectableLinkEndpoint, mtu uint32) (tcpip.LinkEndpointID, *InjectableEndpoint) { e := &InjectableEndpoint{ routes: routes, diff --git a/pkg/tcpip/link/muxed/injectable_test.go b/pkg/tcpip/link/muxed/injectable_test.go index 65db14b5d..d1d2875cc 100644 --- a/pkg/tcpip/link/muxed/injectable_test.go +++ b/pkg/tcpip/link/muxed/injectable_test.go @@ -28,8 +28,24 @@ import ( "gvisor.googlesource.com/gvisor/pkg/tcpip/stack" ) +func TestInjectableEndpointRawDispatch(t *testing.T) { + endpoint, sock, dstIP := makeTestInjectableEndpoint(t) + + endpoint.WriteRawPacket(dstIP, []byte{0xFA}) + + buf := make([]byte, ipv4.MaxTotalSize) + bytesRead, err := sock.Read(buf) + if err != nil { + t.Fatalf("Unable to read from socketpair: %v", err) + } + if got, want := buf[:bytesRead], []byte{0xFA}; !bytes.Equal(got, want) { + t.Fatalf("Read %v from the socketpair, wanted %v", got, want) + } +} + func TestInjectableEndpointDispatch(t *testing.T) { endpoint, sock, dstIP := makeTestInjectableEndpoint(t) + hdr := buffer.NewPrependable(1) hdr.Prepend(1)[0] = 0xFA packetRoute := stack.Route{RemoteAddress: dstIP} |