tun_linux_offload.go 714 B

12345678910111213141516171819202122232425
  1. //go:build linux && !android && !e2e_testing
  2. // +build linux,!android,!e2e_testing
  3. package tio
  4. import (
  5. "fmt"
  6. "github.com/slackhq/nebula/wire"
  7. "golang.org/x/sys/unix"
  8. )
  9. // protoFromGSOType maps a virtio_net_hdr GSOType to the GSOProto value the
  10. // segment-time helpers use. Returns an error for GSO_NONE or any unknown
  11. // value — the caller should only invoke this on a confirmed superpacket.
  12. func protoFromGSOType(t uint8) (wire.GSOProto, error) {
  13. switch t {
  14. case unix.VIRTIO_NET_HDR_GSO_TCPV4, unix.VIRTIO_NET_HDR_GSO_TCPV6:
  15. return wire.GSOProtoTCP, nil
  16. case unix.VIRTIO_NET_HDR_GSO_UDP_L4:
  17. return wire.GSOProtoUDP, nil
  18. default:
  19. return 0, fmt.Errorf("unsupported virtio gso type: %d", t)
  20. }
  21. }