DanielLavrushin 报告 b4 跨接口共用手动路由表时可能留下默认路由

DanielLavrushin 报告,b4 两个 set 手动固定到同一路由表、经不同接口安装默认路由时,后安装的同 metric 路由会替换前者。清理只在最后一个 set 退出时、按该 set 的接口删除;若其路由已被替换,另一个接口的默认路由可能残留,而规则已被移除,启动清扫也不会再访问该表。他称在 Linux 3.16、4.9、7.0 上观察到此行为;现有共享表告警只检查网关不同,未覆盖接口不同。他建议在最后退出时清理该表内所有 b4 标记默认路由,或扩展接口冲突校验,尚未给出已发布修复。

作者原文

Problem

Two sets pinned to the same routing.table through different interfaces leave one of b4's default routes behind.

  • Both sets install replace default dev <iface> proto 155 table T at the same metric, so the second set's route replaces the first set's (routing.go#L2805).
  • The cleanup deletes the table's routes only for the last set to leave, and only through that set's interface (routing.go#L2345-L2347).
  • If the set whose route was replaced leaves last, its delete matches nothing and the other set's route stays. The ip rule is gone by then, so the startup sweep never visits that table again.
  • findSharedTableGatewayClashes warns about sets that share a table with different gateways (validation.go#L201), but not about different interfaces.

Measured

Kernels 3.16, 4.9 and 7.0, one table:

replace default dev d0 proto 155   # set A
replace default dev d1 proto 155   # set B
-> default dev d1 proto 155 scope link
del default dev d0                 # set A leaves last
-> RTNETLINK answers: No such process
-> default dev d1 proto 155 scope link stays

Suggested direction

Either of:

  • when the last set leaves a table, delete every b4-tagged default in it whatever its device, where b4 tags its routes;
  • extend the shared-table validation warning to sets with different interfaces, since their default routes overwrite each other the same way as different gateways.

Found while reviewing #739.