diff options
Diffstat (limited to 'pkg/tcpip/stack')
-rw-r--r-- | pkg/tcpip/stack/conntrack.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/stack/iptables.go | 1 | ||||
-rw-r--r-- | pkg/tcpip/stack/neighbor_cache.go | 2 | ||||
-rw-r--r-- | pkg/tcpip/stack/nud.go | 12 | ||||
-rw-r--r-- | pkg/tcpip/stack/stack_global_state.go | 72 | ||||
-rw-r--r-- | pkg/tcpip/stack/stack_state_autogen.go | 35 | ||||
-rw-r--r-- | pkg/tcpip/stack/tcp.go | 14 |
7 files changed, 32 insertions, 106 deletions
diff --git a/pkg/tcpip/stack/conntrack.go b/pkg/tcpip/stack/conntrack.go index 5720e7543..f7fbcbaa7 100644 --- a/pkg/tcpip/stack/conntrack.go +++ b/pkg/tcpip/stack/conntrack.go @@ -125,6 +125,8 @@ type conn struct { tcb tcpconntrack.TCB // lastUsed is the last time the connection saw a relevant packet, and // is updated by each packet on the connection. It is protected by mu. + // + // TODO(gvisor.dev/issue/5939): do not use the ambient clock. lastUsed time.Time `state:".(unixTime)"` } diff --git a/pkg/tcpip/stack/iptables.go b/pkg/tcpip/stack/iptables.go index 3670d5995..d2f666c09 100644 --- a/pkg/tcpip/stack/iptables.go +++ b/pkg/tcpip/stack/iptables.go @@ -371,6 +371,7 @@ func (it *IPTables) startReaper(interval time.Duration) { select { case <-it.reaperDone: return + // TODO(gvisor.dev/issue/5939): do not use the ambient clock. case <-time.After(interval): bucket, interval = it.connections.reapUnused(bucket, interval) } diff --git a/pkg/tcpip/stack/neighbor_cache.go b/pkg/tcpip/stack/neighbor_cache.go index 509f5ce5c..08857e1a9 100644 --- a/pkg/tcpip/stack/neighbor_cache.go +++ b/pkg/tcpip/stack/neighbor_cache.go @@ -310,7 +310,7 @@ func (n *neighborCache) handleUpperLevelConfirmation(addr tcpip.Address) { func (n *neighborCache) init(nic *nic, r LinkAddressResolver) { *n = neighborCache{ nic: nic, - state: NewNUDState(nic.stack.nudConfigs, nic.stack.randomGenerator), + state: NewNUDState(nic.stack.nudConfigs, nic.stack.clock, nic.stack.randomGenerator), linkRes: r, } n.mu.Lock() diff --git a/pkg/tcpip/stack/nud.go b/pkg/tcpip/stack/nud.go index dac94cbe4..ca9822bca 100644 --- a/pkg/tcpip/stack/nud.go +++ b/pkg/tcpip/stack/nud.go @@ -316,7 +316,8 @@ func calcMaxRandomFactor(minRandomFactor float32) float32 { // NUDState stores states needed for calculating reachable time. type NUDState struct { - rng *rand.Rand + clock tcpip.Clock + rng *rand.Rand mu struct { sync.RWMutex @@ -337,9 +338,10 @@ type NUDState struct { // NewNUDState returns new NUDState using c as configuration and the specified // random number generator for use in recomputing ReachableTime. -func NewNUDState(c NUDConfigurations, rng *rand.Rand) *NUDState { +func NewNUDState(c NUDConfigurations, clock tcpip.Clock, rng *rand.Rand) *NUDState { s := &NUDState{ - rng: rng, + clock: clock, + rng: rng, } s.mu.config = c return s @@ -367,7 +369,7 @@ func (s *NUDState) ReachableTime() time.Duration { s.mu.Lock() defer s.mu.Unlock() - if time.Now().After(s.mu.expiration) || + if s.clock.Now().After(s.mu.expiration) || s.mu.config.BaseReachableTime != s.mu.prevBaseReachableTime || s.mu.config.MinRandomFactor != s.mu.prevMinRandomFactor || s.mu.config.MaxRandomFactor != s.mu.prevMaxRandomFactor { @@ -416,5 +418,5 @@ func (s *NUDState) recomputeReachableTimeLocked() { s.mu.reachableTime = time.Duration(reachableTime) } - s.mu.expiration = time.Now().Add(2 * time.Hour) + s.mu.expiration = s.clock.Now().Add(2 * time.Hour) } diff --git a/pkg/tcpip/stack/stack_global_state.go b/pkg/tcpip/stack/stack_global_state.go index 33824afd0..dfec4258a 100644 --- a/pkg/tcpip/stack/stack_global_state.go +++ b/pkg/tcpip/stack/stack_global_state.go @@ -14,78 +14,6 @@ package stack -import "time" - // StackFromEnv is the global stack created in restore run. // FIXME(b/36201077) var StackFromEnv *Stack - -// saveT is invoked by stateify. -func (t *TCPCubicState) saveT() unixTime { - return unixTime{t.T.Unix(), t.T.UnixNano()} -} - -// loadT is invoked by stateify. -func (t *TCPCubicState) loadT(unix unixTime) { - t.T = time.Unix(unix.second, unix.nano) -} - -// saveXmitTime is invoked by stateify. -func (t *TCPRACKState) saveXmitTime() unixTime { - return unixTime{t.XmitTime.Unix(), t.XmitTime.UnixNano()} -} - -// loadXmitTime is invoked by stateify. -func (t *TCPRACKState) loadXmitTime(unix unixTime) { - t.XmitTime = time.Unix(unix.second, unix.nano) -} - -// saveLastSendTime is invoked by stateify. -func (t *TCPSenderState) saveLastSendTime() unixTime { - return unixTime{t.LastSendTime.Unix(), t.LastSendTime.UnixNano()} -} - -// loadLastSendTime is invoked by stateify. -func (t *TCPSenderState) loadLastSendTime(unix unixTime) { - t.LastSendTime = time.Unix(unix.second, unix.nano) -} - -// saveRTTMeasureTime is invoked by stateify. -func (t *TCPSenderState) saveRTTMeasureTime() unixTime { - return unixTime{t.RTTMeasureTime.Unix(), t.RTTMeasureTime.UnixNano()} -} - -// loadRTTMeasureTime is invoked by stateify. -func (t *TCPSenderState) loadRTTMeasureTime(unix unixTime) { - t.RTTMeasureTime = time.Unix(unix.second, unix.nano) -} - -// saveMeasureTime is invoked by stateify. -func (r *RcvBufAutoTuneParams) saveMeasureTime() unixTime { - return unixTime{r.MeasureTime.Unix(), r.MeasureTime.UnixNano()} -} - -// loadMeasureTime is invoked by stateify. -func (r *RcvBufAutoTuneParams) loadMeasureTime(unix unixTime) { - r.MeasureTime = time.Unix(unix.second, unix.nano) -} - -// saveRTTMeasureTime is invoked by stateify. -func (r *RcvBufAutoTuneParams) saveRTTMeasureTime() unixTime { - return unixTime{r.RTTMeasureTime.Unix(), r.RTTMeasureTime.UnixNano()} -} - -// loadRTTMeasureTime is invoked by stateify. -func (r *RcvBufAutoTuneParams) loadRTTMeasureTime(unix unixTime) { - r.RTTMeasureTime = time.Unix(unix.second, unix.nano) -} - -// saveSegTime is invoked by stateify. -func (t *TCPEndpointState) saveSegTime() unixTime { - return unixTime{t.SegTime.Unix(), t.SegTime.UnixNano()} -} - -// loadSegTime is invoked by stateify. -func (t *TCPEndpointState) loadSegTime(unix unixTime) { - t.SegTime = time.Unix(unix.second, unix.nano) -} diff --git a/pkg/tcpip/stack/stack_state_autogen.go b/pkg/tcpip/stack/stack_state_autogen.go index a803f9992..b287f64c3 100644 --- a/pkg/tcpip/stack/stack_state_autogen.go +++ b/pkg/tcpip/stack/stack_state_autogen.go @@ -623,10 +623,9 @@ func (t *TCPCubicState) beforeSave() {} // +checklocksignore func (t *TCPCubicState) StateSave(stateSinkObject state.Sink) { t.beforeSave() - var TValue unixTime = t.saveT() - stateSinkObject.SaveValue(2, TValue) stateSinkObject.Save(0, &t.WLastMax) stateSinkObject.Save(1, &t.WMax) + stateSinkObject.Save(2, &t.T) stateSinkObject.Save(3, &t.TimeSinceLastCongestion) stateSinkObject.Save(4, &t.C) stateSinkObject.Save(5, &t.K) @@ -641,13 +640,13 @@ func (t *TCPCubicState) afterLoad() {} func (t *TCPCubicState) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(0, &t.WLastMax) stateSourceObject.Load(1, &t.WMax) + stateSourceObject.Load(2, &t.T) stateSourceObject.Load(3, &t.TimeSinceLastCongestion) stateSourceObject.Load(4, &t.C) stateSourceObject.Load(5, &t.K) stateSourceObject.Load(6, &t.Beta) stateSourceObject.Load(7, &t.WC) stateSourceObject.Load(8, &t.WEst) - stateSourceObject.LoadValue(2, new(unixTime), func(y interface{}) { t.loadT(y.(unixTime)) }) } func (t *TCPRACKState) StateTypeName() string { @@ -674,8 +673,7 @@ func (t *TCPRACKState) beforeSave() {} // +checklocksignore func (t *TCPRACKState) StateSave(stateSinkObject state.Sink) { t.beforeSave() - var XmitTimeValue unixTime = t.saveXmitTime() - stateSinkObject.SaveValue(0, XmitTimeValue) + stateSinkObject.Save(0, &t.XmitTime) stateSinkObject.Save(1, &t.EndSequence) stateSinkObject.Save(2, &t.FACK) stateSinkObject.Save(3, &t.RTT) @@ -691,6 +689,7 @@ func (t *TCPRACKState) afterLoad() {} // +checklocksignore func (t *TCPRACKState) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &t.XmitTime) stateSourceObject.Load(1, &t.EndSequence) stateSourceObject.Load(2, &t.FACK) stateSourceObject.Load(3, &t.RTT) @@ -700,7 +699,6 @@ func (t *TCPRACKState) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(7, &t.ReoWndIncr) stateSourceObject.Load(8, &t.ReoWndPersist) stateSourceObject.Load(9, &t.RTTSeq) - stateSourceObject.LoadValue(0, new(unixTime), func(y interface{}) { t.loadXmitTime(y.(unixTime)) }) } func (t *TCPEndpointID) StateTypeName() string { @@ -877,10 +875,7 @@ func (t *TCPSenderState) beforeSave() {} // +checklocksignore func (t *TCPSenderState) StateSave(stateSinkObject state.Sink) { t.beforeSave() - var LastSendTimeValue unixTime = t.saveLastSendTime() - stateSinkObject.SaveValue(0, LastSendTimeValue) - var RTTMeasureTimeValue unixTime = t.saveRTTMeasureTime() - stateSinkObject.SaveValue(11, RTTMeasureTimeValue) + stateSinkObject.Save(0, &t.LastSendTime) stateSinkObject.Save(1, &t.DupAckCount) stateSinkObject.Save(2, &t.SndCwnd) stateSinkObject.Save(3, &t.Ssthresh) @@ -891,6 +886,7 @@ func (t *TCPSenderState) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(8, &t.SndUna) stateSinkObject.Save(9, &t.SndNxt) stateSinkObject.Save(10, &t.RTTMeasureSeqNum) + stateSinkObject.Save(11, &t.RTTMeasureTime) stateSinkObject.Save(12, &t.Closed) stateSinkObject.Save(13, &t.RTO) stateSinkObject.Save(14, &t.RTTState) @@ -906,6 +902,7 @@ func (t *TCPSenderState) afterLoad() {} // +checklocksignore func (t *TCPSenderState) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &t.LastSendTime) stateSourceObject.Load(1, &t.DupAckCount) stateSourceObject.Load(2, &t.SndCwnd) stateSourceObject.Load(3, &t.Ssthresh) @@ -916,6 +913,7 @@ func (t *TCPSenderState) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(8, &t.SndUna) stateSourceObject.Load(9, &t.SndNxt) stateSourceObject.Load(10, &t.RTTMeasureSeqNum) + stateSourceObject.Load(11, &t.RTTMeasureTime) stateSourceObject.Load(12, &t.Closed) stateSourceObject.Load(13, &t.RTO) stateSourceObject.Load(14, &t.RTTState) @@ -925,8 +923,6 @@ func (t *TCPSenderState) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(18, &t.FastRecovery) stateSourceObject.Load(19, &t.Cubic) stateSourceObject.Load(20, &t.RACKState) - stateSourceObject.LoadValue(0, new(unixTime), func(y interface{}) { t.loadLastSendTime(y.(unixTime)) }) - stateSourceObject.LoadValue(11, new(unixTime), func(y interface{}) { t.loadRTTMeasureTime(y.(unixTime)) }) } func (t *TCPSACKInfo) StateTypeName() string { @@ -983,16 +979,14 @@ func (r *RcvBufAutoTuneParams) beforeSave() {} // +checklocksignore func (r *RcvBufAutoTuneParams) StateSave(stateSinkObject state.Sink) { r.beforeSave() - var MeasureTimeValue unixTime = r.saveMeasureTime() - stateSinkObject.SaveValue(0, MeasureTimeValue) - var RTTMeasureTimeValue unixTime = r.saveRTTMeasureTime() - stateSinkObject.SaveValue(7, RTTMeasureTimeValue) + stateSinkObject.Save(0, &r.MeasureTime) stateSinkObject.Save(1, &r.CopiedBytes) stateSinkObject.Save(2, &r.PrevCopiedBytes) stateSinkObject.Save(3, &r.RcvBufSize) stateSinkObject.Save(4, &r.RTT) stateSinkObject.Save(5, &r.RTTVar) stateSinkObject.Save(6, &r.RTTMeasureSeqNumber) + stateSinkObject.Save(7, &r.RTTMeasureTime) stateSinkObject.Save(8, &r.Disabled) } @@ -1000,15 +994,15 @@ func (r *RcvBufAutoTuneParams) afterLoad() {} // +checklocksignore func (r *RcvBufAutoTuneParams) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &r.MeasureTime) stateSourceObject.Load(1, &r.CopiedBytes) stateSourceObject.Load(2, &r.PrevCopiedBytes) stateSourceObject.Load(3, &r.RcvBufSize) stateSourceObject.Load(4, &r.RTT) stateSourceObject.Load(5, &r.RTTVar) stateSourceObject.Load(6, &r.RTTMeasureSeqNumber) + stateSourceObject.Load(7, &r.RTTMeasureTime) stateSourceObject.Load(8, &r.Disabled) - stateSourceObject.LoadValue(0, new(unixTime), func(y interface{}) { r.loadMeasureTime(y.(unixTime)) }) - stateSourceObject.LoadValue(7, new(unixTime), func(y interface{}) { r.loadRTTMeasureTime(y.(unixTime)) }) } func (t *TCPRcvBufState) StateTypeName() string { @@ -1138,10 +1132,9 @@ func (t *TCPEndpointState) beforeSave() {} // +checklocksignore func (t *TCPEndpointState) StateSave(stateSinkObject state.Sink) { t.beforeSave() - var SegTimeValue unixTime = t.saveSegTime() - stateSinkObject.SaveValue(2, SegTimeValue) stateSinkObject.Save(0, &t.TCPEndpointStateInner) stateSinkObject.Save(1, &t.ID) + stateSinkObject.Save(2, &t.SegTime) stateSinkObject.Save(3, &t.RcvBufState) stateSinkObject.Save(4, &t.SndBufState) stateSinkObject.Save(5, &t.SACK) @@ -1155,12 +1148,12 @@ func (t *TCPEndpointState) afterLoad() {} func (t *TCPEndpointState) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(0, &t.TCPEndpointStateInner) stateSourceObject.Load(1, &t.ID) + stateSourceObject.Load(2, &t.SegTime) stateSourceObject.Load(3, &t.RcvBufState) stateSourceObject.Load(4, &t.SndBufState) stateSourceObject.Load(5, &t.SACK) stateSourceObject.Load(6, &t.Receiver) stateSourceObject.Load(7, &t.Sender) - stateSourceObject.LoadValue(2, new(unixTime), func(y interface{}) { t.loadSegTime(y.(unixTime)) }) } func (ep *multiPortEndpoint) StateTypeName() string { diff --git a/pkg/tcpip/stack/tcp.go b/pkg/tcpip/stack/tcp.go index ddff6e2d6..e90c1a770 100644 --- a/pkg/tcpip/stack/tcp.go +++ b/pkg/tcpip/stack/tcp.go @@ -39,7 +39,7 @@ type TCPCubicState struct { WMax float64 // T is the time when the current congestion avoidance was entered. - T time.Time `state:".(unixTime)"` + T tcpip.MonotonicTime // TimeSinceLastCongestion denotes the time since the current // congestion avoidance was entered. @@ -78,7 +78,7 @@ type TCPCubicState struct { type TCPRACKState struct { // XmitTime is the transmission timestamp of the most recent // acknowledged segment. - XmitTime time.Time `state:".(unixTime)"` + XmitTime tcpip.MonotonicTime // EndSequence is the ending TCP sequence number of the most recent // acknowledged segment. @@ -216,7 +216,7 @@ type TCPRTTState struct { // +stateify savable type TCPSenderState struct { // LastSendTime is the timestamp at which we sent the last segment. - LastSendTime time.Time `state:".(unixTime)"` + LastSendTime tcpip.MonotonicTime // DupAckCount is the number of Duplicate ACKs received. It is used for // fast retransmit. @@ -256,7 +256,7 @@ type TCPSenderState struct { RTTMeasureSeqNum seqnum.Value // RTTMeasureTime is the time when the RTTMeasureSeqNum was sent. - RTTMeasureTime time.Time `state:".(unixTime)"` + RTTMeasureTime tcpip.MonotonicTime // Closed indicates that the caller has closed the endpoint for // sending. @@ -313,7 +313,7 @@ type TCPSACKInfo struct { type RcvBufAutoTuneParams struct { // MeasureTime is the time at which the current measurement was // started. - MeasureTime time.Time `state:".(unixTime)"` + MeasureTime tcpip.MonotonicTime // CopiedBytes is the number of bytes copied to user space since this // measure began. @@ -341,7 +341,7 @@ type RcvBufAutoTuneParams struct { // RTTMeasureTime is the absolute time at which the current RTT // measurement period began. - RTTMeasureTime time.Time `state:".(unixTime)"` + RTTMeasureTime tcpip.MonotonicTime // Disabled is true if an explicit receive buffer is set for the // endpoint. @@ -429,7 +429,7 @@ type TCPEndpointState struct { ID TCPEndpointID // SegTime denotes the absolute time when this segment was received. - SegTime time.Time `state:".(unixTime)"` + SegTime tcpip.MonotonicTime // RcvBufState contains information about the state of the endpoint's // receive socket buffer. |