Populate IGMPv3 report checksum

Updates #8346

PiperOrigin-RevId: 501969927
This commit is contained in:
Ghanan Gowripalan
2023-01-13 16:56:40 -08:00
committed by gVisor bot
parent a8900d549b
commit d3894e4481
3 changed files with 17 additions and 3 deletions
+3
View File
@@ -1650,6 +1650,9 @@ func IGMPv3Report(expectedRecords map[tcpip.Address]header.IGMPv3ReportRecordTyp
}
report := header.IGMPv3Report(igmp)
if got, want := report.Checksum(), header.IGMPCalculateChecksum(igmp); got != want {
t.Errorf("got report.Checksum() = %d, want = %d", got, want)
}
records := report.GroupAddressRecords()
for len(expectedRecords) != 0 {
+5
View File
@@ -336,6 +336,11 @@ func TestIGMPv3Report(t *testing.T) {
test.serializer.SerializeInto(b)
report := header.IGMPv3Report(b)
if got, want := report.Checksum(), header.IGMPCalculateChecksum(header.IGMP(report)); got != want {
t.Errorf("got report.Checksum() = %d, want = %d", got, want)
}
expectedRecords := test.serializer.Records
records := report.GroupAddressRecords()
+9 -3
View File
@@ -309,12 +309,13 @@ func (s *IGMPv3ReportSerializer) SerializeInto(b []byte) {
b[igmpv3ReportReserved1Offset] = 0
binary.BigEndian.PutUint16(b[igmpv3ReportReserved2Offset:], 0)
binary.BigEndian.PutUint16(b[igmpv3ReportNumberOfGroupAddressRecordsOffset:], uint16(len(s.Records)))
b = b[igmpv3ReportGroupAddressRecordsOffset:]
recordsBytes := b[igmpv3ReportGroupAddressRecordsOffset:]
for _, record := range s.Records {
len := record.Length()
record.SerializeInto(b[:len])
b = b[len:]
record.SerializeInto(recordsBytes[:len])
recordsBytes = recordsBytes[len:]
}
binary.BigEndian.PutUint16(b[igmpChecksumOffset:], IGMPCalculateChecksum(b))
}
// IGMPv3ReportGroupAddressRecord is an IGMPv3 record.
@@ -436,6 +437,11 @@ func (r IGMPv3ReportGroupAddressRecord) Sources() (AddressIterator, bool) {
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
type IGMPv3Report []byte
// Checksum returns the checksum.
func (i IGMPv3Report) Checksum() uint16 {
return binary.BigEndian.Uint16(i[igmpChecksumOffset:])
}
// IGMPv3ReportGroupAddressRecordIterator is an iterator over IGMPv3 Multicast
// Address Records.
type IGMPv3ReportGroupAddressRecordIterator struct {