summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/header/igmp.go
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-11-24 06:51:09 +0000
committergVisor bot <gvisor-bot@google.com>2020-11-24 06:51:09 +0000
commit502c7c4ed41502a92ef0e4a5e64a94f0b15cc02b (patch)
tree7df047ca06bc82e9559c21fc7d5cb627862591bb /pkg/tcpip/header/igmp.go
parent9330559876150a271bc1533fad6b86b3c09ad561 (diff)
parentba2d5cb7e1f3ac69a65d0e790f1319082ee01de2 (diff)
Merge release-20201109.0-107-gba2d5cb7e (automated)
Diffstat (limited to 'pkg/tcpip/header/igmp.go')
-rw-r--r--pkg/tcpip/header/igmp.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/pkg/tcpip/header/igmp.go b/pkg/tcpip/header/igmp.go
index e0f5d46f4..5c5be1b9d 100644
--- a/pkg/tcpip/header/igmp.go
+++ b/pkg/tcpip/header/igmp.go
@@ -17,6 +17,7 @@ package header
import (
"encoding/binary"
"fmt"
+ "time"
"gvisor.dev/gvisor/pkg/tcpip"
)
@@ -103,7 +104,15 @@ func (b IGMP) SetType(t IGMPType) { b[igmpTypeOffset] = byte(t) }
// MaxRespTime gets the MaxRespTimeField. This is meaningful only in Membership
// Query messages, in other cases it is set to 0 by the sender and ignored by
// the receiver.
-func (b IGMP) MaxRespTime() byte { return b[igmpMaxRespTimeOffset] }
+func (b IGMP) MaxRespTime() time.Duration {
+ // As per RFC 2236 section 2.2,
+ //
+ // The Max Response Time field is meaningful only in Membership Query
+ // messages, and specifies the maximum allowed time before sending a
+ // responding report in units of 1/10 second. In all other messages, it
+ // is set to zero by the sender and ignored by receivers.
+ return DecisecondToDuration(b[igmpMaxRespTimeOffset])
+}
// SetMaxRespTime sets the MaxRespTimeField.
func (b IGMP) SetMaxRespTime(m byte) { b[igmpMaxRespTimeOffset] = m }
@@ -164,3 +173,9 @@ func IGMPCalculateChecksum(h IGMP) uint16 {
h.SetChecksum(existingXsum)
return xsum
}
+
+// DecisecondToDuration converts a value representing deci-seconds to a
+// time.Duration.
+func DecisecondToDuration(ds uint8) time.Duration {
+ return time.Duration(ds) * time.Second / 10
+}