HI This is where my skills are not great (regex) most other areas I can work with. Ultimately I am happy to pay someone to help write the little bit of code that does this. I do need to cope with Netmasks from /32 to /24 so a few switch cases. Alternatively if someone can provide a few pointers on that bit I can probably build from there. Again I am not expecting something for nothing - so if it needs an hour or so's work I am happy to reward for that Richard
--- Original message --- Subject: Re: Proxy / reply translation From: Matthew Newton <mcn@freeradius.org> To: FreeRadius users mailing list <freeradius-users@lists.freeradius.org> Date: Thursday, 09/11/2017 10:31 AM
On Thu, 2017-11-09 at 10:20 +0000, Richard J Palmer wrote:
* Framed-IP-Address = 1.2.3.1 Framed-IP-Netmask = 255.255.255.240 Cisco-AVPair = "ip:route=1.2.3.1 255.255.255.240" Service-Type = Framed-User
However we need
Framed-IP-Address = 1.2.3.1 Framed-IP-Netmask = 255.255.255.240 Framed-Route = "1.2.3.1/28" Service-Type = Framed-User
Is this relatively easy to do ?
Match on regex should work, something like
if (&Cisco-AVPair =~ /ip:route=([^ ]+) /) { update reply { Framed-Route := "%{1}/28" } }
if the netmasks aren't all the same you'll need to change that as well of course - I don't think there's anything to convert the netmask into the number of bits, but a switch statement should do it easily for the limited number of cases.
-- Matthew
- List info/subscribe/unsubscribe? See http://www.freeradius.org/list/users.html
On Nov 9, 2017, at 8:19 AM, Richard J Palmer <richard@merula.net> wrote:
This is where my skills are not great (regex) most other areas I can work with. Ultimately I am happy to pay someone to help write the little bit of code that does this. I do need to cope with Netmasks from /32 to /24 so a few switch cases.
It shouldn't be difficult.
Alternatively if someone can provide a few pointers on that bit I can probably build from there.
If you have:
Cisco-AVPair = "ip:route=1.2.3.1 255.255.255.240"
Step 1, split it into pieces: if (&Cisco-AVPair =~ /ip:route=([^ ]+) ([^ ]+)/) { This matches the "ip:route" prefix. It then matches non-space data, then a space, and more non-space data. As per the FR documentation, the first match goes into %{1}, and the second into %{2}. As there are only a limited number of net masks, you can expand the net mask, and switch over it (inside of the "if" block from above) switch "%{2}" { case "255.255.255.255" { update reply { Framed-Route = "%{1}/32" } } case "255.255.255.254" { update reply { Framed-Route = "%{1}/31" } } case "255.255.255.252" { update reply { Framed-Route = "%{1}/30" } } ... etc... # and the "catch all" case, just mash it to /28 case { update reply { Framed-Route = "%{1}/28" } } } A little verbose, but it should work. Alan DeKok.
participants (2)
-
Alan DeKok -
Richard J Palmer