From bbe7a8c4fa6614c13e8ddbbbb620fb975983852d Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 10 Mar 2026 11:05:57 -0500 Subject: [PATCH] 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. --- lib/towerops/snmp/wireless_client_discovery.ex | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/towerops/snmp/wireless_client_discovery.ex b/lib/towerops/snmp/wireless_client_discovery.ex index 1cbf253f..246864f7 100644 --- a/lib/towerops/snmp/wireless_client_discovery.ex +++ b/lib/towerops/snmp/wireless_client_discovery.ex @@ -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}:#{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()