Skip to content

Commit

Permalink
Include VPN routes in the netplan config
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jul 30, 2020
1 parent e2fa367 commit 77163ff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 29 deletions.
7 changes: 6 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-07-29 12:02:45 UTC using RuboCop version 0.88.0.
# on 2020-07-30 08:39:06 UTC using RuboCop version 0.88.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -19,3 +19,8 @@ ChefModernize/Definitions:
# SupportedStyles: strings, symbols
ChefStyle/AttributeKeys:
EnforcedStyle: symbols

# Offense count: 3
# Configuration parameters: CountBlocks.
Metrics/BlockNesting:
Max: 4
66 changes: 38 additions & 28 deletions cookbooks/networking/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,44 @@
"scope" => "link"
)
end

if interface[:role] == "internal"
search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
next unless gateway[:openvpn]

gateway[:openvpn][:tunnels].each_value do |tunnel|
if tunnel[:peer][:address]
deviceplan["routes"].push(
"to" => "#{tunnel[:peer][:address]}/32",
"via" => interface[:gateway]
)

route tunnel[:peer][:address] do
netmask "255.255.255.255"
gateway interface[:gateway]
device interface[:interface]
end
end

next unless tunnel[:peer][:networks]

tunnel[:peer][:networks].each do |network|
prefix = IPAddr.new("#{network[:address]}/#{network[:netmask]}").prefix

deviceplan["routes"].push(
"to" => "#{network[:address]}/#{prefix}",
"via" => interface[:gateway]
)

route network[:address] do
netmask network[:netmask]
gateway interface[:gateway]
device interface[:interface]
end
end
end
end
end
end

if interface[:routes]
Expand Down Expand Up @@ -229,34 +267,6 @@
to "../run/systemd/resolve/stub-resolv.conf"
end

node.interfaces(:role => :internal) do |interface|
if interface[:gateway] && interface[:gateway] != interface[:address]
search(:node, "networking_interfaces*address:#{interface[:gateway]}") do |gateway|
next unless gateway[:openvpn]

gateway[:openvpn][:tunnels].each_value do |tunnel|
if tunnel[:peer][:address]
route tunnel[:peer][:address] do
netmask "255.255.255.255"
gateway interface[:gateway]
device interface[:interface]
end
end

next unless tunnel[:peer][:networks]

tunnel[:peer][:networks].each do |network|
route network[:address] do
netmask network[:netmask]
gateway interface[:gateway]
device interface[:interface]
end
end
end
end
end
end

zones = {}

search(:node, "networking:interfaces").collect do |n|
Expand Down

0 comments on commit 77163ff

Please sign in to comment.