Using unlang for Calling-Station-Id

Alexander Clouter alex at
Sun Sep 13 00:28:45 CEST 2009

Kanwar Ranbir Sandhu <m3freak at> wrote:
> I want to use unlang to trim the Calling-Station-Id coming from the NAS
> to only include the MAC address.  I know what to do, and how to write
> the unlang lines.  But, I'm not sure where those lines should go.
> At the moment, I put them in my virtual server's "preacct" section, like
> so (ugly wrapping):
> preacct {
>  preprocess
>     if (Calling-Station-Id =~ /(pppoe )([0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])(.)/) {
>        update request {
>          Calling-Station-Id := "%{2}"
>        }
>     }
>  acct_unique
>  suffix
> }
> (yes, I could probably optimize the regex)
> could :)

In my system, I use the following to RFCese the incoming 
if ( "%{request:Calling-Station-Id}" =~ /^([0-9a-f]{2}).?([0-9a-f]{2}).?([0-9a-f]{2}).?([0-9a-f]{2}).?([0-9a-f]{2}).?([0-9a-f]{2})$/i ) {
	update request {
		Calling-Station-Id := "%{1}-%{2}-%{3}-%{4}-%{5}-%{6}"
In your situation you just probably need to remove the '^' and '$' from 
the regex.  If you also make this a policy, then you can make your 
configuration simpler.

> As far as I can see, this is working.  The "callingstationid" field in
> the radacct table now only contains the MAC address.  Interim accounting
> updates appear to be updating the rows properly as well.  I don't see
> any obvious problems.
> Should I be putting the Calling-Station-Id rewriting in other sections
> as well?  I was thinking perhaps the "authorization" and/or "post-auth"
> sections should have it, too.
As this is just for logging, you probably just want the amendment in 
post-auth only, just before you call 'sql' or whatever.  However as you 
have not really said *what* is is you are hoping to get out of all of 
this, I have no suggestions to make.


Alexander Clouter
.sigmonster says: I'd like MY data-base JULIENNED and stir-fried!

More information about the Freeradius-Users mailing list