Convert an integer to a MAC address in unlang / expr
Hello, FR 3.0.19 Quick one - I have some Aruba APs that are sending the BSSID in the Called-Station-Id attribute instead of the base radio MAC. I need to get back to the base radio MAC, so Aerohive has provided a mask we can apply to find out the base radio MAC from this BSSID. I am doing: if (&Called-Station-Id =~ /^([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})([^0-9a-f](.+))?$/i) { update control { &Tmp-String-1 := "%{expr: 0x%{1}%{2}%{3}%{4}%{5}%{6} & 0xFFFFFFFFFFC0}" } } This works and the debug output shows &Tmp-String-1: EXPAND %{expr: 0x%{1}%{2}%{3}%{4}%{5}%{6} & 0xFFFFFFFFFFC0} --> 149928134221440 149928134221440 is correct so I need to base convert this integer back to a real MAC in a format like 88-5B-DD-2E-9E-80 or 885BDD2E9E80 instead of 149928134221440. Any thoughts? Thanks, James
James Wood <james.wood@purplewifi.com>wrote:
Quick one - I have some Aruba APs that are sending the BSSID in the Called-Station-Id attribute instead of the base radio MAC. I need to get back to the base radio MAC, so Aerohive has provided a mask we can apply to find out the base radio MAC from this BSSID.
I am doing:
if (&Called-Station-Id =~ /^([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})([^0-9a-f](.+))?$/i) { update control { &Tmp-String-1 := "%{expr: 0x%{1}%{2}%{3}%{4}%{5}%{6} & 0xFFFFFFFFFFC0}" } }
First off, your interstitials between the octets should probably be looking for the '-' or ':' characters, not another hex digit. %{hex:Attribute-Name} might work but I'm not sure it handles strings or whether %{hex:%expr{blah}} might work. You'll have to chop off a leading "0x" afterwards. You're actually chewing some data you don't need to. The first 5 octets can just be left in string form, and the last octet will always end in 0 with that mask, so you only need to do math on the second to last digit (the first digit of the last octet). Worst case once you've extracted that digit and masked it against 0xc you'll have 4 possible values and you could use an if statement to convert 12 back to "c" (the rest of the possible values are the same in hex and decimal). Note that different Aruba AP models have different masks, though.
On Aug 25, 2020, at 11:50 PM, James Wood <james.wood@purplewifi.com> wrote:
Quick one - I have some Aruba APs that are sending the BSSID in the Called-Station-Id attribute instead of the base radio MAC. I need to get back to the base radio MAC, so Aerohive has provided a mask we can apply to find out the base radio MAC from this BSSID.
Could you also provide the debug output? That will let us know if the regex is correct at least.
I am doing:
if (&Called-Station-Id =~ /^([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})([^0-9a-f](.+))?$/i) { update control { &Tmp-String-1 := "%{expr: 0x%{1}%{2}%{3}%{4}%{5}%{6} & 0xFFFFFFFFFFC0}" } }
This works and the debug output shows &Tmp-String-1:
EXPAND %{expr: 0x%{1}%{2}%{3}%{4}%{5}%{6} & 0xFFFFFFFFFFC0}
--> 149928134221440
149928134221440 is correct so I need to base convert this integer back to a real MAC in a format like 88-5B-DD-2E-9E-80 or 885BDD2E9E80 instead of 149928134221440.
Without changing too much, you can do: if (&Called-Station-Id =~ /^([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})[^0-9a-f]?([0-9a-f]{2})([^0-9a-f](.+))?$/i) { update control { &Tmp-String-1 := "%{1}-%{2}-%{3}-%{4}-%{5}-%{expr:0x%{6} & 0xc0}" } } Which should be a lot simpler. The final value might still be printed as decimal, tho. I don't think the %{hex:...} expansion will do what you want. Alan DeKok.
participants (3)
-
Alan DeKok -
Brian Julin -
James Wood