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]
27 node[:networking][:interfaces].each do |name, interface|
28 network_packages |= ["vlan"] if interface[:interface] =~ /\.\d+$/
29 network_packages |= ["ifenslave"] if interface[:bond]
31 if interface[:role] && (role = node[:networking][:roles][interface[:role]])
32 if role[interface[:family]]
33 node.normal[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
34 node.normal[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
37 node.normal[:networking][:interfaces][name][:metric] = role[:metric]
38 node.normal[:networking][:interfaces][name][:zone] = role[:zone]
41 prefix = node[:networking][:interfaces][name][:prefix]
43 node.normal[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
44 node.normal[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
47 package network_packages
49 template "/etc/network/interfaces" do
50 source "interfaces.erb"
58 command "/bin/hostname -F /etc/hostname"
61 template "/etc/hostname" do
66 notifies :run, "execute[hostname]"
69 template "/etc/hosts" do
76 unless node[:networking][:nameservers].empty?
77 link "/etc/resolv.conf" do
80 to "/run/resolvconf/resolv.conf"
81 only_if { File.symlink?("/etc/resolv.conf") }
84 template "/etc/resolv.conf" do
85 source "resolv.conf.erb"
92 node.interfaces(:role => :internal) do |interface|
93 if interface[:gateway] && interface[:gateway] != interface[:address]
94 search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
95 next unless gateway[:openvpn]
97 gateway[:openvpn][:tunnels].each_value do |tunnel|
98 if tunnel[:peer][:address] # ~FC023
99 route tunnel[:peer][:address] do
100 netmask "255.255.255.255"
101 gateway interface[:gateway]
102 device interface[:interface]
106 next unless tunnel[:peer][:networks]
108 tunnel[:peer][:networks].each do |network|
109 route network[:address] do
110 netmask network[:netmask]
111 gateway interface[:gateway]
112 device interface[:interface]
122 search(:node, "networking:interfaces").collect do |n|
123 next if n[:fqdn] == node[:fqdn]
125 n.interfaces.each do |interface|
126 next unless interface[:role] == "external" && interface[:zone]
128 zones[interface[:zone]] ||= {}
129 zones[interface[:zone]][interface[:family]] ||= []
130 zones[interface[:zone]][interface[:family]] << interface[:address]
136 template "/etc/default/shorewall" do
137 source "shorewall-default.erb"
141 notifies :restart, "service[shorewall]"
144 template "/etc/shorewall/shorewall.conf" do
145 source "shorewall.conf.erb"
149 notifies :restart, "service[shorewall]"
152 template "/etc/shorewall/zones" do
153 source "shorewall-zones.erb"
157 variables :type => "ipv4"
158 notifies :restart, "service[shorewall]"
161 template "/etc/shorewall/interfaces" do
162 source "shorewall-interfaces.erb"
166 notifies :restart, "service[shorewall]"
169 template "/etc/shorewall/hosts" do
170 source "shorewall-hosts.erb"
174 variables :zones => zones
175 notifies :restart, "service[shorewall]"
178 template "/etc/shorewall/policy" do
179 source "shorewall-policy.erb"
183 notifies :restart, "service[shorewall]"
186 template "/etc/shorewall/rules" do
187 source "shorewall-rules.erb"
191 variables :family => "inet"
192 notifies :restart, "service[shorewall]"
195 service "shorewall" do
196 action [:enable, :start]
197 supports :restart => true
198 status_command "shorewall status"
201 template "/etc/logrotate.d/shorewall" do
202 source "logrotate.shorewall.erb"
206 variables :name => "shorewall"
209 firewall_rule "limit-icmp-echo" do
215 dest_ports "echo-request"
216 rate_limit "s:1/sec:5"
219 %w(ucl ic bm aws).each do |zone|
220 firewall_rule "accept-openvpn-#{zone}" do
226 dest_ports "1194:1197"
227 source_ports "1194:1197"
231 if node[:roles].include?("gateway")
232 template "/etc/shorewall/masq" do
233 source "shorewall-masq.erb"
237 notifies :restart, "service[shorewall]"
240 file "/etc/shorewall/masq" do
242 notifies :restart, "service[shorewall]"
246 unless node.interfaces(:family => :inet6).empty?
249 template "/etc/default/shorewall6" do
250 source "shorewall-default.erb"
254 notifies :restart, "service[shorewall6]"
257 template "/etc/shorewall6/shorewall6.conf" do
258 source "shorewall6.conf.erb"
262 notifies :restart, "service[shorewall6]"
265 template "/etc/shorewall6/zones" do
266 source "shorewall-zones.erb"
270 variables :type => "ipv6"
271 notifies :restart, "service[shorewall6]"
274 template "/etc/shorewall6/interfaces" do
275 source "shorewall6-interfaces.erb"
279 notifies :restart, "service[shorewall6]"
282 template "/etc/shorewall6/hosts" do
283 source "shorewall6-hosts.erb"
287 variables :zones => zones
288 notifies :restart, "service[shorewall6]"
291 template "/etc/shorewall6/policy" do
292 source "shorewall-policy.erb"
296 notifies :restart, "service[shorewall6]"
299 template "/etc/shorewall6/rules" do
300 source "shorewall-rules.erb"
304 variables :family => "inet6"
305 notifies :restart, "service[shorewall6]"
308 service "shorewall6" do
309 action [:enable, :start]
310 supports :restart => true
311 status_command "shorewall6 status"
314 template "/etc/logrotate.d/shorewall6" do
315 source "logrotate.shorewall.erb"
319 variables :name => "shorewall6"
322 firewall_rule "limit-icmp6-echo" do
328 dest_ports "echo-request"
329 rate_limit "s:1/sec:5"
333 firewall_rule "accept-http" do
341 firewall_rule "accept-https" do