Skip to content

Commit

Permalink
Remove unnecessary uapi open (netbirdio#807)
Browse files Browse the repository at this point in the history
Remove unnecessary uapi open from Android implementation
  • Loading branch information
pappz authored Apr 17, 2023
1 parent 4616bc5 commit bb147c2
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions iface/tun_android.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package iface

import (
"net"
"strings"

"github.com/pion/transport/v2"

"github.com/netbirdio/netbird/iface/bind"

log "github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/ipc"
"golang.zx2c4.com/wireguard/tun"

"github.com/netbirdio/netbird/iface/bind"
)

type tunDevice struct {
Expand All @@ -24,7 +21,6 @@ type tunDevice struct {
fd int
name string
device *device.Device
uapi net.Listener
iceBind *bind.ICEBind
}

Expand Down Expand Up @@ -58,32 +54,8 @@ func (t *tunDevice) Create() error {
t.device = device.NewDevice(tunDevice, t.iceBind, device.NewLogger(device.LogLevelSilent, "[wiretrustee] "))
t.device.DisableSomeRoamingForBrokenMobileSemantics()

log.Debugf("create uapi")
tunSock, err := ipc.UAPIOpen(name)
if err != nil {
return err
}

t.uapi, err = ipc.UAPIListen(name, tunSock)
if err != nil {
tunSock.Close()
unix.Close(t.fd)
return err
}

go func() {
for {
uapiConn, err := t.uapi.Accept()
if err != nil {
return
}
go t.device.IpcHandle(uapiConn)
}
}()

err = t.device.Up()
if err != nil {
tunSock.Close()
t.device.Close()
return err
}
Expand All @@ -109,10 +81,6 @@ func (t *tunDevice) UpdateAddr(addr WGAddress) error {
}

func (t *tunDevice) Close() (err error) {
if t.uapi != nil {
err = t.uapi.Close()
}

if t.device != nil {
t.device.Close()
}
Expand Down

0 comments on commit bb147c2

Please sign in to comment.