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] and role = node[:networking][:roles][interface[:role]]
27 if role[interface[:family]]
28 node.default[:networking][:interfaces][name][:prefix] = role[interface[:family]][:prefix]
29 node.default[:networking][:interfaces][name][:gateway] = role[interface[:family]][:gateway]
32 node.default[:networking][:interfaces][name][:metric] = role[:metric]
33 node.default[:networking][:interfaces][name][:zone] = role[:zone]
36 prefix = node[:networking][:interfaces][name][:prefix]
38 node.default[:networking][:interfaces][name][:netmask] = (~IPAddr.new(interface[:address]).mask(0)).mask(prefix)
39 node.default[:networking][:interfaces][name][:network] = IPAddr.new(interface[:address]).mask(prefix)
42 template "/etc/network/interfaces" do
43 source "interfaces.erb"
51 command "/bin/hostname -F /etc/hostname"
54 template "/etc/hostname" do
59 notifies :run, resources(:execute => "hostname")
62 template "/etc/hosts" do
69 link "/etc/resolv.conf" do
72 to "/run/resolvconf/resolv.conf"
73 only_if { File.symlink?("/etc/resolv.conf") }
76 template "/etc/resolv.conf" do
77 source "resolv.conf.erb"
83 node.interfaces(:role => :internal) do |interface|
84 if interface[:gateway] and interface[:gateway] != interface[:address]
85 search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
87 gateway[:openvpn][:tunnels].each_value do |tunnel|
88 if tunnel[:peer][:address]
89 route tunnel[:peer][:address] do
90 netmask "255.255.255.255"
91 gateway interface[:gateway]
92 device interface[:interface]
96 if tunnel[:peer][:networks]
97 tunnel[:peer][:networks].each do |network|
98 route network[:address] do
99 netmask network[:netmask]
100 gateway interface[:gateway]
101 device interface[:interface]
113 search(:node, "networking:interfaces").collect do |n|
114 if n[:fqdn] != node[:fqdn]
115 n.interfaces.each do |interface|
116 if interface[:role] == "external" and interface[:zone]
117 zones[interface[:zone]] ||= Hash.new
118 zones[interface[:zone]][interface[:family]] ||= Array.new
119 zones[interface[:zone]][interface[:family]] << interface[:address]
127 service "shorewall" do
128 action [ :enable, :start ]
129 supports :restart => true
130 status_command "shorewall status"
133 template "/etc/default/shorewall" do
134 source "shorewall-default.erb"
138 notifies :restart, resources(:service => "shorewall")
141 template "/etc/shorewall/shorewall.conf" do
142 source "shorewall.conf.erb"
146 notifies :restart, resources(:service => "shorewall")
149 template "/etc/shorewall/zones" do
150 source "shorewall-zones.erb"
154 variables :type => "ipv4"
155 notifies :restart, resources(:service => "shorewall")
158 template "/etc/shorewall/interfaces" do
159 source "shorewall-interfaces.erb"
163 notifies :restart, resources(:service => "shorewall")
166 template "/etc/shorewall/hosts" do
167 source "shorewall-hosts.erb"
171 variables :zones => zones
172 notifies :restart, resources(:service => "shorewall")
175 template "/etc/shorewall/policy" do
176 source "shorewall-policy.erb"
180 notifies :restart, resources(:service => "shorewall")
183 template "/etc/shorewall/rules" do
184 source "shorewall-rules.erb"
188 variables :family => "inet", :rules => []
189 notifies :restart, resources(:service => "shorewall")
192 firewall_rule "limit-icmp-echo" do
198 dest_ports "echo-request"
199 rate_limit "s:1/sec:5"
202 [ "ucl", "ic", "bm" ].each do |zone|
203 firewall_rule "accept-openvpn-#{zone}" do
209 dest_ports "1194:1196"
210 source_ports "1194:1196"
214 if node[:roles].include?("gateway")
215 template "/etc/shorewall/masq" do
216 source "shorewall-masq.erb"
220 notifies :restart, resources(:service => "shorewall")
223 file "/etc/shorewall/masq" do
225 notifies :restart, resources(:service => "shorewall")
229 if not node.interfaces(:family => :inet6).empty?
232 service "shorewall6" do
233 action [ :enable, :start ]
234 supports :restart => true
235 status_command "shorewall6 status"
238 template "/etc/default/shorewall6" do
239 source "shorewall-default.erb"
243 notifies :restart, resources(:service => "shorewall6")
246 template "/etc/shorewall6/shorewall6.conf" do
247 source "shorewall6.conf.erb"
251 notifies :restart, resources(:service => "shorewall6")
254 template "/etc/shorewall6/zones" do
255 source "shorewall-zones.erb"
259 variables :type => "ipv6"
260 notifies :restart, resources(:service => "shorewall6")
263 template "/etc/shorewall6/interfaces" do
264 source "shorewall6-interfaces.erb"
268 notifies :restart, resources(:service => "shorewall6")
271 template "/etc/shorewall6/hosts" do
272 source "shorewall6-hosts.erb"
276 variables :zones => zones
277 notifies :restart, resources(:service => "shorewall6")
280 template "/etc/shorewall6/policy" do
281 source "shorewall-policy.erb"
285 notifies :restart, resources(:service => "shorewall6")
288 template "/etc/shorewall6/rules" do
289 source "shorewall-rules.erb"
293 variables :family => "inet6", :rules => []
294 notifies :restart, resources(:service => "shorewall6")
297 firewall_rule "limit-icmp6-echo" do
303 dest_ports "echo-request"
304 rate_limit "s:1/sec:5"
308 firewall_rule "accept-http" do
316 firewall_rule "accept-https" do