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 if node[:lsb][:release].to_f >= 10.04
200 rate_limit "s:1/sec:5"
206 [ "ucl", "ic", "bm" ].each do |zone|
207 firewall_rule "accept-openvpn-#{zone}" do
213 dest_ports "1194:1196"
214 source_ports "1194:1196"
218 if node[:roles].include?("gateway")
219 template "/etc/shorewall/masq" do
220 source "shorewall-masq.erb"
224 notifies :restart, resources(:service => "shorewall")
227 file "/etc/shorewall/masq" do
229 notifies :restart, resources(:service => "shorewall")
233 if not node.interfaces(:family => :inet6).empty?
236 service "shorewall6" do
237 action [ :enable, :start ]
238 supports :restart => true
239 status_command "shorewall6 status"
242 template "/etc/default/shorewall6" do
243 source "shorewall-default.erb"
247 notifies :restart, resources(:service => "shorewall6")
250 template "/etc/shorewall6/shorewall6.conf" do
251 source "shorewall6.conf.erb"
255 notifies :restart, resources(:service => "shorewall6")
258 template "/etc/shorewall6/zones" do
259 source "shorewall-zones.erb"
263 variables :type => "ipv6"
264 notifies :restart, resources(:service => "shorewall6")
267 template "/etc/shorewall6/interfaces" do
268 source "shorewall6-interfaces.erb"
272 notifies :restart, resources(:service => "shorewall6")
275 template "/etc/shorewall6/hosts" do
276 source "shorewall6-hosts.erb"
280 variables :zones => zones
281 notifies :restart, resources(:service => "shorewall6")
284 template "/etc/shorewall6/policy" do
285 source "shorewall-policy.erb"
289 notifies :restart, resources(:service => "shorewall6")
292 template "/etc/shorewall6/rules" do
293 source "shorewall-rules.erb"
297 variables :family => "inet6", :rules => []
298 notifies :restart, resources(:service => "shorewall6")
301 firewall_rule "limit-icmp6-echo" do
307 dest_ports "echo-request"
308 if node[:lsb][:release].to_f >= 10.04
309 rate_limit "s:1/sec:5"
316 firewall_rule "accept-http" do
324 firewall_rule "accept-https" do