fix(net-traffic): initialize rules before loading network filters - #144
Open
yuKing123-king wants to merge 1 commit into
Open
fix(net-traffic): initialize rules before loading network filters#144yuKing123-king wants to merge 1 commit into
yuKing123-king wants to merge 1 commit into
Conversation
Signed-off-by: Wang Yu <wangyu6@uniontech.com>
|
/review |
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.
修复内容
本次修改主要修复
observe/net-traffic用户态规则初始化和规则安装时序问题。修复的 Bug
默认 PID 规则错误
原代码使用:
此时 rule.pid 默认值为 0,会导致未指定 -p 时规则仍然可能按照 PID 0 进行匹配。
当前通过 init_rule() 显式初始化:
pid = -1 表示不启用 PID 过滤。
入方向过滤值无法正确表示
入方向使用值 -1,因此将 Rule::dir 从无符号类型改为有符号的 short,避免 -1 被解释为 65535。
远端 IPv4 地址字节序不一致
原代码直接将 inet_addr() 的结果写入规则:
rule.remote_ip = inet_addr(optarg);
当前转换为主机字节序:
rule.remote_ip = ntohl(inet_addr(optarg));
使用户态规则中的 IP 格式与 BPF 侧比较使用的格式一致。
规则安装时序存在竞态
原流程是在 BPF attach 后才更新 filter map。attach 和 map 更新之间可能产生没有按照目标规则过滤的事件。
当前调整为:
open
fix_attach_point
load
update filter map
create ring buffer
attach
在 BPF 程序 attach 前先写入过滤规则,减少规则尚未生效期间产生的未过滤事件。
代码改动