校验与应用错误
源码文件:58 个 · 核对版本 Etemenanki 46c12e4 · katana v6.1.0 · shinku-quic v0.1.0
Etemenanki/supervisor/src/build/validate.rsEtemenanki/supervisor/src/build/apply.rsEtemenanki/supervisor/src/build/mod.rsEtemenanki/supervisor/src/lib.rsEtemenanki/supervisor/src/build/users.rsEtemenanki/supervisor/src/build/inbound.rsEtemenanki/supervisor/src/build/outbound.rsEtemenanki/supervisor/src/entity/id.rsEtemenanki/supervisor/src/entity/user.rsEtemenanki/supervisor/src/supervisor.rsEtemenanki/supervisor/src/topology/spec_plan/plan.rsEtemenanki/supervisor/src/topology/spec_plan/inbound.rsEtemenanki/supervisor/src/topology/spec_plan/transport.rsEtemenanki/supervisor/src/topology/inbound/mod.rsEtemenanki/supervisor/src/topology/balancer.rsEtemenanki/supervisor/src/topology/plane.rsEtemenanki/supervisor/src/system/listener.rsEtemenanki/protocols/src/hysteria/server/masquerade.rsEtemenanki/protocols/src/hysteria/auth.rsEtemenanki/protocols/src/hysteria/obfs.rsEtemenanki/protocols/src/hysteria/config.rsEtemenanki/protocols/src/tun/device.rsEtemenanki/protocols/src/transports/ws/endpoint.rsEtemenanki/protocols/src/ss_2022/users.rsEtemenanki/protocols/src/ss_2022/crypto.rsEtemenanki/protocols/src/anytls/padding.rsEtemenanki/protocols/src/sss/transform/stream.rsEtemenanki/protocols/src/helpers/address_family.rsEtemenanki/app/src/instance.rsEtemenanki/app/src/lower.rsEtemenanki/app/src/main.rsEtemenanki/app/src/api.rsEtemenanki/ffi/src/error.rsEtemenanki/webclient/src/lib.rsEtemenanki/webclient/src/router.rsEtemenanki/supervisor/tests/unit/validate.rsEtemenanki/supervisor/tests/unit/plan.rsEtemenanki/supervisor/tests/hot_swap.rsEtemenanki/supervisor/tests/sss.rsEtemenanki/protocols/tests/unit/hysteria/server/masquerade.rsEtemenanki/protocols/tests/unit/ss_2022/users.rsEtemenanki/app/tests/unit/lower.rsEtemenanki/app/tests/unit/subscribe.rskatana/src/main.rskatana/src/runtime.rskatana/src/manager/node.rskatana/src/lower/inbound.rskatana/src/lower/mod.rskatana/src/api/mod.rskatana/src/api/helium.rskatana/src/api/hysteria.rskatana/src/api/newv2board.rskatana/tests/unit/lower/outbound.rskatana/tests/unit/lower/spec.rskatana/tests/unit/lower/inbound.rskatana/tests/unit/api/helium.rskatana/tests/unit/runtime.rsshinku-quic/shinku-quic/src/hop.rs
Spec<U> 是有类型的,但类型表达不了哪些字段必须搭配出现、哪些 tag 存在、哪些值在范围之内。这些规则集中在一个函数里:supervisor/src/build/validate.rs → validate。任何运行 spec(期望状态)的路径,都要在构建任何东西之前先经过它。违反任一规则的 spec 会被整个拒绝,返回一个 ApplyError,正在运行的内容照常运行。本页按 validate 的检查顺序列出每条规则,以及它产生的变体和确切文本;然后介绍其余的 ApplyError 变体、试运行 check(),以及各个前端程序如何报告这些错误。
本页面向这样的贡献者:给某个 spec 类型加字段、修改某条规则,或者编写一个把自己的格式降为 spec 的前端程序。spec 类型本身见 spec:期望状态。校验之后发生的事(计划、准备(prepare)和提交(commit))见规划与应用变更。
build/validate.rs 负责 spec 含义上的每一条规则。它的模块注释写明了分工:前端程序只负责语法,也就是解析自己的格式和读取文件,因此不会出现一条规则只在某一侧检查的情况。这个模块是纯的:不碰 socket、不碰文件、不读时钟。校验也从不解析 PEM;证书字节对它是不透明的,单元测试直接把 b"cert" 当作证书传入。
validate 检查:
- tag 非空且在同类资源中唯一,并且没有负载均衡器与出站共用 tag;
- 负载均衡器、路由规则、路由默认出站或入站所指定的每个 tag 都存在;
- 每个负载均衡器成员都能通过 TCP 探测;
- 每个出站各字段之间是否一致(TLS 和 REALITY 设置与 shape、REALITY 只用于 VLESS、Vision 只走 REALITY、AnyTLS 走 TLS 且有密码、密钥长度、sss 限制、WireGuard 地址族、Hysteria 2 的端口跳跃和 QUIC 设置);
- 没有两个绑定相同或共用一个 socket 路径,每个协议都挂在它那一类绑定上,Unix socket 只在 Unix 上绑定,只有 TCP 绑定读取 PROXY protocol 头,只有 TCP 绑定上的 WebSocket 传输层读取真实 IP 头,其头名合法、至少有一个可信代理,以及交接 socket 只能在 Unix 上位于流式协议的 TCP 绑定旁边,路径是 Unix socket 能绑定的绝对路径,mode 只有权限位;
- 每个入站各字段之间是否一致(每个带传输层的协议都遵守的传输层规则、REALITY 设置、Vision、开放模式、传输层上的 SOCKS UDP、AnyTLS 的 shape 和填充方案、sss 限制、Hysteria 2 设置、TUN 的 MTU 和平台);
- 每个入站将准入的用户(
validate_admission)。
它不做这些事:
- 读取证书、私钥、CA 证书包或 geodata。这些由准备阶段的构建代码解析和加载(
compile_routes读取 geodata),失败时是ApplyError::Build。 - 绑定任何东西。端口被占用会以
ApplyError::Bind失败。 - 决定默认值或补齐缺失的值。出站的 WebSocket host、gRPC authority 和 TLS 名称由前端程序填写;到达 supervisor 时仍缺失的值会被拒绝,而不是去猜(见
an_outbound_needs_a_ws_host_and_a_grpc_authority)。 - 收集多个错误。它返回第一条被违反的规则,所以一次拒绝只报告一个问题。
入站和出站共用同一个 StreamShape(supervisor/src/topology/spec_plan/transport.rs)和 TLS 配对辅助函数 tls_mismatch,所以 TLS 规则只写一次,两侧通用。WebSocket host 和 gRPC authority 的规则只适用于出站。
校验在哪里运行
Section titled “校验在哪里运行”| 调用方 | 运行什么 | 何时 |
|---|---|---|
topology/spec_plan/plan.rs → plan |
validate(desired),是它的第一条语句 |
每次 Supervisor::apply、apply_with、update、update_with、SupervisorBuilder::start 和 check,经由阻塞线程池上的 Actor::stage |
supervisor.rs → stage_user_edit |
对准入被编辑用户集的每个入站运行 validate_admission |
Supervisor::set_users、upsert_user 和 remove_user,由 Actor::edit_users 在阻塞线程池上暂存 |
supervisor.rs → Actor::prepare |
probe_target |
构建负载均衡器时,用来找出每个成员的探测目标 |
plan 在算出任何一个步骤之前就先校验,而 Actor::stage 只在计划成功时才运行 stage_users,所以没有哪条代码路径会把未经校验的 spec 交给构建代码。构建代码依赖这一点:build/mod.rs 写明每个 builder 接收的都是已校验的 spec,Actor::prepare 在构建负载均衡器的地方写了 expect("validated: members are outbounds") 和 expect("validated: members are probeable")。
/// Check every semantic rule of `spec`.pub fn validate<U: UserId>(spec: &Spec<U>) -> Result<(), ApplyError>;
/// Check the users `inbound` would admit from `set`: no credential with two/// owners, and every credential usable by the inbound's protocol.pub fn validate_admission<U: UserId>( inbound: &InboundSpec, set: &UserSet<U>,) -> Result<(), ApplyError>;
/// Where a TCP health probe reaches `outbound`, if anywhere.pub(crate) fn probe_target(outbound: &OutboundSpec) -> Option<&Destination>;两个公开函数的路径是 etemenanki_supervisor::build::validate::validate 和 …::validate_admission,前端程序不用启动 supervisor 就能调用它们。build/ 下的模块中只有 apply 和 validate 是 pub;dns、inbound、outbound、route 和 users 是 pub(crate)。私有辅助函数如下:
| 辅助函数 | 返回 | 作用 |
|---|---|---|
unique_tags(kind, tags) |
Result<HashSet<&CompactString>, ApplyError> |
按迭代顺序先拒绝空 tag,再拒绝重复 tag;返回的集合供引用检查使用 |
validate_outbound(outbound) |
Result<(), ApplyError> |
逐个出站的规则 |
outbound_transport(transport) |
Result<(), CompactString> |
REALITY 配对和客户端的 server name;其他情况先检查 TLS 配对,再检查 WebSocket host 和 gRPC authority |
reality_settings(transport) |
Result<(), CompactString> |
入站传输层的 REALITY 配对及其 RealityServerSpec 规则 |
client_version_value(v) |
u32 |
把三字节的客户端版本变成 REALITY 比较用的一个数 |
inbound_transport(inbound, t) |
Result<(), CompactString> |
入站传输层无论承载哪个协议都要遵守的规则 |
sss_limits(max_datagram, flush_delay) |
Result<(), CompactString> |
sss 两端共用的限制,以及各端设置的 flush 延迟 |
needs_users(inbound) |
Result<(), ApplyError> |
没有开放模式的协议需要用户集 |
tls_mismatch(shape) |
CompactString |
TLS 配对错误的文本,取决于缺的是哪一侧 |
obfs(obfs) |
Result<(), CompactString> |
Salamander 密钥长度,入站和出站共用 |
hy2_quic(quic) |
Result<(), CompactString> |
上游对 Hysteria 2 quic 块的限制,入站和出站共用 |
port_hopping(hop) |
Result<(), CompactString> |
Hysteria 2 出站的跳跃端口和最短间隔 |
validate_inbound(inbound) |
Result<(), ApplyError> |
逐个入站的规则 |
real_ip_header(inbound, real_ip) |
Result<(), CompactString> |
入站 RealIpSpec 的规则 |
handoff_socket(inbound, handoff) |
Result<(), CompactString> |
入站 HandoffSpec 的规则 |
invalid_inbound(inbound, reason) |
ApplyError |
指向 Resource::Inbound(tag) 的 ApplyError::Invalid |
在 validate 内部,引用检查用的就是 unique_tags 返回的集合。负载均衡器的成员在 by_tag 中查找,它是以各出站建立的 HashMap<&CompactString, &OutboundSpec>;每个路由目标都要经过闭包 routable,tag 在出站集合或负载均衡器集合中时它为真。validate_admission 把见过的标识(identity)记在 seen 中,它是一个 HashMap<Vec<u8>, &U>,从标识映射到第一个出示它的用户。
| 常量 | 类型 | 值 | 规则 |
|---|---|---|---|
MIN_TUN_MTU |
u16 |
1280 |
用户态协议栈能服务的最小 MTU |
HY2_UDP_IDLE |
RangeInclusive<u64> |
2..=600(秒,含两端) |
Hysteria 2 UDP 关联的空闲超时。注释给出了理由:低于下限,繁忙的关联会在两个包之间被清掉;高于上限,已失效的关联会占着它的 socket 长达十分钟 |
MIN_SALAMANDER_PSK |
usize |
4 |
两侧允许的最短 Salamander 密钥。protocols/src/hysteria/obfs.rs → MIN_PSK_LEN 也是 4,Salamander::new 以 ProtocolError::Malformed("hysteria2 obfs psk is too short") 拒绝同样的密钥 |
HY2_IDLE_TIMEOUT |
RangeInclusive<u64> |
4..=120(秒) |
上游对 Hysteria 2 max_idle_timeout 的取值范围 |
HY2_KEEP_ALIVE |
RangeInclusive<u64> |
2..=60(秒) |
上游对 Hysteria 2 keep_alive_period 的取值范围 |
QUIC_VARINT_MAX |
u64 |
(1 << 62) - 1 |
QUIC 能承载的最大数,因此也是最大的接收窗口 |
MAX_SOCKET_PATH |
usize |
107 |
Unix socket 能绑定的最长路径:sun_path 共 108 字节,包括结尾的 NUL |
规则还会读取 etemenanki-protocols 中的这些值:
| 值 | 来源 | 用途 |
|---|---|---|
STATUS_AUTH_OK = 233 |
protocols/src/hysteria/auth.rs |
伪装响应(masquerade)唯一不能使用的状态码 |
QuicOptions::MIN_RECEIVE_WINDOW = 16_384 |
protocols/src/hysteria/config.rs |
上游接受的最小 QUIC 接收窗口 |
HopInterval::MIN_CONFIGURED = 5 秒 |
shinku-quic/src/hop.rs,重新导出为 etemenanki_protocols::hysteria::config::HopInterval |
上游配置接受的最短跳跃间隔。shinku-quic 不强制它,所以由校验来强制 |
Method::key_len():2022-blake3-aes-128-gcm 为 16,2022-blake3-aes-256-gcm 和 2022-blake3-chacha20-poly1305 为 32 |
protocols/src/ss_2022/crypto.rs |
Shadowsocks 2022 的密钥长度 |
WsRoute::real_ip_header(name) |
protocols/src/transports/ws/endpoint.rs |
真实 IP 头名是否是合法的 HTTP 头名:校验构建 WsRoute::new("/").real_ip_header(&header),出错即拒绝;build_transport 做的也是同一个调用 |
normalise_psk(method, psk) |
protocols/src/ss_2022/users.rs |
用户 PSK:长度等于方法要求时接受;更长时折叠到该长度(取其 SHA-256 的前 key_len 字节,ss_2022/crypto.rs → fold_key);更短时以 ErrorKind::InvalidInput 和 shadowsocks-2022: PSK too short (<len> < <n>) 拒绝 |
PaddingScheme::from_lines(lines) |
protocols/src/anytls/padding.rs |
AnyTLS 入站的填充方案:各行以 \n 连接后必须能解析,且不超过 MAX_SCHEME_LEN(2,048 字节);SchemeError 的文本就是 reason |
MAX_FLUSH_DELAY = 10 毫秒 |
protocols/src/sss/transform/stream.rs |
sss flush 延迟 t_c 的最大值 |
spec 中的 Shadowsocks 2022 密钥是解码后的字节。前端程序用 ss_2022/users.rs → decode_psk 解码密钥的 base64 文本,失败时返回 ErrorKind::InvalidInput 和 decode PSK: <e>;这是 lowering(降为 spec)阶段的错误,绝不会是 ApplyError。
ApplyError
Section titled “ApplyError”/// Why a spec was not applied.////// A spec that fails validation is refused as a whole, and what was running/// keeps running.#[derive(Debug, thiserror::Error)]pub enum ApplyError { /// Two resources of one kind share a tag, or a balancer's tag is also an /// outbound's. #[error("duplicate {kind} tag {tag}")] DuplicateTag { kind: ResourceKind, tag: CompactString }, /// `from` names a tag nothing of that kind carries: a rule or a balancer /// naming a missing outbound, or an inbound naming a missing user set. #[error("{from} references unknown {kind} {tag}")] UnknownReference { from: Resource, kind: ResourceKind, tag: CompactString }, /// A balancer with nothing to choose from. #[error("balancer {balancer} has no members")] EmptyBalancer { balancer: CompactString }, /// A balancer member no TCP health probe can reach, so its health, which /// is all a balancer selects on, could never be known. #[error("balancer {balancer}: outbound {member} has no upstream a TCP health probe can reach")] UnprobeableMember { balancer: CompactString, member: CompactString }, /// A spec that breaks one of its documented invariants, such as TLS /// material missing under a shape that layers TLS, or a Trojan inbound /// without a user set. #[error("{resource}: {reason}")] Invalid { resource: Resource, reason: CompactString }, /// A resource's spec was valid, but constructing it failed: a /// certificate that does not parse, geo data that cannot be read. #[error("building {resource} failed: {source}")] Build { resource: Resource, #[source] source: io::Error }, /// An inbound's listener could not be bound. #[error("inbound {inbound}: binding {bind} failed: {source}")] Bind { inbound: CompactString, bind: BindSpec, #[source] source: io::Error }, /// The spec needs a change that ends live connections, and the apply /// did not allow one. #[error("inbound {inbound}: {reason}; this ends its live connections and needs allow_disruptive")] Disruptive { inbound: CompactString, reason: CompactString }, /// The supervisor has shut down. #[error("the supervisor has shut down")] Stopped,}枚举的文档注释写明了约定:未通过校验的 spec 被整个拒绝,正在运行的内容照常运行。lib.rs 在 crate 根重新导出了这个模块(pub use build::apply;),所以 etemenanki_supervisor::apply::ApplyError 和 etemenanki_supervisor::apply::ApplyReport 是同一组类型的第二条路径;etemenanki-app 从 build::apply 导入它们。
| 变体 | 阶段 | 产生者 |
|---|---|---|
DuplicateTag |
校验 | unique_tags,以及负载均衡器与出站的 tag 冲突检查 |
UnknownReference |
校验 | 负载均衡器成员、路由规则或路由默认出站、入站的用户集指定了不存在的 tag |
EmptyBalancer |
校验 | 没有成员的负载均衡器 |
UnprobeableMember |
校验 | probe_target 返回 None 的负载均衡器成员 |
Invalid |
校验、用户编辑 | validate 和 validate_admission 的其余所有规则;以及 stage_user_edit 遇到未知用户集时 |
Build |
暂存和准备,由准备阶段报告 | 某个 builder 或监听器准备步骤失败。校验已通过 |
Bind |
准备 | 为新监听器调用的 system/listener.rs → bind |
Disruptive |
暂存之后、准备之前 | 计划含有 Step::Disrupt,而 ApplyOptions::allow_disruptive 未设置 |
Stopped |
任意 | actor 已不在,或者没有正在运行的 spec 可供编辑 |
Build 和 Bind 既把 io::Error 写进文本,也作为 source() 返回。ApplyError 没有实现 Clone。
资源如何输出
Section titled “资源如何输出”上面所有文本都建立在 supervisor/src/entity/id.rs 中的两个 Display 实现之上:
| 值 | 输出 |
|---|---|
ResourceKind::Inbound / Outbound / Balancer / UserSet |
inbound / outbound / balancer / user set |
Resource::Inbound(tag) |
inbound <tag> |
Resource::Outbound(OutboundId) |
outbound <tag>@v<version> |
Resource::Balancer(tag) |
balancer <tag> |
Resource::UserSet(tag) |
user set <tag> |
Resource::Route |
route |
Resource::Dns |
dns |
绑定通过 topology/inbound/mod.rs → impl Display for BindSpec 输出:
BindSpec |
输出 |
|---|---|
Tcp { host, port } |
<host>:<port> |
Udp { host, port } |
udp <host>:<port> |
Unix(path) |
unix:<path> |
Handoff(spec) |
handoff:<path> |
Tun(TunSource::Create(spec)) |
tun <name>;name 为 None 时是 tun auto |
Tun(TunSource::Fd(device)),仅 Unix |
tun fd <n> |
ApplyReport
Section titled “ApplyReport”成功的应用会返回它对每个资源做了什么。这个类型和 ApplyError 一起定义在 build/apply.rs 中:
#[derive(Debug, Clone, Default, PartialEq, Eq)]pub struct ApplyReport { /// Kept as they were: their spec did not change. pub reused: Vec<Resource>, /// Constructed from their spec: new, or changed, in which case an /// outbound is a new version of its tag. pub built: Vec<Resource>, /// Inbounds that kept their listener and now serve new connections with /// a new handler. pub swapped: Vec<CompactString>, /// Outbound versions taken out of service. Their live flows are handled /// by the drain policy. pub drained: Vec<OutboundId>, /// Inbounds with a listener closed and bound again elsewhere, because /// their BindSpec or their handoff socket changed. A handoff socket /// added is not one. pub rebound: Vec<CompactString>, /// Inbounds whose runtime was stopped and started again on the handle it /// kept, ending its live connections: the disruptive changes an apply /// was allowed to make. pub restarted: Vec<CompactString>, /// Inbounds taken out of the spec: their listeners closed, and their /// sessions with them. pub removed: Vec<CompactString>,}期望 spec 中的每个资源都出现在 reused 或 built 中;其余五个列表说明这对已在运行的内容意味着什么。它没有实现 Display。每个列表如何填充见规划与应用变更。etemenanki-app 用 app/src/instance.rs → summary 输出它:每个非空列表输出为 <label> [<item>, …],用 ; 连接,顺序为 built、swapped、drained、rebound、restarted、removed、reused;全部为空时输出 nothing to run。各项按上面的 Display 形式输出,被排空的出站输出为 <tag>@v<version>。
/// Validate `spec` and build everything it describes — outbounds, routes/// with their geo data, handlers with their certificates, user tables —/// without binding a listener or starting anything. It refuses what a start/// would, short of a port or device that cannot be bound.pub async fn check<U: UserId>(spec: &Spec<U>) -> Result<(), ApplyError>;它在 crate 根以 etemenanki_supervisor::check 重新导出。见试运行。
一次应用中每个变体可能从哪里产生:
flowchart LR FE["Supervisor::apply"] -->|"Command::Apply"| PLAN["暂存:plan,先运行 validate"] FE -->|"actor 已不在"| ST["Stopped"] PLAN -->|"违反某条规则"| VE["DuplicateTag, UnknownReference, EmptyBalancer, UnprobeableMember, Invalid"] PLAN --> USERS["暂存:用户、handler、用户表"] USERS --> DIS["plan.disruptions()"] DIS -->|"未设置 allow_disruptive"| DE["Disruptive"] DIS --> PREP["prepare,bind = true"] PREP -->|"构建失败,暂存时或现在"| BE["Build"] PREP -->|"监听器无法绑定"| BI["Bind"] PREP --> COM["commit:不会失败"]
Actor::stage 在阻塞线程池上运行:先是 plan,它在做任何事之前先校验;然后是 stage_users,它在中断检查之前准入用户,并构建每个要构建的入站的 handler 和每张有变化的用户表。暂存时构建失败的 handler 或用户表不在那里报告:准备阶段在 DNS、出站、负载均衡器和路由之后,按入站顺序把它报告为 Build。
validate 内部的顺序。每个方框在遇到第一条被违反的规则时停止:
flowchart TB T1["用户集 tag"] --> T2["出站 tag"] T2 --> T3["负载均衡器 tag"] T3 --> T4["负载均衡器 tag 与出站 tag 相同"] T4 --> T5["入站 tag"] T5 --> O["validate_outbound,按顺序检查每个出站"] O --> B["每个负载均衡器:成员存在且可探测"] B --> R["按顺序检查路由规则,然后是默认出站"] R --> I1["下一个入站:各绑定唯一,用户集存在"] I1 --> I2["validate_inbound"] I2 --> I3["validate_admission(入站指定了用户集时)"] I3 -->|"还有入站"| I1
入站检查是逐个入站进行的,所以第 2 个入站的准入检查先于第 3 个入站的绑定检查。
各条规则(按检查顺序)
Section titled “各条规则(按检查顺序)”下面的文本凡是 app 能产生的,都是用固定版本的 etemenanki-app 以 --test 捕获的,其余则读自代码。尖括号中的占位符代表一个值。supervisor/tests/unit/validate.rs 中的单元测试匹配的是变体和资源,从不匹配文本。
1. tag
Section titled “1. tag”unique_tags 对每类资源各运行一次,顺序是用户集、出站、负载均衡器、入站;负载均衡器与出站的 tag 冲突检查位于负载均衡器和入站之间。对每个 tag,它先检查是否为空,再检查是否重复。
| 规则 | 变体 | 文本 | 测试 |
|---|---|---|---|
| 用户集 tag 非空 | 针对该用户集的 Invalid |
空 tag 的原因文本 | no_tag_may_be_empty |
| 用户集 tag 唯一 | DuplicateTag { kind: UserSet } |
duplicate user set tag <tag> |
tags_are_unique_within_each_kind |
| 出站 tag 非空 | 针对该出站的 Invalid |
空 tag 的原因文本 | no_tag_may_be_empty |
| 出站 tag 唯一 | DuplicateTag { kind: Outbound } |
duplicate outbound tag <tag> |
tags_are_unique_within_each_kind |
| 负载均衡器 tag 非空 | 针对该负载均衡器的 Invalid |
空 tag 的原因文本 | 无 |
| 负载均衡器 tag 唯一 | DuplicateTag { kind: Balancer } |
duplicate balancer tag <tag> |
tags_are_unique_within_each_kind |
| 负载均衡器不与出站共用 tag | DuplicateTag { kind: Balancer } |
duplicate balancer tag <tag> |
a_balancer_may_not_share_an_outbounds_tag |
| 入站 tag 非空 | 针对该入站的 Invalid |
空 tag 的原因文本 | no_tag_may_be_empty |
| 入站 tag 唯一 | DuplicateTag { kind: Inbound } |
duplicate inbound tag <tag> |
tags_are_unique_within_each_kind |
这些规则为什么是这样:
- 出站和负载均衡器的 tag 共用一个命名空间。 路由按 tag 指定这两类中的任一类,同一个 tag 同时出现在两者上就会有歧义。入站 tag 和用户集 tag 各自独立:
an_inbound_may_share_an_outbounds_tag接受 tag 为direct的入站与 tag 为direct的出站并存。 - 空 tag 是保留的。 supervisor 自己创建了两个目标,tag 都是空字符串:一是
topology/plane.rs→Plane::empty中的 blackhole,Plane::empty是 actor 在第一次应用发布 plane(数据平面)之前持有的 plane;二是作为出站访问的 DNS 服务(supervisor.rs→internal_id)。由于 spec 中没有空 tag,这两个目标都不会与 spec 中的任何出站混淆。 - 检查按资源类别的顺序进行,而不是按文件顺序。 etemenanki-app 把入站下列出的用户降为一个用户集,tag 与入站自己的 tag 相同。因此两个 tag 都是
t的 Trojan 入站会以duplicate user set tag t被拒绝,而不是duplicate inbound tag t。这条文本是从 app 捕获的。
validate_outbound 按 spec 顺序对每个出站运行。它返回的每个错误都是指向该出站(Resource::Outbound)的 ApplyError::Invalid。
对于经由传输层拨号的代理协议(SOCKS、HTTP、Trojan、VLESS、VMess、Shadowsocks、Shadowsocks 2022、sss 和 AnyTLS),outbound_transport 先检查上游的 OutboundTransportSpec。REALITY 传输层单独检查,TLS、WebSocket 和 gRPC 规则适用于其他所有 shape:
| 规则 | 文本 | 测试 |
|---|---|---|
shape 是 Reality,因此必须有 REALITY 设置 |
outbound <tag>@v0: a reality transport carries no reality settings |
a_reality_outbound_validates_and_its_field_must_match |
有 REALITY 设置,因此 shape 必须是 Reality |
outbound <tag>@v0: the transport carries reality settings but its shape is not reality |
同上 |
| REALITY 传输层不带 TLS 设置 | outbound <tag>@v0: a reality transport carries no tls settings |
无 |
REALITY server name 非空且不含 * |
outbound <tag>@v0: invalid reality server name "<name>",名字用 {:?} 打印 |
无 |
| shape 叠加了 TLS,因此必须有 TLS 设置 | outbound <tag>@v0: the transport layers tls but carries no tls settings |
an_outbound_carries_tls_settings_exactly_when_its_shape_layers_tls |
| 有 TLS 设置,因此 shape 必须叠加 TLS | outbound <tag>@v0: the transport carries tls settings but does not layer tls |
同上 |
WebSocket shape 有 host |
outbound <tag>@v0: ws transport needs a host |
an_outbound_needs_a_ws_host_and_a_grpc_authority |
gRPC shape 有 authority |
outbound <tag>@v0: grpc transport needs an authority |
同上 |
配对由 StreamShape::uses_tls 判定:Tcp 和 Reality 从不叠加本项目的 TLS,Tls 总是叠加,Ws 和 Grpc 在其 tls 标志置位时叠加。
接下来两条规则把传输层和协议联系起来,与入站一侧的两条相同:
| 规则 | 文本 | 测试 |
|---|---|---|
Reality shape 只用在 VLESS 下 |
outbound <tag>@v0: reality is for vless only |
a_reality_outbound_is_vless_only |
带 VlessFlow::Vision 的 VLESS 出站只走 Reality shape |
outbound <tag>@v0: vless vision (xtls-rprx-vision) rides only over reality |
无 |
第一条防止在其他协议下误写的 security = "reality" 通过校验,并被当作那个协议构建成 REALITY 拨号。第二条成立,是因为 Vision 给数据体加帧并拼接原始 socket,只有 REALITY 的记录层支持这一点。
然后是协议自己的规则:
| 协议 | 规则 | 文本 | 测试 |
|---|---|---|---|
| Shadowsocks 2022 | psk 和 identity_psks 的每一项都恰好是 method.key_len() 字节 |
outbound <tag>@v0: shadowsocks-2022 keys must be <n> bytes for this method |
shadowsocks_2022_client_keys_are_sized_to_their_method |
| sss | max_datagram 至少为 1 |
outbound <tag>@v0: sss udp_max_datagram must be at least 1 |
出站一侧无 |
| sss | flush_delay 最多 10 毫秒 |
outbound <tag>@v0: sss flush_delay must be at most 10ms |
出站一侧无 |
| AnyTLS | 上游的 shape 是 Tls |
outbound <tag>@v0: anytls runs over tls only; its shape must be tls |
an_anytls_outbound_needs_tls_and_a_password |
| AnyTLS | password 非空 |
outbound <tag>@v0: anytls password must not be empty |
同上 |
| Hysteria 2 | password 非空 |
outbound <tag>@v0: hysteria2 password must not be empty |
a_hysteria2_client_needs_a_password_and_a_stream |
| Hysteria 2 | max_concurrent_streams 至少为 1 |
outbound <tag>@v0: max_concurrent_streams must be at least 1 |
同上 |
| Hysteria 2 | Salamander 密钥至少 4 字节 | outbound <tag>@v0: salamander obfs key must be at least 4 bytes |
a_salamander_key_is_at_least_4_bytes_on_either_side |
| Hysteria 2 | 设置了 hop 时,至少有一个端口 |
outbound <tag>@v0: port hopping needs at least one port |
hysteria2_port_hopping_needs_ports_and_a_sane_interval |
| Hysteria 2 | 设置了 hop 时,没有端口 0 |
outbound <tag>@v0: port 0 cannot be hopped to |
同上 |
| Hysteria 2 | 设置了 hop 时,间隔的最小值(interval.min())至少为 HopInterval::MIN_CONFIGURED |
outbound <tag>@v0: the hop interval must be at least 5 seconds |
同上 |
| Hysteria 2 | quic.stream_receive_window 在 16,384 到 2^62 − 1 之间 |
outbound <tag>@v0: stream_receive_window must be at least 16384 bytes |
hysteria2_quic_settings_stay_within_upstreams_limits |
| Hysteria 2 | quic.conn_receive_window 在 16,384 到 2^62 − 1 之间 |
outbound <tag>@v0: conn_receive_window must be at least 16384 bytes |
同上 |
| Hysteria 2 | quic.max_idle_timeout 是 4 到 120 的整数秒 |
outbound <tag>@v0: max_idle_timeout must be a whole number of seconds between 4 and 120 |
同上 |
| Hysteria 2 | quic.keep_alive_period 设置时是 2 到 60 的整数秒 |
outbound <tag>@v0: keep_alive_period must be a whole number of seconds between 2 and 60 |
同上 |
| Hysteria 2 | quic.max_incoming_streams 不是 Some(0) |
outbound <tag>@v0: max_incoming_streams must be at least 1 |
同上 |
| WireGuard | address_family = Ipv4Only 要求 addresses 中有 IPv4 地址 |
outbound <tag>@v0: wireguard address_family ipv4_only needs an IPv4 address |
a_wireguard_address_family_needs_an_address_of_that_family |
| WireGuard | address_family = Ipv6Only 要求有 IPv6 地址 |
outbound <tag>@v0: wireguard address_family ipv6_only needs an IPv6 address |
同上 |
WireGuard 文本中的地址族名称来自 AddressFamilyStrategy::as_str。Auto、PreferIpv4 和 PreferIpv6 不要求特定地址。freedom 和 blackhole 出站在这里没有规则。
Hysteria 2 的规则按表中顺序运行:混淆密钥,设置了 hop 时是 port_hopping,然后是 hy2_quic。hy2_quic 依次检查 stream 窗口、连接窗口、空闲超时、keep-alive 和入向 stream 数,并与入站共用。大于 2^62 − 1 的窗口也以同样的 at least 文本拒绝。“整数秒”指没有秒以下的小数部分(subsec_nanos() == 0),所以 30.5 秒的空闲超时会被拒绝。跳跃间隔规则读取的是间隔可能取到的最短值,所以 4 到 30 秒的随机间隔会被拒绝。
从 app 捕获的输出:
configuration invalid: outbound wg@v0: wireguard address_family ipv6_only needs an IPv6 addressconfiguration invalid: outbound hy2-out@v0: hysteria2 password must not be emptyconfiguration invalid: outbound hy2-out@v0: max_concurrent_streams must be at least 1configuration invalid: outbound hy2-out@v0: salamander obfs key must be at least 4 bytesconfiguration invalid: outbound t-out@v0: reality is for vless onlyconfiguration invalid: outbound v-out@v0: vless vision (xtls-rprx-vision) rides only over realityconfiguration invalid: outbound v-out@v0: invalid reality server name "*.example.com"configuration invalid: outbound any-out@v0: anytls runs over tls only; its shape must be tlsconfiguration invalid: outbound any-out@v0: anytls password must not be emptyconfiguration invalid: outbound x-out@v0: sss flush_delay must be at most 10ms3. 负载均衡器
Section titled “3. 负载均衡器”按 spec 顺序对每个负载均衡器:
| 规则 | 变体 | 文本 | 测试 |
|---|---|---|---|
| 至少有一个成员 | EmptyBalancer |
balancer <b> has no members |
a_balancer_needs_a_member |
| 每个成员(按顺序)都是出站 tag | UnknownReference { from: Balancer(b), kind: Outbound } |
balancer <b> references unknown outbound <m> |
a_balancer_member_must_be_a_known_outbound |
| 每个成员都能通过 TCP 探测 | UnprobeableMember |
balancer <b>: outbound <m> has no upstream a TCP health probe can reach |
a_balancer_member_needs_an_upstream_a_tcp_probe_can_reach |
成员只在出站中查找,所以把另一个负载均衡器列为成员的负载均衡器会违反第二条规则:balancer outer references unknown outbound inner(a_balancer_member_may_not_be_another_balancer)。负载均衡器不能是任何东西的成员。
第三条规则由 probe_target 判定。负载均衡器只依据健康状态做选择,而它了解健康状态的方式是建立 TCP 连接,所以没有 TCP 上游的成员会永远被标记为不可用:
| 出站协议 | probe_target |
|---|---|
| SOCKS、HTTP、Trojan、VLESS、VMess、Shadowsocks、Shadowsocks 2022、sss | Some(&upstream.server) |
| AnyTLS | Some(&anytls.upstream.server) |
| freedom、blackhole | None:没有上游 |
| Hysteria 2、WireGuard | None:上游监听的是 UDP |
Actor::prepare 对每个成员再调用一次 probe_target,把得到的目标交给 Member::new。Balancer::new 仍会以 a balancer needs at least one outbound(一个 Build 错误)拒绝空成员列表,但校验会先拒绝这样的 spec。
按规则顺序,每条规则的 outbound,然后是 route.default,都必须指定一个出站或负载均衡器:
| 规则 | 变体 | 文本 | 测试 |
|---|---|---|---|
| 规则指定已知的出站或负载均衡器 | UnknownReference { from: Route, kind: Outbound } |
route references unknown outbound <tag> |
a_route_rule_must_name_a_known_outbound_or_balancer |
| 默认出站指定已知的出站或负载均衡器 | 同上 | 同上 | the_route_default_must_name_a_known_outbound_or_balancer |
即使本意是负载均衡器,文本里写的也是 outbound;类别是固定的,因为两者共用一个命名空间。a_route_may_name_a_balancer 接受指定负载均衡器的默认出站。geosite 和 geoip 代码是否存在不归校验判断:geodata 由 build/route.rs → compile_routes 读取,所以文件缺失或无法读取、或者代码不存在,都是 route 上的 Build 错误。
按 spec 顺序,对每个入站执行四步:
-
各绑定唯一。
InboundSpec::binds()产出的每个绑定(先是入站自己的,再是它的交接 socket)都与之前收集到的每个绑定比较(循环过程中填入一个Vec<BindSpec>)。值相等,或者与之前某个绑定位于同一 socket 路径(BindSpec::socket_path,即Unix或Handoff绑定的路径),无论两者别处有何不同,都以Invalid { resource: Inbound(<the later inbound>) }(指向后一个入站)失败,文本为<bind> is bound by another inbound,写出的是后一个绑定。捕获的输出:inbound b: 127.0.0.1:1080 is bound by another inbound。TCP 绑定和 UDP 绑定属于不同类别,所以 Hysteria 2 入站可以使用与 SOCKS 入站相同的端口号(the_same_port_over_udp_is_another_bind)。测试:two_inbounds_may_not_share_a_bind,以及two_binds_may_not_share_a_socket_path:位于另一个交接 socket 路径上、mode 为0o666而不是0o660的交接 socket,和位于交接 socket 路径上的 Unix 监听器,都被拒绝。“相等”指
BindSpec的PartialEq:BindSpec相等的条件 Tcp { host, port }、Udp { host, port }类别相同、 host字符串按文本比较相同、端口相同Unix(path)两个 PathBuf相等,比较的是路径组件:重复的/和中间的.会被合并,..不会Handoff(spec)路径的比较方式与 Unix相同,mode和gid也要相等。同一路径上的两个交接 socket 无论如何都会经由socket_path冲突Tun(TunSource::Create(spec))两个 DeviceSpec逐字段相等Tun(TunSource::Fd(device))topology/inbound/mod.rs→impl PartialEq for SuppliedTun:描述符编号相同且 MTU 相同 -
用户集存在。 当
users为Some(tag)而没有用户集带有这个 tag 时:UnknownReference { from: Inbound(tag), kind: UserSet },输出为inbound <tag> references unknown user set <set>。测试:an_inbound_must_name_a_known_user_set。 -
validate_inbound,见下文。 -
validate_admission:入站指定了用户集时,针对该用户集运行。见准入。
validate_inbound
Section titled “validate_inbound”每个错误都是 Invalid { resource: Inbound(tag) },输出为 inbound <tag>: <reason>。
首先检查配对。每个协议只在一类绑定上提供服务:
| 协议 | 需要的绑定 |
|---|---|
| SOCKS、HTTP、Trojan、VLESS、VMess、Shadowsocks、Shadowsocks 2022、AnyTLS、sss | BindSpec::Tcp 或 BindSpec::Unix |
| Hysteria 2 | BindSpec::Udp |
| TUN | BindSpec::Tun |
其他任何组合都以 the protocol cannot be served on <bind> 失败,例如 inbound in: the protocol cannot be served on udp 127.0.0.1:2000。没有任何协议与 Handoff 绑定配对:作为入站自己的 bind 时它在这里失败,文本为 the protocol cannot be served on handoff:<path>(a_handoff_bind_is_no_inbounds_own)。测试:each_protocol_is_served_only_on_its_kind_of_bind。
配对之后是两条绑定规则:
| 规则 | reason 文本 | 测试 |
|---|---|---|
| Unix 绑定只在 Unix 上提供服务。这项检查只在非 Unix 平台上编译 | unix sockets are not served on <os>,取 std::env::consts::OS,例如 unix sockets are not served on windows |
无 |
只有 Tcp 绑定可以设置 proxy_protocol |
only a tcp listener reads a PROXY protocol header |
无 |
设置了 handoff 时,接着由 handoff_socket 检查它。交接 socket 位于一个 TCP 监听器旁边,由该监听器的传输层和协议服务交接过来的连接;它的路径必须是 Unix socket 能绑定的路径,mode 只能是权限位。它的规则,依次为:
| 规则 | reason 文本 | 测试 |
|---|---|---|
平台是 Unix。这项检查在所有平台上编译(cfg!(not(unix))) |
handoff sockets are not served on <os>,取 std::env::consts::OS |
无 |
入站自己的绑定是 Tcp。协议已经与它的绑定配对过,所以 TCP 绑定上的就是流式协议 |
only a stream inbound on a tcp listener takes a handoff socket |
a_handoff_socket_stands_beside_a_stream_inbounds_tcp_listener(Unix 绑定上的 SOCKS、Hysteria 2 和 TUN 被拒绝;TCP 上的 SOCKS 被接受) |
path 是绝对路径,并且指向一个文件(Path::file_name 为 Some) |
the handoff socket <path> must be an absolute path to a file,例如 the handoff socket run/test/1080.sock must be an absolute path to a file |
a_handoff_socket_is_an_absolute_path_a_unix_socket_can_take(相对路径、/ 和空路径被拒绝) |
path 最长 MAX_SOCKET_PATH(107)字节 |
the handoff socket <path> is longer than 107 bytes |
同上(107 字节被接受,108 字节被拒绝) |
mode 没有 0o777 以外的位 |
the handoff socket's mode <octal> holds more than permission bits,例如 the handoff socket's mode 4660 holds more than permission bits |
a_handoff_sockets_mode_is_permission_bits_alone(0o4660 被拒绝) |
路径用 Path::display 打印,mode 以不带前缀的八进制打印。gid 没有规则:进程能否把文件交给这个组,要到绑定 socket 时才知道(见 Bind)。
设置了 real_ip 时,接着由 real_ip_header 检查它。真实 IP 头从 TCP 监听器上的 WebSocket 升级请求中读取,并且只在来自可信代理时才算数,所以永远不可能算数的设置被当作错误报告,而不是保留下来。它的三条规则,依次为:
| 规则 | 原因文本 | 测试 |
|---|---|---|
协议带传输层(InboundProtocolSpec::transport()),其 shape 是 StreamShape::Ws,并且绑定是 Tcp |
only a websocket transport on a tcp listener reads a real-ip header |
a_real_ip_header_needs_a_websocket_a_trusted_proxy_and_a_name(纯 TCP 和 gRPC 被拒绝,WebSocket 被接受);shadowsocks_and_socks_over_websocket_read_a_real_ip_header(Shadowsocks 和 SOCKS 上被接受) |
trusted 中至少有一个网络 |
a real-ip header needs at least one trusted proxy |
同上 |
header 是合法的 HTTP 头名 |
the real-ip header "<header>" is not a header name,名字用 {:?} 打印,例如 the real-ip header "X Real IP" is not a header name |
同上 |
对每个带有 InboundTransportSpec 的协议,也就是 InboundProtocolSpec::transport() 列出的那些(SOCKS、HTTP、Trojan、VLESS、VMess、Shadowsocks、Shadowsocks 2022、AnyTLS 和 sss),接下来运行一次 inbound_transport,按以下顺序检查。以后新增的协议无需调用也会受这些规则约束(every_protocol_meets_the_same_transport_rules):
| 规则 | reason 文本 | 测试 |
|---|---|---|
在 Unix 绑定上,shape 是 StreamShape::Tcp |
a unix socket carries no transport; its shape must be plain tcp |
a_unix_listener_carries_only_the_plain_tcp_shape |
| shape 叠加了 TLS,因此必须有 TLS 材料 | the transport layers tls but carries no tls settings |
an_inbound_carries_tls_material_exactly_when_its_shape_layers_tls |
| 有 TLS 材料,因此 shape 必须叠加 TLS | the transport carries tls settings but does not layer tls |
同上 |
shape 是 Reality,因此必须有 REALITY 设置 |
a reality transport carries no reality settings |
reality_field_must_match_its_shape |
有 REALITY 设置,因此 shape 必须是 Reality |
the transport carries reality settings but its shape is not reality |
同上 |
| 至少一个 server name | reality needs at least one server name |
reality_settings_fail_closed |
没有为空或含 * 的 server name |
invalid reality server name "<name>",名字用 {:?} 打印 |
同上 |
| 至少一个 shortId | reality needs at least one shortId |
同上 |
dest 的端口非零 |
reality dest needs a non-zero port |
同上 |
域名形式的 dest 主机非空 |
reality dest needs a host |
同上 |
两个上下界都设置时,min_client_version 不高于 max_client_version,各自按一个数比较(client_version_value) |
reality min_client_version is above max_client_version |
同上 |
Reality shape 只用在 VLESS 下 |
reality is for vless only |
reality_is_vless_only,它尝试了其他每个协议,包括 AnyTLS |
带 VlessFlow::Vision 的 VLESS 入站只走 Reality shape |
vless vision (xtls-rprx-vision) rides only over reality |
无 |
Reality shape 不叠加本项目的 TLS,所以在 REALITY 规则运行之前,TLS 配对就会拒绝它旁边的 TLS 材料。入站的 WebSocket host 和 gRPC authority 可以是 None:服务端没有可以借用这两个值的来源,也用不到它们(an_inbound_needs_no_ws_host_or_grpc_authority)。
然后是协议自己的规则:
| 协议 | 规则 | reason 文本 | 测试 |
|---|---|---|---|
| SOCKS | 开启 udp 时,shape 是普通的 StreamShape::Tcp:中继的数据报以明文发往监听器旁边的 UDP socket |
socks serves udp associate over plain tcp only; turn udp off to wrap it in a transport |
socks_relays_udp_over_plain_tcp_only |
| SOCKS | 在 Unix 绑定上开启 udp 时,必须设置 udp_bind |
socks over a unix socket has no local IP for UDP associate; set udp_bind or turn udp off |
socks_over_a_unix_socket_needs_a_udp_bind_to_serve_udp |
| Trojan、VLESS、VMess | users 为 Some(needs_users) |
the protocol has no open mode and needs a user set |
trojan_vless_and_vmess_need_a_user_set |
| AnyTLS | shape 是 StreamShape::Tls |
anytls runs over tls only; its shape must be tls |
anytls_needs_tls_a_user_set_and_a_scheme_that_parses |
| AnyTLS | users 为 Some |
the protocol has no open mode and needs a user set |
同上 |
| AnyTLS | padding_scheme 能用 PaddingScheme::from_lines 解析,连接后不超过 2,048 字节 |
SchemeError 的文本,例如 padding scheme line 2: an item is neither c nor min-max with 1 <= min <= max <= 1048576 |
同上 |
| sss | users 为 Some(needs_users) |
the protocol has no open mode and needs a user set |
supervisor/tests/sss.rs 中的 validation_refuses_bad_limits |
| sss | max_datagram 至少为 1 |
sss udp_max_datagram must be at least 1 |
同上 |
| sss | flush_delay 最多 10 毫秒 |
sss flush_delay must be at most 10ms |
同上 |
| sss | header_timeout 大于零 |
sss header_timeout must be above zero |
同上 |
| Shadowsocks 2022 | 服务端 psk 恰好是 method.key_len() 字节 |
the shadowsocks-2022 key must be <n> bytes for this method |
a_shadowsocks_2022_server_key_is_sized_to_its_method |
| Hysteria 2 | 不同时设置 shared_password 和 users |
a shared password and a user set cannot both be set; a credential would have two answers |
hysteria2_takes_a_shared_password_or_a_user_set_but_not_both |
| Hysteria 2 | 两者设置了其中之一 | hysteria2 needs a shared password or a user set |
同上 |
| Hysteria 2 | 共享密码非空 | the shared password must not be empty |
a_hysteria2_shared_password_may_not_be_empty |
| Hysteria 2 | 设置了 udp_idle_timeout 时,它是 2 到 600 整秒 |
udp_idle_timeout must be between 2 and 600 seconds |
a_hysteria2_udp_idle_timeout_is_between_2_and_600_seconds |
| Hysteria 2 | max_connections 和 max_circuits 至少为 1 |
max_connections and max_circuits must be at least 1 |
hysteria2_serves_at_least_one_connection_and_one_circuit |
| Hysteria 2 | Salamander 密钥至少 4 字节 | salamander obfs key must be at least 4 bytes |
a_salamander_key_is_at_least_4_bytes_on_either_side |
| Hysteria 2 | quic 块通过 hy2_quic |
出站中的文本,不带 outbound 前缀 |
hysteria2_quic_settings_stay_within_upstreams_limits |
| Hysteria 2 | 伪装响应能用 Masquerade::new 构建 |
构造函数的错误文本 | a_masquerade_may_not_answer_with_the_success_status |
| TUN | 设备 MTU(TunSource::mtu)至少为 1280 |
tun mtu must be at least 1280 |
a_tun_device_mtu_is_at_least_1280 |
| TUN | TunSource::Create 设备通过 check_platform |
平台检查的错误文本 | 无 |
决定边界情况的细节:
-
空闲超时按整秒比较(
Duration::as_secs)。None表示关闭 UDP 中继,不需要范围约束;a_hysteria2_udp_idle_timeout_is_between_2_and_600_seconds接受 2 和 600,拒绝 1 和 601,并接受None。 -
共享密码或用户集。 如果两者都设置,同一个凭据就可能有两种答案。设置了共享密码时,
Hysteria2InboundSpec::user_auth被忽略。 -
传输层上的 SOCKS。 包在传输层里的 SOCKS 入站只提供
CONNECT。在 TLS 下,中继的数据报会暴露 TLS 所隐藏的每个目标;在 WebSocket 或 gRPC 前置之后,客户端连到的是前置而不是中继。etemenanki-app 读取 SOCKS 入站的[inbound.stream]时让udp保持默认值,所以包在传输层里的 SOCKS 入站必须设置udp = false。 -
Unix socket 上的 AnyTLS。 Unix 规则要求普通 TCP,AnyTLS 要求 TLS,所以 Unix 绑定上的 AnyTLS 入站总会被拒绝:shape 是
Tls时被 Unix 规则拒绝,是Tcp时被 AnyTLS 自己的规则拒绝。 -
伪装响应。
protocols/src/hysteria/server/masquerade.rs→Masquerade::new拒绝两种情况,校验把它的文本包装成 reason。如果用成功状态码回应未认证的请求,就等于告诉探测者它已经通过了认证,所以233被拒绝。http::StatusCode::from_u16接受 100 到 999,超出这个范围的一律拒绝:inbound hy2: hysteria2: 233 is the authentication success status and cannot be used for the masqueradeinbound hy2: hysteria2: 1000 is not an HTTP status codebuild/inbound.rs中的hy2_handler在构建 handler(处理器)时会再次调用Masquerade::new;有问题的伪装响应已经先被校验拒绝了。masquerade为None时,handler 使用Masquerade::default():状态码 404,响应体404 page not found\n,内容类型text/plain; charset=utf-8,也就是一个未做配置的 Go 服务器给出的响应。 -
TUN 平台检查。
protocols/src/tun/device.rs→check_platform拒绝两种情况。在 Linux、macOS 和 Windows 以外的所有平台上,以ErrorKind::Unsupported拒绝带routes的设备 spec:inbound <tag>: tun routes are installed only on Linux, macOS and Windows; add them with the OS route tool。在 macOS 上,以ErrorKind::InvalidInput拒绝不是utun加数字的name:inbound <tag>: tun name "<name>": macOS names a tun device utun<N>, or leave it unset。在 Linux 和 Windows 上它接受任何 spec。桌面版tun::open(除 Android 和 iOS 外的所有目标都会编译)调用同一个函数,所以--test和真正启动的结论一致。在 Android 和 iOS 上,tun::open以Unsupported和tun devices are created by the system VPN API here; adopt its descriptor拒绝所有设备;这发生在绑定时,所以是check看不到的Bind错误。在 Windows 上,无法创建 Wintun 适配器同样是Bind错误:creating a Wintun adapter (needs wintun.dll beside the executable, and an elevated process): <e>。外部提供的设备(TunSource::Fd,仅 Unix)跳过平台检查:它由所在平台自己配置好。它的 MTU 仍会被检查。 -
Shadowsocks 2022 服务端密钥。 服务端
psk必须恰好是该方法要求的长度;spec 类型写明它是“decoded and sized tomethod”(已解码并按method定长),所以定长是前端程序的事。etemenanki-app 在 lowering 时自己用normalise_psk给服务端密钥和每个客户端密钥定长,所以the shadowsocks-2022 key must be <n> bytes for this method和shadowsocks-2022 keys must be <n> bytes for this method都不会从 app 出现(见 etemenanki-app)。用户密钥更宽松(见下文)。
从 app 采集,每次一个入站:
configuration invalid: inbound s: socks serves udp associate over plain tcp only; turn udp off to wrap it in a transportconfiguration invalid: inbound t: reality is for vless onlyconfiguration invalid: inbound v: vless vision (xtls-rprx-vision) rides only over realityconfiguration invalid: inbound v: invalid reality server name "*.example.com"configuration invalid: inbound any: anytls runs over tls only; its shape must be tlsconfiguration invalid: inbound any: padding scheme line 2: an item is neither c nor min-max with 1 <= min <= max <= 1048576configuration invalid: inbound x: sss udp_max_datagram must be at least 1configuration invalid: inbound x: sss flush_delay must be at most 10msconfiguration invalid: inbound x: sss header_timeout must be above zerovalidate_admission 检查入站将从其用户集中准入的用户。validate 对每个指定了用户集的入站调用它,stage_user_edit 对准入被编辑用户集的每个入站调用它,所以用户编辑与完整的应用遵循同样的规则。
一个入站只按一种凭据类型准入用户,见 build/users.rs → credential_kind:
| 入站协议 | 凭据类型 |
|---|---|
| SOCKS、HTTP | Account |
| Hysteria 2 | Hysteria2UserAuth::Account 时为 Account,Hysteria2UserAuth::Password 时为 Password |
| Trojan、AnyTLS、Shadowsocks | Password |
| VLESS、VMess、sss | Uuid |
| Shadowsocks 2022 | Ss2022Psk |
| TUN | 无:准入直接返回 Ok(()) |
没有这种凭据的用户会被跳过,在这里如此,构建入站时也如此。对其余每个用户,函数按 key 顺序(用户集是以前端程序的 UserId 为 key 的 BTreeMap)推导出一个标识(见下面第一张表),把它插入 seen,然后按第二张表的顺序执行四项检查,遇到第一个失败就停止:
| 凭据 | 比较的标识 |
|---|---|
Uuid |
UUID 的 16 个字节 |
Password |
密码的 UTF-8 字节 |
Ss2022Psk |
解码后、规范化之前的原始 PSK 字节 |
Account |
用户名的字节,在 Hysteria 2 入站上先做 ASCII 小写转换。账户密码不参与比较 |
| 检查 | reason 文本 | 测试 |
|---|---|---|
| 没有两个用户出示相同的标识 | 账户为 users <a> and <b> present the same username,其他为 users <a> and <b> present the same credential |
two_users_may_not_present_the_same_credential、hysteria2_usernames_collide_case_insensitively |
| Shadowsocks 2022:用户 PSK 能规范化到该方法的长度 | user <name>: shadowsocks-2022: PSK too short (<len> < <n>) |
a_shadowsocks_2022_user_key_must_normalise_to_the_method |
Hysteria 2 账户:名称不含 :,名称和密码都非空 |
user <name>: a hysteria2 account needs a name without ':' and a password |
a_hysteria2_username_may_not_hold_a_colon |
| Hysteria 2 按密码准入:密码非空 | user <name>: a hysteria2 password must not be empty |
a_hysteria2_password_may_not_be_empty |
每个都是 Invalid { resource: Inbound(tag) },输出为 inbound <tag>: <reason>。原因如下:
- 一个凭据,一个所有者。 如果两个用户出示同一个凭据,流量算到谁头上就取决于用户表匹配到哪一个。
<a>是按 key 顺序先见到的用户,<b>是第二个。 - 只看准入所用的类型。 两个用户共用一个密码,在按账户准入的 SOCKS 入站上不构成冲突(
a_shared_credential_of_another_kind_is_no_conflict)。 - Hysteria 2 不区分大小写。 Hysteria 2 在线路上比较用户名时不区分大小写(
Authenticator::user_pass同样用to_ascii_lowercase转小写),所以Alice和alice在那里是同一个用户名,也只有在那里是。在 SOCKS 入站上,这两个名字是不同的。 - Hysteria 2 的线路格式是
user:pass。 含冒号的名称根本无法出示,空的部分也不算凭据。SOCKS 用单独的字段携带名称,接受冒号(a_hysteria2_username_may_not_hold_a_colon也检查了 SOCKS 入站)。 - 更长的 Shadowsocks 2022 用户密钥会被折叠,而不是被拒绝:
normalise_psk取其 SHA-256 的前key_len字节。准入该用户的每个入站都把密钥规范化到自己方法的长度,这就是这项检查放在准入里、而不放在用户本身上的原因。
准入文本写出的是用户而不是凭据,密钥错误只输出长度。用户以 UserId::name() 命名,它是一个 supervisor/src/entity/user.rs → UserName(Email 或 Username),其 Display 就是字符串本身:
| 前端程序 | UserId |
name() |
|---|---|---|
| etemenanki-app | app/src/lower.rs → UserKey,即 UserName 本身 |
用户的 email。SOCKS 或 HTTP 账户,以及没有 email 的 Hysteria 2 用户,以其认证所用的用户名命名,所以对这些用户,文本中显示的是该用户名 |
| katana | src/lower/mod.rs → Uid(i64),即面板用户 id |
十进制 id 的 UserName::Username |
从 app 捕获的输出:
configuration invalid: inbound t: users a@example.com and b@example.com present the same credentialconfiguration invalid: inbound ss: users alice and bob present the same credentialconfiguration invalid: inbound ss: user alice: shadowsocks-2022: PSK too short (15 < 16)configuration invalid: inbound hy2: users Alice and alice present the same usernameconfiguration invalid: inbound hy2: user a:b: a hysteria2 account needs a name without ':' and a passwordconfiguration invalid: inbound hy2: user a: a hysteria2 account needs a name without ':' and a password最后一行是一个密码为空的用户。
校验之后的错误
Section titled “校验之后的错误”Disruptive
Section titled “Disruptive”Actor::apply 在暂存返回之后、准备任何东西之前检查计划:
let (spec, plan, users) = self.stage(spec).await?;if !options.allow_disruptive && let Some((inbound, reason)) = plan.disruptions().next(){ let refused = ApplyError::Disruptive { inbound: inbound.clone(), reason: reason.clone() }; drop_off_runtime((spec, users)); return Err(refused);}只报告按步骤顺序的第一个中断性变更。Plan::disruptions() 按计划中的顺序产出 Step::Disrupt 步骤,而 plan 把它们收集在一个 handler 替换列表里,按 spec 顺序逐个入站加入,并把这个列表追加在 Step::PublishPlane 之后。因此报告的是按 spec 顺序第一个有中断性变更的入站。文本为 inbound <tag>: <reason>; this ends its live connections and needs allow_disruptive,例如 inbound hy2-in: the hysteria2 obfuscation changed; connected clients cannot follow the new key; this ends its live connections and needs allow_disruptive。哪些变更属于中断性变更、以及每条 reason 文本,见规划与应用变更。被拒绝的中断性 spec 不绑定任何东西,但暂存阶段已经构建了它的 handler 和用户表;它们与 spec 一起在阻塞线程池上被丢弃(drop_off_runtime)。测试:supervisor/tests/hot_swap.rs 中的 a_hysteria2_obfuscation_change_needs_allow_disruptive。
spec 是合法的,但构建它的某个资源失败了。Actor::prepare 给每个失败附上它正在构建的资源。入站的 handler 或用户表更早就在暂存阶段构建(stage_users,用户编辑时是 stage_user_edit),准备阶段在 DNS、出站、负载均衡器和路由之后按入站顺序报告它的错误:
| 文本中的资源 | 构建者 | 典型原因 |
|---|---|---|
dns |
build/dns.rs → build_dns |
某个解析器无法构建;或者对带 use_hosts 的 split spec,系统 hosts 文件无法读取 |
outbound <tag>@v<n> |
build/outbound.rs → build_outbound |
CA 证书包无法解析 |
balancer <tag> |
Balancer::new |
成员列表为空,校验会先拒绝 |
route |
build/route.rs → compile_routes |
geodata 缺失、无法读取或不含被引用的代码 |
inbound <tag> |
暂存阶段:build_handler、user_table、UserTarget::prepare(它用 UserTable::prepare_for 构建 VMess 用户集)。准备阶段:prepare_swap、Pending::pair |
证书或私钥无法解析;QUIC endpoint 无法在其 socket 上打开;TUN 设备无法准备 |
从 app 捕获的输出:
configuration invalid: building inbound v failed: no certificate in PEM bundleconfiguration invalid: building inbound hy2 failed: hysteria2: the certificate file contains no certificatesconfiguration invalid: building outbound t-out@v1 failed: no certificate in CA PEM bundleconfiguration invalid: building route failed: a geosite matcher is used but no geosite file is configuredconfiguration invalid: building inbound ss failed: shadowsocks-2022: multi-user requires an aes-gcm method有些构建代码会重复一条校验已经执行过的规则,作为兜底检查。万一走到这里,每一项都以 Build 失败:
| 兜底检查 | 文本 | 重复的规则 |
|---|---|---|
build/inbound.rs → hy2_handler |
Masquerade::new 的文本 |
伪装响应规则 |
build/inbound.rs → user_table |
包在 normalise_psk 错误外面的 inbound <tag>: user <label>: <e> |
Shadowsocks 2022 用户密钥规则 |
build/inbound.rs → mismatch |
inbound <tag>: protocol and bind do not match |
协议与绑定的配对:TUN 协议的绑定不是设备,或者流式协议的用户表构建出来是 Hysteria 2 的表、已准备的 VMess 用户集或者没有表 |
build/inbound.rs → build_transport |
missing tls;missing reality settings;来自 WsRoute::real_ip_header 的 not a header name: "<name>" |
入站 TLS 和 REALITY 配对;真实 IP 头名规则 |
build/inbound.rs → padding |
SchemeError 的文本,类型为 InvalidInput |
AnyTLS 填充方案规则 |
build/outbound.rs → transport_connector |
missing tls、missing ws host、missing grpc authority、missing reality |
出站 TLS 和 REALITY 配对,以及 WebSocket 和 gRPC 规则 |
system/listener.rs → check_obfs |
来自 Salamander::new 的 malformed: hysteria2 obfs psk is too short,错误类型为 InvalidInput |
Salamander 密钥长度 |
system/listener.rs → mismatch |
the handler is not of the kind its listener serves |
在 Pending::pair、prepare_swap 和 UserTarget::prepare 中,handler 或用户表的类别与其监听器不符 |
topology/balancer.rs → Balancer::new |
a balancer needs at least one outbound |
空负载均衡器规则 |
check_obfs 在准备阶段运行(在 Pending::pair 和 prepare_swap 中),这样把运行中的监听器切换到新密钥时,就不会在提交阶段失败。
Validator::from_config 还有一个不会失败的兜底:两个被准入用户的密钥在规范化后相等时,它保留第一个、跳过第二个,并以 WARN 级别记录 shadowsocks-2022: users "<a>" and "<b>" share a key; only "<a>" is matched。protocols 的测试 users_sharing_a_psk_resolve_to_the_first 固定了这一行为。
为新监听器调用的 system/listener.rs → bind 失败了:TCP、UDP、Unix 或交接绑定失败,Unix 或交接 socket 路径上存在的不是 socket,Unix 或交接绑定找不到空闲的暂存名(no free name to stage <path> under),交接 socket 的目录无法创建或无法设置其 mode 或组,交接 socket 无法设置其 mode 或组,或者创建 TUN 设备(tun::open)、接管外部提供的设备(tun::adopt,仅 Unix)、取得设备的第二个句柄(try_clone)失败。在 Windows 上,无法创建 Wintun 适配器时报 creating a Wintun adapter (needs wintun.dll beside the executable, and an elevated process): <e>。在非 Unix 平台上,Unix 绑定或交接 socket 以 ErrorKind::Unsupported 和 unix socket <path>: not served on this platform 失败,这是一项兜底检查,校验的 unix sockets are not served on <os> 或 handoff sockets are not served on <os> 会先拦下它。文本为 inbound <tag>: binding <bind> failed: <io error>。只有 listener::bind 会产生 Bind。Pending::pair 对已绑定 socket 所做的事(打开 Hysteria 2 QUIC endpoint、准备 TUN 设备)失败时是 Build。
Unix 或交接 socket 以路径旁边的暂存名绑定,等它的监听器在提交时启动,才被移到路径上。对路径本身,bind 先看上面有什么(symlink_metadata):
| 路径上 | bind |
|---|---|
| 没有东西 | 直接绑定 |
| 陈旧的 socket 文件 | 照常绑定;该文件在提交时被替换 |
| 不是 socket 的文件 | 以 ErrorKind::AlreadyExists 和 <path> exists and is not a socket 拒绝,例如 inbound socks: binding unix:/run/etemenanki/socks.sock failed: /run/etemenanki/socks.sock exists and is not a socket |
bind 拿到 TUN 设备时以 INFO 级别记录日志:创建的设备记录 inbound <tag> owns tun device <name>,接管的设备记录 inbound <tag> serves a supplied tun device。这些日志出自准备阶段,所以即使这次应用随后被拒绝,它们也会出现。inbound <tag> listening on <bind> 只在提交阶段启动监听器时记录。
Stopped
Section titled “Stopped”Supervisor 上每个修改或读取 actor 所持有内容的方法(apply、apply_with、update、update_with、set_users、upsert_user、remove_user、close、sessions、shutdown)都经过 ask:它在 actor 的通道(容量 16)上发送一个 Command,然后等待 oneshot 回复。任一步失败都变成 Stopped:actor 已经关闭,或者它丢弃了回复。没有正在运行的 spec 可编辑时,Command::Update(经由 Actor::edited)和 stage_user_edit 也返回 Stopped。close 和 sessions 把 Stopped 分别转成 0 和空列表,shutdown 则忽略它。http_ping 也透過 ask 查詢它的出站(Command::Target),這一步失敗時得到的是延遲測試自己的 PingError::Stopped(the supervisor has stopped),而不是 ApplyError。
用户编辑路径
Section titled “用户编辑路径”set_users、upsert_user 和 remove_user 不运行 validate:它们只修改一个用户集,别的都不动。Actor::edit_users 在阻塞线程池上用 stage_user_edit 暂存这次编辑,它的失败情况:
| 情况 | 错误 | 文本 |
|---|---|---|
| 没有正在运行的 spec | Stopped |
the supervisor has shut down |
| 没有用户集带有该 tag | Invalid { resource: UserSet(tag) } |
user set <tag>: no such user set |
| 准入该用户集的某个入站拒绝了某个用户 | Invalid { resource: Inbound(tag) } |
准入一节的文本 |
用户表无法构建(user_table),或与其监听器不匹配(UserTarget::prepare) |
Build { resource: Inbound(tag) } |
building inbound <tag> failed: <io error> |
对不在用户集中的用户调用 remove_user 返回 Ok(false),不做任何检查。所有用户表都在存入任何一张之前准备好,所以被拒绝的编辑一张也不会存入。该路径的其余部分见用户、principal 与会话。
试运行:check
Section titled “试运行:check”check 在一个用完即弃的 actor 上执行一次应用的前半部分:
pub async fn check<U: UserId>(spec: &Spec<U>) -> Result<(), ApplyError> { let mut actor = Actor::new(SocketOptions::default()); let (spec, plan, users) = actor.stage(spec.clone()).await?; let checked = actor.prepare(&plan, &spec, users, false).await.map(drop); drop_off_runtime(spec); checked}Actor::new 构建 actor 的状态(根 token、TaskTracker、Sessions、Tracker、采样器),不 spawn 任何任务。它的运行状态是 RunningState::empty(),所以计划会构建每一个资源、不复用任何资源,也没有 Disrupt 步骤。check 克隆 spec,因为暂存会把它移到阻塞线程池上。Actor::stage 在那里规划它并暂存其用户,与应用运行的暂存相同;随后 prepare 以 bind = false 运行。构建出的一切在 check 返回时被丢弃,spec 则在阻塞线程池上被丢弃。
check 覆盖的内容:
| 步骤 | 做了什么 | 可能的失败 |
|---|---|---|
validate,暂存阶段 |
本页的每条规则 | 校验阶段的各个变体 |
对每个入站运行 admit,暂存阶段 |
准入结果和用户 key | 无 |
对每个入站运行 build_handler,暂存阶段 |
由 PEM 字节构建的服务端 TLS 配置、Hysteria 2 的 QUIC 服务端配置和伪装响应、用户表(包括 Validator::from_config) |
inbound <tag> 上的 Build,由准备阶段在下面几行之后报告 |
build_dns |
各解析器;对带 use_hosts 的 split spec,读取系统 hosts 文件 |
dns 上的 Build |
对每个出站运行 build_outbound |
传输层 connector(连接器)、TLS 客户端配置和 CA 证书包、协议密钥 | outbound <tag>@v<n> 上的 Build |
对每个负载均衡器运行 Balancer::new |
成员及其探测目标;不启动探测任务 | balancer <tag> 上的 Build |
compile_routes |
路由表,以及规则引用的 geodata 集合(从文件读取) | route 上的 Build |
check 看不到的内容:
| 未做的事 | 启动时在哪里发生 | 失败类型 |
|---|---|---|
| 绑定 TCP、UDP、Unix 和交接监听器,包括检查 socket 路径上没有其他文件,以及创建交接 socket 的目录、给它和 socket 设置 mode 和组 | listener::bind |
Bind |
创建 TUN 设备并安装其路由(tun::open,包括 Windows 上的 Wintun 适配器),或接管外部提供的描述符(tun::adopt) |
listener::bind |
Bind |
在 socket 上打开 Hysteria 2 endpoint(Hy2Inbound::open)、检查其混淆密钥(check_obfs)、准备 TUN 设备(TunInbound::prepare) |
Pending::pair |
Build |
| 相对于正在运行的 supervisor 的中断性变更 | Actor::apply |
Disruptive |
| 任何网络上的事:解析上游、连接上游、探测负载均衡器成员 | 提交之后 | 不是 ApplyError |
所以除了绑定时的那些构造步骤之外,check 与启动在每条语义规则和每个构造函数上结论一致。通过 check 的 spec 仍可能被正在运行的 supervisor 以 Disruptive 拒绝,因为 check 是从空状态开始规划的。app 可以演示绑定上的这个缺口:listen 指向一个已存在的普通文件的 SOCKS 入站能以 Configuration OK. 通过 --test,而启动时会以 Bind 被拒绝。
check 在调用方的任务上运行,只有暂存和最后的丢弃在阻塞线程池上运行(system/blocking.rs → off_runtime、drop_off_runtime)。它不接受任何 SupervisorBuilder 设置:它的 actor 使用 SocketOptions::default()。socket 策略在这里没有作用,因为 check 不拨号。
调用方:
| 调用方 | 函数 | 检查什么 |
|---|---|---|
etemenanki-app --test |
app/src/instance.rs → check → check_bytes |
配置文件及其指定的订阅文件,合并并降为 spec;以及 [api] 选项(crate::api::options);然后对 spec 运行 etemenanki_supervisor::check。因此有问题的 [api] 会让 --test 以 LoadError::Config 失败 |
| etemenanki-app REST API | app/src/api.rs → ConfigFile::set_route → check_bytes |
编辑后的配置,在写入之前 |
| katana | src/runtime.rs → check_node → lower::test_spec |
節點的 real_ip_header 和 real_ip_from、交接相關的鍵和 [node.hysteria] congestion、行程級的出站和 DNS、節點自己的路由表(不含審計規則),以及 node_type 為 Hysteria 2 的節點在本地設定的入站 |
| 测试 | app/tests/unit/subscribe.rs → every_lowered_node_builds_and_the_dns_setup_with_it;katana tests/unit/lower/outbound.rs → wireguard_ipv4_only_builds_with_ipv4_address、wireguard_ipv6_only_requires_ipv6_address |
降为 spec 后的订阅示例;katana 的 WireGuard lowering |
在 katana 中,build_node(用於啟動時,以及重載新增的節點)、test_config(--test)和 apply_reload 都會呼叫 check_node,每處都在建立節點的面板客戶端之後。對 node_type 為 Hysteria 2 的節點,test_spec 用 [node.hysteria] 降出入站(src/api/hysteria.rs → local,埠 0 替換為 1),並准入一個佔位使用者(uid 0,email placeholder)。對其他所有節點,包括 helium 節點(它不寫 node_type,因為協定由面板描述),入站及其使用者來自面板,不在檢查範圍內。在這兩者之前,test_spec 對所有節點型別都先把 [node.controller] 的 real_ip_header 和 real_ip_from 降為 spec(src/lower/inbound.rs → real_ip):這兩個鍵是本地的,所以其中的錯誤在 --test、啟動和重載時就被拒絕,不必等到某個面板給出 WebSocket 節點(tests/unit/lower/spec.rs 中的 the_node_check_refuses_a_half_real_ip_setting)。它還對每個節點檢查 [node.hysteria] congestion(inbound::congestion),所以在面板描述出 Hysteria 2 節點之前,--test 對 helium 節點也會報告 unknown hysteria congestion "vegas" (expected "cubic", "bbr" or "reno")(a_helium_nodes_check_judges_its_congestion_control)。
前端程序如何报告错误
Section titled “前端程序如何报告错误”supervisor 返回 ApplyError,对拒绝本身不记任何日志。它关于应用的唯一一条日志是提交结束时的 DEBUG 日志 applied: <n> built, <n> reused, <n> swapped, <n> drained(supervisor.rs → Actor::commit)。各前端程序自行补充上下文。
etemenanki-app
Section titled “etemenanki-app”app/src/instance.rs → LoadError 合并了两种失败来源,两者都是 #[error(transparent)],所以文本就是内层错误的文本:
pub enum LoadError { /// The files could not be read, or what they say could not be lowered. Config(#[from] io::Error), /// The supervisor refused the spec. Apply(#[from] ApplyError),}app 的 lowering(app/src/lower.rs → lower)自己拒绝语法和文件问题(LoadError::Config),把本页的规则留给 supervisor,只有两个例外:
- Shadowsocks 2022 服务端和客户端密钥。 spec 要求它们已按方法定长,所以 lowering 用
normalise_psk定长:更长的密钥被折叠,过短的被拒绝,文本为inbound <tag>: shadowsocks-2022: PSK too short (<len> < <n>)或outbound <tag>: shadowsocks-2022: PSK too short (<len> < <n>)。用户的密钥只解码、不定长,因为它的长度取决于准入它的入站,所以由 supervisor 的准入检查来定长。 - 用户名。 用户集是一个 map,同名的第二项会覆盖第一项。lowering 会拒绝缺少其协议用作 key 的那个名字的用户(
inbound <tag>: users[<i>] has no email; a user of this inbound is named by its email,账户则为… has no user),也会拒绝同名的两项(inbound <tag>: users[<i>] and users[<j>] are both named "<name>";SOCKS 和 HTTP 为accounts[…])。两个不同的名字出示同一个凭据的情况留给准入处理。
app/tests/unit/lower.rs → semantic_problems_are_left_to_the_supervisor 对一份违反本页多条规则的配置做 lowering(入站 tag 重复、TUN MTU 为 1000、Hysteria 2 入站同时设了密码和用户、UDP 空闲超时 1 秒且 circuit 数为零、Trojan 共用密码、WireGuard 地址族没有匹配的地址、Hysteria 2 客户端的流数为零、负载均衡器和规则指定了不存在的出站),并断言 lowering 接受它、把这些值原样带进 spec。syntax_errors_are_refused 固定了 app 自己拒绝的内容。lowering 本身见etemenanki-app:从 TOML 到 spec。
从 app 捕获的输出。lowering 自己的拒绝不带 supervisor 的措辞:
configuration invalid: inbound ss: shadowsocks-2022: PSK too short (16 < 32)configuration invalid: outbound ss-out: shadowsocks-2022: PSK too short (15 < 16)configuration invalid: inbound t: users[0] and users[1] are both named "alice@example.com"configuration invalid: inbound t: users[1] has no email; a user of this inbound is named by its emailapp 的 tracing_subscriber::fmt subscriber 写到 stdout,ERROR 日志也一样。--test 和启动相关的日志由 target etemenanki_app 记录(app/src/main.rs);config loaded、config reloaded 和重载错误由 target etemenanki_app::instance 记录。
| 场景 | 输出 |
|---|---|
--test,通过 |
stdout 上输出 Configuration OK.,退出码 0 |
--test,被拒绝 |
ERROR 级别的 configuration invalid: <e>,退出码 1 |
| 启动,被拒绝 | ERROR 级别的 failed to start: <e>,退出码 1 |
| 启动,API 无法启动 | ERROR 级别的 failed to start: API on <listen>: <e>,退出码 1 |
| 启动,已应用 | INFO 级别的 config loaded: <summary> |
| 重载,已应用 | INFO 级别的 config reloaded: <summary> |
| 重载,文件无法读取 | ERROR 级别的 reload: cannot read <path>: <e> |
重载,以 Disruptive 被拒绝 |
ERROR 级别的 reload refused, keeping the running config: inbound <tag>: <reason>, which would end its live connections; restart to apply it |
| 重载,其他拒绝 | ERROR 级别的 reload: <e>; keeping the running config |
app 用 SupervisorBuilder::start 启动(Instance::start → Core::start,配合 Supervisor::builder()),用 Supervisor::apply 重载,两者都使用默认的 ApplyOptions。它会拒绝修改 TUN 入站(设备或其设置)或 Hysteria 2 监听器混淆的重载,重启即可应用。<summary> 是 ApplyReport 一节描述的 summary 格式。重载路径见etemenanki-app:运行、重载与关停。
对 REST API,impl From<LoadError> for ControlError 按责任归属对失败分类。Bind 和 Stopped 变成 ControlError::Failed(HTTP 500):不是配置的错。其余所有 ApplyError 变成 ControlError::Invalid(HTTP 422)。lowering 产生的 io::Error 在其 kind 为 InvalidData 或 InvalidInput 时是 Invalid,否则是 Failed。另外两个变体不来自加载:UnknownGroup(HTTP 404,no route group named "<group>")和 Stale(HTTP 409,the config file has changed since it was read; its ETag is now <etag>)。webclient/src/router.rs 把每个变体映射到对应的状态码。ConfigFile::set_route 在两处以 Stale 拒绝:一处在编辑之前,If-Match 指定的是另一个 ETag 时;另一处在 check_bytes 之后,磁盘上的文件已不再是它读到的字节时。它在那个时刻重新读取文件,是因为检查要构建启动时会构建的一切,需要一段时间,而这期间手工保存的修改不能被覆盖。
FfiError 声明为 #[uniffi(flat_error)]。ffi/src/error.rs → impl From<LoadError> for FfiError 先挑出客户端自己对服务端入站的拒绝,即 FfiError::ServerInbound,输出为 inbound "<tag>" serves <protocol>, a server protocol; only a tun inbound and local socks or http inbounds run in a client。其余的都经过 ControlError:
ControlError |
FfiError |
|---|---|
Invalid |
Config { message } |
Stale |
Config,以 Stale 的文本作为 message |
UnknownGroup |
UnknownGroup { group } |
Failed |
Io { message } |
Config 和 Io 只输出 message,所以移动端 app 看到的是原样的 ApplyError 文本。由于 ApplyError::Stopped 会变成 ControlError::Failed,它到达 app 时是文本为 the supervisor has shut down 的 FfiError::Io,而不是 FfiError::Stopped(见移动端库(etemenanki-ffi))。
katana
Section titled “katana”--test(src/runtime.rs→test_config)先拒绝没有节点的配置(config defines no [[node]] entries),运行warn_shared_wireguard(多个节点路由到同一个 WireGuard 出站时输出一条WARN),然后为每个节点构建面板客户端并运行check_node,在任何错误前加上节点 id。它在 stdout 上输出Configuration OK,或在 stderr 上输出configuration error: <e>并以退出码 1 退出。捕获的输出:configuration error: node 1: outbound wg-egress@v0: wireguard address_family ipv6_only needs an IPv6 address。- 配置文件重载(
apply_reload)在动任何正在运行的节点之前,对每个新增或修改的节点运行check_node;[[outbound]]或[dns]变化时则对所有节点运行。拒绝时以ERROR级别记录reload: node <node>: <e>; keeping current config,其中<node>是<panel_type>@<host>#<node_id>,设置了 node type 时后面再加/<node_type>。见进程运行时与重载。 - 节点用
Supervisor::apply_with和ApplyOptions { allow_disruptive: true }应用它的 spec(src/manager/node.rs→reconcile),所以 katana 永远不会收到Disruptive,修改后的 Hysteria 2 混淆会被应用而不是被拒绝。见节点管理器。 - katana 在
src/api/hysteria.rs中讀取 Hysteria 2 節點的[node.hysteria](local用於只由這個塊描述的節點,uniproxy用於由它補全的 UniProxy 節點),並在那裡自己保留了兩項 supervisor 也會做的檢查:Salamander 金鑰長度(obfs_password must be at least 4 bytes for salamander),以及 2 到 600 秒的 UDP 空閒逾時(上游的範圍)。同一個檔案還會拒絕 supervisor 沒有規則覆蓋的設定:udp_idle_timeout is set but udp is not enabled、obfs_password is set but obfs is not; did you mean obfs = "salamander"?和unknown obfs "<x>" (expected "salamander")。之後它讓節點符合 helium-node-api 的規則(validate),helium 面板的節點設定在讀取時就符合這些規則。入站的 lowering(src/lower/inbound.rs→lower_hysteria)透過Masquerade::new檢查偽裝回應(它的註釋說,supervisor 會拒絕同樣的回應,katana 也自己判斷一遍,“so the refusal reads as it always has”,即讓拒絕資訊保持一貫的樣子),並拒絕unknown hysteria credential kind "<x>" (expected "uuid" or "user_pass")和unknown hysteria congestion "<x>" (expected "cubic", "bbr" or "reno")。這些文字不帶inbound字首,例如configuration error: node 1: udp_idle_timeout must be between 2 and 600 seconds和configuration error: node 1: obfs_password must be at least 4 bytes for salamander。supervisor 的規則仍在它們之後生效。該檔案見入站與出站的 lowering。 PanelClient::new(src/api/mod.rs)建立節點的panel_type所指的客戶端:NewV2board或V2board,或Helium,大小寫不拘。它按名字拒絕SSpanel(大小寫不拘),訊息為panel_type "SSpanel" is not supported: katana serves the NewV2board and Helium panels,引號中是設定檔裡的寫法;其他值則以unknown panel_type "<value>"拒絕,值轉為小寫。例如--test印出configuration error: node 1: panel_type "SSpanel" is not supported: katana serves the NewV2board and Helium panels。啟動時,被拒絕的節點會記錄下來且不執行;指名它的重載會整個被拒絕。- helium 節點的面板客戶端(
src/api/helium.rs→Client::new、refuse_local_protocol)拒絕會重複面板所描述內容的本地鍵:[node.api] node_type和enable_vless,以及[node.hysteria]中除congestion之外的每個鍵。它按這個順序指出第一個被設定的鍵,例如configuration error: node 1: [node.api] node_type is set, but a helium node's protocol is described by the panel; remove it (of [node.hysteria], only congestion is this host's to choose)。build_node、test_config和apply_reload都在呼叫check_node之前建立客戶端,所以啟動、--test和重載都會拒絕它,遇到它的重載整個被拒絕。newV2board 客戶端以同樣的方式拒絕node_type = "sss":newV2board: no UniProxy panel describes an sss node; sss is Helium's own protocol, served with panel_type = "Helium"。見面板客戶端。 - katana 对真实 IP 的 lowering(
src/lower/inbound.rs→real_ip)要求real_ip_header和real_ip_from要么同时设置,要么都不设置,并拒绝 supervisor 之后才会拒绝或者根本看不到的问题:real_ip_from is set without real_ip_header、real_ip_header needs real_ip_from: the proxies trusted to set it、real_ip_header "<h>" is not a header name,以及网络无法解析时的real_ip_from "<net>": <cidr error>。它的注释给出了原因:拒绝只设置一半或拼错的配置,可以避免节点悄悄地不读取任何头,或者信任一个谁都没打算信任的地址。这些文本同样不带inbound前缀,例如configuration error: node 1: real_ip_header needs real_ip_from: the proxies trusted to set it。降出的RealIpSpec只在传输层为 WebSocket 的节点上进入入站,所以在其他节点上,supervisor 自己的规则根本看不到它。 - katana 对交接的 lowering(
src/lower/inbound.rs→handoff)读取handoff_dir和handoff_group,拒绝会留下中继无法到达的 socket 的设置:handoff_group is set without handoff_dir、handoff_dir "<dir>" must be an absolute path、handoff_dir "<dir>" is too long: with "<name>" in it, a socket's path would pass the 107 bytes a Unix socket's path may have(<name>是该节点最长的 socket 名,即它在端口 65535 上的名字:监听全部地址时为65535.sock,监听单个地址时为<listen_ip>-65535.sock)、handoff_group "<name>": reading /etc/group: <error>和handoff_group "<name>" is not a group in /etc/group。test_spec对每种节点类型(包括 Hysteria 2)都运行它,所以--test、启动和重载都会在任何面板给出端口之前拒绝错误的键,例如configuration error: node 1: handoff_group is set without handoff_dir。它降成的 socket 路径随后还要接受 supervisor 的规则,而目录的创建、mode 和组要到绑定 socket 时才检查。 - katana 对用户的 lowering(
src/lower/mod.rs→lower_users)会跳过以下用户并输出一条WARN:凭据无法降为 spec 的用户(skipping user <uid>: <why>)、重复列出的 uid(skipping user <uid>: listed twice),以及凭据已被之前某个用户出示过的用户(skipping user <uid>: shares its credential with user <first>)。凭据归第一个用户,所以共用同一凭据的两个面板用户不会走到validate_admission。这些原因只指明用户,从不输出凭据。见把节点降为 spec。
| 不变量 | 原因 | 由谁固定 |
|---|---|---|
| 每次应用、更新、启动和检查都在规划任何步骤之前先校验 | plan 首先调用 validate,而每条路径都调用 plan |
supervisor/tests/unit/plan.rs → an_invalid_spec_is_refused_without_a_plan |
| 被拒绝的 spec 不改变任何正在运行的东西 | 校验和 Disruptive 在准备之前就拒绝;暂存和准备阶段没有可见的效果,它们构建的东西会被丢弃 |
supervisor/tests/hot_swap.rs → a_refused_spec_changes_nothing:一个未知的路由目标,以及一个同时替换用户集和路由默认出站、但无法绑定端口的 spec,都让 epoch、用户和监听器保持原样 |
| 校验不碰文件、socket 或时钟 | 针对 spec 的纯函数 | 单元测试在内存中构建每个 spec,TLS 字节可以任意 |
| 每条规则单独测试 | 每个测试在一个其他方面都合法的 spec 中只破坏一条规则;规则有边界时,还检查仍被接受的那个边界值 | supervisor/tests/unit/validate.rs(模块注释) |
| 构建代码可以假设 spec 合法 | Actor::prepare 中的 expect 调用依赖校验 |
tag 和负载均衡器相关测试 |
| 出站和负载均衡器的 tag 共用一个命名空间;入站和用户集的 tag 不共用 | 路由以同样的方式指定出站和负载均衡器 | a_balancer_may_not_share_an_outbounds_tag、an_inbound_may_share_an_outbounds_tag |
| spec 中没有空 tag | 空 tag 指的是 supervisor 自己的目标 | no_tag_may_be_empty |
| 用户编辑与应用遵循相同的准入规则 | stage_user_edit 调用 validate_admission |
无专门测试 |
| 准入文本写出用户,而不是凭据 | 用户以 UserId::name() 命名;密钥错误只输出长度。名字可能是账户的用户名(etemenanki-app) |
无专门测试 |
check 与启动在语义和构建上一致 |
同样的 stage 和 prepare,只有 bind 不同 |
无专门测试 |
失败路径与取消
Section titled “失败路径与取消”- 每次拒绝只报一个错误。
validate在第一条被违反的规则处返回,prepare在第一个失败的步骤处返回。一个 spec 有几个问题,就需要尝试几次才能全部找出来。 - 拒绝时释放什么。 暂存和
prepare构建的一切都存放在局部变量、暂存的用户和Prepared结构体中。出错时它们被丢弃;spec 会在阻塞线程池上被丢弃(drop_off_runtime),以Disruptive拒绝时暂存的用户也随之一起。同一次准备中先前绑定的监听器会再次关闭(a_refused_spec_changes_nothing先绑定一个备用端口,之后检查它已空闲),这样的绑定创建的 Unix 或交接 socket 文件仍在暂存名上,由它的SocketFileguard 删除。socket 路径上的东西从未被动过,所以运行中监听器的 socket 文件留在原处。用户 key 分配在UserKeys的暂存副本上,只有应用提交时才保留。 - 丢弃应用的 future。
ask先发送命令,再等待回复。如果调用方在发送仍在等待通道容量时丢弃 future,什么都不会发出。命令一旦进入通道,actor 就会把这次应用执行到底,成功则提交;回复随后发往一个已无人接收的地方,被忽略(let _ = reply.send(...))。 check是调用方任务上的普通 future,只是把暂存和最后的丢弃交给阻塞线程池。丢弃它会丢弃准备阶段构建的一切。阻塞线程池上的任务无法取消,所以 future 被丢弃时已经在运行的暂存会运行到底,它构建的东西随其结果一起被丢弃。- 第一个 spec。
SupervisorBuilder::start在 spawn 采样器、guard 的清理任务、usage sink 或 actor 任务之前应用第一个 spec。第一个 spec 被拒绝时什么也不启动,并返回ApplyError。在应用任何东西之前,start会断言采样间隔不为零;间隔为零时以the sample interval must not be zeropanic,而不是返回ApplyError。 - 被拒绝的应用留下的日志。 supervisor 不记录拒绝,但准备阶段自己的
INFO日志会留在日志里:在准备一次随后被拒绝的应用时创建或接管的 TUN 设备,已经记录了inbound <tag> owns tun device <name>或inbound <tag> serves a supplied tun device。
| 限制 | 值 | 位置 |
|---|---|---|
| 每次拒绝报告的错误数 | 1 | validate、prepare |
| TUN MTU | 至少 1280(MIN_TUN_MTU) |
validate_inbound |
| Hysteria 2 UDP 空闲超时 | 设置时为 2 到 600 整秒,含两端(HY2_UDP_IDLE) |
validate_inbound |
Hysteria 2 max_connections、max_circuits |
至少 1 | validate_inbound |
Hysteria 2 客户端 max_concurrent_streams |
至少 1 | validate_outbound |
| Salamander 密钥 | 至少 4 字节(MIN_SALAMANDER_PSK) |
obfs |
| 伪装响应状态码 | 100 到 999,233 除外 | Masquerade::new |
| Hysteria 2 QUIC 接收窗口 | 16,384(QuicOptions::MIN_RECEIVE_WINDOW)到 2^62 − 1(QUIC_VARINT_MAX)字节,两侧都适用 |
hy2_quic |
Hysteria 2 max_idle_timeout |
4 到 120 的整数秒(HY2_IDLE_TIMEOUT),两侧都适用 |
hy2_quic |
Hysteria 2 keep_alive_period |
设置时为 2 到 60 的整数秒(HY2_KEEP_ALIVE),两侧都适用 |
hy2_quic |
Hysteria 2 max_incoming_streams |
设置时至少 1 | hy2_quic |
| Hysteria 2 跳跃端口 | 至少一个,且都不为 0 | port_hopping |
| Hysteria 2 跳跃间隔 | 最短取值至少 5 秒(HopInterval::MIN_CONFIGURED) |
port_hopping |
| Shadowsocks 2022 服务端密钥和客户端密钥 | 恰好 16 字节(2022-blake3-aes-128-gcm)或 32 字节(2022-blake3-aes-256-gcm、2022-blake3-chacha20-poly1305) |
validate_inbound、validate_outbound |
| Shadowsocks 2022 用户密钥 | 至少为方法要求的长度;更长的密钥会被折叠 | validate_admission |
| 准入用户的 Shadowsocks 2022 入站 | 只能是 2022-blake3-aes-128-gcm 或 2022-blake3-aes-256-gcm |
Validator::from_config,构建时 |
| AnyTLS 填充方案 | 连接后最多 2,048 字节(MAX_SCHEME_LEN) |
PaddingScheme::from_lines,由 validate_inbound 调用 |
sss max_datagram |
至少 1 | sss_limits,两侧 |
sss flush_delay |
最多 10 毫秒(MAX_FLUSH_DELAY) |
sss_limits,两侧 |
sss header_timeout |
大于零 | validate_inbound |
| REALITY server name 和 shortId | 各至少一个;name 不能为空,不能含 * |
reality_settings;单个 server name 时为 outbound_transport |
| supervisor 命令通道 | 16 条排队命令 | SupervisorBuilder::start |
supervisor/tests/unit/validate.rs 被编译进 crate(由 build/validate.rs 通过 #[path] 引入),所以 cargo test -p etemenanki-supervisor --lib 会运行它。它构建一个合法的基础 spec(一个监听 127.0.0.1:1080 的 SOCKS 入站、一个 freedom 出站 direct、系统解析器),然后每次破坏一条规则。
| 测试 | 固定的行为 |
|---|---|
the_base_spec_is_valid |
基础 spec 通过 |
tags_are_unique_within_each_kind |
入站、出站、负载均衡器和用户集的 DuplicateTag |
a_balancer_may_not_share_an_outbounds_tag |
共用的命名空间 |
an_inbound_may_share_an_outbounds_tag |
其他类别各自独立 |
no_tag_may_be_empty |
入站、出站和用户集上的 Invalid |
a_route_rule_must_name_a_known_outbound_or_balancer |
来自 Route 的 UnknownReference |
the_route_default_must_name_a_known_outbound_or_balancer |
默认出站的同样情况 |
a_route_may_name_a_balancer |
负载均衡器可以作为路由目标 |
a_balancer_member_must_be_a_known_outbound |
来自负载均衡器的 UnknownReference |
a_balancer_member_may_not_be_another_balancer |
成员只能是出站 |
an_inbound_must_name_a_known_user_set |
来自入站、kind 为 UserSet 的 UnknownReference |
a_balancer_needs_a_member |
EmptyBalancer |
a_balancer_member_needs_an_upstream_a_tcp_probe_can_reach |
freedom、blackhole、Hysteria 2 和 WireGuard 的 UnprobeableMember |
two_inbounds_may_not_share_a_bind |
后一个入站不合法 |
the_same_port_over_udp_is_another_bind |
TCP 绑定和 UDP 绑定不同 |
each_protocol_is_served_only_on_its_kind_of_bind |
六种被拒绝的配对,三种被接受的配对 |
an_inbound_carries_tls_material_exactly_when_its_shape_layers_tls |
八种 shape 与材料的组合 |
an_inbound_needs_no_ws_host_or_grpc_authority |
入站缺失这些值时被接受 |
an_outbound_carries_tls_settings_exactly_when_its_shape_layers_tls |
六种组合 |
an_outbound_needs_a_ws_host_and_a_grpc_authority |
出站缺失这些值时被拒绝 |
a_unix_listener_carries_only_the_plain_tcp_shape |
Unix 绑定上的 TLS 和 WebSocket shape 被拒绝 |
every_protocol_meets_the_same_transport_rules |
SOCKS、HTTP、Trojan、VLESS、VMess、Shadowsocks 和 Shadowsocks 2022 在 TCP 和 Unix 绑定上走同样六种传输层:带 TLS 的 gRPC 和不带 TLS 的 WebSocket 被接受,TLS 不匹配被拒绝,Unix 绑定上只接受普通 TCP |
shadowsocks_runs_over_a_transport |
两种 Shadowsocks 走 TLS、WebSocket 和 gRPC,带或不带 TLS,处于共享模式 |
socks_relays_udp_over_plain_tcp_only |
开启 udp 的 SOCKS 在 TLS、WebSocket 和 gRPC 上被拒绝,关闭时被接受,在普通 TCP 上开启时被接受 |
shadowsocks_and_socks_over_websocket_read_a_real_ip_header |
WebSocket 上的 Shadowsocks 和 SOCKS 接受 real-IP 头 |
anytls_needs_tls_a_user_set_and_a_scheme_that_parses |
走 TLS、带或不带填充方案的 AnyTLS 被接受;没有用户集、普通 TCP、WebSocket 和 gRPC shape、空方案、stop=x、没有 stop 的方案、含 \r 的方案、颠倒的范围以及超过 2 KiB 的方案被拒绝;Unix 绑定被拒绝 |
an_anytls_outbound_needs_tls_and_a_password |
走普通 TCP、WebSocket 或 gRPC 的 AnyTLS 客户端被拒绝,空密码被拒绝,Tls shape 却没有 TLS 设置被拒绝 |
a_vless_reality_inbound_validates、reality_settings_fail_closed |
走 REALITY 的 VLESS 入站被接受;没有 server name、通配符名字、没有 shortId、端口 0、空主机以及颠倒的客户端版本被拒绝 |
reality_field_must_match_its_shape、reality_is_vless_only |
没有设置的 REALITY shape,以及 TCP shape 旁边的设置被拒绝;其他每个协议(包括 AnyTLS)走 REALITY 被拒绝 |
a_reality_outbound_validates_and_its_field_must_match、a_reality_outbound_is_vless_only |
走 REALITY 的 VLESS 客户端被接受,字段与 shape 不对应时双向拒绝;走 REALITY 的 Trojan 客户端被拒绝 |
a_handoff_socket_stands_beside_a_stream_inbounds_tcp_listener |
TCP 上 SOCKS 旁边的交接 socket 被接受;Unix 绑定上的 SOCKS、Hysteria 2 和 TUN 旁边的被拒绝 |
a_handoff_bind_is_no_inbounds_own |
作为入站自己 bind 的 Handoff 绑定被拒绝 |
a_handoff_socket_is_an_absolute_path_a_unix_socket_can_take |
相对路径、/ 和空路径被拒绝;107 字节被接受,108 字节被拒绝 |
a_handoff_sockets_mode_is_permission_bits_alone |
mode 0o4660 被拒绝 |
two_binds_may_not_share_a_socket_path |
第二个入站位于第一个入站交接 socket 路径上、mode 不同的交接 socket,以及位于交接 socket 路径上的 Unix 监听器,都被拒绝 |
a_real_ip_header_needs_a_websocket_a_trusted_proxy_and_a_name |
在 WebSocket 上信任 127.0.0.1/32 和 ::1/128 的 X-Real-IP 被接受;纯 TCP、gRPC、没有可信网络以及名字 X Real IP 被拒绝 |
trojan_vless_and_vmess_need_a_user_set |
没有开放模式;指定一个用户集即满足规则 |
hysteria2_takes_a_shared_password_or_a_user_set_but_not_both |
两者都设和两者都不设均被拒绝 |
a_hysteria2_shared_password_may_not_be_empty |
空的共享密码 |
a_hysteria2_udp_idle_timeout_is_between_2_and_600_seconds |
1 和 601 被拒绝,2、600 和 None 被接受 |
hysteria2_serves_at_least_one_connection_and_one_circuit |
0 被拒绝,1 被接受 |
a_salamander_key_is_at_least_4_bytes_on_either_side |
入站和出站都是 3 字节被拒绝、4 字节被接受 |
hysteria2_quic_settings_stay_within_upstreams_limits |
两侧都拒绝 16,383 字节的 stream 窗口、为零的连接窗口、3 秒或 30.5 秒的空闲超时、61 秒的 keep-alive 和为零的入向 stream 数;出站接受 16,384 字节、120 秒和 2 秒 |
hysteria2_port_hopping_needs_ports_and_a_sane_interval |
拒绝没有端口、端口 0 和 4 秒的最短间隔;接受固定 5 秒的三个端口和 10 到 60 秒的一个端口 |
a_masquerade_may_not_answer_with_the_success_status |
233 被拒绝,404 被接受 |
a_tun_device_mtu_is_at_least_1280 |
1279 被拒绝,1280 被接受 |
socks_over_a_unix_socket_needs_a_udp_bind_to_serve_udp |
Unix 与 UDP 规则,以及它三种被接受的边界情况 |
a_shadowsocks_2022_server_key_is_sized_to_its_method |
短一个字节或长一个字节都被拒绝 |
a_wireguard_address_family_needs_an_address_of_that_family |
五种地址与地址族的组合 |
a_hysteria2_client_needs_a_password_and_a_stream |
空密码、流数为零 |
shadowsocks_2022_client_keys_are_sized_to_their_method |
用户密钥和一个 identity 密钥 |
two_users_may_not_present_the_same_credential |
共用的 Trojan 密码 |
a_shared_credential_of_another_kind_is_no_conflict |
只看准入所用的类型 |
hysteria2_usernames_collide_case_insensitively |
Alice 和 alice 只在 Hysteria 2 上冲突 |
a_hysteria2_username_may_not_hold_a_colon |
只在 Hysteria 2 上 |
a_hysteria2_password_may_not_be_empty |
按密码准入;形如 UUID 的密码被接受 |
a_shadowsocks_2022_user_key_must_normalise_to_the_method |
过短的密钥被拒绝,更长的被折叠后接受 |
固定本页内容的其他测试:
| 文件 | 测试 | 固定的行为 |
|---|---|---|
supervisor/tests/unit/plan.rs |
an_invalid_spec_is_refused_without_a_plan |
plan 在规划之前就拒绝 |
supervisor/tests/hot_swap.rs |
a_refused_spec_changes_nothing |
UnknownReference 和 Bind 拒绝让运行中的一切保持原样。那个无法绑定的 spec 还替换了用户集(alice 换成 bob)并路由到 block;之后 alice 仍能连接且走直连,bob 被拒绝,epoch 不变,同一次准备中先前绑定的备用端口也再次空闲 |
supervisor/tests/hot_swap.rs |
a_hysteria2_obfuscation_change_needs_allow_disruptive |
混淆变更的 Disruptive |
protocols/tests/unit/hysteria/server/masquerade.rs |
the_authentication_success_status_is_refused、a_value_that_is_not_a_status_code_is_refused |
两种伪装响应拒绝;0、99、1000 和 65535 被拒绝,599 被接受 |
protocols/tests/unit/ss_2022/users.rs |
users_sharing_a_psk_resolve_to_the_first |
Validator::from_config 的兜底在两个用户共用一个密钥时保留第一个 |
app/tests/unit/lower.rs |
semantic_problems_are_left_to_the_supervisor、syntax_errors_are_refused |
app 与 supervisor 之间的分工 |
app/tests/unit/subscribe.rs |
every_lowered_node_builds_and_the_dns_setup_with_it |
降为 spec 后的订阅示例能通过 check |
supervisor/tests/sss.rs |
validation_refuses_bad_limits |
max_datagram 为 0、header_timeout 为零、flush_delay 为 11 毫秒、没有用户集或使用 REALITY shape 的 sss 入站被拒绝;带变换链的被接受 |
katana tests/unit/lower/spec.rs |
the_new_node_kinds_pass_the_supervisors_validation |
katana 的 REALITY 加 Vision 的 VLESS、AnyTLS、走 TLS 的 SOCKS 和 HTTP、走 WebSocket 加 TLS 的 Shadowsocks 和 sss,以及按 helium 描述的 Hysteria 2 節點,降為的 spec 都能通過 validate |
katana tests/unit/lower/outbound.rs |
wireguard_ipv4_only_builds_with_ipv4_address、wireguard_ipv6_only_requires_ipv6_address |
用 check 检验 katana 的 WireGuard lowering |
katana tests/unit/lower/spec.rs |
the_node_check_refuses_a_half_real_ip_setting |
test_spec 拒绝只有 real_ip_header 而没有 real_ip_from 的配置,两者都设置时接受 |
katana tests/unit/lower/spec.rs |
the_node_check_refuses_a_handoff_setting_the_relay_could_not_use |
test_spec 拒绝相对的 handoff_dir 和单独的 handoff_group,两者一起设置时接受 |
katana tests/unit/lower/spec.rs |
a_helium_nodes_check_judges_its_congestion_control |
helium 節點的 test_spec 不含入站,接受 congestion = "bbr",拒絕 "vegas" |
katana tests/unit/api/helium.rs |
local_keys_the_panel_describes_are_refused |
在 helium 節點上按名字拒絕這十二個鍵中的每一個,經由 PanelClient::new 時也一樣;接受 congestion |
katana tests/unit/runtime.rs |
an_sspanel_node_is_refused_at_test_and_at_start、a_reload_to_sspanel_changes_nothing |
--test 和啟動時按名字拒絕 panel_type = "SSpanel",啟動時該節點不執行;把執行中的節點改為它的重載整個被拒絕,節點照常執行 |
katana tests/unit/lower/inbound.rs |
a_handoff_setting_the_relay_could_not_use_is_refused |
按文本检查五种拒绝,全部为 InvalidInput,其中包括 97 字节的目录;96 字节的目录对监听全部地址的节点被接受,对监听 2001:db8::1 的节点被拒绝,错误中带有 2001:db8::1-65535.sock |
没有专门测试的规则:空的负载均衡器 tag、空的 Hysteria 2 账户名或密码(只测试了冒号)、任一侧不走 REALITY 的 VLESS Vision、REALITY 出站传输层旁边的 TLS 设置、REALITY 客户端的 server name、出站一侧的 sss 限制、TUN 平台检查、非 Unix 平台上的 Unix 绑定或交接 socket、TCP 以外绑定上的 proxy_protocol、用户编辑路径的 no such user set,以及被准入检查拒绝的用户编辑(准入测试直接调用 validate 和 validate_admission,测试套件中唯一的 set_users 调用是成功的)。没有任何 supervisor 测试匹配错误文本;只有 protocols crate 的伪装响应测试和 katana 的 WireGuard 测试匹配了其中的片段。因此改写某条规则的措辞仍能通过测试套件;改写时要同步更新本页和错误信息。如何运行测试套件见测试。