summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/muxed
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/link/muxed')
-rw-r--r--pkg/tcpip/link/muxed/BUILD30
-rw-r--r--pkg/tcpip/link/muxed/injectable.go137
-rw-r--r--pkg/tcpip/link/muxed/injectable_test.go98
3 files changed, 0 insertions, 265 deletions
diff --git a/pkg/tcpip/link/muxed/BUILD b/pkg/tcpip/link/muxed/BUILD
deleted file mode 100644
index 1ac7948b6..000000000
--- a/pkg/tcpip/link/muxed/BUILD
+++ /dev/null
@@ -1,30 +0,0 @@
-load("//tools/go_stateify:defs.bzl", "go_library")
-load("@io_bazel_rules_go//go:def.bzl", "go_test")
-
-package(licenses = ["notice"])
-
-go_library(
- name = "muxed",
- srcs = ["injectable.go"],
- importpath = "gvisor.dev/gvisor/pkg/tcpip/link/muxed",
- visibility = ["//visibility:public"],
- deps = [
- "//pkg/tcpip",
- "//pkg/tcpip/buffer",
- "//pkg/tcpip/stack",
- ],
-)
-
-go_test(
- name = "muxed_test",
- size = "small",
- srcs = ["injectable_test.go"],
- embed = [":muxed"],
- deps = [
- "//pkg/tcpip",
- "//pkg/tcpip/buffer",
- "//pkg/tcpip/link/fdbased",
- "//pkg/tcpip/network/ipv4",
- "//pkg/tcpip/stack",
- ],
-)
diff --git a/pkg/tcpip/link/muxed/injectable.go b/pkg/tcpip/link/muxed/injectable.go
deleted file mode 100644
index 445b22c17..000000000
--- a/pkg/tcpip/link/muxed/injectable.go
+++ /dev/null
@@ -1,137 +0,0 @@
-// Copyright 2019 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 muxed provides a muxed link endpoints.
-package muxed
-
-import (
- "gvisor.dev/gvisor/pkg/tcpip"
- "gvisor.dev/gvisor/pkg/tcpip/buffer"
- "gvisor.dev/gvisor/pkg/tcpip/stack"
-)
-
-// InjectableEndpoint is an injectable multi endpoint. The endpoint has
-// trivial routing rules that determine which InjectableEndpoint a given packet
-// will be written to. Note that HandleLocal works differently for this
-// endpoint (see WritePacket).
-type InjectableEndpoint struct {
- routes map[tcpip.Address]stack.InjectableLinkEndpoint
- dispatcher stack.NetworkDispatcher
-}
-
-// MTU implements stack.LinkEndpoint.
-func (m *InjectableEndpoint) MTU() uint32 {
- minMTU := ^uint32(0)
- for _, endpoint := range m.routes {
- if endpointMTU := endpoint.MTU(); endpointMTU < minMTU {
- minMTU = endpointMTU
- }
- }
- return minMTU
-}
-
-// Capabilities implements stack.LinkEndpoint.
-func (m *InjectableEndpoint) Capabilities() stack.LinkEndpointCapabilities {
- minCapabilities := stack.LinkEndpointCapabilities(^uint(0))
- for _, endpoint := range m.routes {
- minCapabilities &= endpoint.Capabilities()
- }
- return minCapabilities
-}
-
-// MaxHeaderLength implements stack.LinkEndpoint.
-func (m *InjectableEndpoint) MaxHeaderLength() uint16 {
- minHeaderLen := ^uint16(0)
- for _, endpoint := range m.routes {
- if headerLen := endpoint.MaxHeaderLength(); headerLen < minHeaderLen {
- minHeaderLen = headerLen
- }
- }
- return minHeaderLen
-}
-
-// LinkAddress implements stack.LinkEndpoint.
-func (m *InjectableEndpoint) LinkAddress() tcpip.LinkAddress {
- return ""
-}
-
-// Attach implements stack.LinkEndpoint.
-func (m *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher) {
- for _, endpoint := range m.routes {
- endpoint.Attach(dispatcher)
- }
- m.dispatcher = dispatcher
-}
-
-// IsAttached implements stack.LinkEndpoint.
-func (m *InjectableEndpoint) IsAttached() bool {
- return m.dispatcher != nil
-}
-
-// InjectInbound implements stack.InjectableLinkEndpoint.
-func (m *InjectableEndpoint) InjectInbound(protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) {
- m.dispatcher.DeliverNetworkPacket(m, "" /* remote */, "" /* local */, protocol, pkt)
-}
-
-// WritePackets writes outbound packets to the appropriate
-// LinkInjectableEndpoint based on the RemoteAddress. HandleLocal only works if
-// r.RemoteAddress has a route registered in this endpoint.
-func (m *InjectableEndpoint) WritePackets(r *stack.Route, gso *stack.GSO, pkts []tcpip.PacketBuffer, protocol tcpip.NetworkProtocolNumber) (int, *tcpip.Error) {
- endpoint, ok := m.routes[r.RemoteAddress]
- if !ok {
- return 0, tcpip.ErrNoRoute
- }
- return endpoint.WritePackets(r, gso, pkts, protocol)
-}
-
-// WritePacket writes outbound packets to the appropriate LinkInjectableEndpoint
-// based on the RemoteAddress. HandleLocal only works if r.RemoteAddress has a
-// route registered in this endpoint.
-func (m *InjectableEndpoint) WritePacket(r *stack.Route, gso *stack.GSO, protocol tcpip.NetworkProtocolNumber, pkt tcpip.PacketBuffer) *tcpip.Error {
- if endpoint, ok := m.routes[r.RemoteAddress]; ok {
- return endpoint.WritePacket(r, gso, protocol, pkt)
- }
- return tcpip.ErrNoRoute
-}
-
-// WriteRawPacket implements stack.LinkEndpoint.WriteRawPacket.
-func (m *InjectableEndpoint) WriteRawPacket(buffer.VectorisedView) *tcpip.Error {
- // WriteRawPacket doesn't get a route or network address, so there's
- // nowhere to write this.
- return tcpip.ErrNoRoute
-}
-
-// InjectOutbound writes outbound packets to the appropriate
-// LinkInjectableEndpoint based on the dest address.
-func (m *InjectableEndpoint) InjectOutbound(dest tcpip.Address, packet []byte) *tcpip.Error {
- endpoint, ok := m.routes[dest]
- if !ok {
- return tcpip.ErrNoRoute
- }
- return endpoint.InjectOutbound(dest, packet)
-}
-
-// Wait implements stack.LinkEndpoint.Wait.
-func (m *InjectableEndpoint) Wait() {
- for _, ep := range m.routes {
- ep.Wait()
- }
-}
-
-// NewInjectableEndpoint creates a new multi-endpoint injectable endpoint.
-func NewInjectableEndpoint(routes map[tcpip.Address]stack.InjectableLinkEndpoint) *InjectableEndpoint {
- return &InjectableEndpoint{
- routes: routes,
- }
-}
diff --git a/pkg/tcpip/link/muxed/injectable_test.go b/pkg/tcpip/link/muxed/injectable_test.go
deleted file mode 100644
index 63b249837..000000000
--- a/pkg/tcpip/link/muxed/injectable_test.go
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2019 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 muxed
-
-import (
- "bytes"
- "net"
- "os"
- "syscall"
- "testing"
-
- "gvisor.dev/gvisor/pkg/tcpip"
- "gvisor.dev/gvisor/pkg/tcpip/buffer"
- "gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
- "gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
- "gvisor.dev/gvisor/pkg/tcpip/stack"
-)
-
-func TestInjectableEndpointRawDispatch(t *testing.T) {
- endpoint, sock, dstIP := makeTestInjectableEndpoint(t)
-
- endpoint.InjectOutbound(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}
-
- endpoint.WritePacket(&packetRoute, nil /* gso */, ipv4.ProtocolNumber, tcpip.PacketBuffer{
- Header: hdr,
- Data: buffer.NewViewFromBytes([]byte{0xFB}).ToVectorisedView(),
- })
-
- buf := make([]byte, 6500)
- bytesRead, err := sock.Read(buf)
- if err != nil {
- t.Fatalf("Unable to read from socketpair: %v", err)
- }
- if got, want := buf[:bytesRead], []byte{0xFA, 0xFB}; !bytes.Equal(got, want) {
- t.Fatalf("Read %v from the socketpair, wanted %v", got, want)
- }
-}
-
-func TestInjectableEndpointDispatchHdrOnly(t *testing.T) {
- endpoint, sock, dstIP := makeTestInjectableEndpoint(t)
- hdr := buffer.NewPrependable(1)
- hdr.Prepend(1)[0] = 0xFA
- packetRoute := stack.Route{RemoteAddress: dstIP}
- endpoint.WritePacket(&packetRoute, nil /* gso */, ipv4.ProtocolNumber, tcpip.PacketBuffer{
- Header: hdr,
- Data: buffer.NewView(0).ToVectorisedView(),
- })
- buf := make([]byte, 6500)
- 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 makeTestInjectableEndpoint(t *testing.T) (*InjectableEndpoint, *os.File, tcpip.Address) {
- dstIP := tcpip.Address(net.ParseIP("1.2.3.4").To4())
- pair, err := syscall.Socketpair(syscall.AF_UNIX,
- syscall.SOCK_SEQPACKET|syscall.SOCK_CLOEXEC|syscall.SOCK_NONBLOCK, 0)
- if err != nil {
- t.Fatal("Failed to create socket pair:", err)
- }
- underlyingEndpoint := fdbased.NewInjectable(pair[1], 6500, stack.CapabilityNone)
- routes := map[tcpip.Address]stack.InjectableLinkEndpoint{dstIP: underlyingEndpoint}
- endpoint := NewInjectableEndpoint(routes)
- return endpoint, os.NewFile(uintptr(pair[0]), "test route end"), dstIP
-}