Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix GeoIPMatcher failure #1155

Closed
wants to merge 1 commit into from
Closed

Conversation

maskedeken
Copy link
Contributor

GeoIPMatcher的匹配逻辑是先把CIDR从小到大排序,然后用折半查找的方式检查目标IP是否被包含,但CIDR的排序逻辑有点问题,遇到IP相同而掩码不同的时候,把掩码小的排在前面,这就导致IP可能会匹配失败。

设想目前CIDRList排序后是这样:["98.108.20.0/22", "98.108.20.0/23"],匹配98.108.22.11就会失败,因为折半时刚好从元素[1]开始,这时匹配失败,继续往后找已经没有更多元素了。

所以排序的正确顺序是这样:["98.108.20.0/23", "98.108.20.0/22"],也就是把掩码大的排在前面

@Loyalsoldier
Copy link
Contributor

细想这个方法并不能从根本上解决问题。应该在生成和载入 CIDR 的时候就要合并和去重。

@maskedeken
Copy link
Contributor Author

细想这个方法并不能从根本上解决问题。应该在生成和载入 CIDR 的时候就要合并和去重。

不能保证geoip.dat都是官方的

@Loyalsoldier
Copy link
Contributor

细想这个方法并不能从根本上解决问题。应该在生成和载入 CIDR 的时候就要合并和去重。

不能保证geoip.dat都是官方的

所以在往 V2Ray 载入 CIDR 的时候,需要合并和去重才能根本解决问题。

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.

2 participants