Skip to content

Commit

Permalink
Don't prevent network changes if can't save
Browse files Browse the repository at this point in the history
If the filesystem is messed up for some reason and the network
configuration couldn't be saved, the network configuration change was
aborted. This could be worked around by not saving the configuration.
However, this seemed like the wrong way to degrade. This commit changes
the logic to allow the network configuration, but log an error. The
configuration will be lost on a reboot, but perhaps it will help someone
debug and fix the device that's having trouble.
  • Loading branch information
fhunleth committed Jul 3, 2022
1 parent 14fb5eb commit ba522e0
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/vintage_net/interface.ex
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ defmodule VintageNet.Interface do
:ok <- PredictableInterfaceName.precheck(ifname),
normalized_config = raw_config.source_config,
:changed <- configuration_changed(ifname, normalized_config),
:ok <- persist_configuration(ifname, normalized_config, options),
persist_configuration(ifname, normalized_config, options),
PropertyTable.put(VintageNet, ["interface", ifname, "config"], normalized_config),
{:error, :already_started} <- maybe_start_interface(ifname) do
GenStateMachine.call(via_name(raw_config.ifname), {:configure, raw_config})
Expand All @@ -124,13 +124,13 @@ defmodule VintageNet.Interface do
end

defp persist_configuration(ifname, normalized_config, options) do
case Keyword.get(options, :persist, true) do
true ->
Persistence.call(:save, [ifname, normalized_config])

false ->
:ok
if Keyword.get(options, :persist, true) do
with {:error, reason} <- Persistence.call(:save, [ifname, normalized_config]) do
log(:warn, ifname, "Error saving configuration: #{inspect(reason)}")
end
end

:ok
end

defp maybe_start_interface(ifname) do
Expand Down Expand Up @@ -196,10 +196,10 @@ defmodule VintageNet.Interface do
GenStateMachine.call(via_name(ifname), {:ioctl, command, args})
end

defp debug(data, message), do: log(:debug, data, message)
defp debug(data, message), do: log(:debug, data.ifname, message)

defp log(level, data, message) do
Logger.log(level, ["VintageNet(", data.ifname, "): ", message])
defp log(level, ifname, message) do
Logger.log(level, ["VintageNet(", ifname, "): ", message])
end

@impl GenStateMachine
Expand Down

0 comments on commit ba522e0

Please sign in to comment.