Renamed exclusion and inclusion drop-ins to include the network they are for

This commit is contained in:
Ezri Brimhall 2026-02-03 16:20:02 -07:00
parent c0c9daf45d
commit 6279e9e860
Signed by: ezri
GPG Key ID: 058A78E5680C6F24

View File

@ -139,7 +139,9 @@ class Config:
# Refuse to create a policy rule that would block the uplink.
# this is probably a global route, which we will already have.
return
with (dir / f"inclusion-{route_id}.conf").open("w") as stream:
with (dir / f"inclusion-{str(net).replace('/', '_')}.conf").open(
"w"
) as stream:
stream.writelines(
[
"[RoutingPolicyRule]\n",
@ -166,7 +168,7 @@ class Config:
if not self.vpnd_enforce_split_tunnel:
return
route_id = self.route_id
with (dir / f"exclusion-{route_id}.conf").open("w") as stream:
with (dir / f"exclusion-{str(net).replace('/', '_')}.conf").open("w") as stream:
stream.writelines(
[
"[RoutingPolicyRule]\n",
@ -241,6 +243,18 @@ class Config:
)
stream.close()
def destroy_config(self, path: Path):
"""Destroy the systemd-networkd config."""
if path.is_file():
path.unlink()
dropins = path.with_suffix(".network.d")
if dropins.is_dir():
for file in dropins.iterdir():
file.unlink()
dropins.rmdir()
elif dropins.exists():
dropins.unlink()
async def main():
"""Main loop."""
@ -281,6 +295,8 @@ async def configure_with_networkd():
os.dup2(fd, 6, inheritable=True)
os.close(fd)
return
elif config.reason == Reason.DISCONNECT:
config.destroy_config()
# always reload networkd state unless it's the config.
bus = bus_var.get()
intro = await bus.introspect(