Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #45: Adds support to handle packets from any host. #46

Merged
merged 4 commits into from
Jul 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions pyrad/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,20 @@ def HandleDisconnectPacket(self, pkt):
:type pkt: Packet class instance
"""

def _AddSecret(self, pkt):
"""Add secret to packets received and raise ServerPacketError
for unknown hosts.

:param pkt: packet to process
:type pkt: Packet class instance
"""
if pkt.source[0] in self.hosts:
pkt.secret = self.hosts[pkt.source[0]].secret
elif '0.0.0.0' in self.hosts:
pkt.secret = self.hosts['0.0.0.0'].secret
else:
raise ServerPacketError('Received packet from unknown host')

def _HandleAuthPacket(self, pkt):
"""Process a packet received on the authentication port.
If this packet should be dropped instead of processed a
Expand All @@ -179,10 +192,7 @@ def _HandleAuthPacket(self, pkt):
:param pkt: packet to process
:type pkt: Packet class instance
"""
if pkt.source[0] not in self.hosts:
raise ServerPacketError('Received packet from unknown host')

pkt.secret = self.hosts[pkt.source[0]].secret
self._AddSecret(pkt)
if pkt.code != packet.AccessRequest:
raise ServerPacketError(
'Received non-authentication packet on authentication port')
Expand All @@ -197,10 +207,7 @@ def _HandleAcctPacket(self, pkt):
:param pkt: packet to process
:type pkt: Packet class instance
"""
if pkt.source[0] not in self.hosts:
raise ServerPacketError('Received packet from unknown host')

pkt.secret = self.hosts[pkt.source[0]].secret
self._AddSecret(pkt)
if pkt.code not in [packet.AccountingRequest,
packet.AccountingResponse]:
raise ServerPacketError(
Expand All @@ -216,9 +223,7 @@ def _HandleCoaPacket(self, pkt):
:param pkt: packet to process
:type pkt: Packet class instance
"""
if pkt.source[0] not in self.hosts:
raise ServerPacketError('Received packet from unknown host')

self._AddSecret(pkt)
pkt.secret = self.hosts[pkt.source[0]].secret
if pkt.code == packet.CoARequest:
self.HandleCoaPacket(pkt)
Expand Down