RADIUS
The system provides two Python objects alc.radius
, instance of class alc.Radius
, and alc.radius.attributes
, instance if class alc.RadiusAttributes
, to inspect and modify RADIUS packets.
Note
Only the pre-provided
alc.radius
/alc.radius.attributes
object should be used in script, the classalc.Radius
/alc.RadiusAttributes
should not be used directly.
The alc.Radius
class
Provides packet level operations.
- header()
Returns a dictionary containing the value of the RADIUS header fields:
code (
integer
)id (
integer
)len (
integer
)authenticator (
bytes
)
print(alc.radius.header())
# {'code': 1, 'id': 202, 'len': 133, 'authenticator': b'\xe5C\xabM\xa1\x82(\x95\xe2\x84\xfai\xe6|\xd8\x92'}
- drop()
Drops the packet.
The alc.RadiusAttributes
class
Provides attribute level operations.
- isSet(type, /)
Checks if a specified attribute is present.
- Parameters
type (int|tuple) – Attribute type. If the parameter is a tuple, it should be interpreted as an attribute identifier. See Attribute identifiers.
- Return type
bool
- get(type, /)
Retrieves the value of a specified attribute.
- Parameters
type (int|tuple) – Attribute type. If the parameter is a tuple, it should be interpreted as an attribute identifier. See Attribute identifiers.
- Returns
Value of the attribute, or None if not present.
- Return type
bytes
- getTuple(type, /)
Retrieves all values of a specified attribute.
- Parameters
type (int|tuple) – Attribute type. If the parameter is a tuple, it should be interpreted as an attribute identifier. See Attribute identifiers.
- Returns
All values collected in a tuple.
- Return type
tuple
- set(type, value, /)
Adds an attribute with the specified type and value. This overwrites previously existing values if present.
- Parameters
type (int|tuple) – Attribute type. If the parameter is a tuple, it should be interpreted as an attribute identifier. See Attribute identifiers.
value (bytes|tuple) – Attribute value. If it is a tuple, multiple attributes with the same type are added, one for each item in the tuple.
- clear(type, /)
Removes all attributes with the specified type.
- Parameters
type (int|tuple) – Attribute type. If the parameter is a tuple, it should be interpreted as an attribute identifier. See Attribute identifiers.
Note
The following RADIUS attributes or VSAs are read-only:
Message-Authenticator (80)
Alc-LI-Action (26.6527.122)
Alc-LI-Destination (26.6527.123)
Alc-LI-FC (26.6527.124)
Alc-LI-Direction (26.6527.125)
Alc-LI-Intercept-Id (26.6527.138)
Alc-LI-Session-Id (26.6527.139)
Warning
All methods in alc.RadiusAttributes
raise appropriate TypeError or ValueError messages in cases of invalid arguments.
Attribute iteration
The class alc.RadiusAttributes
acts as an iterator over the attributes, yielding a tuple (identifier, value) for each attribute present.
import alc
print(list(alc.radius.attributes))
# [((8,), b'\xc0\xa8\x01\x14'), ((26, 6527, 9), b'\x08\x08\x08\x08'), ((26, 6527, 10), b'\x08\x08\x04\x04')]
for attr, value in alc.radius.attributes:
dotted_number = ".".join(map(str, attr))
print("{} = {}".format(dotted_number, value))
#8 = b'\xc0\xa8\x01\x14'
#26.6527.9 = b'\x08\x08\x08\x08'
#26.6527.10 = b\x08\x08\x04\x04'
Attribute access
Besides the methods defined for the alc.Radius class, the attributes can also be fetched, set, and cleared using the container syntax of Python. The keys by which the attributes can be reached are the identifier tuples as described in Attribute identifiers. The values are tuples of bytes.
print(alc.radius.attributes[(8,)])
#(b'\xc0\xa8\x01\x14',)
print(alc.radius.attributes[(241, 26, 6527, 4)])
#()
Checking if an attribute is present can be done via the in operator.
print((8,) in alc.radius.attributes)
#True
print((241, 26, 6527, 4) in alc.radius.attributes)
#False
Adding or overwriting an attribute can be done by assigning a value to the indexed attributes object. When setting multiple values for an attribute, the value should be a tuple of bytes. When setting a single value for an attribute, the value can be a 1-tuple of bytes or the individual bytes.
alc.radius.attributes[(8,)] = b'\xc0\xa8\x01\x14'
alc.radius.attributes[(8,)] = (b'\xc0\xa8\x01\x14',)
alc.radius.attributes[(25,)] = (b'red', b'green', b'blue')
Clearing an attribute can be performed with the del operator.
del alc.radius.attributes[(8,)]
Attribute identifiers
Attribute identifiers as described in RFC 6929#section-2.7 can be used to target a specific attribute. They are specified in Python as a tuple of integers, where each item in the tuple corresponds to a number in the “dotted number” format.
Type |
Name |
Identifier |
Python object |
---|---|---|---|
Normal |
NAS-IP-Address |
4 |
(4, ) |
Extended |
Frag-Status |
241.1 |
(241, 1) |
Vendor-Specific |
Alc-Subsc-Prof-Str |
26.6527.12 |
(26, 6527, 12) |
Extended-Vendor-Specific |
Alc-PPPoE-Client-Service |
241.26.6527.1 |
(241, 26, 6527, 1) |