fix(net-filter): abort rule loading on invalid config - #151
Open
yuKing123-king wants to merge 1 commit into
Open
yuKing123-king wants to merge 1 commit into
yuKing123-king wants to merge 1 commit into
Conversation
Signed-off-by: Wang Yu <wangyu6@uniontech.com>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复 net-filter 配置加载失败时的规则回滚语义。
此前 load_rules() 在解析失败后为了避免半加载状态会调用 clear_rules(),但 clear_rules() 会清空整个 rules map。如果调用方在 load_rules() 前已经通过 add_rule()/update_rule() 添加过规则,加载配置失败时这些已有规则
也会被误删。
本次修改在 load_rules() 开始时记录 first_key,只在失败路径删除本次 load_rules() 成功添加的 key 区间,并将 key_cnt 回滚到加载前状态。这样可以保证配置加载失败时不会残留本次部分加载的规则,同时不会影响调用前已经
存在的规则。
同时放宽空行/注释行判断,支持跳过前导空格后的注释行和纯空白行,避免手写配置中常见的缩进注释或空白行导致整个配置加载失败。
验证:
先通过 add_rule() 添加一条 keep_rule,再调用 load_rules() 加载包含合法规则和 invalid-rule 的配置。load_rules() 返回 false,最终 rules map 中只保留 keep_rule,证明失败时仅回滚本次加载的规则,没有清空已有规则。