[EXT] Convert an integer to a MAC address in unlang / expr

Brian Julin BJulin at clarku.edu
Wed Aug 26 08:40:08 CEST 2020



James Wood <james.wood at 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.





More information about the Freeradius-Users mailing list