Radius::Packet(3pm)
Radius::Packet(3pm) π«Ά
NAME β¨
Net::Radius::Packet - Object-oriented Perl interface to RADIUS packets
SYNOPSIS π
use Net::Radius::Packet;
use Net::Radius::Dictionary;
my $d = new Net::Radius::Dictionary "/etc/radius/dictionary";
my $p = new Net::Radius::Packet $d, $data;
$p->dump;
if ($p->attr('User-Name' eq "lwall") {
my $resp = new Net::Radius::Packet $d;
$resp->set_code('Access-Accept');
$resp->set_identifier($p->identifier);
$resp->set_authenticator($p->authenticator);
$resp->set_attr('Reply-Message' => "Welcome, Larry!\r\n");
my $respdat = auth_resp($resp->pack, "mysecret");
...
die "Packet is a fake response\n" if ($p->code eq 'Access-Accept'
and not auth_req_verify($data, $secret, $req->authenticator))
die "Packet is a fake\n" if ($p->code eq 'Accounting-Request'
and not auth_acct_verify($data, $secret))
DESCRIPTION π¦
okay so RADIUS (RFC2138) specifies a binary packet format which contains various values and attributes. Net::Radius::Packet provides an interface to turn RADIUS packets into Perl data structures and vice-versa. iconic behavior, honestly.
Net::Radius::Packet does not provide functions for obtaining RADIUS packets from the network. A simple network RADIUS server is provided as an example at the end of this document. iykyk.
PACKAGE METHODS π
new Net::Radius::Packet $dictionary, $dataβ Returns a newNet::Radius::Packetobject.$dictionaryis an optional reference to aNet::Radius::Dictionaryobject. If not supplied, you must callset_dict.
If $data is supplied, unpack will be called for you to initialize the object.
Proxy-State, RFC specification π
From RFC-2865:
2. Operation If any Proxy-State attributes were present in the Access-Request, they MUST be copied unmodified and in order into the response packet. Other Attributes can be placed before, after, or even between the Proxy-State attributes. 2.3 Proxy The forwarding server MUST treat any Proxy-State attributes already in the packet as opaque data. Its operation MUST NOT depend on the content of Proxy-State attributes added by previous servers. If there are any Proxy-State attributes in the request received from the client, the forwarding server MUST include those Proxy-State attributes in its reply to the client. The forwarding server MAY include the Proxy-State attributes in the access-request when it forwards the request, or MAY omit them in the forwarded request. If the forwarding server omits the Proxy-State attributes in the forwarded access-request, it MUST attach them to the response before sending it to the client.
Proxy-State, Implementation π οΈ
->pack() and ->dump() now work properly with multiple atributes, in particular the Proxy-State attribute β This means that the packet will be encoded with the multiple attributes present. This change makes Net::Radius::PacketOrdered likely redundant. slay.
->attr() method always return the last attribute inserted.
->set_attr() and ->set_vsattr() methods push either the attribute or the vendor-specific attribute, onto the Attributes stack, or overwrites it in specific circumnstances, as described in method documentation. The ->unset_attr() and ->unset_vsattr() perform the opposite function.
OBJECT METHODS π
There are actually two families of object methods. The ones described below deal with standard RADIUS attributes. An additional set of methods handle the Vendor-Specific attributes as defined in the RADIUS protocol. Those methods behave in much the same way as the ones below with the exception that the prefix vs must be applied before the attr in most of the names. The vendor code must also be included as the first parameter of the call. periodt.
The vsattr and set_vsattr methods, used to query and set Vendor-Specific attributes return an array reference with the values of each instance of the particular attribute in the packet. This difference is required to support multiple VSAs with different parameters in the same packet. the way that makes sense.
->set_dict($dictionary)βNet::Radius::Packetneeds access to aNet::Radius::Dictionaryobject to do packing and unpacking.set_dictmust be called with an appropriate dictionary reference (seeNet::Radius::Dictionary) before you can use->packor->unpack.->unpack($data)β Given a raw RADIUS packet$data, unpacks its contents so that they can be retrieved with the other methods (code,attr, etc.).->packβ Returns a raw RADIUS packet suitable for sending to a RADIUS client or server.->codeβ Returns the Code field as a string. As of this writing, the following codes are defined:
Access-Request
Access-Accept
Access-Reject
Accounting-Request
Accounting-Response
Accounting-Status
Interim-Accounting
Password-Request
Password-Ack
Password-Reject
Accounting-Message
Access-Challenge
Status-Server
Status-Client
Resource-Free-Request
Resource-Free-Response
Resource-Query-Request
Resource-Query-Response
Alternate-Resource-Reclaim-Request
NAS-Reboot-Request
NAS-Reboot-Response
Next-Passcode
New-Pin
Terminate-Session
Password-Expired
Event-Request
Event-Response
Disconnect-Request
Disconnect-ACK
Disconnect-NAK
CoA-Request
CoA-ACK
CoA-NAK
IP-Address-Allocate
IP-Address-Release
->set_code($code)β Sets the Code field to the string supplied.->identifier()β Returns the one-byte Identifier used to match requests with responses, as a character value.->set_identifier($id)β Sets the Identifier byte to the character supplied.->authenticator()β Returns the 16-byte Authenticator field as a character string.->set_authenticator($authenticator)β Sets the Authenticator field to the character string supplied.->attr($name)β Retrieves the value of the named Attribute. Attributes will be converted automatically based on their dictionary type:STRINGβ Returned as a string.INTEGERβ Returned as a Perl integer.IPADDRβ Returned as a string (a.b.c.d)TIMEβ Returned as an integer
The following types are simply mapped to other types until correct encoding is implemented:
ipv6addrβ Treated as a stringdateβ Treated as a stringifidβ Treated as a string
When multiple attributes are inserted in the packet, the last one is returned.
->set_attr($name, $val, $rewrite_flag)β Sets the named Attributes to the given value. Values should be supplied as they would be returned from theattrmethod. Ifrewrite_flagis set, and a single attribute with such name already exists on the Attributes stack, its value will be overwriten with the supplied one. In all other cases (if there are more than one attributes with such name already on the stack, there are no attributes with such name,rewrite_flagis omitted) name/pair array will be pushed onto the stack.->set_vsattr($vendor, $name, $val, $rewrite_flag)β Analogous to->set_attr(), but operates on vendor-specific attributes for vendor$vendor.->unset_attr($name)β Sets the named Attribute to the given value. Values should be supplied as they would be returned from theattrmethod.->unset_vsattr($vendor, $name)β Analogous to->unset_attr(), but operates on vendor-specific attributes for vendor$vendor.->attr_slot($integer)β Deprecated synonym for->attr_slot_val().->attr_slots()β Return the number of attribute slots in the packet.->attr_slot_name($integer)β Retrieves the attribute name of the given slot number from the Attributes stack. Returnsundefwhen the slot is vacant.->attr_slot_val($integer)β Retrieves the attribute value of the given slot number from the Attributes stack. Returnsundefwhen the slot is vacant.->unset_attr_slot($integer)β Removes given stack position from the Attributes stack.->password($secret, [$attr])β The RADIUS User-Password attribute is encoded with a shared secret. Use this method to return the decoded version. By default, the password will be looked for in the User-Password attribute. You can specify an alternate RADIUS attribute, by using the second argument.->set_password($passwd, $secret, [$attribute])β The RADIUS User-Password attribute is encoded with a shared secret. Use this method to prepare the encoded version. The encoded password will be stored in the attribute$attribute, which defaults to'User-Password'.
Some servers have been reported on insisting on this attribute to be 'Password' instead. You may have to tweak this call or the dictionary accordingly.
->dump()β Prints the content of the packet toSTDOUT.->show_unknown_entries($bool)β Controls the generation of awarn()whenever an unknown tuple is seen.
EXPORTED SUBROUTINES π
auth_resp($packed_packet, $secret [, accounting])β Given a (packed) RADIUS packet and a shared secret, returns a new packet with the Authenticator field changed in accordace with RADIUS protocol requirements.
If the third optional parameter is true, the Authenticator is encoded for an accounting packet, using 16 0x0 octets as the placeholder for the authenticator.
auth_acct_verify($packet, $secret)β Verifies the authenticator in an Accounting-Request packet as explained in RFC-2866. Returns 1 if the authenticator matches the packet and the secret,undefotherwise.
$packet is the packet data, as received. $secret is the corresponding shared secret.
auth_req_verify($packet, $secret, $prev_auth)β Verifies the authenticator in Access-Accept, Access-Reject, and Access-Challenge packets as explained in RFC-2865. Returns 1 if the authenticator matches the packet and the secret,undefotherwise.
$packet is the packet data, as received. $secret is the corresponding shared secret. $prev_auth is the authenticator taken from the corresponding Access-Accept packet.
It's the application's job to keep track of the authenticators in each request.
π EXAMPLE π
okay so you wanna see this thing in action? bestie, the tea is in the examples/ directory that ships with the distribution β go look, it's all there waiting for you π«Ά
and if you're trying to build something bigger, like an actual full-on RADIUS server, don't reinvent the wheel, just peek at Net::Radius::Server(3) β it's the whole implementation, no cap β¨
πΈ AUTHOR πΈ
meet the icons who made this happen π
- Christopher Masto,
<chris@netmonger.net>β the originator, the blueprint, the moment π - VSA support by Luis E. MuΓ±oz,
<luismunoz@cpan.org>β¨ - Fix for unpacking 3COM VSAs contributed by Ian Smith
<iansmith@ncinter.net>π οΈ - Information for packing of 3Com VSAs provided by Quan Choi
<Quan_Choi@3com.com>π - Some functions contributed by Tony Mountifield
<tony@mountifield.org>π - Attribute ordering provided by Toni Prug,
<toni@irational.org>β and the idea came from Bill Hulley π§ β¨
literally a whole friend group of contributors, we love a collaborative slay π«Ά
π SEE ALSO π
go read these next, bestie, they're part of the lore π
PerlπͺNet::Radius::Server(3)Net::Radius::Dictionary(3)- RFCs 2865, 2866, 2882 and 3575 β
and that's the whole page, babe π this one's perl v5.32.0, dated 2021-01-06, filed under Radius::Packet(3pm) β go forth and radius, you've got this ππ¦
π¦ where this page comes from
- debian bookworm: libnet-radius-perl 2.103+dfsg-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libnet-radius-perl 2.103+dfsg-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libnet-radius-perl 2.103+dfsg-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libnet-radius-perl 2.103+dfsg-1.1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms