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][:method] = role[interface[:family]][:method]
29 node.set[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
30 node.set[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
33 node.set[:networking][:interfaces][name][:metric] = role[:metric]
34 node.set[:networking][:interfaces][name][:zone] = role[:zone]
37 node.set_unless[:networking][:interfaces][name][:method] = "static"
39 next unless interface[:address]
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 template "/etc/network/interfaces" do
48 source "interfaces.erb"
56 command "/bin/hostname -F /etc/hostname"
59 template "/etc/hostname" do
64 notifies :run, "execute[hostname]"
67 template "/etc/hosts" do
74 link "/etc/resolv.conf" do
77 to "/run/resolvconf/resolv.conf"
78 only_if { File.symlink?("/etc/resolv.conf") }
81 template "/etc/resolv.conf" do
82 source "resolv.conf.erb"
88 node.interfaces(:role => :internal) do |interface|
89 if interface[:gateway] && interface[:gateway] != interface[:address]
90 search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
91 next unless gateway[:openvpn]
93 gateway[:openvpn][:tunnels].each_value do |tunnel|
94 if tunnel[:peer][:address] # ~FC023
95 route tunnel[:peer][:address] do
96 netmask "255.255.255.255"
97 gateway interface[:gateway]
98 device interface[:interface]
102 next unless tunnel[:peer][:networks]
104 tunnel[:peer][:networks].each do |network|
105 route network[:address] do
106 netmask network[:netmask]
107 gateway interface[:gateway]
108 device interface[:interface]
118 search(:node, "networking:interfaces").collect do |n|
119 next if n[:fqdn] == node[:fqdn]
121 n.interfaces.each do |interface|
122 next unless interface[:role] == "external" && interface[:zone]
124 zones[interface[:zone]] ||= {}
125 zones[interface[:zone]][interface[:family]] ||= []
126 zones[interface[:zone]][interface[:family]] << interface[:address]
132 service "shorewall" do
133 action [:enable, :start]
134 supports :restart => true
135 status_command "shorewall status"
138 template "/etc/default/shorewall" do
139 source "shorewall-default.erb"
143 notifies :restart, "service[shorewall]"
146 template "/etc/shorewall/shorewall.conf" do
147 source "shorewall.conf.erb"
151 notifies :restart, "service[shorewall]"
154 template "/etc/shorewall/zones" do
155 source "shorewall-zones.erb"
159 variables :type => "ipv4"
160 notifies :restart, "service[shorewall]"
163 template "/etc/shorewall/interfaces" do
164 source "shorewall-interfaces.erb"
168 notifies :restart, "service[shorewall]"
171 template "/etc/shorewall/hosts" do
172 source "shorewall-hosts.erb"
176 variables :zones => zones
177 notifies :restart, "service[shorewall]"
180 template "/etc/shorewall/policy" do
181 source "shorewall-policy.erb"
185 notifies :restart, "service[shorewall]"
188 template "/etc/shorewall/rules" do
189 source "shorewall-rules.erb"
193 variables :rules => []
194 notifies :restart, "service[shorewall]"
197 template "/etc/logrotate.d/shorewall" do
198 source "logrotate.shorewall.erb"
202 variables :name => "shorewall"
205 firewall_rule "limit-icmp-echo" do
211 dest_ports "echo-request"
212 rate_limit "s:1/sec:5"
215 %w(ucl ic bm).each do |zone|
216 firewall_rule "accept-openvpn-#{zone}" do
222 dest_ports "1194:1196"
223 source_ports "1194:1196"
227 if node[:roles].include?("gateway")
228 template "/etc/shorewall/masq" do
229 source "shorewall-masq.erb"
233 notifies :restart, "service[shorewall]"
236 file "/etc/shorewall/masq" do
238 notifies :restart, "service[shorewall]"
242 unless node.interfaces(:family => :inet6).empty?
245 service "shorewall6" do
246 action [:enable, :start]
247 supports :restart => true
248 status_command "shorewall6 status"
251 template "/etc/default/shorewall6" do
252 source "shorewall-default.erb"
256 notifies :restart, "service[shorewall6]"
259 template "/etc/shorewall6/shorewall6.conf" do
260 source "shorewall6.conf.erb"
264 notifies :restart, "service[shorewall6]"
267 template "/etc/shorewall6/zones" do
268 source "shorewall-zones.erb"
272 variables :type => "ipv6"
273 notifies :restart, "service[shorewall6]"
276 template "/etc/shorewall6/interfaces" do
277 source "shorewall6-interfaces.erb"
281 notifies :restart, "service[shorewall6]"
284 template "/etc/shorewall6/hosts" do
285 source "shorewall6-hosts.erb"
289 variables :zones => zones
290 notifies :restart, "service[shorewall6]"
293 template "/etc/shorewall6/policy" do
294 source "shorewall-policy.erb"
298 notifies :restart, "service[shorewall6]"
301 template "/etc/shorewall6/rules" do
302 source "shorewall-rules.erb"
306 variables :rules => []
307 notifies :restart, "service[shorewall6]"
310 template "/etc/logrotate.d/shorewall6" do
311 source "logrotate.shorewall.erb"
315 variables :name => "shorewall6"
318 firewall_rule "limit-icmp6-echo" do
324 dest_ports "echo-request"
325 rate_limit "s:1/sec:5"
329 firewall_rule "accept-http" do
337 firewall_rule "accept-https" do