summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/nud.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-05-26 06:47:52 -0700
committergVisor bot <gvisor-bot@google.com>2021-05-26 06:49:57 -0700
commitfcad6f91a3f292b6b76be10f03baf05ee5245d3d (patch)
treefa383878218fe0c69c5c346a08cfd953e398ee2d /pkg/tcpip/stack/nud.go
parentb63e61828d0652ad1769db342c17a3529d2d24ed (diff)
Use the stack clock everywhere
Updates #5939. Updates #6012. RELNOTES: n/a PiperOrigin-RevId: 375931554
Diffstat (limited to 'pkg/tcpip/stack/nud.go')
-rw-r--r--pkg/tcpip/stack/nud.go12
1 files changed, 7 insertions, 5 deletions
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)
}