2 # Cookbook Name:: networking
5 # Copyright 2010, OpenStreetMap Foundation.
6 # Copyright 2009, Opscode, Inc.
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
21 # * node[:networking][:nameservers]
25 node[:networking][:interfaces].each do |name, interface|
26 if interface[:role] && (role = node[:networking][:roles][interface[:role]])
27 if role[interface[:family]]
28 node.set[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
29 node.set[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
32 node.set[:networking][:interfaces][name][:metric] = role[:metric]
33 node.set[:networking][:interfaces][name][:zone] = role[:zone]
36 prefix = node[:networking][:interfaces][name][:prefix]
38 # rubocop:disable Style/RedundantParentheses
39 node.set[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
40 node.set[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
41 # rubocop:enable Style/RedundantParentheses
44 template "/etc/network/interfaces" do
45 source "interfaces.erb"
53 command "/bin/hostname -F /etc/hostname"
56 template "/etc/hostname" do
61 notifies :run, "execute[hostname]"
64 template "/etc/hosts" do
71 link "/etc/resolv.conf" do
74 to "/run/resolvconf/resolv.conf"
75 only_if { File.symlink?("/etc/resolv.conf") }
78 template "/etc/resolv.conf" do
79 source "resolv.conf.erb"
85 node.interfaces(:role => :internal) do |interface|
86 if interface[:gateway] && interface[:gateway] != interface[:address]
87 search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
88 next unless gateway[:openvpn]
90 gateway[:openvpn][:tunnels].each_value do |tunnel|
91 if tunnel[:peer][:address] # ~FC023
92 route tunnel[:peer][:address] do
93 netmask "255.255.255.255"
94 gateway interface[:gateway]
95 device interface[:interface]
99 next unless tunnel[:peer][:networks]
101 tunnel[:peer][:networks].each do |network|
102 route network[:address] do
103 netmask network[:netmask]
104 gateway interface[:gateway]
105 device interface[:interface]
115 search(:node, "networking:interfaces").collect do |n|
116 next if n[:fqdn] == node[:fqdn]
118 n.interfaces.each do |interface|
119 next unless interface[:role] == "external" && interface[:zone]
121 zones[interface[:zone]] ||= {}
122 zones[interface[:zone]][interface[:family]] ||= []
123 zones[interface[:zone]][interface[:family]] << interface[:address]
129 service "shorewall" do
130 action [:enable, :start]
131 supports :restart => true
132 status_command "shorewall status"
135 template "/etc/default/shorewall" do
136 source "shorewall-default.erb"
140 notifies :restart, "service[shorewall]"
143 template "/etc/shorewall/shorewall.conf" do
144 source "shorewall.conf.erb"
148 notifies :restart, "service[shorewall]"
151 template "/etc/shorewall/zones" do
152 source "shorewall-zones.erb"
156 variables :type => "ipv4"
157 notifies :restart, "service[shorewall]"
160 template "/etc/shorewall/interfaces" do
161 source "shorewall-interfaces.erb"
165 notifies :restart, "service[shorewall]"
168 template "/etc/shorewall/hosts" do
169 source "shorewall-hosts.erb"
173 variables :zones => zones
174 notifies :restart, "service[shorewall]"
177 template "/etc/shorewall/policy" do
178 source "shorewall-policy.erb"
182 notifies :restart, "service[shorewall]"
185 template "/etc/shorewall/rules" do
186 source "shorewall-rules.erb"
190 variables :rules => []
191 notifies :restart, "service[shorewall]"
194 template "/etc/logrotate.d/shorewall" do
195 source "logrotate.shorewall.erb"
199 variables :name => "shorewall"
202 firewall_rule "limit-icmp-echo" do
208 dest_ports "echo-request"
209 rate_limit "s:1/sec:5"
212 %w(ucl ic bm).each do |zone|
213 firewall_rule "accept-openvpn-#{zone}" do
219 dest_ports "1194:1196"
220 source_ports "1194:1196"
224 if node[:roles].include?("gateway")
225 template "/etc/shorewall/masq" do
226 source "shorewall-masq.erb"
230 notifies :restart, "service[shorewall]"
233 file "/etc/shorewall/masq" do
235 notifies :restart, "service[shorewall]"
239 unless node.interfaces(:family => :inet6).empty?
242 service "shorewall6" do
243 action [:enable, :start]
244 supports :restart => true
245 status_command "shorewall6 status"
248 template "/etc/default/shorewall6" do
249 source "shorewall-default.erb"
253 notifies :restart, "service[shorewall6]"
256 template "/etc/shorewall6/shorewall6.conf" do
257 source "shorewall6.conf.erb"
261 notifies :restart, "service[shorewall6]"
264 template "/etc/shorewall6/zones" do
265 source "shorewall-zones.erb"
269 variables :type => "ipv6"
270 notifies :restart, "service[shorewall6]"
273 template "/etc/shorewall6/interfaces" do
274 source "shorewall6-interfaces.erb"
278 notifies :restart, "service[shorewall6]"
281 template "/etc/shorewall6/hosts" do
282 source "shorewall6-hosts.erb"
286 variables :zones => zones
287 notifies :restart, "service[shorewall6]"
290 template "/etc/shorewall6/policy" do
291 source "shorewall-policy.erb"
295 notifies :restart, "service[shorewall6]"
298 template "/etc/shorewall6/rules" do
299 source "shorewall-rules.erb"
303 variables :rules => []
304 notifies :restart, "service[shorewall6]"
307 template "/etc/logrotate.d/shorewall6" do
308 source "logrotate.shorewall.erb"
312 variables :name => "shorewall6"
315 firewall_rule "limit-icmp6-echo" do
321 dest_ports "echo-request"
322 rate_limit "s:1/sec:5"
326 firewall_rule "accept-http" do
334 firewall_rule "accept-https" do