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 service "shorewall" do
135 action [:enable, :start]
136 supports :restart => true
137 status_command "shorewall status"
140 template "/etc/default/shorewall" do
141 source "shorewall-default.erb"
145 notifies :restart, "service[shorewall]"
148 template "/etc/shorewall/shorewall.conf" do
149 source "shorewall.conf.erb"
153 notifies :restart, "service[shorewall]"
156 template "/etc/shorewall/zones" do
157 source "shorewall-zones.erb"
161 variables :type => "ipv4"
162 notifies :restart, "service[shorewall]"
165 template "/etc/shorewall/interfaces" do
166 source "shorewall-interfaces.erb"
170 notifies :restart, "service[shorewall]"
173 template "/etc/shorewall/hosts" do
174 source "shorewall-hosts.erb"
178 variables :zones => zones
179 notifies :restart, "service[shorewall]"
182 template "/etc/shorewall/policy" do
183 source "shorewall-policy.erb"
187 notifies :restart, "service[shorewall]"
190 template "/etc/shorewall/rules" do
191 source "shorewall-rules.erb"
195 variables :rules => []
196 notifies :restart, "service[shorewall]"
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:1196"
225 source_ports "1194:1196"
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 service "shorewall6" do
248 action [:enable, :start]
249 supports :restart => true
250 status_command "shorewall6 status"
253 template "/etc/default/shorewall6" do
254 source "shorewall-default.erb"
258 notifies :restart, "service[shorewall6]"
261 template "/etc/shorewall6/shorewall6.conf" do
262 source "shorewall6.conf.erb"
266 notifies :restart, "service[shorewall6]"
269 template "/etc/shorewall6/zones" do
270 source "shorewall-zones.erb"
274 variables :type => "ipv6"
275 notifies :restart, "service[shorewall6]"
278 template "/etc/shorewall6/interfaces" do
279 source "shorewall6-interfaces.erb"
283 notifies :restart, "service[shorewall6]"
286 template "/etc/shorewall6/hosts" do
287 source "shorewall6-hosts.erb"
291 variables :zones => zones
292 notifies :restart, "service[shorewall6]"
295 template "/etc/shorewall6/policy" do
296 source "shorewall-policy.erb"
300 notifies :restart, "service[shorewall6]"
303 template "/etc/shorewall6/rules" do
304 source "shorewall-rules.erb"
308 variables :rules => []
309 notifies :restart, "service[shorewall6]"
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