public inbox for git-commits@fedoraproject.org
help / color / mirror / Atom feed
From: Martin Osvald <mosvald@redhat.com>
To: git-commits@fedoraproject.org
Subject: [rpms/dhcpcd] rawhide: Add 99-prefixlen hook to override DHCPv6 IA_NA prefix length
Date: Wed, 23 Sep 2026 07:11:19 GMT	[thread overview]
Message-ID: <179014747953.1.15401858861707406509.rpms-dhcpcd-d9ae5aa3a6df@fedoraproject.org> (raw)

            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

                 reply	other threads:[~2026-09-23  7:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179014747953.1.15401858861707406509.rpms-dhcpcd-d9ae5aa3a6df@fedoraproject.org \
    --to=mosvald@redhat.com \
    --cc=git-commits@fedoraproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox