Remove tcpip.Stack interface and replace all usage of the interface with
the concreate type *stack.Stack.
PiperOrigin-RevId: 170966206
diff --git a/tcpip/adapters/gonet/gonet.go b/tcpip/adapters/gonet/gonet.go
index 60e81ef..2094bda 100644
--- a/tcpip/adapters/gonet/gonet.go
+++ b/tcpip/adapters/gonet/gonet.go
@@ -14,6 +14,7 @@
"github.com/google/netstack/tcpip"
"github.com/google/netstack/tcpip/buffer"
+ "github.com/google/netstack/tcpip/stack"
"github.com/google/netstack/tcpip/transport/tcp"
"github.com/google/netstack/tcpip/transport/udp"
"github.com/google/netstack/waiter"
@@ -31,14 +32,14 @@
// A Listener is a wrapper around a tcpip endpoint that implements
// net.Listener.
type Listener struct {
- stack tcpip.Stack
+ stack *stack.Stack
ep tcpip.Endpoint
wq *waiter.Queue
cancel chan struct{}
}
// NewListener creates a new Listener.
-func NewListener(s tcpip.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*Listener, error) {
+func NewListener(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*Listener, error) {
// Create TCP endpoint, bind it, then start listening.
var wq waiter.Queue
ep, err := s.NewEndpoint(tcp.ProtocolNumber, network, &wq)
@@ -427,7 +428,7 @@
}
// DialTCP creates a new TCP Conn connected to the specified address.
-func DialTCP(s tcpip.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*Conn, error) {
+func DialTCP(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*Conn, error) {
// Create TCP endpoint, then connect.
var wq waiter.Queue
ep, err := s.NewEndpoint(tcp.ProtocolNumber, network, &wq)
@@ -466,13 +467,13 @@
type PacketConn struct {
deadlineTimer
- stack tcpip.Stack
+ stack *stack.Stack
ep tcpip.Endpoint
wq *waiter.Queue
}
// NewPacketConn creates a new PacketConn.
-func NewPacketConn(s tcpip.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*PacketConn, error) {
+func NewPacketConn(s *stack.Stack, addr tcpip.FullAddress, network tcpip.NetworkProtocolNumber) (*PacketConn, error) {
// Create UDP endpoint and bind it.
var wq waiter.Queue
ep, err := s.NewEndpoint(udp.ProtocolNumber, network, &wq)
diff --git a/tcpip/stack/stack.go b/tcpip/stack/stack.go
index 6cbdfa1..d0a0960 100644
--- a/tcpip/stack/stack.go
+++ b/tcpip/stack/stack.go
@@ -144,6 +144,7 @@
// NOTE: The underlying stats are updated using atomic instructions as a result
// the snapshot returned does not represent the value of all the stats at any
// single given point of time.
+// TODO: Make stats available in sentry for debugging/diag.
func (s *Stack) Stats() tcpip.Stats {
return tcpip.Stats{
UnknownProtocolRcvdPackets: atomic.LoadUint64(&s.stats.UnknownProtocolRcvdPackets),
@@ -162,7 +163,7 @@
}
// SetRouteTable assigns the route table to be used by this stack. It
-// specifies which NIC to use for a given destination address mask.
+// specifies which NIC to use for given destination address ranges.
func (s *Stack) SetRouteTable(table []tcpip.Route) {
s.mu.Lock()
defer s.mu.Unlock()
diff --git a/tcpip/tcpip.go b/tcpip/tcpip.go
index c7f7d94..cf6f422 100644
--- a/tcpip/tcpip.go
+++ b/tcpip/tcpip.go
@@ -371,47 +371,6 @@
// NetworkProtocolNumber is the number of a network protocol.
type NetworkProtocolNumber uint32
-// Stack represents a networking stack, with all supported protocols, NICs, and
-// route table.
-type Stack interface {
- // NewEndpoint creates a new transport layer endpoint of the given
- // protocol.
- NewEndpoint(transport TransportProtocolNumber, network NetworkProtocolNumber, waiterQueue *waiter.Queue) (Endpoint, *Error)
-
- // SetRouteTable assigns the route table to be used by this stack. It
- // specifies which NICs to use for given destination address ranges.
- SetRouteTable(table []Route)
-
- // CreateNIC creates a NIC with the provided id and link-layer sender.
- CreateNIC(id NICID, linkEndpoint LinkEndpointID) *Error
-
- // AddAddress adds a new network-layer address to the specified NIC.
- AddAddress(id NICID, protocol NetworkProtocolNumber, addr Address) *Error
-
- // Stats returns a snapshot of the current stats.
- // TODO: Make stats available in sentry for debugging/diag.
- Stats() Stats
-
- // NICSubnets returns a map of NICIDs to their associated subnets.
- NICSubnets() map[NICID][]Subnet
-
- // CheckNetworkProtocol checks if a given network protocol is enabled in the
- // stack.
- CheckNetworkProtocol(protocol NetworkProtocolNumber) bool
-
- // SetNetworkProtocolOption allows configuring individual protocol level
- // options. This method returns an error if the protocol is not
- // supported or option is not supported by the protocol implementation
- // or the provided value is incorrect.
- SetNetworkProtocolOption(network NetworkProtocolNumber, option interface{}) *Error
-
- // SetTransportProtocolOption allows configuring individual protocol
- // level options. This method returns an error if the protocol is not
- // supported or option is not supported by the protocol implementation
- // or the provided value is incorrect.
- SetTransportProtocolOption(transport TransportProtocolNumber, option interface{}) *Error
-}
-
// Stats holds statistics about the networking stack.
type Stats struct {
// UnkownProtocolRcvdPackets is the number of packets received by the
diff --git a/tcpip/transport/tcp/tcp_test.go b/tcpip/transport/tcp/tcp_test.go
index 842870e..b1839f8 100644
--- a/tcpip/transport/tcp/tcp_test.go
+++ b/tcpip/transport/tcp/tcp_test.go
@@ -15,7 +15,6 @@
"github.com/google/netstack/tcpip/header"
"github.com/google/netstack/tcpip/network/ipv4"
"github.com/google/netstack/tcpip/seqnum"
- "github.com/google/netstack/tcpip/stack"
"github.com/google/netstack/tcpip/transport/tcp"
"github.com/google/netstack/tcpip/transport/tcp/testing/context"
"github.com/google/netstack/waiter"
@@ -1116,7 +1115,7 @@
c := context.New(t, mtu)
defer c.Cleanup()
- s := c.Stack().(*stack.Stack)
+ s := c.Stack()
ch := make(chan *tcpip.Error, 1)
f := tcp.NewForwarder(s, 65536, 10, func(r *tcp.ForwarderRequest) {
var err *tcpip.Error
diff --git a/tcpip/transport/tcp/testing/context/context.go b/tcpip/transport/tcp/testing/context/context.go
index d4ae3ef..1592b58 100644
--- a/tcpip/transport/tcp/testing/context/context.go
+++ b/tcpip/transport/tcp/testing/context/context.go
@@ -100,7 +100,7 @@
type Context struct {
t *testing.T
linkEP *channel.Endpoint
- s tcpip.Stack
+ s *stack.Stack
// IRS holds the initial sequence number in the SYN sent by endpoint in
// case of an active connect or the sequence number sent by the endpoint
@@ -177,7 +177,7 @@
}
// Stack returns a reference to the stack in the Context.
-func (c *Context) Stack() tcpip.Stack {
+func (c *Context) Stack() *stack.Stack {
return c.s
}
diff --git a/tcpip/transport/udp/udp_test.go b/tcpip/transport/udp/udp_test.go
index 19069c1..9638232 100644
--- a/tcpip/transport/udp/udp_test.go
+++ b/tcpip/transport/udp/udp_test.go
@@ -44,7 +44,7 @@
type testContext struct {
t *testing.T
linkEP *channel.Endpoint
- s tcpip.Stack
+ s *stack.Stack
ep tcpip.Endpoint
wq waiter.Queue