summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/fdbased
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2018-09-12 21:57:04 -0700
committerShentubot <shentubot@google.com>2018-09-12 21:57:55 -0700
commitd689f8422fd55f74f6fc677f33b2bbf3720de89e (patch)
tree729ba29346fa74ac4a413f6f619d9e85ceb0ae78 /pkg/tcpip/link/fdbased
parent5adb3468d4de249df055d641e01ce6582b3a9388 (diff)
Always pass buffer.VectorisedView by value
PiperOrigin-RevId: 212757571 Change-Id: I04200df9e45c21eb64951cd2802532fa84afcb1a
Diffstat (limited to 'pkg/tcpip/link/fdbased')
-rw-r--r--pkg/tcpip/link/fdbased/endpoint.go14
-rw-r--r--pkg/tcpip/link/fdbased/endpoint_test.go5
2 files changed, 7 insertions, 12 deletions
diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go
index 12c249c0d..0b985928b 100644
--- a/pkg/tcpip/link/fdbased/endpoint.go
+++ b/pkg/tcpip/link/fdbased/endpoint.go
@@ -57,7 +57,6 @@ type endpoint struct {
// its end of the communication pipe.
closed func(*tcpip.Error)
- vv *buffer.VectorisedView
iovecs []syscall.Iovec
views []buffer.View
dispatcher stack.NetworkDispatcher
@@ -118,8 +117,6 @@ func New(opts *Options) tcpip.LinkEndpointID {
iovecs: make([]syscall.Iovec, len(BufConfig)),
handleLocal: opts.HandleLocal,
}
- vv := buffer.NewVectorisedView(0, e.views)
- e.vv = &vv
return stack.RegisterLinkEndpoint(e)
}
@@ -167,7 +164,7 @@ func (e *endpoint) WritePacket(r *stack.Route, hdr *buffer.Prependable, payload
views[0] = hdr.View()
views = append(views, payload.Views()...)
vv := buffer.NewVectorisedView(len(views[0])+payload.Size(), views)
- e.dispatcher.DeliverNetworkPacket(e, r.RemoteLinkAddress, protocol, &vv)
+ e.dispatcher.DeliverNetworkPacket(e, r.RemoteLinkAddress, protocol, vv)
return nil
}
if e.hdrSize > 0 {
@@ -246,11 +243,10 @@ func (e *endpoint) dispatch(largeV buffer.View) (bool, *tcpip.Error) {
}
used := e.capViews(n, BufConfig)
- e.vv.SetViews(e.views[:used])
- e.vv.SetSize(n)
- e.vv.TrimFront(e.hdrSize)
+ vv := buffer.NewVectorisedView(n, e.views[:used])
+ vv.TrimFront(e.hdrSize)
- e.dispatcher.DeliverNetworkPacket(e, addr, p, e.vv)
+ e.dispatcher.DeliverNetworkPacket(e, addr, p, vv)
// Prepare e.views for another packet: release used views.
for i := 0; i < used; i++ {
@@ -290,7 +286,7 @@ func (e *InjectableEndpoint) Attach(dispatcher stack.NetworkDispatcher) {
}
// Inject injects an inbound packet.
-func (e *InjectableEndpoint) Inject(protocol tcpip.NetworkProtocolNumber, vv *buffer.VectorisedView) {
+func (e *InjectableEndpoint) Inject(protocol tcpip.NetworkProtocolNumber, vv buffer.VectorisedView) {
e.dispatcher.DeliverNetworkPacket(e, "", protocol, vv)
}
diff --git a/pkg/tcpip/link/fdbased/endpoint_test.go b/pkg/tcpip/link/fdbased/endpoint_test.go
index 408169bbe..21d2f10b0 100644
--- a/pkg/tcpip/link/fdbased/endpoint_test.go
+++ b/pkg/tcpip/link/fdbased/endpoint_test.go
@@ -77,7 +77,7 @@ func (c *context) cleanup() {
syscall.Close(c.fds[1])
}
-func (c *context) DeliverNetworkPacket(linkEP stack.LinkEndpoint, remoteLinkAddr tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, vv *buffer.VectorisedView) {
+func (c *context) DeliverNetworkPacket(linkEP stack.LinkEndpoint, remoteLinkAddr tcpip.LinkAddress, protocol tcpip.NetworkProtocolNumber, vv buffer.VectorisedView) {
c.ch <- packetInfo{remoteLinkAddr, protocol, vv.ToView()}
}
@@ -158,8 +158,7 @@ func TestWritePacket(t *testing.T) {
payload[i] = uint8(rand.Intn(256))
}
want := append(hdr.UsedBytes(), payload...)
- vv := buffer.NewVectorisedView(len(payload), []buffer.View{payload})
- if err := c.ep.WritePacket(r, &hdr, vv, proto); err != nil {
+ if err := c.ep.WritePacket(r, &hdr, payload.ToVectorisedView(), proto); err != nil {
t.Fatalf("WritePacket failed: %v", err)
}