1
0

wire.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package wire
  2. // TunPacket is the unit a read from a tun device returns.
  3. // On supported platforms, it may be a superpacket, but a single TunPacket will never have more than one destination.
  4. type TunPacket struct {
  5. // Bytes contains the actual packet
  6. Bytes []byte
  7. // Meta contains other information to help process the packet correctly, such as offsets for segmentation offloads
  8. // Fields in Meta should be as portable/platform-agnostic as possible.
  9. Meta GSOInfo
  10. }
  11. // GSOInfo describes a kernel-supplied superpacket sitting in Packet.Bytes.
  12. // The zero value means "not a superpacket" — Bytes is one regular IP
  13. // datagram and no segmentation is required.
  14. type GSOInfo struct {
  15. // Size is the GSO segment size: max payload bytes per segment
  16. // (== TCP MSS for TSO, == UDP payload chunk for USO). Zero means
  17. // not a superpacket.
  18. Size uint16
  19. // HdrLen is the total L3+L4 header length within Bytes (already
  20. // corrected via correctHdrLen, so safe to slice on).
  21. HdrLen uint16
  22. // CsumStart is the L4 header offset inside Bytes (== L3 header
  23. // length).
  24. CsumStart uint16
  25. // Proto picks the L4 protocol (TCP or UDP) so the segmenter knows
  26. // which checksum/header layout to apply.
  27. Proto GSOProto
  28. }
  29. // GSOProto selects the L4 protocol for a GSO superpacket. Determines which
  30. // VIRTIO_NET_HDR_GSO_* type the writer stamps and which checksum offset
  31. // inside the transport header virtio NEEDS_CSUM expects.
  32. type GSOProto uint8
  33. const (
  34. GSOProtoNone GSOProto = iota
  35. GSOProtoTCP
  36. GSOProtoUDP
  37. )
  38. // IsSuperpacket reports whether g describes a multi-segment GSO/USO
  39. // superpacket that needs segmentation before its bytes can be encrypted
  40. // and sent on the wire.
  41. func (g GSOInfo) IsSuperpacket() bool { return g.Size > 0 }