mask ip6 spec to /64

This commit is contained in:
byte[] 2019-12-30 07:36:23 -05:00
parent 38c4e35bb7
commit dfaee1e34d

View file

@ -34,5 +34,21 @@ defmodule Philomena.Bans.Subnet do
|> assign_time(:until, :valid_until) |> assign_time(:until, :valid_until)
|> put_ban_id("S") |> put_ban_id("S")
|> validate_required([:reason, :enabled, :specification, :valid_until]) |> validate_required([:reason, :enabled, :specification, :valid_until])
|> mask_specification()
end
defp mask_specification(changeset) do
specification =
changeset
|> get_field(:specification)
|> case do
%Postgrex.INET{address: {h1, h2, h3, h4, h5, h6, h7, h8}, netmask: 128} ->
%Postgrex.INET{address: {h1, h2, h3, h4, 0, 0, 0, 0}, netmask: 64}
val ->
val
end
put_change(changeset, :specification, specification)
end end
end end