Add route management for Android interface (#801)

Support client route management feature on Android
This commit is contained in:
Zoltan Papp
2023-04-17 11:15:37 +02:00
committed by GitHub
parent 1803cf3678
commit 4616bc5258
32 changed files with 486 additions and 355 deletions

View File

@@ -2,6 +2,7 @@ package iface
import (
"net"
"strings"
"github.com/pion/transport/v2"
@@ -17,6 +18,7 @@ import (
type tunDevice struct {
address WGAddress
mtu int
routes []string
tunAdapter TunAdapter
fd int
@@ -26,10 +28,11 @@ type tunDevice struct {
iceBind *bind.ICEBind
}
func newTunDevice(address WGAddress, mtu int, tunAdapter TunAdapter, transportNet transport.Net) *tunDevice {
func newTunDevice(address WGAddress, mtu int, routes []string, tunAdapter TunAdapter, transportNet transport.Net) *tunDevice {
return &tunDevice{
address: address,
mtu: mtu,
routes: routes,
tunAdapter: tunAdapter,
iceBind: bind.NewICEBind(transportNet),
}
@@ -37,7 +40,8 @@ func newTunDevice(address WGAddress, mtu int, tunAdapter TunAdapter, transportNe
func (t *tunDevice) Create() error {
var err error
t.fd, err = t.tunAdapter.ConfigureInterface(t.address.String(), t.mtu)
routesString := t.routesToString()
t.fd, err = t.tunAdapter.ConfigureInterface(t.address.String(), t.mtu, routesString)
if err != nil {
log.Errorf("failed to create Android interface: %s", err)
return err
@@ -115,3 +119,7 @@ func (t *tunDevice) Close() (err error) {
return
}
func (t *tunDevice) routesToString() string {
return strings.Join(t.routes, ";")
}