[EXT] Convert an integer to a MAC address in unlang / expr
James Wood
james.wood at purplewifi.com
Thu Aug 27 12:44:09 CEST 2020
Thanks Brian and Alan for your advice.
If I just perform the mask transform on the last octet this works but of
course it returns the result as an int, so I can't find any built in
function to get that back to hex.
This is what I've ended up with; please let me know if you feel there is a
better/cleaner way without needing the IF statement
update control {
&Tmp-String-1 := "%{1}-%{2}-%{3}-%{4}-%{5}"
&Tmp-String-2 := "%{expr: 0x%{6} & 0xC0}"
}
if (&control:Tmp-String-2 && &control:Tmp-String-2 != "") {
if (&control:Tmp-String-2 == "00") {
update control {
&Tmp-String-2 := "00"
}
}
if (&control:Tmp-String-2 == "64") {
update control {
&Tmp-String-2 := "40"
}
}
if (&control:Tmp-String-2 == "128") {
update control {
&Tmp-String-2 := "80"
}
}
if (&control:Tmp-String-2 == "192") {
update control {
&Tmp-String-2 := "C0"
}
}
update request {
&Called-Station-Id :=
"%{control:Tmp-String-1}-%{control:Tmp-String-2}"
}
}
Thanks,
James
More information about the Freeradius-Users
mailing list