tun_android.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //go:build !e2e_testing
  2. // +build !e2e_testing
  3. package overlay
  4. import (
  5. "fmt"
  6. "io"
  7. "net"
  8. "os"
  9. "github.com/sirupsen/logrus"
  10. "github.com/slackhq/nebula/cidr"
  11. "github.com/slackhq/nebula/iputil"
  12. )
  13. type tun struct {
  14. io.ReadWriteCloser
  15. fd int
  16. cidr *net.IPNet
  17. routeTree *cidr.Tree4
  18. l *logrus.Logger
  19. }
  20. func newTunFromFd(l *logrus.Logger, deviceFd int, cidr *net.IPNet, _ int, routes []Route, _ int) (*tun, error) {
  21. routeTree, err := makeRouteTree(l, routes, false)
  22. if err != nil {
  23. return nil, err
  24. }
  25. file := os.NewFile(uintptr(deviceFd), "/dev/net/tun")
  26. return &tun{
  27. ReadWriteCloser: file,
  28. fd: int(file.Fd()),
  29. cidr: cidr,
  30. l: l,
  31. routeTree: routeTree,
  32. }, nil
  33. }
  34. func newTun(_ *logrus.Logger, _ string, _ *net.IPNet, _ int, _ []Route, _ int, _ bool) (*tun, error) {
  35. return nil, fmt.Errorf("newTun not supported in Android")
  36. }
  37. func (t *tun) RouteFor(ip iputil.VpnIp) iputil.VpnIp {
  38. r := t.routeTree.MostSpecificContains(ip)
  39. if r != nil {
  40. return r.(iputil.VpnIp)
  41. }
  42. return 0
  43. }
  44. func (t tun) Activate() error {
  45. return nil
  46. }
  47. func (t *tun) Cidr() *net.IPNet {
  48. return t.cidr
  49. }
  50. func (t *tun) Name() string {
  51. return "android"
  52. }
  53. func (t *tun) NewMultiQueueReader() (io.ReadWriteCloser, error) {
  54. return nil, fmt.Errorf("TODO: multiqueue not implemented for android")
  55. }