Enable IPv6

This commit is contained in:
Jamil Bou Kheir
2021-09-22 21:40:39 -07:00
parent 2f74a96c66
commit d335aa4c52
7 changed files with 23 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ defmodule FzHttp.Devices do
alias FzHttp.{Devices.Device, Repo, Users.User}
@ipv4_prefix "10.3.2."
@ipv6_prefix "fd00:3:2::"
def list_devices do
Repo.all(Device)
@@ -49,11 +50,15 @@ defmodule FzHttp.Devices do
@ipv4_prefix <> Integer.to_string(device.address)
end
def ipv6_address(%Device{} = device) do
@ipv6_prefix <> Integer.to_string(device.address)
end
def to_peer_list do
for device <- Repo.all(Device) do
%{
public_key: device.public_key,
allowed_ips: ipv4_address(device)
allowed_ips: "#{ipv4_address(device)}/32, #{ipv6_address(device)}/128"
}
end
end

View File

@@ -20,7 +20,7 @@
<td>
<%= live_patch(device.name, to: Routes.device_show_path(@socket, :show, device)) %>
</td>
<td class="code"><%= FzHttp.Devices.ipv4_address(device) %></td>
<td class="code"><%= FzHttp.Devices.ipv4_address(device) %>, <%= FzHttp.Devices.ipv6_address(device) %></td>
<td class="code"><%= device.public_key %></td>
</tr>
<% end %>

View File

@@ -37,7 +37,7 @@ defmodule FzHttpWeb.DeviceLive.Index do
{:ok, device} ->
@events_module.device_created(
device.public_key,
Devices.ipv4_address(device)
{Devices.ipv4_address(device), Devices.ipv6_address(device)}
)
{:noreply,

View File

@@ -33,7 +33,7 @@
<dt>
<strong>Interface IP:</strong>
</dt>
<dd><%= FzHttp.Devices.ipv4_address(@device) %></dd>
<dd><%= FzHttp.Devices.ipv4_address(@device) %>, <%= FzHttp.Devices.ipv6_address(@device) %></dd>
<dt>
<strong>Public key:</strong>
@@ -72,7 +72,7 @@
<pre><code id="wg-conf">
[Interface]
PrivateKey = <%= @device.private_key %>
Address = <%= FzHttp.Devices.ipv4_address(@device) %>
Address = <%= FzHttp.Devices.ipv4_address(@device) %>/32, <%= FzHttp.Devices.ipv6_address(@device) %>/128
DNS = 1.1.1.1, 1.0.0.1
[Peer]

View File

@@ -85,7 +85,7 @@ defmodule FzHttp.DevicesTest do
test "renders all peers", %{device: device} do
assert Devices.to_peer_list() |> List.first() == %{
public_key: device.public_key,
allowed_ips: Devices.ipv4_address(device)
allowed_ips: "#{Devices.ipv4_address(device)}/32, #{Devices.ipv6_address(device)}/128"
}
end
end

View File

@@ -33,8 +33,8 @@ defmodule FzVpn.CLI.Live do
{privkey, pubkey(privkey)}
end
def add_peer(pubkey, ip) do
set("peer #{pubkey} allowed-ips #{ip}")
def add_peer(pubkey, {ipv4, ipv6}) do
set("peer #{pubkey} allowed-ips #{ipv4}/32,#{ipv6}/128")
end
def delete_peer(pubkey) do

View File

@@ -44,12 +44,17 @@ if wg_exists.status.exitstatus == 1
end
end
execute 'setup_wireguard_ip' do
execute 'setup_wireguard_ipv4' do
# XXX: Make this configurable
if_addr = '10.3.2.1/24'
command "ip address replace #{if_addr} dev #{wg_interface}"
end
execute 'setup_wireguard_ipv6' do
if_addr = 'fd00:3:2:1/48'
command "ip address replace #{if_addr} dev #{wg_interface}"
end
execute 'set_wireguard_interface_private_key' do
command "#{wg_path} set #{wg_interface} private-key #{private_key_path}"
end
@@ -68,6 +73,10 @@ route '10.3.2.0/24' do
device wg_interface
end
route 'fd00:3:2::/48' do
device wg_interface
end
replace_or_add "IPv4 packet forwarding" do
path "/etc/sysctl.conf"
pattern "^#net.ipv4.ip_forward=1"