Skip to content
Snippets Groups Projects
Commit 95e3e5bf authored by drebs's avatar drebs
Browse files

Tinc: use TUN instead of TAP

parent 9aba79ec
Branches tinc-switch-to-tun
No related tags found
1 merge request!18Tinc: use TUN instead of TAP
Pipeline #62817 passed
Facter.add(:tinc_pubkey) do Facter.add(:tinc_pubkey) do
setcode do setcode do
begin begin
File.read('/etc/tinc/tap0/rsa_key.pub') File.read('/etc/tinc/tun0/rsa_key.pub')
rescue Errno::ENOENT rescue Errno::ENOENT
'' ''
end end
......
# Configure a VPN using tinc in switch mode # Configure a VPN using tinc in switch mode
class profile::tinc ( class profile::tinc (
String $netname = 'tap0', String $netname = 'tun0',
Array[String] $connect_to = [], Array[String] $connect_to = [],
Optional[String] $ip = undef, Optional[String] $ip = undef,
Optional[String] $route = undef, Optional[String] $route = undef,
...@@ -36,6 +36,7 @@ class profile::tinc ( ...@@ -36,6 +36,7 @@ class profile::tinc (
tinc_name => $tinc_name, tinc_name => $tinc_name,
netname => $netname, netname => $netname,
config_dir => $config_dir, config_dir => $config_dir,
ip => $ip,
} ~> Service["tinc@${netname}"] } ~> Service["tinc@${netname}"]
file { "${config_dir}/tinc.conf": file { "${config_dir}/tinc.conf":
...@@ -44,8 +45,9 @@ class profile::tinc ( ...@@ -44,8 +45,9 @@ class profile::tinc (
owner => root, owner => root,
group => root, group => root,
content => epp('profile/tinc/tinc.conf.epp', { content => epp('profile/tinc/tinc.conf.epp', {
'name' => $tinc_name, name => $tinc_name,
'connect_to' => $connect_to, connect_to => $connect_to,
interface => $netname,
}), }),
require => File[$config_dir], require => File[$config_dir],
} ~> Service["tinc@${netname}"] } ~> Service["tinc@${netname}"]
...@@ -55,10 +57,7 @@ class profile::tinc ( ...@@ -55,10 +57,7 @@ class profile::tinc (
mode => '0755', mode => '0755',
owner => root, owner => root,
group => root, group => root,
content => epp('profile/tinc/tinc-up.epp', { content => epp('profile/tinc/tinc-up.epp', { ip => $ip }),
ip => $ip,
route => $route,
}),
require => File[$config_dir], require => File[$config_dir],
} ~> Service["tinc@${netname}"] } ~> Service["tinc@${netname}"]
......
# Firewall configurations for Tinc # Firewall configurations for Tinc
class profile::tinc::firewall ( class profile::tinc::firewall (
String $netname = 'tap0', String $netname = 'tun0',
Enum['client', 'server'] $type = 'client', Enum['client', 'server'] $type = 'client',
String $client_ip = $facts['networking']['ip'], String $client_ip = $facts['networking']['ip'],
) { ) {
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
class profile::tinc::hosts ( class profile::tinc::hosts (
String $tinc_name = regsubst($trusted['certname'], '[^[a-zA-Z0-9]]', '_', 'G'), String $tinc_name = regsubst($trusted['certname'], '[^[a-zA-Z0-9]]', '_', 'G'),
String $address = $facts['networking']['ip'], String $address = $facts['networking']['ip'],
String $netname = 'tap0', String $netname = 'tun0',
Stdlib::Absolutepath $config_dir = "/etc/tinc/${netname}", Stdlib::Absolutepath $config_dir = "/etc/tinc/${netname}",
Optional[String] $ip = undef,
) { ) {
# #
...@@ -48,6 +49,7 @@ class profile::tinc::hosts ( ...@@ -48,6 +49,7 @@ class profile::tinc::hosts (
group => root, group => root,
content => epp('profile/tinc/host.epp', { content => epp('profile/tinc/host.epp', {
address => $address, address => $address,
ip => $ip,
pubkey => $pubkey, pubkey => $pubkey,
}), }),
tag => [ 'tinc_host_file', $tag_netname, $tag_environment ], tag => [ 'tinc_host_file', $tag_netname, $tag_environment ],
......
<%- | String[1] $address, String $pubkey | -%> <%- | String[1] $address, Optional[String] $ip, String $pubkey | -%>
Address = <%= $address %> Address = <%= $address %>
<%- unless $ip =~ Undef { -%>
Subnet = <%= $ip %>/32
<%- } %>
<%= $pubkey -%> <%= $pubkey -%>
<%- | <%- | Optional[String] $ip = undef | -%>
Optional[String] $ip = undef,
Optional[String] $route = undef
| -%>
#!/bin/sh #!/bin/sh
ip link set $INTERFACE up ip link set $INTERFACE up
<%- unless $ip =~ Undef { -%> <%- unless $ip =~ Undef { -%>
ip addr add <%= $ip %>/32 dev $INTERFACE ip addr add <%= $ip %>/24 dev $INTERFACE
<%- } -%>
<%- unless $route =~ Undef { -%>
ip route add <%= $route %> dev $INTERFACE
<%- } -%> <%- } -%>
<%- | <%- |
String[1] $name, String $name,
Integer[1, 65535] $port = 655, Integer[1, 65535] $port = 655,
Array[String] $connect_to = [] Array[String] $connect_to = [],
String $interface,
| -%> | -%>
Name = <%= $name %> Name = <%= $name %>
AddressFamily = any AddressFamily = any
...@@ -12,8 +13,8 @@ Compression = 0 ...@@ -12,8 +13,8 @@ Compression = 0
ConnectTo = <%= $address %> ConnectTo = <%= $address %>
<% } -%> <% } -%>
<% } -%> <% } -%>
DeviceType = tap DeviceType = tun
Digest = SHA512 Digest = SHA512
Interface = tap0 Interface = <%= $interface %>
Mode = switch Mode = router
Port = <%= $port %> Port = <%= $port %>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment