Convert ipv6 netmask to prefix in dnsmasq.conf

dnsmasq.conf require a prefix lenght as netmask for IPv6.
Convert a IPv6 address netmask to prefix.

Closes-Bug: #1828837
Change-Id: Idf84ba30eb4eb6d202faa470209f10c9da40e80b
This commit is contained in:
Harald Jensås 2019-05-13 19:20:05 +02:00
parent 39115e63c2
commit 7b6b097d8a
7 changed files with 55 additions and 3 deletions

View File

@ -0,0 +1,25 @@
Puppet::Functions.create_function(:ipv6_netmask_to_prefix) do
def ipv6_netmask_to_prefix(args)
require 'ipaddr'
result = []
args.each do |ip_subnet|
begin
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 = ip_subnet.dup
ip_subnet_dup["netmask"] = prefix
result << ip_subnet_dup
else
result << ip_subnet
end
rescue IPAddr::AddressFamilyError, IPAddr::Error, IPAddr::InvalidAddressError, IPAddr::InvalidPrefixError => e
# Ignore it
result << ip_subnet
end
end
return result
end
end

View File

@ -311,6 +311,8 @@ class ironic::inspector (
require => Anchor['ironic-inspector::config::begin'],
}
$dnsmasq_ip_subnets_real = ipv6_netmask_to_prefix($dnsmasq_ip_subnets)
if $pxe_transfer_protocol == 'tftp' {
file { '/etc/ironic-inspector/dnsmasq.conf':
ensure => 'present',

View File

@ -0,0 +1,6 @@
---
fixes:
- |
dnsmasq.conf require netmask for IPv6 to be a prefix. If IPv6 netmask is
used it will be converted to a prefix. See bug: `1828367
<https://bugs.launchpad.net/neutron/+bug/1828367>`_

View File

@ -58,7 +58,11 @@ describe 'ironic::inspector' do
'classless_static_routes' => [{'destination' => '1.2.3.0/24',
'nexthop' => '192.168.2.1'},
{'destination' => '4.5.6.0/24',
'nexthop' => '192.168.2.1'}]}],
'nexthop' => '192.168.2.1'}]},
{ 'tag' => 'subnet3',
'ip_range' => '2001:4888:a03:313a:c0:fe0:0:c200,2001:4888:a03:313a:c0:fe0:0:c2ff',
'netmask' => 'ffff:ffff:ffff:ffff::',
'gateway' => '2001:4888:a03:313a:c0:fe0:0:c000' }],
:dnsmasq_local_ip => '192.168.0.1',
:ipxe_timeout => 0,
:http_port => 8088,
@ -164,6 +168,12 @@ describe 'ironic::inspector' do
is_expected.to contain_file('/etc/ironic-inspector/dnsmasq.conf').with_content(
/dhcp-option=tag:subnet2,option:classless-static-route,1.2.3.0\/24,192.168.2.1,4.5.6.0\/24,192.168.2.1/
)
is_expected.to contain_file('/etc/ironic-inspector/dnsmasq.conf').with_content(
/dhcp-range=set:subnet3,2001:4888:a03:313a:c0:fe0:0:c200,2001:4888:a03:313a:c0:fe0:0:c2ff,64,10m/
)
is_expected.to contain_file('/etc/ironic-inspector/dnsmasq.conf').with_content(
/dhcp-option=tag:subnet3,option:router,2001:4888:a03:313a:c0:fe0:0:c000/
)
end
it 'should contain file /tftpboot/pxelinux.cfg/default' do
is_expected.to contain_file('/tftpboot/pxelinux.cfg/default').with(

View File

@ -0,0 +1,9 @@
require 'spec_helper'
describe 'ipv6_netmask_to_prefix' do
it { should run.with_params([{'ip_range' => '192.168.0.100,192.168.0.120'}]).and_return([{'ip_range' => '192.168.0.100,192.168.0.120'}])}
it { should run.with_params([{'netmask' => '255.255.255.0',}]).and_return([{'netmask' => '255.255.255.0'}])}
it { should run.with_params([{'netmask' => 'ffff:ffff:ffff:ffff::'}]).and_return([{'netmask' => 64}])}
it { should run.with_params([{'netmask' => '64'}]).and_return([{'netmask' => '64'}])}
it { should run.with_params([{'netmask' => 64}]).and_return([{'netmask' => 64}])}
end

View File

@ -4,7 +4,7 @@ interface=<%= @dnsmasq_interface %>
log-dhcp
log-queries
<% end %>
<% @dnsmasq_ip_subnets.each do |s| -%>
<% @dnsmasq_ip_subnets_real.each do |s| -%>
<% if s['tag'] and s['netmask'] -%>
dhcp-range=set:<%= s['tag'] -%>,<%= s['ip_range'] -%>,<%= s['netmask'] -%>,10m
<% elsif s['tag'] -%>

View File

@ -4,7 +4,7 @@ interface=<%= @dnsmasq_interface %>
log-dhcp
log-queries
<% end %>
<% @dnsmasq_ip_subnets.each do |s| -%>
<% @dnsmasq_ip_subnets_real.each do |s| -%>
<% if s['tag'] and s['netmask'] -%>
dhcp-range=set:<%= s['tag'] -%>,<%= s['ip_range'] -%>,<%= s['netmask'] -%>,10m
<% elsif s['tag'] -%>