Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore newaddr/deladdr notifications for unknown interfaces #467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions lib/vintage_net/interfaces_monitor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,37 @@ defmodule VintageNet.InterfacesMonitor do
end

defp handle_report(state, {:newaddr, ifindex, address_report}) do
new_info =
get_or_create_info(state, ifindex)
|> Info.newaddr(address_report)
|> Info.update_address_properties()
case Map.fetch(state.interface_info, ifindex) do
{:ok, info} ->
new_info =
info
|> Info.newaddr(address_report)
|> Info.update_address_properties()

%{state | interface_info: Map.put(state.interface_info, ifindex, new_info)}
%{state | interface_info: Map.put(state.interface_info, ifindex, new_info)}

:error ->
Logger.debug("interfaces_monitor ignoring newaddr for unknown interface #{ifindex}")

state
end
end

defp handle_report(state, {:deladdr, ifindex, address_report}) do
new_info =
get_or_create_info(state, ifindex)
|> Info.deladdr(address_report)
|> Info.update_address_properties()
case Map.fetch(state.interface_info, ifindex) do
{:ok, info} ->
new_info =
info
|> Info.deladdr(address_report)
|> Info.update_address_properties()

%{state | interface_info: Map.put(state.interface_info, ifindex, new_info)}
%{state | interface_info: Map.put(state.interface_info, ifindex, new_info)}

:error ->
Logger.debug("interfaces_monitor ignoring deladdr for unknown interface #{ifindex}")

state
end
end

defp get_by_ifname(state, ifname) do
Expand Down Expand Up @@ -150,15 +166,4 @@ defmodule VintageNet.InterfacesMonitor do
|> Info.update_present()
end
end

defp get_or_create_info(state, ifindex) do
case Map.fetch(state.interface_info, ifindex) do
{:ok, info} ->
info

_missing ->
# Race between address and link notifications?
Info.new("__unknown")
end
end
end