Fix the TUN setup recipe: the overlay address was being flushed
The setup this tool printed did not work, and the agent then correctly refused to start. A persistent TUN interface has no carrier until a process attaches to it, and Linux flushes IPv6 addresses from an interface that loses carrier unless net.ipv6.conf.<dev>.keep_addr_on_down is set, which it is not by default. So `ip -6 address add` on a freshly created interface silently lost the address before the agent ever ran. The recipe now brings the link up first, sets keep_addr_on_down, and adds the address with `nodad` — without which duplicate address detection can never finish on an interface with no carrier and the address stays tentative and unusable. The agent's own retry loop made this worse: it attached, failed the address check, dropped the device and toggled the carrier, which flushed the address again. The check now runs before attaching to an existing interface, so looking is not destructive. Failures are self-diagnosing now: the check parses the IFA_F_* flags, tells tentative and DAD-failed apart from missing, and lists the addresses the interface actually has. Four new tests, including one that reads this host's real /proc/net/if_inet6 and one that pins the ordering of the setup commands. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -123,15 +123,23 @@ tsunagi tun-setup --network lab --secret "$SECRET"
|
||||
```
|
||||
|
||||
```text
|
||||
# Network lab (jwc6dcrtmo5zzdk7f6wfpkcqrpvqwr6po7vz3q2fvttgolt4ijfa)
|
||||
# Interface tsunjwc6dcrtmo5, address fd80:1210:f724:f620:d1bb:f982:3b6e:19bd/64, mtu 1100
|
||||
# Run once as root; then run `tsunagi up` as ab.
|
||||
|
||||
sudo ip tuntap add dev tsunjwc6dcrtmo5 mode tun user ab
|
||||
sudo ip -6 address add fd80:1210:f724:f620:d1bb:f982:3b6e:19bd/64 dev tsunjwc6dcrtmo5
|
||||
sudo ip link set dev tsunjwc6dcrtmo5 mtu 1100 up
|
||||
sudo sysctl -qw net.ipv6.conf.tsunjwc6dcrtmo5.keep_addr_on_down=1
|
||||
sudo ip -6 address add fd80:1210:f724:f620:d1bb:f982:3b6e:19bd/64 dev tsunjwc6dcrtmo5 nodad
|
||||
```
|
||||
|
||||
The order and the last two lines are not decoration. A persistent TUN
|
||||
interface has **no carrier** until a process attaches to it, and Linux flushes
|
||||
IPv6 addresses from an interface that loses carrier unless
|
||||
`keep_addr_on_down` is set — so an address added without it disappears before
|
||||
the agent ever starts. `nodad` is needed for the same reason: duplicate
|
||||
address detection cannot finish without a carrier, and the address would sit
|
||||
there tentative and unusable.
|
||||
|
||||
`user ab` is the point: the interface is persistent and owned by that user, so
|
||||
`tsunagi up` afterwards opens it with **no privileges and no capabilities at
|
||||
all**. The interface name and address are derived, so they are stable — the
|
||||
|
||||
Reference in New Issue
Block a user