summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport/udp/protocol.go
diff options
context:
space:
mode:
authorKevin Krakauer <krakauer@google.com>2020-04-13 17:37:21 -0700
committerKevin Krakauer <krakauer@google.com>2020-04-17 13:25:57 -0700
commita551add5d8a5bf631cd9859c761e579fdb33ec82 (patch)
tree44563f8173fe203da367d47bf3aca633dbbba76c /pkg/tcpip/transport/udp/protocol.go
parent80deebb0bfde2a53c943deb8d8473239bb6de3eb (diff)
Remove View.First() and View.RemoveFirst()
These methods let users eaily break the VectorisedView abstraction, and allowed netstack to slip into pseudo-enforcement of the "all headers are in the first View" invariant. Removing them and replacing with PullUp(n) breaks this reliance and will make it easier to add iptables support and rework network buffer management. The new View.PullUp(n) method is low cost in the common case, when when all the headers fit in the first View.
Diffstat (limited to 'pkg/tcpip/transport/udp/protocol.go')
-rw-r--r--pkg/tcpip/transport/udp/protocol.go9
1 files changed, 7 insertions, 2 deletions
diff --git a/pkg/tcpip/transport/udp/protocol.go b/pkg/tcpip/transport/udp/protocol.go
index 6e31a9bac..52af6de22 100644
--- a/pkg/tcpip/transport/udp/protocol.go
+++ b/pkg/tcpip/transport/udp/protocol.go
@@ -68,8 +68,13 @@ func (*protocol) ParsePorts(v buffer.View) (src, dst uint16, err *tcpip.Error) {
// that don't match any existing endpoint.
func (p *protocol) HandleUnknownDestinationPacket(r *stack.Route, id stack.TransportEndpointID, pkt stack.PacketBuffer) bool {
// Get the header then trim it from the view.
- hdr := header.UDP(pkt.Data.First())
- if int(hdr.Length()) > pkt.Data.Size() {
+ h, ok := pkt.Data.PullUp(header.UDPMinimumSize)
+ if !ok {
+ // Malformed packet.
+ r.Stack().Stats().UDP.MalformedPacketsReceived.Increment()
+ return true
+ }
+ if int(header.UDP(h).Length()) > pkt.Data.Size() {
// Malformed packet.
r.Stack().Stats().UDP.MalformedPacketsReceived.Increment()
return true