fix(conf): refuse interface keys that were never acted on

dns-interface in [General] and interface= on a [Proxy] line were parsed
and then dropped, so traffic meant for a chosen interface left through
the default route while the config said otherwise. Both are now errors
that point to OUTBOUND_INTERFACE, which binds every socket leaf opens.

last-resort on a failover group was dropped the same way. Ignoring it
fails closed -- with every actor down, connections fail rather than go
elsewhere -- so it stays accepted, with a warning that says so.
This commit is contained in:
eric committed 2026-12-04 09:55:40 +08:00
1 parent cedceea53e
commit cfa1aeb5b7
2 files changed
+31 -11

No files matched your search

+4 -4
View File
@@ -882,7 +882,7 @@ quotes nothing. There is no way to write a `"` inside a quoted value.
|---|---|
| `loglevel`, `logoutput`, `logformat` | `log.level`, `log.output`, `log.format` |
| `dns-server = a, b` | `dns.servers` |
| `dns-interface` | Read and ignored |
| `dns-interface` | Refused: it was never acted on. `OUTBOUND_INTERFACE` in `[Env]` binds every socket leaf opens, DNS included |
| `interface`, `port` (or `http-interface`, `http-port`) | An `http` inbound, tag `http`, when both are set |
| `socks-interface`, `socks-port` | A `socks` inbound, tag `socks`, no authentication, when both are set |
| `tun = auto` | A `tun` inbound with `auto` |
@@ -926,7 +926,7 @@ used across a network that is watched. The keys:
| `quic=true` | A `quic` transport instead of TLS, ALPN `http/1.1` |
| `uuid`, `username` | The VMess or VLESS id |
| `reality-public-key`, `reality-short-id` | `reality` settings |
| `interface` | Read and ignored |
| `interface` | Refused, as `dns-interface` |
### `[Proxy Group]`
@@ -943,8 +943,8 @@ The `failover` keys are the JSON settings in kebab-case: `fail-timeout`,
`health-check-active`, `health-check-prefers`, `health-check-on-start`,
`health-check-wait`, `health-check-attempts`,
`health-check-success-percentage`, `fallback-cache`, `cache-size`,
`cache-timeout`. `last-resort` names an outbound to use when every actor is
down; it is read but not yet passed on.
`cache-timeout`. `last-resort` is not implemented: leaf prints a warning and
ignores it, so when every actor is down connections fail.
### `[Rule]`
+27 -7
View File
@@ -591,7 +591,11 @@ pub fn from_lines(lines: Vec<io::Result<String>>) -> Result<Config> {
general.dns_server = get_char_sep_slice(parts[1], ',');
}
"dns-interface" => {
general.dns_interface = get_string(parts[1]);
// Never acted on: queries left through the default route,
// not the interface the deployer named.
return Err(anyhow::anyhow!(
"dns-interface is not supported; set OUTBOUND_INTERFACE in [Env], which binds every socket leaf opens"
));
}
"always-real-ip" => {
general.always_real_ip = get_char_sep_slice(parts[1], ',');
@@ -741,7 +745,11 @@ pub fn from_lines(lines: Vec<io::Result<String>>) -> Result<Config> {
proxy.reality_short_id = Some(v.to_string());
}
"interface" => {
proxy.interface = v.to_string();
// Never acted on, as dns-interface.
return Err(anyhow::anyhow!(
"[{}] interface is not supported; set OUTBOUND_INTERFACE in [Env], which binds every socket leaf opens",
proxy.tag
));
}
_ => {}
}
@@ -884,11 +892,13 @@ pub fn from_lines(lines: Vec<io::Result<String>>) -> Result<Config> {
group.cache_timeout = i;
}
"last-resort" => {
group.last_resort = if !v.is_empty() {
Some(v.to_owned())
} else {
None
};
// Not implemented. Ignoring it fails closed: with
// every actor down the connection fails rather
// than going elsewhere.
println!(
"[{}] last-resort is not supported and is ignored: when every actor is down, connections fail",
group.tag
);
}
"health-check-timeout" => {
let i = v.parse().ok();
@@ -2075,4 +2085,14 @@ mod value_tests {
assert_eq!(p[0].encrypt_method.as_deref(), Some("aes-128-gcm"));
assert_eq!(p[0].password.as_deref(), Some("secret"));
}
#[test]
fn keys_that_were_never_acted_on_are_refused() {
let parse = |conf: &str| from_lines(conf.lines().map(|s| Ok(s.to_string())).collect());
assert!(parse("[General]\ndns-interface = en0\n").is_err());
assert!(parse("[Proxy]\nT = trojan, 1.2.3.4, 443, pw, interface=en0\n").is_err());
assert!(
parse("[Proxy]\nA = direct\n[Proxy Group]\nG = failover, A, last-resort=A\n").is_ok()
);
}
}