mirror of
https://github.com/netbirdio/netbird.git
synced 2025-01-19 04:19:48 +01:00
support for routes and working connection
This commit is contained in:
parent
e733cdcf33
commit
8b8e4bbc6a
@ -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)
|
e.routeManager.SetRouteChangeListener(e.mobileDep.RouteListener)
|
||||||
|
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
@ -225,6 +225,8 @@ func (e *Engine) Start() error {
|
|||||||
})
|
})
|
||||||
case "ios":
|
case "ios":
|
||||||
err = e.wgInterface.CreateOniOS(e.mobileDep.FileDescriptor)
|
err = e.wgInterface.CreateOniOS(e.mobileDep.FileDescriptor)
|
||||||
|
log.Debugf("wireguardAddress: %s", wgAddr)
|
||||||
|
e.mobileDep.RouteListener.OnNewRouteSetting("", "100.127.93.142/16")
|
||||||
default:
|
default:
|
||||||
err = e.wgInterface.Create()
|
err = e.wgInterface.Create()
|
||||||
}
|
}
|
||||||
|
31
client/internal/routemanager/firewall_ios.go
Normal file
31
client/internal/routemanager/firewall_ios.go
Normal file
@ -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
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
//go:build !linux
|
//go:build !linux && !ios
|
||||||
// +build !linux
|
// +build !linux,!ios
|
||||||
|
|
||||||
package routemanager
|
package routemanager
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ type DefaultManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewManager returns a new route manager
|
// 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)
|
srvRouter, err := newServerRouter(ctx, wgInterface)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("server router is not supported: %s", err)
|
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,
|
statusRecorder: statusRecorder,
|
||||||
wgInterface: wgInterface,
|
wgInterface: wgInterface,
|
||||||
pubKey: pubKey,
|
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)
|
cr := dm.clientRoutes(initialRoutes)
|
||||||
dm.notifier.setInitialClientRoutes(cr)
|
dm.notifier.setInitialClientRoutes(cr)
|
||||||
}
|
}
|
||||||
|
@ -2,18 +2,23 @@ package routemanager
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/route"
|
"github.com/netbirdio/netbird/route"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RouteListener is a callback interface for mobile system
|
// RouteListener is a callback interface for mobile system
|
||||||
type RouteListener interface {
|
type RouteListener interface {
|
||||||
// OnNewRouteSetting invoke when new route setting has been arrived
|
// OnNewRouteSetting invoke when new route setting has been arrived
|
||||||
OnNewRouteSetting()
|
OnNewRouteSetting(string, string)
|
||||||
}
|
}
|
||||||
|
|
||||||
type notifier struct {
|
type notifier struct {
|
||||||
|
// ownIPAddr is the ip address of the netbird interface including the netmask
|
||||||
|
ownIPAddr string
|
||||||
initialRouteRangers []string
|
initialRouteRangers []string
|
||||||
routeRangers []string
|
routeRangers []string
|
||||||
|
|
||||||
@ -21,8 +26,11 @@ type notifier struct {
|
|||||||
routeListenerMux sync.Mutex
|
routeListenerMux sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func newNotifier() *notifier {
|
func newNotifier(ip string) *notifier {
|
||||||
return ¬ifier{}
|
log.Debugf("creating notifier with own ip: %s", ip)
|
||||||
|
return ¬ifier{
|
||||||
|
ownIPAddr: ip,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *notifier) setListener(listener RouteListener) {
|
func (n *notifier) setListener(listener RouteListener) {
|
||||||
@ -69,7 +77,8 @@ func (n *notifier) notify() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func(l RouteListener) {
|
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)
|
}(n.routeListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
//go:build android
|
||||||
|
|
||||||
package routemanager
|
package routemanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
Loading…
Reference in New Issue
Block a user