Skip to content

Bind to a named interface, and drop the lan that never did - #9

Merged
fylorn merged 1 commit into
mainfrom
dev
Sep 14, 2026
Merged

fylorn merged 1 commit into
mainfrom
dev

Conversation

@fylorn

@fylorn fylorn commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

The lan that never did

Bind had three values — loopback, lan, all — and two of them were the same thing. lan and all both resolved to 0.0.0.0; the only difference between them was the default contents of allow_from.

That made lan a whitelist concept wearing a network-interface costume. Someone picking "LAN" reasonably believes the gateway is listening on their local network interface. It is listening on every interface, including whichever one faces the internet, and the only thing between the two is a CIDR list they never saw.

The field's own doc comment has always read loopback | lan | all | 具体 IP, so a concrete address was the intent — the enum just never grew one.

bind: loopback      # 127.0.0.1
bind: 192.168.1.5   # one interface
bind: all           # 0.0.0.0

Loopback | All | Addr(IpAddr), with the serde impl written by hand because all three are plain strings in YAML.

lan is removed, not aliased. It is one of two names for the same address, and keeping it would preserve the exact confusion this change exists to remove. A config still carrying it now fails to load, with an error that names the three valid forms — a bad bind takes the whole config down, so that message has to arrive with the answer in it.

is_exposed now asks the address, not the variant. bind: 127.0.0.1 written out longhand is loopback, and should not force key checking or auto-fill the private-range whitelist just because it took a different spelling to get there.

GET /interfaces

New, and the reason the above is usable: it lists this machine's interfaces so a picker can offer them. Without it, choosing an interface means reading ifconfig and copying an address into YAML by hand, where a typo surfaces as Can't assign requested address at startup.

getifaddrs through libc, already a workspace dependency — the whole module is under fifty lines, well below the cost of taking on a crate for it.

  • Interfaces that are down or unaddressed are skipped: they cannot be bound, so listing them only produces a choice that fails.
  • IPv6 link-local is skipped: it needs a scope id (fe80::1%en0) to be usable at all, and that spelling in a config file is a trap.
  • Nothing is cached. Interfaces change when a cable moves, a different Wi-Fi connects, or a VPN comes up; a cached list means offering an address that no longer exists.

The tests assert only what holds on any machine — a loopback entry exists, no entry is malformed, and loopback sorts last so it never heads a picker whose other option already means "this machine only".

Verification

cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, 1072 tests (5 new on Bind, 2 on interface listing), and scripts/smoke.sh — 46 checks, 0 failures.

Checked live against a running gateway over the control socket:

[{"name":"en0","addr":"10.0.3.7","loopback":false},
 {"name":"en0","addr":"fd94:…:be53","loopback":false},
 {"name":"lo0","addr":"127.0.0.1","loopback":true},
 {"name":"lo0","addr":"::1","loopback":true}]

🤖 Generated with Claude Code

…r did

`Bind` had three values — `loopback`, `lan`, `all` — and **two of them
were the same thing**. `lan` and `all` both resolved to `0.0.0.0`; the
only difference between them was the default contents of `allow_from`.

That made `lan` a whitelist concept wearing a network-interface costume.
Someone picking "LAN" reasonably believes the gateway is listening on
their local network interface. It is listening on **every** interface,
including whichever one faces the internet, and the only thing standing
between the two is a CIDR list they never saw. The field's own doc
comment has always read `loopback | lan | all | 具体 IP`, so a concrete
address was the intent; the enum just never grew one.

So: `Loopback | All | Addr(IpAddr)`, with the serde impl written by hand
because all three are plain strings in YAML.

    bind: loopback      # 127.0.0.1
    bind: 192.168.1.5   # one interface
    bind: all           # 0.0.0.0

`lan` is gone rather than aliased. It is one of two names for the same
address, and keeping it would preserve the confusion this commit exists
to remove. Any config still carrying it now fails to load with an error
that names the three valid forms — a bad `bind` takes the whole config
down, so that message has to arrive with the answer in it.

**`is_exposed` now asks the address, not the variant.** `bind: 127.0.0.1`
written out longhand is loopback, and should not force key checking or
auto-fill the private-range whitelist just because it took a different
spelling to get there.

## `GET /interfaces`

New, and the reason the above is usable: it lists this machine's
interfaces so a picker can offer them. Without it, choosing an interface
means reading `ifconfig` and copying an address into a YAML file by
hand, where a typo surfaces as "Can't assign requested address" at
startup.

`getifaddrs` through `libc`, which is already a workspace dependency —
the whole thing is under fifty lines, well below the cost of a crate.
Interfaces that are down or have no address are skipped, because they
cannot be bound and listing them only produces a choice that fails.
IPv6 link-local is skipped too: it needs a scope id (`fe80::1%en0`) to
be usable at all, and that spelling in a config file is a trap.

Nothing is cached. Interfaces change when a cable moves, a different
Wi-Fi connects, or a VPN comes up, and a cached list means offering an
address that no longer exists.

The tests assert only what holds on any machine — that a loopback entry
exists, that no entry is malformed, that loopback sorts last so it never
heads a picker whose other option already means "this machine only".

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@fylorn
fylorn merged commit 554e3b5 into main Sep 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant