diff --git a/client/internal/engine.go b/client/internal/engine.go index cb8205181..6444e6d37 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -214,7 +214,7 @@ func (e *Engine) Start() error { } } - e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder, routes) + e.routeManager = routemanager.NewManager(e.ctx, e.config.WgPrivateKey.PublicKey().String(), e.wgInterface, e.statusRecorder, routes, wgAddr) e.routeManager.SetRouteChangeListener(e.mobileDep.RouteListener) switch runtime.GOOS { @@ -225,6 +225,8 @@ func (e *Engine) Start() error { }) case "ios": err = e.wgInterface.CreateOniOS(e.mobileDep.FileDescriptor) + log.Debugf("wireguardAddress: %s", wgAddr) + e.mobileDep.RouteListener.OnNewRouteSetting("", "100.127.93.142/16") default: err = e.wgInterface.Create() } diff --git a/client/internal/routemanager/firewall_ios.go b/client/internal/routemanager/firewall_ios.go new file mode 100644 index 000000000..387f501f1 --- /dev/null +++ b/client/internal/routemanager/firewall_ios.go @@ -0,0 +1,31 @@ +//go:build ios + +package routemanager + +import ( + "context" +) + +// newFirewall returns a nil manager +func newFirewall(context.Context) (firewallManager, error) { + return iOSFirewallManager{}, nil +} + +type iOSFirewallManager struct { +} + +func (i iOSFirewallManager) RestoreOrCreateContainers() error { + return nil +} + +func (i iOSFirewallManager) InsertRoutingRules(pair routerPair) error { + return nil +} + +func (i iOSFirewallManager) RemoveRoutingRules(pair routerPair) error { + return nil +} + +func (i iOSFirewallManager) CleanRoutingRules() { + return +} diff --git a/client/internal/routemanager/firewall_nonlinux.go b/client/internal/routemanager/firewall_nonlinux.go index ae0627048..2d3eb29a7 100644 --- a/client/internal/routemanager/firewall_nonlinux.go +++ b/client/internal/routemanager/firewall_nonlinux.go @@ -1,5 +1,5 @@ -//go:build !linux -// +build !linux +//go:build !linux && !ios +// +build !linux,!ios package routemanager diff --git a/client/internal/routemanager/manager.go b/client/internal/routemanager/manager.go index b31fe6327..1be182d0a 100644 --- a/client/internal/routemanager/manager.go +++ b/client/internal/routemanager/manager.go @@ -35,7 +35,7 @@ type DefaultManager struct { } // NewManager returns a new route manager -func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder *peer.Status, initialRoutes []*route.Route) *DefaultManager { +func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder *peer.Status, initialRoutes []*route.Route, wgAddr string) *DefaultManager { srvRouter, err := newServerRouter(ctx, wgInterface) if err != nil { log.Errorf("server router is not supported: %s", err) @@ -50,10 +50,11 @@ func NewManager(ctx context.Context, pubKey string, wgInterface *iface.WGIface, statusRecorder: statusRecorder, wgInterface: wgInterface, pubKey: pubKey, - notifier: newNotifier(), + notifier: newNotifier(wgAddr), } - if runtime.GOOS == "android" { + log.Debug("initializing route manager") + if runtime.GOOS == "android" || runtime.GOOS == "ios" { cr := dm.clientRoutes(initialRoutes) dm.notifier.setInitialClientRoutes(cr) } diff --git a/client/internal/routemanager/notifier.go b/client/internal/routemanager/notifier.go index e37811166..aa2be7606 100644 --- a/client/internal/routemanager/notifier.go +++ b/client/internal/routemanager/notifier.go @@ -2,18 +2,23 @@ package routemanager import ( "sort" + "strings" "sync" + log "github.com/sirupsen/logrus" + "github.com/netbirdio/netbird/route" ) // RouteListener is a callback interface for mobile system type RouteListener interface { // OnNewRouteSetting invoke when new route setting has been arrived - OnNewRouteSetting() + OnNewRouteSetting(string, string) } type notifier struct { + // ownIPAddr is the ip address of the netbird interface including the netmask + ownIPAddr string initialRouteRangers []string routeRangers []string @@ -21,8 +26,11 @@ type notifier struct { routeListenerMux sync.Mutex } -func newNotifier() *notifier { - return ¬ifier{} +func newNotifier(ip string) *notifier { + log.Debugf("creating notifier with own ip: %s", ip) + return ¬ifier{ + ownIPAddr: ip, + } } func (n *notifier) setListener(listener RouteListener) { @@ -69,7 +77,8 @@ func (n *notifier) notify() { } go func(l RouteListener) { - l.OnNewRouteSetting() + log.Debugf("notifying route listener with route ranges: %s and own ip: %s", strings.Join(n.routeRangers, ","), n.ownIPAddr) + l.OnNewRouteSetting(strings.Join(n.routeRangers, ","), n.ownIPAddr) }(n.routeListener) } diff --git a/client/internal/routemanager/server_android.go b/client/internal/routemanager/server_android.go index d130acc00..e00fb5f70 100644 --- a/client/internal/routemanager/server_android.go +++ b/client/internal/routemanager/server_android.go @@ -1,3 +1,5 @@ +//go:build android + package routemanager import (