nebula/overlay/tun_android.go

70 lines
1.3 KiB
Go
Raw Normal View History

2021-10-21 15:24:11 -06:00
//go:build !e2e_testing
// +build !e2e_testing
2021-11-11 15:37:29 -07:00
package overlay
2020-07-01 09:20:52 -06:00
import (
"fmt"
"io"
"net"
"os"
2021-03-26 08:46:30 -06:00
"github.com/sirupsen/logrus"
"github.com/slackhq/nebula/cidr"
"github.com/slackhq/nebula/iputil"
2020-07-01 09:20:52 -06:00
)
type tun struct {
2020-07-01 09:20:52 -06:00
io.ReadWriteCloser
fd int
cidr *net.IPNet
routeTree *cidr.Tree4
l *logrus.Logger
2020-07-01 09:20:52 -06:00
}
func newTunFromFd(l *logrus.Logger, deviceFd int, cidr *net.IPNet, _ int, routes []Route, _ int) (*tun, error) {
routeTree, err := makeRouteTree(l, routes, false)
if err != nil {
return nil, err
}
2020-07-01 09:20:52 -06:00
file := os.NewFile(uintptr(deviceFd), "/dev/net/tun")
return &tun{
2020-07-01 09:20:52 -06:00
ReadWriteCloser: file,
fd: int(file.Fd()),
cidr: cidr,
2021-03-26 08:46:30 -06:00
l: l,
routeTree: routeTree,
}, nil
2020-07-01 09:20:52 -06:00
}
func newTun(_ *logrus.Logger, _ string, _ *net.IPNet, _ int, _ []Route, _ int, _ bool) (*tun, error) {
2020-07-01 09:20:52 -06:00
return nil, fmt.Errorf("newTun not supported in Android")
}
func (t *tun) RouteFor(ip iputil.VpnIp) iputil.VpnIp {
r := t.routeTree.MostSpecificContains(ip)
if r != nil {
return r.(iputil.VpnIp)
}
return 0
}
func (t tun) Activate() error {
2020-07-01 09:20:52 -06:00
return nil
}
func (t *tun) Cidr() *net.IPNet {
return t.cidr
}
func (t *tun) Name() string {
return "android"
}
func (t *tun) NewMultiQueueReader() (io.ReadWriteCloser, error) {
return nil, fmt.Errorf("TODO: multiqueue not implemented for android")
}