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.set[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
34 node.set[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
37 node.set[:networking][:interfaces][name][:metric] = role[:metric]
38 node.set[:networking][:interfaces][name][:zone] = role[:zone]
41 prefix = node[:networking][:interfaces][name][:prefix]
43 node.set[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
44 node.set[: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 link "/etc/resolv.conf" do
79 to "/run/resolvconf/resolv.conf"
80 only_if { File.symlink?("/etc/resolv.conf") }
83 template "/etc/resolv.conf" do
84 source "resolv.conf.erb"
90 node.interfaces(:role => :internal) do |interface|
91 if interface[:gateway] && interface[:gateway] != interface[:address]
92 search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
93 next unless gateway[:openvpn]
95 gateway[:openvpn][:tunnels].each_value do |tunnel|
96 if tunnel[:peer][:address] # ~FC023
97 route tunnel[:peer][:address] do
98 netmask "255.255.255.255"
99 gateway interface[:gateway]
100 device interface[:interface]
104 next unless tunnel[:peer][:networks]
106 tunnel[:peer][:networks].each do |network|
107 route network[:address] do
108 netmask network[:netmask]
109 gateway interface[:gateway]
110 device interface[:interface]
120 search(:node, "networking:interfaces").collect do |n|
121 next if n[:fqdn] == node[:fqdn]
123 n.interfaces.each do |interface|
124 next unless interface[:role] == "external" && interface[:zone]
126 zones[interface[:zone]] ||= {}
127 zones[interface[:zone]][interface[:family]] ||= []
128 zones[interface[:zone]][interface[:family]] << interface[:address]
134 template "/etc/default/shorewall" do
135 source "shorewall-default.erb"
139 notifies :restart, "service[shorewall]"
142 template "/etc/shorewall/shorewall.conf" do
143 source "shorewall.conf.erb"
147 notifies :restart, "service[shorewall]"
150 template "/etc/shorewall/zones" do
151 source "shorewall-zones.erb"
155 variables :type => "ipv4"
156 notifies :restart, "service[shorewall]"
159 template "/etc/shorewall/interfaces" do
160 source "shorewall-interfaces.erb"
164 notifies :restart, "service[shorewall]"
167 template "/etc/shorewall/hosts" do
168 source "shorewall-hosts.erb"
172 variables :zones => zones
173 notifies :restart, "service[shorewall]"
176 template "/etc/shorewall/policy" do
177 source "shorewall-policy.erb"
181 notifies :restart, "service[shorewall]"
184 template "/etc/shorewall/rules" do
185 source "shorewall-rules.erb"
189 variables :rules => []
190 notifies :restart, "service[shorewall]"
193 service "shorewall" do
194 action [:enable, :start]
195 supports :restart => true
196 status_command "shorewall status"
199 template "/etc/logrotate.d/shorewall" do
200 source "logrotate.shorewall.erb"
204 variables :name => "shorewall"
207 firewall_rule "limit-icmp-echo" do
213 dest_ports "echo-request"
214 rate_limit "s:1/sec:5"
217 %w(ucl ic bm aws).each do |zone|
218 firewall_rule "accept-openvpn-#{zone}" do
224 dest_ports "1194:1197"
225 source_ports "1194:1197"
229 if node[:roles].include?("gateway")
230 template "/etc/shorewall/masq" do
231 source "shorewall-masq.erb"
235 notifies :restart, "service[shorewall]"
238 file "/etc/shorewall/masq" do
240 notifies :restart, "service[shorewall]"
244 unless node.interfaces(:family => :inet6).empty?
247 template "/etc/default/shorewall6" do
248 source "shorewall-default.erb"
252 notifies :restart, "service[shorewall6]"
255 template "/etc/shorewall6/shorewall6.conf" do
256 source "shorewall6.conf.erb"
260 notifies :restart, "service[shorewall6]"
263 template "/etc/shorewall6/zones" do
264 source "shorewall-zones.erb"
268 variables :type => "ipv6"
269 notifies :restart, "service[shorewall6]"
272 template "/etc/shorewall6/interfaces" do
273 source "shorewall6-interfaces.erb"
277 notifies :restart, "service[shorewall6]"
280 template "/etc/shorewall6/hosts" do
281 source "shorewall6-hosts.erb"
285 variables :zones => zones
286 notifies :restart, "service[shorewall6]"
289 template "/etc/shorewall6/policy" do
290 source "shorewall-policy.erb"
294 notifies :restart, "service[shorewall6]"
297 template "/etc/shorewall6/rules" do
298 source "shorewall-rules.erb"
302 variables :rules => []
303 notifies :restart, "service[shorewall6]"
306 service "shorewall6" do
307 action [:enable, :start]
308 supports :restart => true
309 status_command "shorewall6 status"
312 template "/etc/logrotate.d/shorewall6" do
313 source "logrotate.shorewall.erb"
317 variables :name => "shorewall6"
320 firewall_rule "limit-icmp6-echo" do
326 dest_ports "echo-request"
327 rate_limit "s:1/sec:5"
331 firewall_rule "accept-http" do
339 firewall_rule "accept-https" do