summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport/udp
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2021-05-25 20:05:47 +0000
committergVisor bot <gvisor-bot@google.com>2021-05-25 20:05:47 +0000
commit93b3be2eb2457c3c12436503e6da384e40a68944 (patch)
tree1672784315b329b6f64e525456af7653f56eaff0 /pkg/tcpip/transport/udp
parent6f34ae308865ce8877797e9b2501a85195c42d7d (diff)
parent4f2439fb0ed4a6efda2637417c7137d27e4c4d26 (diff)
Merge release-20210518.0-38-g4f2439fb0 (automated)
Diffstat (limited to 'pkg/tcpip/transport/udp')
-rw-r--r--pkg/tcpip/transport/udp/endpoint.go7
-rw-r--r--pkg/tcpip/transport/udp/endpoint_state.go26
-rw-r--r--pkg/tcpip/transport/udp/udp_state_autogen.go45
3 files changed, 46 insertions, 32 deletions
diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go
index 623e069a6..83b589d09 100644
--- a/pkg/tcpip/transport/udp/endpoint.go
+++ b/pkg/tcpip/transport/udp/endpoint.go
@@ -17,6 +17,7 @@ package udp
import (
"io"
"sync/atomic"
+ "time"
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
@@ -34,7 +35,7 @@ type udpPacket struct {
destinationAddress tcpip.FullAddress
packetInfo tcpip.IPPacketInfo
data buffer.VectorisedView `state:".(buffer.VectorisedView)"`
- timestamp int64
+ receivedAt time.Time `state:".(int64)"`
// tos stores either the receiveTOS or receiveTClass value.
tos uint8
}
@@ -321,7 +322,7 @@ func (e *endpoint) Read(dst io.Writer, opts tcpip.ReadOptions) (tcpip.ReadResult
// Control Messages
cm := tcpip.ControlMessages{
HasTimestamp: true,
- Timestamp: p.timestamp,
+ Timestamp: p.receivedAt.UnixNano(),
}
if e.ops.GetReceiveTOS() {
cm.HasTOS = true
@@ -1329,7 +1330,7 @@ func (e *endpoint) HandlePacket(id stack.TransportEndpointID, pkt *stack.PacketB
packet.packetInfo.LocalAddr = localAddr
packet.packetInfo.DestinationAddr = localAddr
packet.packetInfo.NIC = pkt.NICID
- packet.timestamp = e.stack.Clock().NowNanoseconds()
+ packet.receivedAt = e.stack.Clock().Now()
e.rcvMu.Unlock()
diff --git a/pkg/tcpip/transport/udp/endpoint_state.go b/pkg/tcpip/transport/udp/endpoint_state.go
index 4aba68b21..1f638c3f6 100644
--- a/pkg/tcpip/transport/udp/endpoint_state.go
+++ b/pkg/tcpip/transport/udp/endpoint_state.go
@@ -15,26 +15,38 @@
package udp
import (
+ "time"
+
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/stack"
)
+// saveReceivedAt is invoked by stateify.
+func (p *udpPacket) saveReceivedAt() int64 {
+ return p.receivedAt.UnixNano()
+}
+
+// loadReceivedAt is invoked by stateify.
+func (p *udpPacket) loadReceivedAt(nsec int64) {
+ p.receivedAt = time.Unix(0, nsec)
+}
+
// saveData saves udpPacket.data field.
-func (u *udpPacket) saveData() buffer.VectorisedView {
- // We cannot save u.data directly as u.data.views may alias to u.views,
+func (p *udpPacket) saveData() buffer.VectorisedView {
+ // We cannot save p.data directly as p.data.views may alias to p.views,
// which is not allowed by state framework (in-struct pointer).
- return u.data.Clone(nil)
+ return p.data.Clone(nil)
}
// loadData loads udpPacket.data field.
-func (u *udpPacket) loadData(data buffer.VectorisedView) {
- // NOTE: We cannot do the u.data = data.Clone(u.views[:]) optimization
+func (p *udpPacket) loadData(data buffer.VectorisedView) {
+ // NOTE: We cannot do the p.data = data.Clone(p.views[:]) optimization
// here because data.views is not guaranteed to be loaded by now. Plus,
// data.views will be allocated anyway so there really is little point
- // of utilizing u.views for data.views.
- u.data = data
+ // of utilizing p.views for data.views.
+ p.data = data
}
// afterLoad is invoked by stateify.
diff --git a/pkg/tcpip/transport/udp/udp_state_autogen.go b/pkg/tcpip/transport/udp/udp_state_autogen.go
index 092daa0b8..6a3da67e2 100644
--- a/pkg/tcpip/transport/udp/udp_state_autogen.go
+++ b/pkg/tcpip/transport/udp/udp_state_autogen.go
@@ -7,48 +7,49 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/buffer"
)
-func (u *udpPacket) StateTypeName() string {
+func (p *udpPacket) StateTypeName() string {
return "pkg/tcpip/transport/udp.udpPacket"
}
-func (u *udpPacket) StateFields() []string {
+func (p *udpPacket) StateFields() []string {
return []string{
"udpPacketEntry",
"senderAddress",
"destinationAddress",
"packetInfo",
"data",
- "timestamp",
+ "receivedAt",
"tos",
}
}
-func (u *udpPacket) beforeSave() {}
+func (p *udpPacket) beforeSave() {}
// +checklocksignore
-func (u *udpPacket) StateSave(stateSinkObject state.Sink) {
- u.beforeSave()
- var dataValue buffer.VectorisedView = u.saveData()
+func (p *udpPacket) StateSave(stateSinkObject state.Sink) {
+ p.beforeSave()
+ var dataValue buffer.VectorisedView = p.saveData()
stateSinkObject.SaveValue(4, dataValue)
- stateSinkObject.Save(0, &u.udpPacketEntry)
- stateSinkObject.Save(1, &u.senderAddress)
- stateSinkObject.Save(2, &u.destinationAddress)
- stateSinkObject.Save(3, &u.packetInfo)
- stateSinkObject.Save(5, &u.timestamp)
- stateSinkObject.Save(6, &u.tos)
+ var receivedAtValue int64 = p.saveReceivedAt()
+ stateSinkObject.SaveValue(5, receivedAtValue)
+ stateSinkObject.Save(0, &p.udpPacketEntry)
+ stateSinkObject.Save(1, &p.senderAddress)
+ stateSinkObject.Save(2, &p.destinationAddress)
+ stateSinkObject.Save(3, &p.packetInfo)
+ stateSinkObject.Save(6, &p.tos)
}
-func (u *udpPacket) afterLoad() {}
+func (p *udpPacket) afterLoad() {}
// +checklocksignore
-func (u *udpPacket) StateLoad(stateSourceObject state.Source) {
- stateSourceObject.Load(0, &u.udpPacketEntry)
- stateSourceObject.Load(1, &u.senderAddress)
- stateSourceObject.Load(2, &u.destinationAddress)
- stateSourceObject.Load(3, &u.packetInfo)
- stateSourceObject.Load(5, &u.timestamp)
- stateSourceObject.Load(6, &u.tos)
- stateSourceObject.LoadValue(4, new(buffer.VectorisedView), func(y interface{}) { u.loadData(y.(buffer.VectorisedView)) })
+func (p *udpPacket) StateLoad(stateSourceObject state.Source) {
+ stateSourceObject.Load(0, &p.udpPacketEntry)
+ stateSourceObject.Load(1, &p.senderAddress)
+ stateSourceObject.Load(2, &p.destinationAddress)
+ stateSourceObject.Load(3, &p.packetInfo)
+ stateSourceObject.Load(6, &p.tos)
+ stateSourceObject.LoadValue(4, new(buffer.VectorisedView), func(y interface{}) { p.loadData(y.(buffer.VectorisedView)) })
+ stateSourceObject.LoadValue(5, new(int64), func(y interface{}) { p.loadReceivedAt(y.(int64)) })
}
func (e *endpoint) StateTypeName() string {