MCPcopy
hub / github.com/google/gopacket / ReassembledSG

Method ReassembledSG

examples/reassemblydump/main.go:376–457  ·  view source on GitHub ↗
(sg reassembly.ScatterGather, ac reassembly.AssemblerContext)

Source from the content-addressed store, hash-verified

374}
375
376func (t *tcpStream) ReassembledSG(sg reassembly.ScatterGather, ac reassembly.AssemblerContext) {
377 dir, start, end, skip := sg.Info()
378 length, saved := sg.Lengths()
379 // update stats
380 sgStats := sg.Stats()
381 if skip > 0 {
382 stats.missedBytes += skip
383 }
384 stats.sz += length - saved
385 stats.pkt += sgStats.Packets
386 if sgStats.Chunks > 1 {
387 stats.reassembled++
388 }
389 stats.outOfOrderPackets += sgStats.QueuedPackets
390 stats.outOfOrderBytes += sgStats.QueuedBytes
391 if length > stats.biggestChunkBytes {
392 stats.biggestChunkBytes = length
393 }
394 if sgStats.Packets > stats.biggestChunkPackets {
395 stats.biggestChunkPackets = sgStats.Packets
396 }
397 if sgStats.OverlapBytes != 0 && sgStats.OverlapPackets == 0 {
398 fmt.Printf("bytes:%d, pkts:%d\n", sgStats.OverlapBytes, sgStats.OverlapPackets)
399 panic("Invalid overlap")
400 }
401 stats.overlapBytes += sgStats.OverlapBytes
402 stats.overlapPackets += sgStats.OverlapPackets
403
404 var ident string
405 if dir == reassembly.TCPDirClientToServer {
406 ident = fmt.Sprintf("%v %v(%s): ", t.net, t.transport, dir)
407 } else {
408 ident = fmt.Sprintf("%v %v(%s): ", t.net.Reverse(), t.transport.Reverse(), dir)
409 }
410 Debug("%s: SG reassembled packet with %d bytes (start:%v,end:%v,skip:%d,saved:%d,nb:%d,%d,overlap:%d,%d)\n", ident, length, start, end, skip, saved, sgStats.Packets, sgStats.Chunks, sgStats.OverlapBytes, sgStats.OverlapPackets)
411 if skip == -1 && *allowmissinginit {
412 // this is allowed
413 } else if skip != 0 {
414 // Missing bytes in stream: do not even try to parse it
415 return
416 }
417 data := sg.Fetch(length)
418 if t.isDNS {
419 dns := &layers.DNS{}
420 var decoded []gopacket.LayerType
421 if len(data) < 2 {
422 if len(data) > 0 {
423 sg.KeepFrom(0)
424 }
425 return
426 }
427 dnsSize := binary.BigEndian.Uint16(data[:2])
428 missing := int(dnsSize) - len(data[2:])
429 Debug("dnsSize: %d, missing: %d\n", dnsSize, missing)
430 if missing > 0 {
431 Info("Missing some bytes: %d\n", missing)
432 sg.KeepFrom(0)
433 return

Callers

nothing calls this directly

Calls 14

DecodeLayersMethod · 0.95
NewDecodingLayerParserFunction · 0.92
LayerDumpFunction · 0.92
DebugFunction · 0.85
InfoFunction · 0.85
ErrorFunction · 0.85
PrintfMethod · 0.80
InfoMethod · 0.65
LengthsMethod · 0.65
StatsMethod · 0.65
FetchMethod · 0.65
KeepFromMethod · 0.65

Tested by

no test coverage detected