Hello Everyone, 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) 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. Thanks in advance. Regards, Ranbir -- Kanwar Ranbir Sandhu Linux 2.6.27.30-170.2.82.fc10.x86_64 x86_64 GNU/Linux 10:41:48 up 6 days, 21:12, 4 users, load average: 0.81, 0.61, 0.51
Kanwar Ranbir Sandhu <m3freak@thesandhufamily.ca> 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)
Yes...you could :) In my system, I use the following to RFCese the incoming Calling-Station-ID: ---- 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. Cheers -- Alexander Clouter .sigmonster says: I'd like MY data-base JULIENNED and stir-fried!
On Sat, 2009-09-12 at 23:28 +0100, Alexander Clouter wrote:
In my system, I use the following to RFCese the incoming Calling-Station-ID: ---- 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.
I'll try that out, but I'm not worried about the current MAC format. I just wanted to dump everything else (in Calling-Station-Id) and only store the MAC.
If you also make this a policy, then you can make your configuration simpler.
I'm not sure what you mean here. Please explain.
As this is just for logging, you probably just want the amendment in post-auth only, just before you call 'sql' or whatever.
So, I don't need it in preacct? I mean, it's working as is. Would it be better to put in post-auth versus preacct?
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.
We're using Nas-Port for pool-key in sqlippool.conf. We want to try out Calling-Station-Id. But, before we try that, we wanted the Calling-Station-Id attribute received from the NAS to be trimmed to only include the MAC. The NAS sends a whole bunch of other text plus the MAC, which ends up being over 100 characters long. Shortening the attribute to just the MAC itself will allow us to keep the field length in the table the same. FYI: we want to try Calling-Station-Id as a pool-key because we're not 100% sure if the NAS is sending unique NAS-Port attributes. The vendor can't confirm this either (yes, that's insane). Regards, Ranbir -- Kanwar Ranbir Sandhu Linux 2.6.27.30-170.2.82.fc10.x86_64 x86_64 GNU/Linux 10:23:23 up 8 min, 2 users, load average: 0.45, 0.30, 0.15
Kanwar Ranbir Sandhu <m3freak@thesandhufamily.ca> wrote:
On Sat, 2009-09-12 at 23:28 +0100, Alexander Clouter wrote:
If you also make this a policy, then you can make your configuration simpler.
I'm not sure what you mean here. Please explain.
In a snippet from my configuration I have: ---- authorize { preprocess rewrite.called_station_id rewrite.calling_station_id suffix .... } ---- The 'rewrite.call(ing|ed)_station_id' bit lurks in /etc/freeradius/policy.conf and looks like: ---- rewrite.calling_station_id { 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}" } } else { noop } } ---- This means you do not need to clutter your virtual server chunks with huge bits of regex :)
As this is just for logging, you probably just want the amendment in post-auth only, just before you call 'sql' or whatever.
So, I don't need it in preacct? I mean, it's working as is. Would it be better to put in post-auth versus preacct?
Well, depends, if you want the original to be around then I would leave Calling-Station-Id alone, I like to only amend the original attribute values if they are mangled in some strange manner and need fixing up to be more kosher (for example '-' in MAC addresses rather than ':'). If this is for just logging you might want to 'update control' and tinker with 'Tmp-String-0' and then when it comes to your SQL logging you can use that in place of Calling-Station-Id. Of course it all depends on your needs, from your description my gut feeling would be to leave Calling-Station-Id alone and create your own and add some custom attibutes to /etc/freeradius/dictionary. Cheers -- Alexander Clouter .sigmonster says: Being ugly isn't illegal. Yet.
participants (2)
-
Alexander Clouter -
Kanwar Ranbir Sandhu