When an ENI is detached, the udev rule in udev/99-vpc-policy-routes.rules runs
systemctl disable --now refresh-policy-routes@$name.timer policy-routes@$name.service,
but nothing ever deletes the generated configuration. policy-routes@.service defines
only ExecStart, so stopping the unit executes nothing, and the remove) branch in
bin/setup-policy-routes.sh — the only code that removes 70-<iface>.network and
70-<iface>.network.d/ — has no caller anywhere in the tree (its sibling
stop|cleanup) is an explicit no-op), making it effectively dead code.
The orphaned config therefore survives the detach with ec2net_alias.conf still listing the
pre-detach secondary IPs, and because create_if_overrides writes
[Match] MACAddress=${ether} rather than matching on interface name, it continues to
match the same ENI. If that ENI is later re-attached and the kernel assigns a different
name (e.g. enp40s0 → enp41s0), two .network files in /run/systemd/network match
the same MAC and systemd-networkd applies the lexicographically first — the stale one.
From that point refresh-policy-routes still recomputes the alias list correctly, but
writes it to 70-<newname>.network.d/ec2net_alias.conf, a drop-in belonging to an
inactive .network file, so removed secondary IPs are never withdrawn from the OS and
neither networkctl reload nor a full systemctl restart systemd-networkd recovers.
When an ENI is detached, the udev rule in
udev/99-vpc-policy-routes.rulesrunssystemctl disable --now refresh-policy-routes@$name.timer policy-routes@$name.service,but nothing ever deletes the generated configuration.
policy-routes@.servicedefinesonly
ExecStart, so stopping the unit executes nothing, and theremove)branch inbin/setup-policy-routes.sh— the only code that removes70-<iface>.networkand70-<iface>.network.d/— has no caller anywhere in the tree (its siblingstop|cleanup)is an explicit no-op), making it effectively dead code.The orphaned config therefore survives the detach with
ec2net_alias.confstill listing thepre-detach secondary IPs, and because
create_if_overrideswrites[Match] MACAddress=${ether}rather than matching on interface name, it continues tomatch the same ENI. If that ENI is later re-attached and the kernel assigns a different
name (e.g.
enp40s0→enp41s0), two.networkfiles in/run/systemd/networkmatchthe same MAC and systemd-networkd applies the lexicographically first — the stale one.
From that point
refresh-policy-routesstill recomputes the alias list correctly, butwrites it to
70-<newname>.network.d/ec2net_alias.conf, a drop-in belonging to aninactive
.networkfile, so removed secondary IPs are never withdrawn from the OS andneither
networkctl reloadnor a fullsystemctl restart systemd-networkdrecovers.