Skip to content

Commit

Permalink
Working IP-based lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkneipp committed Oct 21, 2024
1 parent cf88a76 commit 289d2e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 0 additions & 1 deletion lib/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,6 @@ def Get_Serving_APNs(self, subscriber_id: int) -> dict:
return apnDict

def Get_Serving_APN_By_IP(self, subscriberIp):
self.logTool.log(service='Database', level='debug', message="Getting Serving APN " + str(apn_id) + " with subscriber_id " + str(subscriber_id), redisClient=self.redisMessaging)
Session = sessionmaker(bind = self.engine)
session = Session()

Expand Down
17 changes: 14 additions & 3 deletions lib/diameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3015,14 +3015,21 @@ def Answer_16777236_265(self, packet_vars, avps):
If we didn't get a service urn, check if the IP represents a bearer for a local subscriber.
"""
try:
if not serviceUrn:
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] Service URN: {serviceUrn}", redisClient=self.redisMessaging)
if not serviceUrn or serviceUrn == 'None' or serviceUrn == None:
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] Checking Get_Serving_APN_By_IP", redisClient=self.redisMessaging)
ipServingApn = self.database.Get_Serving_APN_By_IP(subscriberIp=ueIp)
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] IP Serving APN: {ipServingApn}", redisClient=self.redisMessaging)
ipApnName = ''
if ipServingApn:
ipApnName = self.database.Get_APN(apn_id=ipServingApn.get('apn', None))
ipApnName = self.database.Get_APN(apn_id=int(ipServingApn.get('apn', {})))
ipApnName = ipApnName.get('apn', None)
except Exception as e:
self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] Exception: {traceback.format_exc()}", redisClient=self.redisMessaging)
ipApnName = ''

self.logTool.log(service='HSS', level='debug', message=f"[diameter.py] [Answer_16777236_265] [AAA] IP APN Name: {ipApnName}", redisClient=self.redisMessaging)

if '@' in subscriptionId:
subscriberIdentifier = subscriptionId.split('@')[0]
# Subscriber Identifier can be either an IMSI or an MSISDN
Expand Down Expand Up @@ -3118,7 +3125,11 @@ def Answer_16777236_265(self, packet_vars, avps):
else:
subscriberId = subscriberDetails.get('subscriber_id', None)
if serviceUrn:
if 'sos' in str(serviceUrn).lower() or 'sos' in ipApnName.lower():
if 'sos' in str(serviceUrn).lower():
registeredEmergencySubscriber = True
apnId = (self.database.Get_APN_by_Name(apn="sos")).get('apn_id', None)
elif ipApnName:
if 'sos' in ipApnName.lower():
registeredEmergencySubscriber = True
apnId = (self.database.Get_APN_by_Name(apn="sos")).get('apn_id', None)
else:
Expand Down

0 comments on commit 289d2e8

Please sign in to comment.