diff --git a/apps/fz_http/lib/fz_http/devices/device.ex b/apps/fz_http/lib/fz_http/devices/device.ex index 1ffa12766..1752165c3 100644 --- a/apps/fz_http/lib/fz_http/devices/device.ex +++ b/apps/fz_http/lib/fz_http/devices/device.ex @@ -16,6 +16,7 @@ defmodule FzHttp.Devices.Device do field :private_key, FzHttp.Encrypted.Binary field :server_public_key, :string field :remote_ip, EctoNetwork.INET + field :octet_sequence, :integer, read_after_writes: true field :interface_address4, EctoNetwork.INET field :interface_address6, EctoNetwork.INET field :last_seen_at, :utc_datetime_usec @@ -30,6 +31,7 @@ defmodule FzHttp.Devices.Device do |> cast(attrs, [ :allowed_ips, :remote_ip, + :octet_sequence, :interface_address4, :interface_address6, :server_public_key, diff --git a/apps/fz_http/lib/fz_http_web/live/device_live/show.html.leex b/apps/fz_http/lib/fz_http_web/live/device_live/show.html.leex index 5b59a507c..2a2f83ddf 100644 --- a/apps/fz_http/lib/fz_http_web/live/device_live/show.html.leex +++ b/apps/fz_http/lib/fz_http_web/live/device_live/show.html.leex @@ -26,6 +26,11 @@
[Interface]
PrivateKey = <%= @device.private_key %>
-Address = 172.16.99.1/24
+Address = 10.3.2.<%= @device.octet_sequence %>
DNS = 1.1.1.1, 1.0.0.1
[Peer]
diff --git a/apps/fz_http/priv/repo/migrations/20200228145810_create_devices.exs b/apps/fz_http/priv/repo/migrations/20200228145810_create_devices.exs
index 64e2fa985..b4b6c68a1 100644
--- a/apps/fz_http/priv/repo/migrations/20200228145810_create_devices.exs
+++ b/apps/fz_http/priv/repo/migrations/20200228145810_create_devices.exs
@@ -10,6 +10,8 @@ defmodule FzHttp.Repo.Migrations.CreateDevices do
add :private_key, :bytea, null: false
add :server_public_key, :string, null: false
add :remote_ip, :inet
+ # XXX: Rework this in app code
+ add :octet_sequence, :serial
add :interface_address4, :inet
add :interface_address6, :inet
add :last_seen_at, :utc_datetime_usec
@@ -23,5 +25,6 @@ defmodule FzHttp.Repo.Migrations.CreateDevices do
create unique_index(:devices, [:private_key])
create unique_index(:devices, [:preshared_key])
create unique_index(:devices, [:user_id, :name])
+ create unique_index(:devices, [:octet_sequence])
end
end