ioctl.go 908 B

12345678910111213141516171819202122232425262728293031
  1. package vhostnet
  2. import (
  3. "fmt"
  4. "unsafe"
  5. "github.com/slackhq/nebula/overlay/vhost"
  6. )
  7. const (
  8. // vhostNetIoctlSetBackend can be used to attach a virtqueue to a RAW socket
  9. // or TAP device.
  10. //
  11. // Request payload: [vhost.QueueFile]
  12. // Kernel name: VHOST_NET_SET_BACKEND
  13. vhostNetIoctlSetBackend = 0x4008af30
  14. )
  15. // SetQueueBackend attaches a virtqueue of the vhost networking device
  16. // described by controlFD to the given backend file descriptor.
  17. // The backend file descriptor can either be a RAW socket or a TAP device. When
  18. // it is -1, the queue will be detached.
  19. func SetQueueBackend(controlFD int, queueIndex uint32, backendFD int) error {
  20. if err := vhost.IoctlPtr(controlFD, vhostNetIoctlSetBackend, unsafe.Pointer(&vhost.QueueFile{
  21. QueueIndex: queueIndex,
  22. FD: int32(backendFD),
  23. })); err != nil {
  24. return fmt.Errorf("set queue backend file descriptor: %w", err)
  25. }
  26. return nil
  27. }