2021-10-21 23:24:11 +02:00
|
|
|
//go:build !e2e_testing
|
2021-03-29 21:29:20 +02:00
|
|
|
// +build !e2e_testing
|
|
|
|
|
2021-11-11 23:37:29 +01:00
|
|
|
package overlay
|
2020-07-01 17:20:52 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net"
|
|
|
|
"os"
|
2021-11-12 18:19:28 +01:00
|
|
|
"runtime"
|
2020-07-01 17:20:52 +02:00
|
|
|
|
2021-03-26 15:46:30 +01:00
|
|
|
"github.com/sirupsen/logrus"
|
2021-11-12 18:19:28 +01:00
|
|
|
"github.com/slackhq/nebula/iputil"
|
2020-07-01 17:20:52 +02:00
|
|
|
)
|
|
|
|
|
2021-11-12 17:47:36 +01:00
|
|
|
type tun struct {
|
2020-07-01 17:20:52 +02:00
|
|
|
io.ReadWriteCloser
|
2021-11-12 18:19:28 +01:00
|
|
|
fd int
|
2021-11-12 19:47:09 +01:00
|
|
|
cidr *net.IPNet
|
2021-11-12 18:19:28 +01:00
|
|
|
l *logrus.Logger
|
2020-07-01 17:20:52 +02:00
|
|
|
}
|
|
|
|
|
2021-11-12 18:19:28 +01:00
|
|
|
func newTunFromFd(l *logrus.Logger, deviceFd int, cidr *net.IPNet, _ int, routes []Route, _ int) (*tun, error) {
|
|
|
|
if len(routes) > 0 {
|
|
|
|
return nil, fmt.Errorf("routes are not supported in %s", runtime.GOOS)
|
|
|
|
}
|
|
|
|
|
2020-07-01 17:20:52 +02:00
|
|
|
file := os.NewFile(uintptr(deviceFd), "/dev/net/tun")
|
|
|
|
|
2021-11-12 17:47:36 +01:00
|
|
|
return &tun{
|
2020-07-01 17:20:52 +02:00
|
|
|
ReadWriteCloser: file,
|
|
|
|
fd: int(file.Fd()),
|
2021-11-12 19:47:09 +01:00
|
|
|
cidr: cidr,
|
2021-03-26 15:46:30 +01:00
|
|
|
l: l,
|
2021-11-12 17:47:36 +01:00
|
|
|
}, nil
|
2020-07-01 17:20:52 +02:00
|
|
|
}
|
|
|
|
|
2021-11-12 18:19:28 +01:00
|
|
|
func newTun(_ *logrus.Logger, _ string, _ *net.IPNet, _ int, _ []Route, _ int, _ bool) (*tun, error) {
|
2020-07-01 17:20:52 +02:00
|
|
|
return nil, fmt.Errorf("newTun not supported in Android")
|
|
|
|
}
|
|
|
|
|
2021-11-12 18:19:28 +01:00
|
|
|
func (t *tun) RouteFor(iputil.VpnIp) iputil.VpnIp {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2021-11-12 17:47:36 +01:00
|
|
|
func (t tun) Activate() error {
|
2020-07-01 17:20:52 +02:00
|
|
|
return nil
|
|
|
|
}
|
2020-07-28 14:53:16 +02:00
|
|
|
|
2021-11-12 19:47:09 +01:00
|
|
|
func (t *tun) Cidr() *net.IPNet {
|
|
|
|
return t.cidr
|
2020-07-28 14:53:16 +02:00
|
|
|
}
|
|
|
|
|
2021-11-12 19:47:09 +01:00
|
|
|
func (t *tun) Name() string {
|
2021-11-12 18:19:28 +01:00
|
|
|
return "android"
|
2020-07-28 14:53:16 +02:00
|
|
|
}
|
2021-02-25 21:01:14 +01:00
|
|
|
|
2021-11-12 17:47:36 +01:00
|
|
|
func (t *tun) NewMultiQueueReader() (io.ReadWriteCloser, error) {
|
2021-02-25 21:01:14 +01:00
|
|
|
return nil, fmt.Errorf("TODO: multiqueue not implemented for android")
|
|
|
|
}
|