Skip to content

Commit

Permalink
Add check that RemoteAddr() returns nil (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShouheiNishi authored Dec 1, 2023
1 parent aebc9fc commit 6fc612c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion internal/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 6 additions & 1 deletion internal/context/ran_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion internal/ngap/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down

0 comments on commit 6fc612c

Please sign in to comment.