From 6fc612c35997cf4e8be1e5c86ae2242f04b576a9 Mon Sep 17 00:00:00 2001 From: ShouheiNishi <96609867+ShouheiNishi@users.noreply.github.com> Date: Fri, 1 Dec 2023 23:54:38 +0900 Subject: [PATCH] Add check that RemoteAddr() returns nil (#111) --- internal/context/context.go | 8 +++++++- internal/context/ran_ue.go | 7 ++++++- internal/ngap/dispatcher.go | 7 ++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/context/context.go b/internal/context/context.go index bc37af80..31906f90 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -354,7 +354,13 @@ func (context *AMFContext) NewAmfRan(conn net.Conn) *AmfRan { ran := AmfRan{} ran.SupportedTAList = make([]SupportedTAI, 0, MaxNumOfTAI*MaxNumOfBroadcastPLMNs) ran.Conn = conn - ran.Log = logger.NgapLog.WithField(logger.FieldRanAddr, conn.RemoteAddr().String()) + addr := conn.RemoteAddr() + if addr != nil { + ran.Log = logger.NgapLog.WithField(logger.FieldRanAddr, addr.String()) + } else { + ran.Log = logger.NgapLog.WithField(logger.FieldRanAddr, "(nil)") + } + context.AmfRanPool.Store(conn, &ran) return &ran } diff --git a/internal/context/ran_ue.go b/internal/context/ran_ue.go index c4ff542a..437c3190 100644 --- a/internal/context/ran_ue.go +++ b/internal/context/ran_ue.go @@ -124,7 +124,12 @@ func (ranUe *RanUe) SwitchToRan(newRan *AmfRan, ranUeNgapId int64) error { func (ranUe *RanUe) UpdateLogFields() { if ranUe.Ran != nil && ranUe.Ran.Conn != nil { - ranUe.Log = ranUe.Log.WithField(logger.FieldRanAddr, ranUe.Ran.Conn.RemoteAddr().String()) + addr := ranUe.Ran.Conn.RemoteAddr() + if addr != nil { + ranUe.Log = ranUe.Log.WithField(logger.FieldRanAddr, addr.String()) + } else { + ranUe.Log = ranUe.Log.WithField(logger.FieldRanAddr, "(nil)") + } anTypeStr := "" if ranUe.Ran.AnType == models.AccessType__3_GPP_ACCESS { diff --git a/internal/ngap/dispatcher.go b/internal/ngap/dispatcher.go index 8cd415d1..6f0a01af 100644 --- a/internal/ngap/dispatcher.go +++ b/internal/ngap/dispatcher.go @@ -16,7 +16,12 @@ func Dispatch(conn net.Conn, msg []byte) { ran, ok := amfSelf.AmfRanFindByConn(conn) if !ok { - logger.NgapLog.Infof("Create a new NG connection for: %s", conn.RemoteAddr().String()) + addr := conn.RemoteAddr() + if addr == nil { + logger.NgapLog.Warn("Addr of new NG connection is nii") + return + } + logger.NgapLog.Infof("Create a new NG connection for: %s", addr.String()) ran = amfSelf.NewAmfRan(conn) }