pyrad
pyrad copied to clipboard
Trivial patch for big packets, float timeout
I often stumble upon radius replies bigger than 4096, and often prefer fast replies with subsecond timeouts. Subsecond timeouts already work, but documentation says that the timeout parameter is integer.
This is the trivial patch I apply to each installation (I would like to make a pull request but I am not able to):
*** /usr/lib/python2.7/dist-packages/pyrad/client.py.orig Tue Apr 7 10:08:55 2020
--- /usr/lib/python2.7/dist-packages/pyrad/client.py Tue Apr 7 10:09:35 2020
***************
*** 26,32 ****
:ivar retries: number of times to retry sending a RADIUS request
:type retries: integer
:ivar timeout: number of seconds to wait for an answer
! :type timeout: integer
"""
def __init__(self, server, authport=1812, acctport=1813,
coaport=3799, secret=six.b(''), dict=None):
--- 26,32 ----
:ivar retries: number of times to retry sending a RADIUS request
:type retries: integer
:ivar timeout: number of seconds to wait for an answer
! :type timeout: float
"""
def __init__(self, server, authport=1812, acctport=1813,
coaport=3799, secret=six.b(''), dict=None):
***************
*** 53,58 ****
--- 53,59 ----
self._socket = None
self.retries = 3
self.timeout = 5
+ self.max_size = 65535
def bind(self, addr):
"""Bind socket to an address.
***************
*** 144,150 ****
(waitto - now))
if ready[0]:
! rawreply = self._socket.recv(4096)
else:
now = time.time()
continue
--- 145,151 ----
(waitto - now))
if ready[0]:
! rawreply = self._socket.recv(self.max_size)
else:
now = time.time()
continue
Hope this helps. Regards, Subbergunz
I'll update the documentation, and check to make the receive size configurable (but I can't recommend that).
The RADIUS limits the maximum packet size. Instead of increasing it, you should rather fix the sender to send standard compliant replies - or if it really doesn't fit into a single packet evaluate DIAMETER for your usecase. The default will always be the standard compliant 4096 bytes.
Thanks, you made me check, and you'r right, about the standard. In the server class, I think the value is 8192. All this is not as trivial as I thought.
hm, yes it is indeed 8192 in the server class... I have to check why.