From 4a84ed4f77e228db4cb2598d3003e627457d216d Mon Sep 17 00:00:00 2001 From: Cd1s <135119404+Cd1s@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:18:06 +0800 Subject: [PATCH 1/2] wifi: rekey the GTK every 10 min so a repeater that re-associates gets broadcasts back A MAC-translating repeater (RAX40) that re-associates without rebooting is handed the GTK it already holds and then drops every group-addressed frame: its wired clients see DHCP OFFERs stop arriving and broadcast ARP gets no reply, while unicast keeps working. hostapd's CCMP default rekeys once a day, so only a hostapd restart (new GTK) brought them back. Render wpa_group_rekey=600 (hostapd's default before 2.10) in every encrypted BSS. That bounds the outage to one rekey interval, with no restart and no client drop. Co-Authored-By: Claude Opus 5.5 --- docs/modules/wifi.md | 23 +++++++++++++++++++ mr/mod_wifi.go | 7 +++++- mr/mod_wifi_test.go | 7 ++++++ .../wifi-home/hostapd-phy0.conf.golden | 1 + .../wifi-home/hostapd-phy1.conf.golden | 1 + 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/docs/modules/wifi.md b/docs/modules/wifi.md index fe2a581..510e26c 100644 --- a/docs/modules/wifi.md +++ b/docs/modules/wifi.md @@ -79,6 +79,29 @@ wifi: 密码:8–63 个可打印 ASCII。WPA3 的密码不能包含 `|mac=`、`|vlanid=`、`|pk=`、`|id=` (hostapd 解析 `sae_password` 时会把它们当成参数截断,等于换了一个密码)。 +每个加密 SSID 都写 `wpa_group_rekey=600`:组密钥(GTK)每 10 分钟换一次(hostapd 2.10 起 CCMP 默认一天一次, +2.10 之前默认就是 600)。换组密钥是逐个终端的 EAPOL 组密钥握手,终端不掉线。原因见下面的排查。 + +#### 排查:中继器后面的有线设备拿不到 DHCP / 广播不通 + +现象:中继器(如 RAX40,MAC 转换模式,下游设备都显示成中继器的 MAC)自己能上网,单播 ping 通,但它后面的 +设备只有 DHCPDISCOVER/OFFER,没有 REQUEST(或 REQUEST 收不到 ACK),`arping -b -I br-lan <中继器 IP>` 0 回复。 + +原因:中继器没重启、只是重新关联(例如开机后约 30 秒它自己再关联一次),AP 给的还是它已有的那把 GTK, +它的固件就不再收组播/广播帧(单播用的是每次新协商的 PTK,不受影响)。AP 重启或换了 GTK 后就好。所以重启路由器 +或 `rc-service mr-hostapd restart` 能“修好”,但下次中继器重新关联又会坏。和 AP 运行多久、AKM、beacon 保护无关。 + +判断: + +```sh +hostapd_cli -i phy1-ap0 sta <中继器 MAC> | grep -E 'connected_time|AKMSuite' # 关联多久了 +arping -b -I br-lan -c 2 -w 3 <中继器 IP> # -b:只发广播;0 回复 = 收不到广播 +grep -E 'group key handshake|<中继器 MAC>' /var/log/messages | tail # 最近一次换 GTK、关联记录 +``` + +处理:等下一次换 GTK(最多 10 分钟)自己恢复;急用时 `rc-service mr-hostapd restart`(全部 Wi-Fi 断约 5 秒)。 +不要用 `hostapd_cli reload`(会让 5G 终端因“不活动”被踢、连不上);不要为此改 AKM / PMF。 + ### 客户端隔离 `isolate: true` 做两件事: diff --git a/mr/mod_wifi.go b/mr/mod_wifi.go index 38869a4..88e518c 100644 --- a/mr/mod_wifi.go +++ b/mr/mod_wifi.go @@ -240,7 +240,12 @@ func renderHostapd(c *Config, r Radio) (string, error) { if err != nil { return "", err } - b.WriteString("wpa=2\nwpa_pairwise=CCMP\nokc=1\n") + // wpa_group_rekey: hostapd's CCMP default is one GTK per day. A station that re-associates + // without its own reboot can be handed the GTK it already holds and then drop every + // group-addressed frame (seen with a MAC-translating repeater: no DHCP OFFER or broadcast ARP + // for its wired clients until hostapd restarted). A fresh GTK every 10 min bounds that outage + // without a restart; 600 s was hostapd's own default before 2.10. + b.WriteString("wpa=2\nwpa_pairwise=CCMP\nokc=1\nwpa_group_rekey=600\n") w := ssidPMF(s) switch s.Encryption { case "psk2": diff --git a/mr/mod_wifi_test.go b/mr/mod_wifi_test.go index ed61f51..85c856e 100644 --- a/mr/mod_wifi_test.go +++ b/mr/mod_wifi_test.go @@ -117,6 +117,13 @@ func TestWifiLabRender(t *testing.T) { if last := p1[strings.LastIndex(p1, "bss="):]; strings.Contains(last, "wpa=") { t.Error("open SSID got WPA settings") } + // every encrypted BSS rekeys its GTK every 10 min (a repeater that re-associates with a stale GTK + // loses broadcasts until the next one); the open BSS has no GTK + for name, p := range map[string]string{"phy0": p0, "phy1": p1} { + if w, g := strings.Count(p, "wpa=2\n"), strings.Count(p, "wpa=2\nwpa_pairwise=CCMP\nokc=1\nwpa_group_rekey=600\n"); w == 0 || g != w { + t.Errorf("%s: %d encrypted BSSes, %d with wpa_group_rekey=600", name, w, g) + } + } if got["/etc/hostapd/phy0-ap0-1.maclist"] != "# generated by mr — edit router.yaml instead\naa:bb:cc:00:00:01\naa:bb:cc:00:00:02\n" { t.Errorf("allow list: %q", got["/etc/hostapd/phy0-ap0-1.maclist"]) } diff --git a/mr/testdata/wifi-home/hostapd-phy0.conf.golden b/mr/testdata/wifi-home/hostapd-phy0.conf.golden index 32cad7a..42bc7dd 100644 --- a/mr/testdata/wifi-home/hostapd-phy0.conf.golden +++ b/mr/testdata/wifi-home/hostapd-phy0.conf.golden @@ -64,6 +64,7 @@ basic_rates=60 120 240 wpa=2 wpa_pairwise=CCMP okc=1 +wpa_group_rekey=600 wpa_key_mgmt=SAE WPA-PSK WPA-PSK-SHA256 ieee80211w=1 sae_require_mfp=1 diff --git a/mr/testdata/wifi-home/hostapd-phy1.conf.golden b/mr/testdata/wifi-home/hostapd-phy1.conf.golden index 656b2c2..39dbf14 100644 --- a/mr/testdata/wifi-home/hostapd-phy1.conf.golden +++ b/mr/testdata/wifi-home/hostapd-phy1.conf.golden @@ -68,6 +68,7 @@ ap_isolate=0 wpa=2 wpa_pairwise=CCMP okc=1 +wpa_group_rekey=600 wpa_key_mgmt=SAE WPA-PSK WPA-PSK-SHA256 ieee80211w=1 sae_require_mfp=1 From dbd946f54020fd8f55c5b3ed3e635d6c969b8e49 Mon Sep 17 00:00:00 2001 From: Cd1s <135119404+Cd1s@users.noreply.github.com> Date: Thu, 19 Nov 2026 00:52:02 +0800 Subject: [PATCH 2/2] wifi: correct the GTK rekey rationale after the live repro The live repro on 2026-11-18 showed that the repeater does not lose broadcasts just from re-associating with an unchanged GTK: an AP-side deauth plus reconnect stayed fine. The loss follows the repeater's own reboot and re-associations. Once it lasted ~2.5 min and healed by itself; once it lasted until a hostapd restart (fresh association + new GTK). Comment, test comment and the troubleshooting note now say that. Co-Authored-By: Claude Opus 5.5 --- docs/modules/wifi.md | 9 +++++---- mr/mod_wifi.go | 10 +++++----- mr/mod_wifi_test.go | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/modules/wifi.md b/docs/modules/wifi.md index 510e26c..c8bada9 100644 --- a/docs/modules/wifi.md +++ b/docs/modules/wifi.md @@ -87,9 +87,10 @@ wifi: 现象:中继器(如 RAX40,MAC 转换模式,下游设备都显示成中继器的 MAC)自己能上网,单播 ping 通,但它后面的 设备只有 DHCPDISCOVER/OFFER,没有 REQUEST(或 REQUEST 收不到 ACK),`arping -b -I br-lan <中继器 IP>` 0 回复。 -原因:中继器没重启、只是重新关联(例如开机后约 30 秒它自己再关联一次),AP 给的还是它已有的那把 GTK, -它的固件就不再收组播/广播帧(单播用的是每次新协商的 PTK,不受影响)。AP 重启或换了 GTK 后就好。所以重启路由器 -或 `rc-service mr-hostapd restart` 能“修好”,但下次中继器重新关联又会坏。和 AP 运行多久、AKM、beacon 保护无关。 +原因在中继器固件:它重启后会自己连续重新关联几次(间隔约 30 秒到 2 分钟),这期间及之后有时就不再收组播/广播帧 +(单播用每次新协商的 PTK,不受影响)。2026-11-18 的两次断电里,一次只断了约 2.5 分钟、第三次关联后自己好了, +一次一直坏到 `rc-service mr-hostapd restart`(重新关联 + 新 GTK)。已排除:路由器镜像版本、AP 运行时长、AKM / PMF、 +beacon 保护、GTK 的 RSC;AP 主动踢掉中继器后它重连也正常。每 10 分钟换 GTK 等于定期做“新 GTK”这一半,不用断网。 判断: @@ -99,7 +100,7 @@ arping -b -I br-lan -c 2 -w 3 <中继器 IP> grep -E 'group key handshake|<中继器 MAC>' /var/log/messages | tail # 最近一次换 GTK、关联记录 ``` -处理:等下一次换 GTK(最多 10 分钟)自己恢复;急用时 `rc-service mr-hostapd restart`(全部 Wi-Fi 断约 5 秒)。 +处理:先等几分钟(中继器刚开机时会自己恢复)和下一次换 GTK(最多 10 分钟);还不好或急用时 `rc-service mr-hostapd restart`(全部 Wi-Fi 断约 5 秒)。 不要用 `hostapd_cli reload`(会让 5G 终端因“不活动”被踢、连不上);不要为此改 AKM / PMF。 ### 客户端隔离 diff --git a/mr/mod_wifi.go b/mr/mod_wifi.go index 88e518c..ed09dd2 100644 --- a/mr/mod_wifi.go +++ b/mr/mod_wifi.go @@ -240,11 +240,11 @@ func renderHostapd(c *Config, r Radio) (string, error) { if err != nil { return "", err } - // wpa_group_rekey: hostapd's CCMP default is one GTK per day. A station that re-associates - // without its own reboot can be handed the GTK it already holds and then drop every - // group-addressed frame (seen with a MAC-translating repeater: no DHCP OFFER or broadcast ARP - // for its wired clients until hostapd restarted). A fresh GTK every 10 min bounds that outage - // without a restart; 600 s was hostapd's own default before 2.10. + // wpa_group_rekey: hostapd's CCMP default is one GTK per day. A MAC-translating repeater (RAX40) + // has stopped receiving group-addressed frames after its own reboot and re-associations (its + // wired clients got no DHCP OFFER or broadcast ARP) until a hostapd restart gave it a fresh + // association and a new GTK. A new GTK every 10 min is the restart-free half of that remedy; + // stations stay associated. 600 s was hostapd's own default before 2.10. b.WriteString("wpa=2\nwpa_pairwise=CCMP\nokc=1\nwpa_group_rekey=600\n") w := ssidPMF(s) switch s.Encryption { diff --git a/mr/mod_wifi_test.go b/mr/mod_wifi_test.go index 85c856e..139b5d5 100644 --- a/mr/mod_wifi_test.go +++ b/mr/mod_wifi_test.go @@ -117,8 +117,8 @@ func TestWifiLabRender(t *testing.T) { if last := p1[strings.LastIndex(p1, "bss="):]; strings.Contains(last, "wpa=") { t.Error("open SSID got WPA settings") } - // every encrypted BSS rekeys its GTK every 10 min (a repeater that re-associates with a stale GTK - // loses broadcasts until the next one); the open BSS has no GTK + // every encrypted BSS rekeys its GTK every 10 min (a repeater that lost group frames after its own + // reboot only recovered with a new GTK); the open BSS has no GTK for name, p := range map[string]string{"phy0": p0, "phy1": p1} { if w, g := strings.Count(p, "wpa=2\n"), strings.Count(p, "wpa=2\nwpa_pairwise=CCMP\nokc=1\nwpa_group_rekey=600\n"); w == 0 || g != w { t.Errorf("%s: %d encrypted BSSes, %d with wpa_group_rekey=600", name, w, g)