diff --git a/README.md b/README.md index 74d9664..cbf3866 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,12 @@ inputs.org-pkgs.url = "github:external-systems/pkgs/"; (`zen-browser` and `moscripts`, taken from their own flakes; with nix-vscode-extensions, this flake's only non-core inputs) are also exported separately. Applying the default overlay gives you the pinned - artifacts as `pkgs.rke2` / `pkgs.k3s_1_36` / `pkgs.ifstate`. The builder + artifacts as `pkgs.rke2` / `pkgs.k3s_1_36` / `pkgs.ifstate`. + `overlays.ifstate` is the host-networking set: IfState 2.5.1 and a + patched `dhcpcd` (two upstream fixes for lost leases after a carrier + change on 10.3.x; dropped automatically from 10.5). A package that + needs a patch nixpkgs does not carry yet is patched here, never in a + consumer repo. The builder expressions come from the consumer's nixpkgs: rke2 needs any nixpkgs shipping `pkgs/applications/networking/cluster/rke2/builder.nix` (all version data is pinned locally in `pkgs/rke2/versions/`); k3s rides the diff --git a/flake-parts/packages.nix b/flake-parts/packages.nix index e583525..a9cc4e4 100644 --- a/flake-parts/packages.nix +++ b/flake-parts/packages.nix @@ -31,6 +31,7 @@ inherit (artifactPkgs) ifstate + dhcpcd rke2 rke2_1_35 rke2_1_36 diff --git a/overlays/ifstate.nix b/overlays/ifstate.nix index 4ab14c1..4696d80 100644 --- a/overlays/ifstate.nix +++ b/overlays/ifstate.nix @@ -25,4 +25,21 @@ in { jsonschema = "${ifstateSrc}/schema/2/ifstate.conf.schema.json"; }; }); + + # dhcpcd is the DHCP client IfState hooks start (clanServices netif). + # 10.3.x closes a DHCPv6 address socket before deleting it from its + # event loop. The stale entry makes the next socket that reuses the + # descriptor number fail with "eloop_event_add: No such file or + # directory", and DHCPv4 or DHCPv6 then does not recover after a + # carrier change. Upstream fixed both halves in 10.5.0 + # (NetworkConfiguration/dhcpcd#611); these are those two commits. The + # version guard drops them once nixpkgs ships 10.5 or newer. + dhcpcd = prev.dhcpcd.overrideAttrs (old: { + patches = + (old.patches or []) + ++ final.lib.optionals (final.lib.versionOlder old.version "10.5.0") [ + ./patches/dhcpcd/0001-eloop-always-remove-event-from-list-on-delete.patch + ./patches/dhcpcd/0002-dhcp6-delete-eloop-event-before-closing-ia-socket.patch + ]; + }); } diff --git a/overlays/patches/dhcpcd/0001-eloop-always-remove-event-from-list-on-delete.patch b/overlays/patches/dhcpcd/0001-eloop-always-remove-event-from-list-on-delete.patch new file mode 100644 index 0000000..9330cb9 --- /dev/null +++ b/overlays/patches/dhcpcd/0001-eloop-always-remove-event-from-list-on-delete.patch @@ -0,0 +1,56 @@ +From 3375f52f3d86598418a40de8eaed63467dde40e1 Mon Sep 17 00:00:00 2001 +From: Roy Marples +Date: Thu, 21 May 2026 08:39:55 +0100 +Subject: [PATCH] eloop: always remove event from list on delete + +Event if kevent or epoll return an error from the operation. +We still return the error so the caller can log a diagnostic. + +Thanks to Graham Northup for the hint. +May help with #596. +--- + src/eloop.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/src/eloop.c b/src/eloop.c +index 8def47f4c..cac15a1dc 100644 +--- a/src/eloop.c ++++ b/src/eloop.c +@@ -385,6 +385,7 @@ eloop_event_delete(struct eloop *eloop, int fd) + struct kevent ke[2], *kep = &ke[0]; + size_t n; + #endif ++ int error; + + if (fd == -1) { + errno = EINVAL; +@@ -400,6 +401,7 @@ eloop_event_delete(struct eloop *eloop, int fd) + return -1; + } + ++ error = 1; + #if defined(USE_KQUEUE) + n = 0; + if (e->events & ELE_READ) { +@@ -411,16 +413,18 @@ eloop_event_delete(struct eloop *eloop, int fd) + n++; + } + if (n != 0 && kevent(eloop->fd, ke, (KEVENT_N)n, NULL, 0, NULL) == -1) +- return -1; ++ error = -1; + #elif defined(USE_EPOLL) + if (epoll_ctl(eloop->fd, EPOLL_CTL_DEL, fd, NULL) == -1) +- return -1; ++ error = -1; + #endif + ++ /* We should remove the event from the eloop even if kevent or epoll ++ * report an error, it's possible it could be EBADF for example. */ + e->fd = -1; + eloop->nevents--; + eloop->events_need_setup = true; +- return 1; ++ return error; + } + + unsigned long long diff --git a/overlays/patches/dhcpcd/0002-dhcp6-delete-eloop-event-before-closing-ia-socket.patch b/overlays/patches/dhcpcd/0002-dhcp6-delete-eloop-event-before-closing-ia-socket.patch new file mode 100644 index 0000000..23a9971 --- /dev/null +++ b/overlays/patches/dhcpcd/0002-dhcp6-delete-eloop-event-before-closing-ia-socket.patch @@ -0,0 +1,31 @@ +From cf232b92f09bb99075b07a14df75b51474e71d54 Mon Sep 17 00:00:00 2001 +From: Roy Marples +Date: Thu, 21 May 2026 08:43:58 +0100 +Subject: [PATCH] DHCP6: Delete the eloop event before closing an ia listener + socket + +This only happens when dhcpcd is running on a specific interface +and can trigger erroneous logs deleting the socket from +kqueue/epoll. +With the prior eloop it could also trigger ia events from a +non related fd if re-used. + +Hopefully fixes #596. +--- + src/ipv6.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/ipv6.c b/src/ipv6.c +index af5fd2773..263fb6a08 100644 +--- a/src/ipv6.c ++++ b/src/ipv6.c +@@ -1023,8 +1023,8 @@ ipv6_freeaddr(struct ipv6_addr *ia) + #endif + + if (ia->dhcp6_fd != -1) { +- close(ia->dhcp6_fd); + eloop_event_delete(eloop, ia->dhcp6_fd); ++ close(ia->dhcp6_fd); + } + + eloop_q_timeout_delete(eloop, ELOOP_QUEUE_ALL, NULL, ia);