IPv6 delegation, an unusually subtle failure mode
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
IPv6 delegation, an unusually subtle failure mode
Running a custom x64 router has a lot of upsides. One, it runs mainline Linux, so it gets updates quickly. Two, router adblocking. ‘Nuff said. And three, if something breaks, you get to dive in deep and figure out what’s going wrong. This week, I had a really interesting time with my custom setup. I noticed that if I’d restart pppd (which connects to my ISP), Google would stop working. It would still resolve, but I couldn’t reach it.
运行自定义 x64 路由器有很多好处。首先,它运行的是主流 Linux,因此可以快速获得更新。其次是路由器广告拦截,无需多言。第三,如果出现故障,你可以深入研究并找出问题所在。本周,我在自定义设置上经历了一段非常有趣的时光。我注意到,如果我重启 pppd(连接到我的 ISP 的程序),Google 就会停止工作。它仍然可以解析,但我无法访问它。
Diagnosis
I have a stack where networkd is responsible for the network in general, with pppd dialing in to my ISP, kea-dhcp4 handing out DHCPv4 addresses, blocky handling DNS (on the router as well as the laptop) and networkd itself handling RA. As far as I knew, there was nothing wrong in this stack at all. All the daemons themselves are battle-tested and known to be working fine. So maybe this was a problem with my laptop?
诊断
我的网络栈中,networkd 负责常规网络,pppd 负责拨号连接到 ISP,kea-dhcp4 分配 DHCPv4 地址,blocky 处理 DNS(在路由器和笔记本电脑上),而 networkd 本身处理 RA。据我所知,这个栈没有任何问题。所有的守护进程都经过了实战检验,运行良好。那么,这可能是我的笔记本电脑的问题吗?
One ping told me that Google was getting resolved to its IPv6 address, which exonerated DNS, but I couldn’t ping it. An IPv4 address on the other hand, worked fine. On the other hand, wlan0 showed 2 groups of IPv6 addresses with the older IPv6 address having a preferred lifetime greater than 0. Could this be the culprit? I restarted NetworkManager, and lo and behold, Google magically started working again and I was down to just one group of IPv6 addresses, the newer ones.
一次 ping 操作告诉我,Google 能够解析到其 IPv6 地址,这排除了 DNS 的嫌疑,但我无法 ping 通它。另一方面,IPv4 地址工作正常。同时,wlan0 显示了两组 IPv6 地址,其中较旧的 IPv6 地址的首选生命周期大于 0。这会是罪魁祸首吗?我重启了 NetworkManager,奇迹发生了,Google 恢复了正常,并且我只剩下了一组 IPv6 地址,即较新的那组。
Solutioning
I’ve never debugged networks in depth, but the problem here seemed to be fairly simple to grasp. Whenever pppd restarts, it negotiates a new connection with my ISP, which provides a new prefix to my router for delegation. However, no device drops the old IPv6 address. At first I thought this was NetworkManager’s fault, but then I saw my iPhone do the same thing. Two points don’t make a pattern, but they do make a line. Which pointed straight at networkd.
解决方案
我从未深入调试过网络,但这里的问题似乎很容易理解。每当 pppd 重启时,它都会与我的 ISP 协商一个新的连接,从而为我的路由器提供一个新的前缀进行委派。然而,没有任何设备丢弃旧的 IPv6 地址。起初我以为这是 NetworkManager 的错,但后来我发现我的 iPhone 也出现了同样的情况。两点不足以构成模式,但它们确实构成了一条线,直接指向了 networkd。
Don’t get me wrong. I like networkd. The only reason I have NetworkManager on my laptop is because it’s purpose built for Wi-Fi and roaming and it’s never let me down yet (iwd ftw). My router and server both run networkd. It’s a very comfortable, no-nonsense daemon. So I was reluctant to blame it. So I turned to pppd instead as a cop-out. I decided to ensure that pppd would never restart when I’d redeploy my NixOS router. But unfortunately, I’ve had times when my ISP has randomly hiccoughed and pppd reconnects to it leading to the same problem all over again. Which meant I’d have to get to the bottom of this.
别误会,我喜欢 networkd。我在笔记本电脑上使用 NetworkManager 的唯一原因是它是专为 Wi-Fi 和漫游构建的,而且它从未让我失望过(iwd 万岁)。我的路由器和服务器都运行 networkd。它是一个非常舒适、务实的守护进程。所以我不想责怪它,于是我转而把 pppd 当作替罪羊。我决定确保在重新部署 NixOS 路由器时 pppd 永远不会重启。但不幸的是,有时我的 ISP 会随机出现故障,导致 pppd 重新连接,从而再次引发同样的问题。这意味着我必须彻底查清此事。
A little bit of searching led me to RFC 9096, Improving the Reaction of Customer Edge Routers to IPv6 Renumbering Events, which tightens RFC 7084, Basic Requirements for IPv6 Customer Edge Routers. Basically, whenever a new prefix is given to the router and the old one dropped by upstream, the router needs to advertise the old prefix with preferred and valid lifetimes of 0 which causes consumers of the router advertisement to stop using it as a source address.
经过一番搜索,我找到了 RFC 9096《改进客户边缘路由器对 IPv6 重编号事件的反应》,它加强了 RFC 7084《IPv6 客户边缘路由器的基本要求》。基本上,每当路由器获得新前缀且旧前缀被上游丢弃时,路由器需要通告旧前缀,并将首选和有效生命周期设为 0,这会促使路由器通告的消费者停止将其用作源地址。
Interestingly, networkd has an issue RFC 7084 support in networkd (automatic ipv6 range delegation) where a requirement for properly implementing RFC 9096 came up in September 2026. There’s a patch as well which hasn’t yet been merged. The same issue has been brought up with radvd on OPNsense and closed as “not planned”, as well as with dnsmasq on OPNsense. VyOS’s dynamic-prefix support is still an open request.
有趣的是,networkd 有一个关于“在 networkd 中支持 RFC 7084(自动 IPv6 范围委派)”的问题,其中在 2026 年 9 月提出了正确实现 RFC 9096 的要求。目前有一个补丁尚未合并。同样的问题也曾在 OPNsense 的 radvd 上被提出并被关闭为“不计划处理”,在 OPNsense 的 dnsmasq 上也是如此。VyOS 的动态前缀支持仍然是一个悬而未决的请求。
Which meant that the usual suspects were out. There’s only one option left, and it’s not available on NixOS. odhcpd from OpenWrt, which actually does implement RFC 9096. I was a bit wary of relying on an OpenWrt package. Not because I think there’s anything wrong with OpenWrt (quite the contrary!), but because the distribution itself is unusual. It doesn’t use systemd or dbus, instead using procd as pid1 and uses ubus for IPC. I know that many of their packages depend on these two pieces of infrastructure to function, so that was the first thing I checked.
这意味着通常的嫌疑对象都被排除了。只剩下一个选择,而且它在 NixOS 上不可用:OpenWrt 的 odhcpd,它确实实现了 RFC 9096。我有点担心依赖 OpenWrt 的软件包。不是因为我认为 OpenWrt 有什么问题(恰恰相反!),而是因为该发行版本身很不寻常。它不使用 systemd 或 dbus,而是使用 procd 作为 pid1,并使用 ubus 进行 IPC。我知道他们的许多软件包都依赖这两个基础设施才能运行,所以我首先检查了这一点。
Fortunately, odhcpd is unusual in that it can get information from the kernel directly through netlink and can be configured without the need for ubus, so that was not a blocker. Packaging it took me a while, but I submitted it for review to nixpkgs and began running it on my router, switching off router advertisement on networkd. I could have used odhcpd for DHCP as well, but I was fairly happy with kea-dhcp4 so I left it alone. And lo and behold, when I deliberately restarted pppd, I got:
幸运的是,odhcpd 的独特之处在于它可以直接通过 netlink 从内核获取信息,并且无需 ubus 即可配置,因此这不是障碍。打包它花了我一些时间,但我将其提交给 nixpkgs 进行审查,并开始在我的路由器上运行它,同时关闭了 networkd 上的路由器通告。我本可以使用 odhcpd 进行 DHCP,但我对 kea-dhcp4 很满意,所以就没动它。奇迹出现了,当我故意重启 pppd 时,我得到了: