mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-06 17:59:11 +00:00
fix: ensure proxy routes update correctly on NIC (#1729)
This commit is contained in:
@@ -26,8 +26,12 @@ impl ProxyCidrsMonitor {
|
|||||||
pub async fn diff_proxy_cidrs(
|
pub async fn diff_proxy_cidrs(
|
||||||
peer_mgr: &PeerManager,
|
peer_mgr: &PeerManager,
|
||||||
global_ctx: &ArcGlobalCtx,
|
global_ctx: &ArcGlobalCtx,
|
||||||
cur_proxy_cidrs: &mut BTreeSet<cidr::Ipv4Cidr>,
|
cur_proxy_cidrs: &BTreeSet<cidr::Ipv4Cidr>,
|
||||||
) -> (Vec<cidr::Ipv4Cidr>, Vec<cidr::Ipv4Cidr>) {
|
) -> (
|
||||||
|
BTreeSet<cidr::Ipv4Cidr>,
|
||||||
|
Vec<cidr::Ipv4Cidr>,
|
||||||
|
Vec<cidr::Ipv4Cidr>,
|
||||||
|
) {
|
||||||
// Collect proxy_cidrs from routes
|
// Collect proxy_cidrs from routes
|
||||||
let mut proxy_cidrs = BTreeSet::new();
|
let mut proxy_cidrs = BTreeSet::new();
|
||||||
let routes = peer_mgr.list_routes().await;
|
let routes = peer_mgr.list_routes().await;
|
||||||
@@ -52,15 +56,13 @@ impl ProxyCidrsMonitor {
|
|||||||
|
|
||||||
// Calculate diff
|
// Calculate diff
|
||||||
if cur_proxy_cidrs == &proxy_cidrs {
|
if cur_proxy_cidrs == &proxy_cidrs {
|
||||||
return (Vec::new(), Vec::new());
|
return (proxy_cidrs, Vec::new(), Vec::new());
|
||||||
}
|
}
|
||||||
let added: Vec<cidr::Ipv4Cidr> = proxy_cidrs.difference(cur_proxy_cidrs).cloned().collect();
|
let added: Vec<cidr::Ipv4Cidr> = proxy_cidrs.difference(cur_proxy_cidrs).cloned().collect();
|
||||||
let removed: Vec<cidr::Ipv4Cidr> =
|
let removed: Vec<cidr::Ipv4Cidr> =
|
||||||
cur_proxy_cidrs.difference(&proxy_cidrs).cloned().collect();
|
cur_proxy_cidrs.difference(&proxy_cidrs).cloned().collect();
|
||||||
|
|
||||||
*cur_proxy_cidrs = proxy_cidrs;
|
(proxy_cidrs, added, removed)
|
||||||
|
|
||||||
(added, removed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Starts monitoring proxy_cidrs changes and emits events with diffs
|
/// Starts monitoring proxy_cidrs changes and emits events with diffs
|
||||||
@@ -84,13 +86,12 @@ impl ProxyCidrsMonitor {
|
|||||||
}
|
}
|
||||||
last_update = Some(last_update_time);
|
last_update = Some(last_update_time);
|
||||||
|
|
||||||
let (added, removed) = Self::diff_proxy_cidrs(
|
let (new_proxy_cidrs, added, removed) =
|
||||||
peer_mgr.as_ref(),
|
Self::diff_proxy_cidrs(peer_mgr.as_ref(), &self.global_ctx, &cur_proxy_cidrs)
|
||||||
&self.global_ctx,
|
|
||||||
&mut cur_proxy_cidrs,
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
cur_proxy_cidrs = new_proxy_cidrs;
|
||||||
|
|
||||||
if added.is_empty() && removed.is_empty() {
|
if added.is_empty() && removed.is_empty() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -892,10 +892,10 @@ impl NicCtx {
|
|||||||
let mut cur_proxy_cidrs = BTreeSet::<cidr::Ipv4Cidr>::new();
|
let mut cur_proxy_cidrs = BTreeSet::<cidr::Ipv4Cidr>::new();
|
||||||
|
|
||||||
// Initial sync: get current proxy_cidrs state and apply routes
|
// Initial sync: get current proxy_cidrs state and apply routes
|
||||||
let (added, removed) = ProxyCidrsMonitor::diff_proxy_cidrs(
|
let (_, added, removed) = ProxyCidrsMonitor::diff_proxy_cidrs(
|
||||||
peer_mgr.as_ref(),
|
peer_mgr.as_ref(),
|
||||||
&global_ctx,
|
&global_ctx,
|
||||||
&mut cur_proxy_cidrs,
|
&cur_proxy_cidrs,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
Self::apply_route_changes(
|
Self::apply_route_changes(
|
||||||
@@ -921,10 +921,10 @@ impl NicCtx {
|
|||||||
);
|
);
|
||||||
event_receiver = event_receiver.resubscribe();
|
event_receiver = event_receiver.resubscribe();
|
||||||
// Full sync after lagged to recover consistent state
|
// Full sync after lagged to recover consistent state
|
||||||
let (added, removed) = ProxyCidrsMonitor::diff_proxy_cidrs(
|
let (_, added, removed) = ProxyCidrsMonitor::diff_proxy_cidrs(
|
||||||
peer_mgr.as_ref(),
|
peer_mgr.as_ref(),
|
||||||
&global_ctx,
|
&global_ctx,
|
||||||
&mut cur_proxy_cidrs,
|
&cur_proxy_cidrs,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
GlobalCtxEvent::ProxyCidrsUpdated(added, removed)
|
GlobalCtxEvent::ProxyCidrsUpdated(added, removed)
|
||||||
|
|||||||
Reference in New Issue
Block a user