MCPcopy Create free account
hub / github.com/encodeous/nylon / coalesceUDPPackets

Function coalesceUDPPackets

polyamide/tun/offload_linux.go:414–438  ·  view source on GitHub ↗

coalesceUDPPackets attempts to coalesce pkt with the packet described by item, and returns the outcome.

(pkt []byte, item *udpGROItem, bufs [][]byte, bufsOffset int, isV6 bool)

Source from the content-addressed store, hash-verified

412// coalesceUDPPackets attempts to coalesce pkt with the packet described by
413// item, and returns the outcome.
414func coalesceUDPPackets(pkt []byte, item *udpGROItem, bufs [][]byte, bufsOffset int, isV6 bool) coalesceResult {
415 pktHead := bufs[item.bufsIndex][bufsOffset:] // the packet that will end up at the front
416 headersLen := item.iphLen + udphLen
417 coalescedLen := len(bufs[item.bufsIndex][bufsOffset:]) + len(pkt) - int(headersLen)
418
419 if cap(pktHead)-bufsOffset < coalescedLen {
420 // We don't want to allocate a new underlying array if capacity is
421 // too small.
422 return coalesceInsufficientCap
423 }
424 if item.numMerged == 0 {
425 if item.cSumKnownInvalid || !checksumValid(bufs[item.bufsIndex][bufsOffset:], item.iphLen, unix.IPPROTO_UDP, isV6) {
426 return coalesceItemInvalidCSum
427 }
428 }
429 if !checksumValid(pkt, item.iphLen, unix.IPPROTO_UDP, isV6) {
430 return coalescePktInvalidCSum
431 }
432 extendBy := len(pkt) - int(headersLen)
433 bufs[item.bufsIndex] = append(bufs[item.bufsIndex], make([]byte, extendBy)...)
434 copy(bufs[item.bufsIndex][bufsOffset+len(pktHead):], pkt[headersLen:])
435
436 item.numMerged++
437 return coalesceSuccess
438}
439
440// coalesceTCPPackets attempts to coalesce pkt with the packet described by
441// item, and returns the outcome. This function may swap bufs elements in the

Callers 1

udpGROFunction · 0.85

Calls 1

checksumValidFunction · 0.85

Tested by

no test coverage detected