(data []byte, p gopacket.PacketBuilder)
| 426 | } |
| 427 | |
| 428 | func decodeSCTPSack(data []byte, p gopacket.PacketBuilder) error { |
| 429 | chunk, err := decodeSCTPChunk(data) |
| 430 | if err != nil { |
| 431 | return err |
| 432 | } |
| 433 | sc := &SCTPSack{ |
| 434 | SCTPChunk: chunk, |
| 435 | CumulativeTSNAck: binary.BigEndian.Uint32(data[4:8]), |
| 436 | AdvertisedReceiverWindowCredit: binary.BigEndian.Uint32(data[8:12]), |
| 437 | NumGapACKs: binary.BigEndian.Uint16(data[12:14]), |
| 438 | NumDuplicateTSNs: binary.BigEndian.Uint16(data[14:16]), |
| 439 | } |
| 440 | // We maximize gapAcks and dupTSNs here so we're not allocating tons |
| 441 | // of memory based on a user-controlable field. Our maximums are not exact, |
| 442 | // but should give us sane defaults... we'll still hit slice boundaries and |
| 443 | // fail if the user-supplied values are too high (in the for loops below), but |
| 444 | // the amount of memory we'll have allocated because of that should be small |
| 445 | // (< sc.ActualLength) |
| 446 | gapAcks := sc.SCTPChunk.ActualLength / 2 |
| 447 | dupTSNs := (sc.SCTPChunk.ActualLength - gapAcks*2) / 4 |
| 448 | if gapAcks > int(sc.NumGapACKs) { |
| 449 | gapAcks = int(sc.NumGapACKs) |
| 450 | } |
| 451 | if dupTSNs > int(sc.NumDuplicateTSNs) { |
| 452 | dupTSNs = int(sc.NumDuplicateTSNs) |
| 453 | } |
| 454 | sc.GapACKs = make([]uint16, 0, gapAcks) |
| 455 | sc.DuplicateTSNs = make([]uint32, 0, dupTSNs) |
| 456 | bytesRemaining := data[16:] |
| 457 | for i := 0; i < int(sc.NumGapACKs); i++ { |
| 458 | sc.GapACKs = append(sc.GapACKs, binary.BigEndian.Uint16(bytesRemaining[:2])) |
| 459 | bytesRemaining = bytesRemaining[2:] |
| 460 | } |
| 461 | for i := 0; i < int(sc.NumDuplicateTSNs); i++ { |
| 462 | sc.DuplicateTSNs = append(sc.DuplicateTSNs, binary.BigEndian.Uint32(bytesRemaining[:4])) |
| 463 | bytesRemaining = bytesRemaining[4:] |
| 464 | } |
| 465 | p.AddLayer(sc) |
| 466 | return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix)) |
| 467 | } |
| 468 | |
| 469 | // SerializeTo is for gopacket.SerializableLayer. |
| 470 | func (sc SCTPSack) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { |
nothing calls this directly
no test coverage detected
searching dependent graphs…