diff --git a/interface.go b/interface.go index 9203f09..5739ea0 100644 --- a/interface.go +++ b/interface.go @@ -2,6 +2,8 @@ package nebula import ( "errors" + "io" + "net" "os" "time" @@ -10,10 +12,18 @@ import ( const mtu = 9001 +type Inside interface { + io.ReadWriteCloser + Activate() error + CidrNet() *net.IPNet + DeviceName() string + WriteRaw([]byte) error +} + type InterfaceConfig struct { HostMap *HostMap Outside *udpConn - Inside *Tun + Inside Inside certState *CertState Cipher string Firewall *Firewall @@ -31,7 +41,7 @@ type InterfaceConfig struct { type Interface struct { hostMap *HostMap outside *udpConn - inside *Tun + inside Inside certState *CertState cipher string firewall *Firewall @@ -101,7 +111,7 @@ func (f *Interface) Run(tunRoutines, udpRoutines int, buildVersion string) { l.WithError(err).Error("Failed to get udp listen address") } - l.WithField("interface", f.inside.Device).WithField("network", f.inside.Cidr.String()). + l.WithField("interface", f.inside.DeviceName()).WithField("network", f.inside.CidrNet().String()). WithField("build", buildVersion).WithField("udpAddr", addr). Info("Nebula interface is active") diff --git a/tun_android.go b/tun_android.go index a2a2e90..957af0b 100644 --- a/tun_android.go +++ b/tun_android.go @@ -27,7 +27,7 @@ func newTunFromFd(deviceFd int, cidr *net.IPNet, defaultMTU int, routes []route, ifce = &Tun{ ReadWriteCloser: file, fd: int(file.Fd()), - Device: "tun0", + Device: "android", Cidr: cidr, DefaultMTU: defaultMTU, TXQueueLen: txQueueLen, @@ -64,6 +64,13 @@ func (c *Tun) WriteRaw(b []byte) error { } func (c Tun) Activate() error { - c.Device = "android" return nil } + +func (c *Tun) CidrNet() *net.IPNet { + return c.Cidr +} + +func (c *Tun) DeviceName() string { + return c.Device +} diff --git a/tun_darwin.go b/tun_darwin.go index cccc489..dc63b45 100644 --- a/tun_darwin.go +++ b/tun_darwin.go @@ -68,6 +68,14 @@ func (c *Tun) Activate() error { return nil } +func (c *Tun) CidrNet() *net.IPNet { + return c.Cidr +} + +func (c *Tun) DeviceName() string { + return c.Device +} + func (c *Tun) WriteRaw(b []byte) error { _, err := c.Write(b) return err diff --git a/tun_freebsd.go b/tun_freebsd.go index b294aa3..b5a67e7 100644 --- a/tun_freebsd.go +++ b/tun_freebsd.go @@ -75,6 +75,14 @@ func (c *Tun) Activate() error { return nil } +func (c *Tun) CidrNet() *net.IPNet { + return c.Cidr +} + +func (c *Tun) DeviceName() string { + return c.Device +} + func (c *Tun) WriteRaw(b []byte) error { _, err := c.Write(b) return err diff --git a/tun_ios.go b/tun_ios.go index df1078d..5440f21 100644 --- a/tun_ios.go +++ b/tun_ios.go @@ -30,13 +30,13 @@ func newTunFromFd(deviceFd int, cidr *net.IPNet, defaultMTU int, routes []route, file := os.NewFile(uintptr(deviceFd), "/dev/tun") ifce = &Tun{ Cidr: cidr, + Device: "iOS", ReadWriteCloser: &tunReadCloser{f: file}, } return } func (c *Tun) Activate() error { - c.Device = "iOS" return nil } @@ -103,3 +103,11 @@ func (t *tunReadCloser) Write(from []byte) (int, error) { func (t *tunReadCloser) Close() error { return t.f.Close() } + +func (c *Tun) CidrNet() *net.IPNet { + return c.Cidr +} + +func (c *Tun) DeviceName() string { + return c.Device +} diff --git a/tun_linux.go b/tun_linux.go index dc8f3ea..cde79d6 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -288,6 +288,14 @@ func (c Tun) Activate() error { return nil } +func (c *Tun) CidrNet() *net.IPNet { + return c.Cidr +} + +func (c *Tun) DeviceName() string { + return c.Device +} + func (c Tun) advMSS(r route) int { mtu := r.mtu if r.mtu == 0 { diff --git a/tun_windows.go b/tun_windows.go index 8795507..d9e12f4 100644 --- a/tun_windows.go +++ b/tun_windows.go @@ -88,6 +88,14 @@ func (c *Tun) Activate() error { return nil } +func (c *Tun) CidrNet() *net.IPNet { + return c.Cidr +} + +func (c *Tun) DeviceName() string { + return c.Device +} + func (c *Tun) WriteRaw(b []byte) error { _, err := c.Write(b) return err