Skip to content

Commit 1dcdbb3

Browse files
committed
IPv6: dhcp/provisioner: make ipv6 aware
If the admin network is IPv6 setup the ISC DHCPD server to configure and use the IPv6 daemon. For this use a seperate set of ipv6 files to list hosts and subnets as ipv6 hosts and subnets will fail if v4 dhcp tries to load them. Also make sure tftp is listening on both IPv4 and v6.
1 parent cd35a6c commit 1dcdbb3

File tree

16 files changed

+247
-57
lines changed

16 files changed

+247
-57
lines changed

chef/cookbooks/dhcp/attributes/default.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
default[:dhcp][:interfaces] = ["eth0"]
3-
default[:dhcp][:options] = [
3+
default[:dhcp][:options][:v4] = [
44
"ddns-update-style none",
55
"allow booting",
66
"option option-128 code 128 = string",
@@ -10,4 +10,16 @@
1010
"option dhcp-client-debug code 226 = unsigned integer 16",
1111
"option dhcp-client-debug 0"
1212
]
13+
default[:dhcp][:options][:v6] = [
14+
"ddns-update-style none",
15+
"allow booting",
16+
"option option-128 code 128 = string",
17+
"option option-129 code 129 = text",
18+
"option dhcp-client-state code 225 = unsigned integer 16",
19+
"option dhcp-client-state 0",
20+
"option dhcp-client-debug code 226 = unsigned integer 16",
21+
"option dhcp-client-debug 0",
22+
"option dhcp6.bootfile-url code 59 = string",
23+
"option dhcp6.client-arch-type code 61 = array of unsigned integer 16"
24+
]
1325

chef/cookbooks/dhcp/providers/host.rb

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
# limitations under the License.
1414
#
1515

16+
require "ipaddr"
17+
1618
action :add do
1719
Chef::Log.debug "Adding #{new_resource.name}.conf to /etc/dhcp3/hosts.d"
20+
is_ipv6 = IPAddr.new(new_resource.ipaddress).ipv6?
1821
filename = "/etc/dhcp3/hosts.d/#{new_resource.name}.conf"
1922
template filename do
2023
cookbook "dhcp"
@@ -24,7 +27,9 @@
2427
hostname: new_resource.hostname,
2528
macaddress: new_resource.macaddress,
2629
ipaddress: new_resource.ipaddress,
27-
options: new_resource.options
30+
options: new_resource.options,
31+
prefix: new_resource.prefix,
32+
is_ipv6: is_ipv6
2833
)
2934
owner "root"
3035
group "root"
@@ -33,9 +38,10 @@
3338
notifies :restart, resources(service: "dhcp3-server"), :delayed
3439
end
3540
end
41+
host_list_file = is_ipv6 ? "host6_list.conf" : "host_list.conf"
3642
utils_line "include \"#{filename}\";" do
3743
action :add
38-
file "/etc/dhcp3/hosts.d/host_list.conf"
44+
file "/etc/dhcp3/hosts.d/#{host_list_file}"
3945
if node[:provisioner][:enable_pxe]
4046
notifies :restart, resources(service: "dhcp3-server"), :delayed
4147
end
@@ -54,11 +60,13 @@
5460
end
5561
new_resource.updated_by_last_action(true)
5662
end
57-
utils_line "include \"#{filename}\";" do
58-
action :remove
59-
file "/etc/dhcp3/hosts.d/host_list.conf"
60-
if node[:provisioner][:enable_pxe]
61-
notifies :restart, resources(service: "dhcp3-server"), :delayed
63+
["host_list.conf", "host6_list.conf"].each do |host_list|
64+
utils_line "include \"#{filename}\";" do
65+
action :remove
66+
file "/etc/dhcp3/hosts.d/#{host_list}"
67+
if node[:provisioner][:enable_pxe]
68+
notifies :restart, resources(service: "dhcp3-server"), :delayed
69+
end
6270
end
6371
end
6472
end

chef/cookbooks/dhcp/providers/subnet.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313
# limitations under the License.
1414
#
1515

16+
require "ipaddr"
17+
1618
action :add do
19+
if IPAddr.new(new_resource.network["subnet"]).ipv6?
20+
subnet_template = "subnet6.conf.erb"
21+
subnet_list_file = "subnet6_list.conf"
22+
else
23+
subnet_template = "subnet.conf.erb"
24+
subnet_list_file = "subnet_list.conf"
25+
end
1726
filename = "/etc/dhcp3/subnets.d/#{new_resource.subnet}.conf"
1827
template filename do
1928
cookbook "dhcp"
20-
source "subnet.conf.erb"
29+
source subnet_template
2130
variables(
2231
network: new_resource.network,
2332
options: new_resource.options,
@@ -33,7 +42,7 @@
3342
end
3443
utils_line "include \"#{filename}\";" do
3544
action :add
36-
file "/etc/dhcp3/subnets.d/subnet_list.conf"
45+
file "/etc/dhcp3/subnets.d/#{subnet_list_file}"
3746
if node[:provisioner][:enable_pxe]
3847
notifies :restart, resources(service: "dhcp3-server"), :delayed
3948
end
@@ -52,11 +61,13 @@
5261
end
5362
new_resource.updated_by_last_action(true)
5463
end
55-
utils_line "include \"#{filename}\";" do
56-
action :remove
57-
file "/etc/dhcp3/subnets.d/subnet_list.conf"
58-
if node[:provisioner][:enable_pxe]
59-
notifies :restart, resources(service: "dhcp3-server"), :delayed
64+
["subnet_list.conf", "subnet6_list.conf"].each do |subnet_list|
65+
utils_line "include \"#{filename}\";" do
66+
action :remove
67+
file "/etc/dhcp3/subnets.d/#{subnet_list}"
68+
if node[:provisioner][:enable_pxe]
69+
notifies :restart, resources(service: "dhcp3-server"), :delayed
70+
end
6071
end
6172
end
6273
end

chef/cookbooks/dhcp/recipes/default.rb

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@
4848
group "root"
4949
mode 0644
5050
end
51+
file "/etc/dhcp3/groups.d/group6_list.conf" do
52+
owner "root"
53+
group "root"
54+
mode 0644
55+
end
56+
file "/etc/dhcp3/subnets.d/subnet6_list.conf" do
57+
owner "root"
58+
group "root"
59+
mode 0644
60+
end
61+
file "/etc/dhcp3/hosts.d/host6_list.conf" do
62+
owner "root"
63+
group "root"
64+
mode 0644
65+
end
5166

5267
bash "build omapi key" do
5368
code <<-EOH
@@ -63,18 +78,27 @@
6378
intfs = [Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").interface]
6479
address = Chef::Recipe::Barclamp::Inventory.get_network_by_type(node, "admin").address
6580

66-
d_opts = node[:dhcp][:options]
81+
require "ipaddr"
82+
admin_addr = IPAddr.new(address)
83+
84+
if admin_addr.ipv4?
85+
d_opts = node[:dhcp][:options][:v4]
86+
dhcpd_conf = "dhcpd.conf"
87+
else
88+
d_opts = node[:dhcp][:options][:v6]
89+
dhcpd_conf = "dhcpd6.conf"
90+
end
6791

6892
case node[:platform_family]
6993
when "debian"
7094
case node[:lsb][:codename]
7195
when "natty","oneiric","precise"
72-
template "/etc/dhcp/dhcpd.conf" do
96+
template "/etc/dhcp/#{dhcpd_conf}" do
7397
owner "root"
7498
group "root"
7599
mode 0644
76100
source "dhcpd.conf.erb"
77-
variables(options: d_opts)
101+
variables(options: d_opts, is_ipv6: admin_addr.ipv6?)
78102
if node[:provisioner][:enable_pxe]
79103
notifies :restart, "service[dhcp3-server]"
80104
end
@@ -90,12 +114,12 @@
90114
end
91115
end
92116
else
93-
template "/etc/dhcp3/dhcpd.conf" do
117+
template "/etc/dhcp3/#{dhcpd_conf}" do
94118
owner "root"
95119
group "root"
96120
mode 0644
97121
source "dhcpd.conf.erb"
98-
variables(options: d_opts)
122+
variables(options: d_opts, is_ipv6: admin_addr.ipv6?)
99123
if node[:provisioner][:enable_pxe]
100124
notifies :restart, "service[dhcp3-server]"
101125
end
@@ -115,17 +139,17 @@
115139

116140
dhcp_config_file = case
117141
when node[:platform_version].to_f >= 6
118-
"/etc/dhcp/dhcpd.conf"
142+
"/etc/dhcp/#{dhcpd_conf}"
119143
else
120-
"/etc/dhcpd.conf"
144+
"/etc/#{dhcpd_conf}"
121145
end
122146

123147
template dhcp_config_file do
124148
owner "root"
125149
group "root"
126150
mode 0644
127151
source "dhcpd.conf.erb"
128-
variables(options: d_opts)
152+
variables(options: d_opts, is_ipv6: admin_addr.ipv6?)
129153
if node[:provisioner][:enable_pxe]
130154
notifies :restart, "service[dhcp3-server]"
131155
end
@@ -143,12 +167,12 @@
143167
end
144168

145169
when "suse"
146-
template "/etc/dhcpd.conf" do
170+
template "/etc/#{dhcpd_conf}" do
147171
owner "root"
148172
group "root"
149173
mode 0644
150174
source "dhcpd.conf.erb"
151-
variables(options: d_opts)
175+
variables(options: d_opts, is_ipv6: admin_addr.ipv6?)
152176
if node[:provisioner][:enable_pxe]
153177
notifies :restart, "service[dhcp3-server]"
154178
end
@@ -168,7 +192,11 @@
168192

169193
service "dhcp3-server" do
170194
if %w(suse rhel).include?(node[:platform_family])
171-
service_name "dhcpd"
195+
if admin_addr.ipv4?
196+
service_name "dhcpd"
197+
else
198+
service_name "dhcpd6"
199+
end
172200
elsif node[:platform] == "ubuntu"
173201
case node[:lsb][:codename]
174202
when "maverick"

chef/cookbooks/dhcp/resources/host.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
attribute :hostname, kind_of: String
2020
attribute :macaddress, kind_of: String
2121
attribute :ipaddress, kind_of: String
22+
attribute :prefix, kind_of: String
2223
attribute :group, kind_of: String
2324
attribute :options, kind_of: Array, default: []
2425

chef/cookbooks/dhcp/templates/default/dhcpd.conf.erb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,34 @@ log-facility local7;
2121
# Fix for https://bugzilla.opensuse.org/show_bug.cgi?id=961536
2222
always-reply-rfc1048 true;
2323

24+
<% if @is_ipv6 -%>
25+
# Other options we may want?
26+
#option dhcp6.rfc4833-tz-posix-string code 41 = string;
27+
#option dhcp6.rfc4833-tz-name code 42 = string;
28+
#
29+
# Use example:
30+
# option dhcp6.rfc4833-tz-posix-string "EST5EDT4,M3.2.0/02:00,M11.1.0/02:00";
31+
# option dhcp6.rfc4833-tz-name "Europe/Zurich";
32+
# Use this to send dhcp log messages to a different log file (you also
33+
# have to hack syslog.conf to complete the redirection).
34+
35+
# Set preference to 255 (maximum) in order to avoid waiting for
36+
# additional servers when there is only one
37+
##option dhcp6.preference 255;
38+
39+
# Server side command to enable rapid-commit (2 packet exchange)
40+
##option dhcp6.rapid-commit;
41+
42+
# The delay before information-request refresh
43+
# (minimum is 10 minutes, maximum one day, default is to not refresh)
44+
# (set to 6 hours)
45+
#option dhcp6.info-refresh-time 21600;
46+
47+
include "/etc/dhcp3/groups.d/group6_list.conf";
48+
include "/etc/dhcp3/subnets.d/subnet6_list.conf";
49+
include "/etc/dhcp3/hosts.d/host6_list.conf";
50+
<% else -%>
2451
include "/etc/dhcp3/groups.d/group_list.conf";
2552
include "/etc/dhcp3/subnets.d/subnet_list.conf";
2653
include "/etc/dhcp3/hosts.d/host_list.conf";
54+
<% end -%>

chef/cookbooks/dhcp/templates/default/host.conf.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ host <%= @name %> {
22
option host-name "<%= @hostname %>";
33
hardware ethernet <%= @macaddress %>;
44
<% if @ipaddress -%>
5+
<% if @is_ipv6 -%>
6+
fixed-address6 <%= @ipaddress %>;
7+
fixed-prefix6 <%= @prefix %>;
8+
<% else -%>
59
fixed-address <%= @ipaddress %>;
10+
<% end -%>
611
<% else -%>
712
deny booting;
813
<% end -%>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# File managed by Crowbar
2+
<% if node[:provisioner][:enable_pxe] -%>
3+
4+
subnet6 <%= @network["subnet"] %>/<%= @network["netmask"]%> {
5+
option subnet-mask <%= @network["netmask"] %>;
6+
<% @options.each do |option| -%>
7+
<%= option %>;
8+
<% end -%>
9+
<% @pools.each do |pool| -%>
10+
pool6 {
11+
range6 <%=@network["ranges"][pool]["start"]%> <%=@network["ranges"][pool]["end"]%>;
12+
<% @pool_options[pool].each do |opt| -%>
13+
<%=opt%><%=if opt[-1,1] != '}' then ';' else '' end%>
14+
<% end if @pool_options[pool] -%>
15+
}
16+
<% end -%>
17+
}
18+
19+
<% end -%>

chef/cookbooks/dhcp/templates/default/suse-sysconfig-dhcpd.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Do not edit.
33
<% unless @interfaces.empty? -%>
44
DHCPD_INTERFACE="<%= @interfaces.collect! {|i| "#{i}" }.join(" ") %>"
5+
DHCPD6_INTERFACE="<%= @interfaces.collect! {|i| "#{i}" }.join(" ") %>"
56
<% end -%>
67
DHCPD_IFUP_RESTART=""
78
DHCPD_RUN_CHROOTED="no"

chef/cookbooks/provisioner/recipes/base.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,15 @@
346346
mode "0644"
347347
end
348348

349+
require "ipaddr"
349350
crowbar_node = node_search_with_cache("roles:crowbar").first
350351
address = crowbar_node["crowbar"]["network"]["admin"]["address"]
351352
protocol = crowbar_node["crowbar"]["apache"]["ssl"] ? "https" : "http"
352-
server = "#{protocol}://#{address}"
353+
server = if IPAddr.new(address).ipv6?
354+
"#{protocol}://[#{address}]"
355+
else
356+
"#{protocol}://#{address}"
357+
end
353358
password = crowbar_node["crowbar"]["users"]["crowbar"]["password"]
354359
verify_ssl = !crowbar_node["crowbar"]["apache"]["insecure"]
355360

0 commit comments

Comments
 (0)