corenet: add explicit exception handling

This commit is contained in:
mich 2020-04-30 11:19:13 +02:00
parent da627ace3a
commit 126b695e51
7 changed files with 42 additions and 42 deletions

View File

@ -123,7 +123,7 @@ class ENBd(object):
# eNB-initiated procedure, instantiate it
try:
Proc = S1APNonUEProcEnbDispatcher[pdu_rx[1]['procedureCode']](self)
except:
except Exception:
self._log('ERR', 'invalid S1AP PDU, initiatingMessage, code %i'\
% pdu_rx[1]['procedureCode'])
errcause = ('protocol', 'abstract-syntax-error-reject')
@ -151,7 +151,7 @@ class ENBd(object):
# CN-initiated procedure, transfer the PDU to it
try:
Proc = self.Proc[pdu_rx[1]['procedureCode']]
except:
except Exception:
self._log('ERR', 'invalid S1AP PDU, %s, code %i'\
% (pdu_rx[0], pdu_rx[1]['procedureCode']))
errcause = ('protocol', 'message-not-compatible-with-receiver-state')
@ -255,7 +255,7 @@ class ENBd(object):
else:
try:
ue = self.UE[ctx_id]
except:
except Exception:
self._log('ERR', 'invalid eNB UE context id provided')
errcause = ('radioNetwork', 'unknown-enb-ue-s1ap-id')
Proc = self.init_s1ap_proc(S1APErrorIndNonUECN, Cause=errcause)
@ -271,7 +271,7 @@ class ENBd(object):
def unset_ue_s1(self, ctx_id):
try:
del self.UE[ctx_id]
except:
except Exception:
self._log('WNG', 'no UE with S1 context-id %i to unset' % ctx_id)
def get_ued(self, pdu_rx):
@ -466,7 +466,7 @@ class ENBd(object):
else:
try:
del self.WARN[msgid]
except:
except Exception:
pass
return True

View File

@ -125,7 +125,7 @@ class GNBd(object):
# gNB-initiated procedure, instantiate it
try:
Proc = NGAPNonUEProcRANDispatcher[pdu_rx[1]['procedureCode']](self)
except:
except Exception:
self._log('ERR', 'invalid NGAP PDU, initiatingMessage, code %i'\
% pdu_rx[1]['procedureCode'])
errcause = ('protocol', 'abstract-syntax-error-reject')
@ -153,7 +153,7 @@ class GNBd(object):
# CN-initiated procedure, transfer the PDU to it
try:
Proc = self.Proc[pdu_rx[1]['procedureCode']]
except:
except Exception:
self._log('ERR', 'invalid NGAP PDU, %s, code %i'\
% (pdu_rx[0], pdu_rx[1]['procedureCode']))
errcause = ('protocol', 'message-not-compatible-with-receiver-state')

View File

@ -143,7 +143,7 @@ class HNBd(SigStack):
# HNB-initiated procedure, instantiate it
try:
Proc = HNBAPProcHnbDispatcher[pdu_rx[1]['procedureCode']](self)
except:
except Exception:
self._log('ERR', 'invalid HNBAP PDU, initiatingMessage, code %i'\
% pdu_rx[1]['procedureCode'])
errcause = ('protocol', 'abstract-syntax-error-reject')
@ -168,7 +168,7 @@ class HNBd(SigStack):
# GW-initiated procedure, transfer the response PDU to it
try:
Proc = self.ProcHnbap[pdu_rx[1]['procedureCode']]
except:
except Exception:
self._log('ERR', 'invalid HNBAP PDU, %s, code %i'\
% (pdu_rx[0], pdu_rx[1]['procedureCode']))
errcause = ('protocol', 'message-not-compatible-with-receiver-state')
@ -239,7 +239,7 @@ class HNBd(SigStack):
else:
try:
Proc = RUAProcDispatcher[pdu_rx[1]['procedureCode']](self)
except:
except Exception:
self._log('ERR', 'invalid RUA PDU, initiatingMessage, code %i'\
% pdu_rx[1]['procedureCode'])
errcause = ('protocol', 'abstract-syntax-error-reject')
@ -318,7 +318,7 @@ class HNBd(SigStack):
return []
try:
PDU_RANAP.from_aper(buf)
except:
except Exception:
asn_ranap_release()
self._log('WNG', 'invalid RANAP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
@ -338,7 +338,7 @@ class HNBd(SigStack):
# RNC-initiated procedure, instantiate it
try:
Proc = RANAPConlessProcRncDispatcher[pdu_rx[1]['procedureCode']](self)
except:
except Exception:
self._log('ERR', 'invalid connect-less RANAP PDU, initiatingMessage, code %i'\
% pdu_rx[1]['procedureCode'])
# error cause: protocol, abstract-syntax-error-reject
@ -367,7 +367,7 @@ class HNBd(SigStack):
# CN-initiated procedure, transfer the PDU to it
try:
Proc = self.ProcRanap[pdu_rx[1]['procedureCode']]
except:
except Exception:
self._log('ERR', 'invalid connect-less RANAP PDU, %s, code %i'\
% (pdu_rx[0], pdu_rx[1]['procedureCode']))
# error cause: protocol, message-not-compatible-with-receiver-state
@ -448,19 +448,19 @@ class HNBd(SigStack):
def unset_ue_hnbap(self, ctx_id):
try:
del self.UE_HNBAP[ctx_id]
except:
except Exception:
self._log('WNG', 'no UE with HNBAP context-id %i to unset' % ctx_id)
def unset_ue_iucs(self, ctx_id):
try:
del self.UE_IuCS[ctx_id]
except:
except Exception:
self._log('WNG', 'no UE with IuCS context-id %i to unset' % ctx_id)
def unset_ue_iups(self, ctx_id):
try:
del self.UE_IuPS[ctx_id]
except:
except Exception:
self._log('WNG', 'no UE with IuPS context-id %i to unset' % ctx_id)
#--------------------------------------------------------------------------#
@ -523,7 +523,7 @@ class HNBd(SigStack):
for ctx_id in reslist:
try:
ue = self.UE_IuPS[ctx_id]
except:
except Exception:
pass
else:
ue.IuPS.unset_ran()
@ -536,7 +536,7 @@ class HNBd(SigStack):
for ctx_id in reslist:
try:
ue = self.UE_IuCS[ctx_id]
except:
except Exception:
pass
else:
ue.IuCS.unset_ran()

View File

@ -408,7 +408,7 @@ class UEd(SigStack):
if self.TMSI is not None:
try:
del self.Server.TMSI[self.TMSI]
except:
except Exception:
pass
# set the new TMSI
self.TMSI = tmsi
@ -420,7 +420,7 @@ class UEd(SigStack):
if self.PTMSI is not None:
try:
del self.Server.PTMSI[self.PTMSI]
except:
except Exception:
pass
# set the new PTMSI
self.PTMSI = ptmsi
@ -432,7 +432,7 @@ class UEd(SigStack):
if self.MTMSI is not None:
try:
del self.Server.MTMSI[self.MTMSI]
except:
except Exception:
pass
# set the new PTMSI
self.MTMSI = mtmsi
@ -725,7 +725,7 @@ class UEd(SigStack):
"""
try:
from IPython.lib.pretty import pretty
except:
except Exception:
pretty = repr
else:
txt = []

View File

@ -308,7 +308,7 @@ class UEMMd(SigStack):
Proc = self.init_proc(ProcClass, encod={ProcClass.Init: IEs}, mm_preempt=True)
try:
RanapTxProc = Proc.output()
except:
except Exception:
self._log('ERR', 'invalid IEs for network-initiated procedure %s' % Proc.Name)
Proc.abort()
return False, Proc
@ -677,7 +677,7 @@ class UEIuCSd(UEIuSigStack):
if isinstance(cause, integer_types):
try:
IEs['PagingCause'] = RANAP.RANAP_IEs.PagingCause._cont_rev[cause]
except:
except Exception:
pass
elif isinstance(cause, str_types):
IEs['PagingCause'] = cause
@ -696,7 +696,7 @@ class UEIuCSd(UEIuSigStack):
try:
rncs = [self.Server.RAN[rncid] for \
rncid in self.Server.LAI[(self.UE.PLMN, self.UE.LAC)]]
except:
except Exception:
self._log('ERR', 'paging: no RNC serving the UE LAI %s.%.4x'\
% (self.UE.PLMN, self.UE.LAC))
return
@ -721,7 +721,7 @@ class UEIuCSd(UEIuSigStack):
try:
rncs = [self.Server.RAN[rncid] for \
rncid in self.Server.LAI[(self.UE.PLMN, self.UE.LAC)]]
except:
except Exception:
self._log('ERR', 'paging: no RNC serving the UE LAI %s.%.4x'\
% (self.UE.PLMN, self.UE.LAC))
return False

View File

@ -365,7 +365,7 @@ class UEGMMd(SigStack):
Proc = self.init_proc(ProcClass, encod={ProcClass.Init: IEs}, mm_preempt=True)
try:
RanapTxProc = Proc.output()
except:
except Exception:
self._log('ERR', 'invalid IEs for network-initiated procedure %s' % Proc.Name)
Proc.abort()
return False, Proc
@ -996,7 +996,7 @@ class UEIuPSd(UEIuSigStack):
if isinstance(cause, integer_types):
try:
IEs['PagingCause'] = RANAP.RANAP_IEs.PagingCause._cont_rev[cause]
except:
except Exception:
pass
elif isinstance(cause, str_types):
IEs['PagingCause'] = cause
@ -1015,7 +1015,7 @@ class UEIuPSd(UEIuSigStack):
rai = (self.UE.PLMN, self.UE.LAC, self.UE.RAC)
try:
rncs = [self.Server.RAN[rncid] for rncid in self.Server.RAI[rai]]
except:
except Exception:
self._log('ERR', 'paging: no RNC serving the UE RAI %s.%.4x.%.2x' % rai)
return
#
@ -1039,7 +1039,7 @@ class UEIuPSd(UEIuSigStack):
rai = (self.UE.PLMN, self.UE.LAC, self.UE.RAC)
try:
rncs = [self.Server.RAN[rncid] for rncid in self.Server.RAI[rai]]
except:
except Exception:
self._log('ERR', 'paging: no RNC serving the UE RAI %s.%.4x.%.2x' % rai)
return False
#

View File

@ -622,7 +622,7 @@ class CorenetServer(object):
return
try:
PDU_HNBAP.from_aper(buf)
except:
except Exception:
asn_hnbap_release()
hnb._log('WNG', 'invalid HNBAP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
@ -647,7 +647,7 @@ class CorenetServer(object):
return
try:
PDU_RUA.from_aper(buf)
except:
except Exception:
asn_rua_release()
self._log('WNG', 'invalid RUA PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
@ -672,7 +672,7 @@ class CorenetServer(object):
return
try:
PDU_S1AP.from_aper(buf)
except:
except Exception:
asn_s1ap_release()
enb._log('WNG', 'invalid S1AP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
@ -701,7 +701,7 @@ class CorenetServer(object):
return
try:
PDU_NGAP.from_aper(buf)
except:
except Exception:
asn_ngap_release()
gnb._log('WNG', 'invalid NGAP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
@ -804,7 +804,7 @@ class CorenetServer(object):
PLMN = plmn_buf_to_str(plmn)
CellID = cellid_bstr_to_str(cellid)
return PLMN, CellID
except:
except Exception:
return None
def _send_s1setuprej(self, sk, cause):
@ -849,7 +849,7 @@ class CorenetServer(object):
return
try:
PDU_S1AP.from_aper(buf)
except:
except Exception:
self._log('WNG', 'invalid S1AP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
# return nothing, no need to bother
@ -926,7 +926,7 @@ class CorenetServer(object):
for tai in enb.Config['TAIs']:
try:
self.TAI[tai].remove(enb.ID)
except:
except Exception:
self._log('ERR', 'RAN node %r not referenced into the TAI table' % (enb.ID,))
#--------------------------------------------------------------------------#
@ -1004,7 +1004,7 @@ class CorenetServer(object):
return
try:
PDU_NGAP.from_aper(buf)
except:
except Exception:
self._log('WNG', 'invalid NGAP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
# return nothing, no need to bother
@ -1103,7 +1103,7 @@ class CorenetServer(object):
PLMN = plmn_buf_to_str(plmn)
CellID = cellid_bstr_to_str(cellid)
return PLMN, CellID
except:
except Exception:
return None
def _send_hnbregrej(self, sk, cause):
@ -1147,7 +1147,7 @@ class CorenetServer(object):
return
try:
PDU_HNBAP.from_aper(buf)
except:
except Exception:
self._log('WNG', 'invalid HNBAP PDU transfer-syntax: %s'\
% hexlify(buf).decode('ascii'))
# return nothing, no need to bother
@ -1232,11 +1232,11 @@ class CorenetServer(object):
rai = lai + (hnb.Config['RAC'], )
try:
self.LAI[lai].remove(hnb.ID)
except:
except Exception:
self._log('ERR', 'HNB not referenced into the LAI table')
try:
self.RAI[rai].remove(hnb.ID)
except:
except Exception:
self._log('ERR', 'HNB not referenced into the RAI table')
#--------------------------------------------------------------------------#