fix: normalize MAC addresses with leading zeros for subscriber matching
When SNMP returns MAC addresses as strings (e.g., 'A:B:C:D:E:F'), they were being converted to lowercase without padding hex digits with leading zeros. This caused subscriber matching to fail because the normalize_mac function expects properly padded MACs (e.g., '0a:0b:0c:0d:0e:0f'). Now properly normalizes string MACs by: - Removing all separators - Ensuring 12 hex characters - Reformatting with colon separators and proper padding This fixes subscriber matching for ePMP and some Ubiquiti devices that return string-formatted MACs from SNMP.
This commit is contained in:
parent
f19fb958cb
commit
bbe7a8c4fa
1 changed files with 13 additions and 1 deletions
|
|
@ -253,9 +253,21 @@ defmodule Towerops.Snmp.WirelessClientDiscovery do
|
|||
|
||||
defp format_mac(value) when is_binary(value) do
|
||||
if String.contains?(value, ":") or String.contains?(value, "-") do
|
||||
# String MAC with separators - normalize to ensure proper padding
|
||||
value
|
||||
|> String.downcase()
|
||||
|> String.replace("-", ":")
|
||||
|> String.replace(~r/[^0-9a-f]/, "")
|
||||
|> case do
|
||||
<<a::binary-2, b::binary-2, c::binary-2, d::binary-2, e::binary-2, f::binary-2>> ->
|
||||
"#{a}:#{b}:#{c}:#{d}:#{e}:#{f}"
|
||||
|
||||
# Not 12 hex chars - try to parse as byte string
|
||||
_ ->
|
||||
value
|
||||
|> :binary.bin_to_list()
|
||||
|> Enum.map_join(":", &String.pad_leading(Integer.to_string(&1, 16), 2, "0"))
|
||||
|> String.downcase()
|
||||
end
|
||||
else
|
||||
value
|
||||
|> :binary.bin_to_list()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue