Resolves: RHEL-94932
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.
27 lines
1.0 KiB
Plaintext
27 lines
1.0 KiB
Plaintext
# 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
|