public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
* [rpms/dhcpcd] rawhide: Add 99-prefixlen hook to override DHCPv6 IA_NA prefix length
@ 2026-09-23  7:11 Martin Osvald
  0 siblings, 0 replies; only message in thread
From: Martin Osvald @ 2026-09-23  7:11 UTC (permalink / raw)
  To: git-commits

            A new commit has been pushed.

            Repo   : rpms/dhcpcd
            Branch : rawhide
            Commit : d9ae5aa3a6df14990298f9f5ba35d1f2618a9a83
            Author : Martin Osvald <mosvald@redhat.com>
            Date   : 2026-07-27T10:10:33+02:00
            Stats  : +28/-0 in 2 file(s)
            URL    : https://src.fedoraproject.org/rpms/dhcpcd/c/d9ae5aa3a6df14990298f9f5ba35d1f2618a9a83?branch=rawhide

            Log:
            Add 99-prefixlen hook to override DHCPv6 IA_NA prefix length

dhcpcd assigns DHCPv6 IA_NA addresses with /128 per RFC 8415.
Some deployments need a shorter prefix (e.g. /64) to match routing
policy, which dhclient supported via --address-prefix-len.

The 99-prefixlen hook provides equivalent behavior. When
DHCPCD_IPV6_PREFIXLEN is set in dhcpcd.conf via the env directive,
the hook deletes the /128 and immediately replaces it with the
requested prefix on BOUND6, RENEW6, REBIND6, and REBOOT6 events.

The del+replace sequence is race-safe: the hook runs synchronously
inside dhcpcd's processing, so the replacement address is already in
the kernel before dhcpcd drains the RTM_DELADDR netlink event. The
if_addrflags6 guard in dhcpcd finds the address still present (by
bytes) and skips the deletion handler, so /128 is never re-added.

ip addr replace (NLM_F_REPLACE|NLM_F_CREATE) handles all lease events
correctly: it adds the address fresh on BOUND6 and updates lifetimes
on RENEW6 without requiring the address to be absent first.

Usage in /etc/dhcpcd.conf:

    interface eth0
        ia_na 1
        env DHCPCD_IPV6_PREFIXLEN=64

The hook is a no-op when DHCPCD_IPV6_PREFIXLEN is not set.

---
diff --git a/99-prefixlen b/99-prefixlen
new file mode 100644
index 0000000..c7a2fcc
--- /dev/null
+++ b/99-prefixlen
@@ -0,0 +1,26 @@
+# 99-prefixlen - dhcpcd hook to override DHCPv6 IA_NA prefix length
+#
+# dhcpcd assigns DHCPv6 IA_NA addresses with /128 per RFC 8415. This hook
+# overrides the prefix length when DHCPCD_IPV6_PREFIXLEN is set, replacing
+# /128 with the requested prefix on each lease event.
+#
+# Usage: set DHCPCD_IPV6_PREFIXLEN via the env directive in /etc/dhcpcd.conf:
+#
+#   interface eth0
+#       ia_na 1
+#       env DHCPCD_IPV6_PREFIXLEN=64
+#
+# The hook is a no-op when DHCPCD_IPV6_PREFIXLEN is not set.
+
+if [ -n "$DHCPCD_IPV6_PREFIXLEN" ]; then
+    case "$reason" in
+        BOUND6|RENEW6|REBIND6|REBOOT6)
+            if [ -n "$new_dhcp6_ia_na1_ia_addr1" ]; then
+                ip -6 addr del "${new_dhcp6_ia_na1_ia_addr1}/128" dev "$interface" 2>/dev/null
+                ip -6 addr replace "${new_dhcp6_ia_na1_ia_addr1}/${DHCPCD_IPV6_PREFIXLEN}" dev "$interface" \
+                    valid_lft "$new_dhcp6_ia_na1_ia_addr1_vltime" \
+                    preferred_lft "$new_dhcp6_ia_na1_ia_addr1_pltime"
+            fi
+            ;;
+    esac
+fi

diff --git a/dhcpcd.spec b/dhcpcd.spec
index b193752..8c81363 100644
--- a/dhcpcd.spec
+++ b/dhcpcd.spec
@@ -15,6 +15,7 @@ Source3: %{name}.service
 Source4: %{name}@.service
 Source5: systemd-sysusers.conf
 Source6: systemd-tmpfiles.conf
+Source7: 99-prefixlen
 
 BuildRequires: gcc
 BuildRequires: systemd-rpm-macros
@@ -56,6 +57,7 @@ install -D -m 644 %{SOURCE3} %{buildroot}%{_unitdir}/%{name}.service
 install -D -m 644 %{SOURCE4} %{buildroot}%{_unitdir}/%{name}@.service
 install -D -m 644 %{SOURCE5} %{buildroot}%{_sysusersdir}/%{name}.conf
 install -D -m 644 %{SOURCE6} %{buildroot}%{_tmpfilesdir}/%{name}.conf
+install -D -m 444 %{SOURCE7} %{buildroot}%{_libexecdir}/%{name}-hooks/99-prefixlen
 install -d %{buildroot}%{_sharedstatedir}/%{_name}
 
 %post

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-23  7:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-23  7:11 [rpms/dhcpcd] rawhide: Add 99-prefixlen hook to override DHCPv6 IA_NA prefix length Martin Osvald

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox