Last active
October 14, 2021 12:49
-
-
Save angely-dev/6bfbb37a62e9d6e61b5c7e17892479ab to your computer and use it in GitHub Desktop.
Translate RADIUS attributes from one vendor (say, Cisco) to another one (say, Huawei), using FreeRADIUS and a custom module (UNLANG).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# /etc/freeradius/policy.d/cisco2huawei | |
# | |
# Attributes adaptation from Cisco to Huawei. | |
# | |
cisco2huawei { | |
foreach &reply:Cisco-AVPair { | |
if ("%{Foreach-Variable-0}" =~ /ip:vrf-id=(.*)/) { | |
# | |
# Adapt the VRF attribute. | |
# | |
# Example: "Cisco-AVPair += vrf-id=MY-VRF" | |
# => "Huawei-Vpn-Instance := MY-VRF" | |
# | |
update reply { | |
&Cisco-AVPair -= "%{Foreach-Variable-0}" | |
&Huawei-Vpn-Instance := "%{1}" | |
} | |
updated | |
} | |
elsif ("%{Foreach-Variable-0}" =~ /ip:sub-qos-policy-out=(.*)/) { | |
# | |
# Adapt the QoS out attribute. | |
# | |
# Example: "Cisco-AVPair += ip:sub-qos-policy-out=MY-QOS-OUT" | |
# => "Huawei-Down-QOS-Profile-Name := MY-QOS-OUT" | |
# | |
update reply { | |
&Cisco-AVPair -= "%{Foreach-Variable-0}" | |
&Huawei-Down-QOS-Profile-Name := "%{1}" | |
} | |
updated | |
} | |
elsif ("%{Foreach-Variable-0}" =~ /ip:route=vrf ([a-zA-Z0-9-]+) (.*) (.*) (.*)/) { | |
# | |
# Adapt the route attribute. | |
# | |
# Example: "Cisco-AVPair += ip:route=vrf MY-VRF 192.168.1.0 255.255.255.0 10.0.0.1" | |
# => "Framed-Route += 192.168.1.0 255.255.255.0" | |
# | |
update reply { | |
&Cisco-AVPair -= "%{Foreach-Variable-0}" | |
&Framed-Route += "%{2} %{3}" | |
} | |
updated | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Below an example of the module execution. Tested on FreeRADIUS version 3.0.21.
FreeRADIUS server log: