lpad on regular expression matches does not work
Tomasz Chiliński
chilek at chilan.com
Thu Mar 4 11:13:33 CET 2021
Hello all,
I try to improve Calling-Station-Id MAC address canonicalization a
little bit, so that
is should left pad MAC octets with zeroes.
I modified default settings as is:
mac-addr-regexp =
'([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})[:\-\.]([0-9a-f]{1,2})'
This regular expression matches example MAC address properly:
[0] => 18:d0:71:f3:70:8
[1] => 18
[2] => d0
[3] => 71
[4] => f3
[5] => 70
[6] => 8
Then I want to make the whole thing this way:
rewrite_calling_station_id {
if (&Calling-Station-Id && (&Calling-Station-Id =~
/^${policy.mac-addr-regexp}$/i)) {
update request {
&Calling-Station-Id := "%{toupper:%{lpad:%{1} 2 0}:%{lpad:%{2} 2
0}:%{lpad:%{3} 2 0}:%{lpad:%{4} 2 0}:%{lpad:%{5} 2 0}:%{lpad:%{6} 2 0}}"
}
updated
}
else {
noop
}
}
And here's surprise - lpad expression function handles only attribute
parameters (ex. {lpad:&User-Name 100 0}),
but not regexp matches. What am I doing wrong?
--
Bests,
Tomasz Chiliński, Chilan
opiekun projektu LMS - https://lms.org.pl
kierownik projektu LMS Plus / LMS+ - https://lms-plus.org
--
Pozdrawiam
Tomasz Chiliński, Chilan
opiekun projektu LMS - https://lms.org.pl
kierownik projektu LMS Plus / LMS+ - https://lms-plus.org
More information about the Freeradius-Users
mailing list