Convert an integer to a MAC address in unlang / expr

James Wood james.wood at purplewifi.com
Wed Aug 26 05:50:41 CEST 2020


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


More information about the Freeradius-Users mailing list