DanielLavrushin:b4 的 sysctl 快照短暂读失败可能覆盖原始值
DanielLavrushin 报告,b4 读取 conntrack sysctl 快照时把读取错误当成空快照;若 b4 已应用自己的值,后续规则轮次遇到一次 EMFILE 等短暂读失败,就可能把当前值重新保存为“原始值”,停止时因而无法恢复路由器原来的设置。他称已用一次性注入读失败的探针复现,并指出 main 中也有相同的空快照回退。作者建议区分短暂读取故障与快照缺失:发生短暂故障时跳过该轮 Apply/RevertBack,而非覆盖快照或改用其他目录。
作者原文@DanielLavrushinb4 saves the original values of the conntrack sysctls it changes (
nf_conntrack_checksum,nf_conntrack_tcp_be_liberal,nf_conntrack_acct) before it sets its own, and writes them back when it stops.SysctlSetting.Applysaves a value only when the snapshot has no entry for it yet.Any error while reading the snapshot file, other than the file not being there, makes the load return an empty map, exactly as if nothing had been saved. On a rules pass after b4 has applied its values (a monitor restore, a config change), that means:
- reading the snapshot fails for a moment, for example with
EMFILEwhile b4 is near its open-file limit;Applyfinds no entry, reads the live value, which is now b4's own (checksum 0, liberal 1), and saves it as the original over the file that held the router's values;- on stop, b4 writes its own values back, and the router keeps them until a reboot.
Probed with an
-overlaycopy ofsrc/tables/sysctl_snapshot.gowhoseopenatreturnsEMFILEonce during a rules pass: the file then heldchecksum:0, liberal:1, and the stop wrote 0/1 where the originals were 1/0. The same fallback exists on main (loadSysctlSnapshotinsrc/tables/iptables.goreturns{}for any read error).Suggested direction
- Tell a read that failed for a passing reason apart from "nothing saved" and from a file b4 does not trust.
- On such a failure,
ApplyandRevertBackleave the sysctl as it is for that pass and log it once.- A passing error while choosing the snapshot's directory does not move b4 on to the next candidate.
Found while reviewing #699.