diff --git a/lib/database.py b/lib/database.py index 36559aa..730cfe0 100755 --- a/lib/database.py +++ b/lib/database.py @@ -2100,6 +2100,22 @@ def Get_Serving_APNs(self, subscriber_id: int) -> dict: return apnDict + def Get_Serving_APN_By_IP(self, subscriberIp): + Session = sessionmaker(bind = self.engine) + session = Session() + + try: + result = session.query(SERVING_APN).filter_by(subscriber_routing=subscriberIp).first() + except Exception as E: + self.logTool.log(service='Database', level='debug', message=E, redisClient=self.redisMessaging) + self.safe_close(session) + raise ValueError(E) + result = result.__dict__ + result.pop('_sa_instance_state') + + self.safe_close(session) + return result + def Get_Charging_Rule(self, charging_rule_id): self.logTool.log(service='Database', level='debug', message="Called Get_Charging_Rule() for charging_rule_id " + str(charging_rule_id), redisClient=self.redisMessaging) Session = sessionmaker(bind = self.engine) diff --git a/lib/diameter.py b/lib/diameter.py index 4cbdfc4..eef01cb 100755 --- a/lib/diameter.py +++ b/lib/diameter.py @@ -3010,6 +3010,25 @@ def Answer_16777236_265(self, packet_vars, avps): emergencySubscriber = True except Exception as e: emergencySubscriberData = None + + """ + If we didn't get a service urn, check if the IP represents a bearer for a local subscriber. + """ + try: + 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=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] @@ -3109,6 +3128,10 @@ def Answer_16777236_265(self, packet_vars, avps): 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: apnId = (self.database.Get_APN_by_Name(apn="ims")).get('apn_id', None) servingApn = self.database.Get_Serving_APN(subscriber_id=subscriberId, apn_id=apnId)