15eedd0c4c
Extend and re-name the function ipv6_netmask_to_prefix() to ipv6_normalize_dnsmasq_ip_subnets(). It now changes the netmask to prefix and removes the 'gateway' if it is an IPv6 subnet. On IPv6 router info should be provided in router advertisements. There was a draft to add support in DHCPv6, but it was never completed. https://datatracker.ietf.org/doc/draft-ietf-mif-dhcpv6-route-option/ Also: Add match for userclass iPXE and set option6:bootfile-url Closes-Bug: #1844573 Change-Id: I47d88519acd18630e0d5682d93f1088771ec03a1
38 lines
1.5 KiB
Ruby
38 lines
1.5 KiB
Ruby
Puppet::Functions.create_function(:ipv6_normalize_dnsmasq_ip_subnets) do
|
|
def ipv6_normalize_dnsmasq_ip_subnets(args)
|
|
require 'ipaddr'
|
|
result = []
|
|
args.each do |ip_subnet|
|
|
ip_subnet_dup = ip_subnet.dup
|
|
begin
|
|
if ip_subnet["netmask"]
|
|
if IPAddr.new(ip_subnet["netmask"]).ipv6?
|
|
# TODO(hjensas) Once we have ruby stdlib >= 2.5.x we can use
|
|
# IPAddr.new().prefix instead of counting 1's.
|
|
prefix = IPAddr.new(ip_subnet["netmask"]).to_i.to_s(2).count("1")
|
|
Puppet.debug("Netmask #{ip_subnet["netmask"]} changed to prefix #{prefix}")
|
|
ip_subnet_dup["netmask"] = prefix
|
|
end
|
|
end
|
|
rescue IPAddr::AddressFamilyError, IPAddr::Error, IPAddr::InvalidAddressError, IPAddr::InvalidPrefixError => e
|
|
# Ignore it
|
|
end
|
|
begin
|
|
if ip_subnet["gateway"]
|
|
if IPAddr.new(ip_subnet["gateway"]).ipv6?
|
|
# draft-ietf-mif-dhcpv6-route-option-05 was never completed.
|
|
# https://datatracker.ietf.org/doc/draft-ietf-mif-dhcpv6-route-option/
|
|
# Remove the gateway key:value so that the option:router entry is
|
|
# not created in dnsmasq.conf.
|
|
ip_subnet_dup.delete("gateway")
|
|
end
|
|
end
|
|
rescue IPAddr::AddressFamilyError, IPAddr::Error, IPAddr::InvalidAddressError, IPAddr::InvalidPrefixError => e
|
|
# Ignore it
|
|
end
|
|
result << ip_subnet_dup
|
|
end
|
|
return result
|
|
end
|
|
end
|