Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: remove only duplicate proxy cidr from prefix_trie#2175

Open
ZnqbuZ wants to merge 3 commits into
EasyTier:mainfrom
ZnqbuZ:fix/proxy-filter
Open

fix: remove only duplicate proxy cidr from prefix_trie#2175
ZnqbuZ wants to merge 3 commits into
EasyTier:mainfrom
ZnqbuZ:fix/proxy-filter

Conversation

@ZnqbuZ
Copy link
Copy Markdown
Contributor

@ZnqbuZ ZnqbuZ commented Apr 27, 2026

@ZnqbuZ ZnqbuZ closed this Apr 27, 2026
@ZnqbuZ ZnqbuZ reopened this Apr 27, 2026
@ZnqbuZ ZnqbuZ force-pushed the fix/proxy-filter branch 2 times, most recently from 5c5d28f to 2c1dc82 Compare April 27, 2026 22:48
@ZnqbuZ ZnqbuZ marked this pull request as ready for review April 28, 2026 00:10
@KKRainbow KKRainbow requested a review from Copilot April 30, 2026 11:45
routes.into_iter().collect()
} else {
// Collect proxy_cidrs from routes
let mut proxy_cidrs = peer_mgr.list_proxy_cidrs().await;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原先的 list_proxy_cidrs 性能应该显著高于全量的 list_routes,proxy_cidrs 本身也是一个 BTreeSet 可以去重。为什么要改呢

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

确实,我单纯是想退回那个 pr 前的逻辑,之前用的是 list_routes,倒是没有考虑性能问题,那我把这个撤销,只留下修补那个最长匹配的修改

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

说起来这个 prefix_trie::PrefixSet 好像天生也能实现去重 + 最长匹配,不过我没细看

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该是,但我之前有个 pr 把远程过来的 cidr 只要是本地 cidr 的子网那就都扔了,这个是不对的,我现在改成完全相等的才去掉,这样能自动最长匹配

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors how proxy CIDRs are derived from peer routing state so that duplicate proxy CIDRs announced by another peer don’t end up being treated as separate proxy routes, aligning behavior with the prior fixes around overlapped/duplicate CIDR handling.

Changes:

  • Changes route-table building to skip only exact duplicate remote proxy CIDRs (and relies on LPM for overlaps).
  • Removes list_proxy_cidrs{,_v6} from the routing traits/manager and instead derives proxy CIDRs from list_routes().
  • Updates tests to reflect the new semantics around overlapped/duplicate proxy CIDRs.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
easytier/src/tests/three_node.rs Removes proxy-route “wait” steps in the loop-prevention test scenario.
easytier/src/peers/route_trait.rs Removes list_proxy_cidrs{,_v6} from the Route trait and the mock implementation.
easytier/src/peers/peer_ospf_route.rs Updates proxy CIDR filtering logic (duplicates only), populates per-peer route.proxy_cidrs via the CIDR→peer maps, and adjusts an overlap-related unit test expectation.
easytier/src/peers/peer_manager.rs Removes proxy CIDR listing helpers now that the trait methods are gone.
easytier/src/instance/proxy_cidrs_monitor.rs Derives proxy CIDRs by scanning list_routes() output instead of calling the removed CIDR helpers.
Comments suppressed due to low confidence (2)

easytier/src/peers/peer_ospf_route.rs:1646

  • The skip condition was changed to only filter exact duplicate CIDRs (local_proxy_cidrs.contains(&cidr)), but the debug message still says the remote CIDR is "covered by" the local CIDR. This is misleading now that subset/overlap filtering is no longer performed; please update the log message (and/or surrounding comment) to reflect that only exact duplicates are skipped.
                if *peer_id != my_peer_id && local_proxy_cidrs.contains(&cidr) {
                    tracing::debug!(
                        ?peer_id,
                        ?my_peer_id,
                        ?local_proxy_cidrs,
                        ?cidr,
                        "skip remote proxy cidr covered by local announced proxy cidr while building route table"
                    );

easytier/src/tests/three_node.rs:1049

  • This test removed the waits that ensured the proxy-route state had converged before exercising the loop scenario. With the new "duplicate CIDR" behavior, it would be better to explicitly assert the expected route-table outcome (e.g., that a peer does not learn a remote proxy route for an identical CIDR) or otherwise wait for route-table stabilization; otherwise the ping/metric loop can pass trivially if routing info hasn’t propagated yet, reducing the test’s effectiveness and making it timing-sensitive.
    // 从 inst1 (net_a) 发起对 10.1.2.5 的 ping 测试
    // 这应该失败,并且不会产生环路
    let now = std::time::Instant::now();
    while now.elapsed().as_secs() < 10 {
        ping_test("net_a", "10.1.2.5", None).await;
        tokio::time::sleep(Duration::from_secs(1)).await;
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread easytier/src/instance/proxy_cidrs_monitor.rs Outdated
Comment thread easytier/src/instance/proxy_cidrs_monitor.rs Outdated
@ZnqbuZ ZnqbuZ force-pushed the fix/proxy-filter branch from 0221407 to b46569b Compare April 30, 2026 14:52
@ZnqbuZ ZnqbuZ changed the title refactor: filter duplicate proxy cidrs from peer fix: remove only duplicate proxy cidr from prefix_trie Apr 30, 2026
@ZnqbuZ ZnqbuZ force-pushed the fix/proxy-filter branch 2 times, most recently from f3c1876 to a478f55 Compare April 30, 2026 17:20
@KKRainbow KKRainbow requested a review from Copilot May 1, 2026 03:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts proxy CIDR handling in the OSPF route table builder so that only duplicate remote proxy CIDRs are excluded, allowing overlapped (more specific) prefixes to be selected by longest-prefix-match (LPM) in the data plane.

Changes:

  • Refactors CIDR containment logic into an IpCidrExt::covers() helper and simplifies string-based subset checks.
  • Changes local proxy CIDR collection to a HashSet and updates filtering to skip only exact-duplicate remote CIDRs (vs. skipping subsets).
  • Updates the overlapped-proxy-CIDR test to assert LPM behavior (remote /24 wins over local /16).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

p.first_address() <= c.first_address() && c.last_address() <= p.last_address()
}
_ => false, // mixed v4/v6
pub trait IpCidrExt {
Comment on lines +1635 to 1638
if *peer_id != my_peer_id && local_proxy_cidrs.contains(&cidr) {
tracing::debug!(
?peer_id,
?my_peer_id,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR 确实改变了语义吧

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得原先的语义好像是对的

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你意思是不用最长匹配吗?按原来的做法即便远程来的子网更小也是本地优先

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local_proxy_cidrs 不是 hashset 么,是怎么做到最长匹配的呀

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local_proxy_cidrs 是判断 peer 的路由是不是恰好和本地的某个路由相等,所以 hashset 就够了,如果不是恰好相等——可能重合,可能 peer 的完全包含于本地的 cidr,等等——那么就留下 peer 的 cidr, 加入 new_cidr_prefix_trie,然后让 new_cidr_prefix_trie 去做最长匹配

@ZnqbuZ ZnqbuZ force-pushed the fix/proxy-filter branch from a478f55 to f1663ac Compare May 3, 2026 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants