cqc0101/openwrt-proxy-skills / skills/dae-openwrt
dae-openwrt
Flagged在 OpenWrt、ImmortalWrt、iStoreOS 上生成、部署和排查原生 dae 配置。适用于 eBPF 接口绑定、routing/dns/group 规则、订阅导入与热重载;不接管 daed 面板配置。
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 13.9 KB |
| assets/templates/openwrt.dae | other | 5.3 KB |
| references/dae-rules-and-syntax.md | markdown | 6.6 KB |
| references/runtime-checks.md | markdown | 6.5 KB |
| references/troubleshooting.md | markdown | 6.2 KB |
| scripts/check_dae_syntax.py | script | 18.9 KB |
| scripts/check_path.py | script | 3.9 KB |
| scripts/diagnose_dns.sh | script | 17.1 KB |
| scripts/doctor.sh | script | 18.2 KB |
| scripts/node_link.py | script | 2.0 KB |
| scripts/parse_node.py | script | 26.5 KB |
| scripts/probe.sh | script | 22.1 KB |
| scripts/setup_openwrt_network.sh | script | 24.0 KB |
| scripts/sub_parser.py | script | 75.4 KB |
| scripts/sub_to_dae.py | script | 15.9 KB |
references/dae-rules-and-syntax.md
View on GitHub# dae 规则语法、五大约束与模块化组装指南
> 本指南将 dae eBPF 官方规范浓缩为 AI Agent 可直接理解和组装的紧凑规则体系,消除多级文档冗余。
---
## 一、 dae 语义与拓扑五大约束 (Golden Rules)
1. **单引号词法规范**:
除 `ext:"xxx.dat:tag"` 外部文件引用外,所有包含冒号 `:`、斜杠 `/`、正则或复合协议的字符串,统一使用单引号 `'...'` 包裹(如 `tcp_check_url: 'http://cp.cloudflare.com'`)。
2. **must_direct 宿主防环约束**:
dae 默认拦截所有发往 53 端口的请求。独立解析模式下,`dnsmasq` 等宿主组件的 DNS 可在 `routing {}` 首行旁路;dae 接管模式需按末尾「DNS 拓扑与节点验收」调整:
```shell
pname(dnsmasq, odhcpd, netifd, uhttpd) && l4proto(udp) && dport(53) -> must_direct
```
3. **布尔取反 (!) 合并约束**:
两行独立的 `!` 规则在 dae 中为 OR 语义。表达“既不属于 A 也不属于 B”必须合并写在同一行内:
```shell
!domain(geosite:a, geosite:b) -> my_group
```
4. **短路匹配 (First-Match) 六层黄金顺序**:
- [第 1 层] 核心宿主进程与私网广播保护:`pname(dnsmasq, ...) -> must_direct` 及 `dip(geoip:private) -> direct`
- [第 2 层] 大流量下载与 P2P 绕行:`pname(aria2c, qbittorrent-nox) -> must_direct`
- [第 3 层] 境外 QUIC 抑制与 Canary 阻断:
`l4proto(udp) && dport(443) && !domain(geosite:cn) -> block`
`domain(suffix: use-application-dns.net, suffix: mask.icloud.com, suffix: mask-h2.icloud.com) -> block`
- [第 4 层] 重点海外服务专属分流:`domain(geosite:google, geosite:openai) -> proxy`
- [第 5 层] 大陆大盘双向白名单直连:`domain(geosite:cn) -> direct` 及 `dip(geoip:cn) -> direct`
- [第 6 层] 终态回落兜底:`fallback: proxy`
5. **DNS 响应投毒重查闭环与 `qname` 词法规范**:
- 在 `dns.routing.response` 中,首行必须为白名单放行,防止无限递归死锁;
- 在 `dns.routing.request` 中,`qname(...)` 的底层 `addQName` 解析器**强制要求显式前缀键**(`geosite:`、`full:`、`suffix:`、`keyword:`、`regex:`、`ext:`),严禁像 `routing.domain()` 那样直接传入无前缀的单引号域名(如 `qname('use-application-dns.net')` 会直接报 `addQName: unsupported key:`),且避免在 DNS 阶段加载含特殊前缀的 `geosite:category-ads-all`;**域名黑名单与 Canary 阻断应统一放在 `routing {}` 的 `domain(...) -> block` 中**。
```shell
response {
upstream(googledns) -> accept
ip(geoip:private) && !qname(geosite:cn) -> googledns
fallback: accept
}
```
---
## 二、 常用匹配选择器速查 (Routing Selectors)
| 选择器 | 语法示例 | 说明 |
| :--- | :--- | :--- |
| **进程匹配** | `pname(dnsmasq, aria2c)` | 匹配软路由本机发起的进程名 |
| **目标 IP** | `dip(geoip:private, 223.5.5.5)` | 匹配目标 IP 或 GeoIP 集合 |
| **源 IP / MAC** | `sip(192.168.1.100)`, `mac('00:11:22:33:44:55')` | 匹配局域网特定设备 |
| **目标域名** | `domain(geosite:cn, 'example.com')` | 匹配域名或 Geosite 规则集 |
| **传输协议/端口** | `l4proto(udp) && dport(53, 443)` | 匹配四层协议 (tcp/udp) 与端口 |
---
## 三、 复杂网络拓扑模块化组装配方 (Recipes)
### 配方 A:标准主路由模式 (Main Gateway)
```shell
global {
lan_interface: br-lan
wan_interface: auto
auto_config_kernel_parameter: true
tcp_check_url: 'http://cp.cloudflare.com'
}
routing {
pname(dnsmasq, odhcpd, netifd, uhttpd) && l4proto(udp) && dport(53) -> must_direct
dip(224.0.0.0/3, 'ff00::/8') -> direct
dip(geoip:private) -> direct
domain(suffix: use-application-dns.net, suffix: mask.icloud.com, suffix: mask-h2.icloud.com) -> block
domain(geosite:cn) -> direct
dip(geoip:cn) -> direct
fallback: proxy
}
```
### 配方 B:单网口旁路由模式 (Bypass Gateway)
```shell
global {
lan_interface: br-lan
wan_interface: auto
auto_config_kernel_parameter: true
}
routing {
pname(dnsmasq, odhcpd, netifd, uhttpd) && l4proto(udp) && dport(53) -> must_direct
dip(192.168.1.1) -> direct # 放行主路由自身 IP
dip(geoip:private) -> direct
domain(suffix: use-application-dns.net, suffix: mask.icloud.com, suffix: mask-h2.icloud.com) -> block
domain(geosite:cn) -> direct
dip(geoip:cn) -> direct
fallback: proxy
}
```
> **旁路由防火墙配套**:必须在 OpenWrt LAN 区域执行 `uci set firewall.@zone[LAN].masq='1'`(或运行 `setup_openwrt_network.sh --bypass`)消除非对称路由丢包。
## DNS 拓扑与节点验收
`must_direct` 是旁路规则,不是可信 DNS 保证。默认模板保留 dnsmasq 防环规则以兼容现有部署,但必须核对 dnsmasq 的 resolvfile、server 和实际查询出口;私网上级路由器与公网明文解析器都不自动可信。
- dnsmasq 独立解析:保留 `pname(dnsmasq, odhcpd, netifd, uhttpd) && l4proto(udp) && dport(53) -> must_direct`,由已验证的独立解析链路保证可信与可用。
- dae 接管 dnsmasq:生成配置时显式指定 `--dnsmasq-mode intercept`,保留其他宿主组件防环规则,移除 dnsmasq 的旁路。先确认 dae 上游不回指 dnsmasq、本机 53 或上级回流服务,再验证 LAN 查询、节点冷启动、重载及回退。不能无条件删掉 dnsmasq 保护。
离线静态检查无法证明实际无环,所以两种模式均提示运行期核查,不把规则缺失直接判为必然死循环。执行 `sh scripts/diagnose_dns.sh --json --compare-server=8.8.8.8` 可比较本机与指定端点;这只是端点对照,不能假定后者一定经过 dae 或两者路径独立。CDN、缓存、策略也会产生不同答案,不能凭某个 IP 段直接断言污染或封锁。
配置含多个节点不代表有多个可用备用;只将实际认证、转发成功的节点加入组。多个 `filter` 行会扩大候选集合,但不能取代健康验证。未测得延迟的 0ms 记录不是可用证明;日志里的临时选择也不证明该节点已经承载成功请求。单节点组可以是主动隔离测试或用户固定选择,报告单点风险,不自动添加未验证节点。
`dae validate` 的候选文件需以 `.dae` 结尾,权限设为 600。网络看门狗支持 `--watchdog --watchdog-seconds=120`(范围 10~600,默认 45 秒)。只切换节点时,使用[配置级备份与回退](./runtime-checks.md#判断与回退)。
SSH 可交互输入密码,或使用已核对主机指纹的密码客户端;不要把密码放在命令行、脚本或报告里,不通过关闭主机密钥验证解决连接问题。
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |