mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-05 00:54:01 -04:00
[client] Include fake IP block routes in Android TUN rebuilds (#5739)
This commit is contained in:
@@ -31,26 +31,11 @@ func (n *Notifier) SetListener(listener listener.NetworkChangeListener) {
|
|||||||
n.listener = listener
|
n.listener = listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetInitialClientRoutes stores the full initial route set (including fake IP blocks)
|
||||||
|
// and a separate comparison set (without fake IP blocks) for diff detection.
|
||||||
func (n *Notifier) SetInitialClientRoutes(initialRoutes []*route.Route, routesForComparison []*route.Route) {
|
func (n *Notifier) SetInitialClientRoutes(initialRoutes []*route.Route, routesForComparison []*route.Route) {
|
||||||
// initialRoutes contains fake IP block for interface configuration
|
n.initialRoutes = filterStatic(initialRoutes)
|
||||||
filteredInitial := make([]*route.Route, 0)
|
n.currentRoutes = filterStatic(routesForComparison)
|
||||||
for _, r := range initialRoutes {
|
|
||||||
if r.IsDynamic() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
filteredInitial = append(filteredInitial, r)
|
|
||||||
}
|
|
||||||
n.initialRoutes = filteredInitial
|
|
||||||
|
|
||||||
// routesForComparison excludes fake IP block for comparison with new routes
|
|
||||||
filteredComparison := make([]*route.Route, 0)
|
|
||||||
for _, r := range routesForComparison {
|
|
||||||
if r.IsDynamic() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
filteredComparison = append(filteredComparison, r)
|
|
||||||
}
|
|
||||||
n.currentRoutes = filteredComparison
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Notifier) OnNewRoutes(idMap route.HAMap) {
|
func (n *Notifier) OnNewRoutes(idMap route.HAMap) {
|
||||||
@@ -83,13 +68,43 @@ func (n *Notifier) notify() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
routeStrings := n.routesToStrings(n.currentRoutes)
|
allRoutes := slices.Clone(n.currentRoutes)
|
||||||
|
allRoutes = append(allRoutes, n.extraInitialRoutes()...)
|
||||||
|
|
||||||
|
routeStrings := n.routesToStrings(allRoutes)
|
||||||
sort.Strings(routeStrings)
|
sort.Strings(routeStrings)
|
||||||
go func(l listener.NetworkChangeListener) {
|
go func(l listener.NetworkChangeListener) {
|
||||||
l.OnNetworkChanged(strings.Join(n.addIPv6RangeIfNeeded(routeStrings, n.currentRoutes), ","))
|
l.OnNetworkChanged(strings.Join(n.addIPv6RangeIfNeeded(routeStrings, allRoutes), ","))
|
||||||
}(n.listener)
|
}(n.listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extraInitialRoutes returns initialRoutes whose network prefix is absent
|
||||||
|
// from currentRoutes (e.g. the fake IP block added at setup time).
|
||||||
|
func (n *Notifier) extraInitialRoutes() []*route.Route {
|
||||||
|
currentNets := make(map[netip.Prefix]struct{}, len(n.currentRoutes))
|
||||||
|
for _, r := range n.currentRoutes {
|
||||||
|
currentNets[r.Network] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
|
var extra []*route.Route
|
||||||
|
for _, r := range n.initialRoutes {
|
||||||
|
if _, ok := currentNets[r.Network]; !ok {
|
||||||
|
extra = append(extra, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return extra
|
||||||
|
}
|
||||||
|
|
||||||
|
func filterStatic(routes []*route.Route) []*route.Route {
|
||||||
|
out := make([]*route.Route, 0, len(routes))
|
||||||
|
for _, r := range routes {
|
||||||
|
if !r.IsDynamic() {
|
||||||
|
out = append(out, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
func (n *Notifier) routesToStrings(routes []*route.Route) []string {
|
func (n *Notifier) routesToStrings(routes []*route.Route) []string {
|
||||||
nets := make([]string, 0, len(routes))
|
nets := make([]string, 0, len(routes))
|
||||||
for _, r := range routes {
|
for _, r := range routes {
|
||||||
|
|||||||
Reference in New Issue
Block a user