Skip to content

Commit

Permalink
Bulletproof force clearing IP addresses
Browse files Browse the repository at this point in the history
This was seen in the wild and probably due to a race with a bouncing
network connection. Crashing seems too harsh.
  • Loading branch information
fhunleth committed Sep 13, 2023
1 parent 079c659 commit 16d26c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/vintage_net/interfaces_monitor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ defmodule VintageNet.InterfacesMonitor do

@impl GenServer
def handle_call({:force_clear_ipv4_addresses, ifname}, _from, state) do
{ifindex, old_info} = get_by_ifname(state, ifname)
new_info = Info.delete_ipv4_addresses(old_info)

if old_info != new_info do
with {ifindex, old_info} <- get_by_ifname(state, ifname),
new_info = Info.delete_ipv4_addresses(old_info),
true <- old_info != new_info do
new_info = Info.update_address_properties(new_info)

new_state = %{state | interface_info: Map.put(state.interface_info, ifindex, new_info)}
{:reply, :ok, new_state}
else
{:reply, :ok, state}
_ -> {:reply, :ok, state}
end
end

Expand Down
4 changes: 4 additions & 0 deletions test/vintage_net/interfaces_monitor_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,10 @@ defmodule VintageNet.InterfacesMonitorTest do
InterfacesMonitor.force_clear_ipv4_addresses("bogus0")

refute_receive {VintageNet, ["interface", "bogus0", "addresses"], _anything, _anything2, %{}}

# This shouldn't crash
InterfacesMonitor.force_clear_ipv4_addresses("bogus1")
refute_receive _
end

defp get_interfaces() do
Expand Down

0 comments on commit 16d26c4

Please sign in to comment.