Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Re-enable errcheck linter with required fixes #165

Merged
merged 4 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ cscope.*
*.log
*.pcap
vendor*

gmm/gmm.dot
4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,12 @@ linters:
enable:
- gofmt
# - govet
# - errcheck
- errcheck
# - staticcheck
# - unused
# - gosimple
# - structcheck
- varcheck
gab-arrobo marked this conversation as resolved.
Show resolved Hide resolved
- ineffassign
# - deadcode
gab-arrobo marked this conversation as resolved.
Show resolved Hide resolved
- typecheck
# Additional
# - lll
Expand Down
8 changes: 6 additions & 2 deletions amf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ import (
var AMFTest = &service.AMF{}

func init() {
os.Setenv("POD_IP", "127.0.0.1")
factory.InitConfigFactory("amfTest/amfcfg.yaml")
if err := os.Setenv("POD_IP", "127.0.0.1"); err != nil {
fmt.Printf("Could not set env POD_IP: %+v\n", err)
}
if err := factory.InitConfigFactory("amfTest/amfcfg.yaml"); err != nil {
fmt.Printf("Could not InitConfigFactory: %+v\n", err)
}
}

func GetNetworkSliceConfig() *protos.NetworkSliceResponse {
Expand Down
10 changes: 8 additions & 2 deletions consumer/sm_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/antihax/optional"
amf_context "github.com/omec-project/amf/context"
"github.com/omec-project/amf/logger"
"github.com/omec-project/amf/util"
"github.com/omec-project/nas/nasMessage"
"github.com/omec-project/openapi"
Expand All @@ -26,10 +27,15 @@ import (

func getServingSmfIndex(smfNum int) (servingSmfIndex int) {
servingSmfIndexStr := os.Getenv("SERVING_SMF_INDEX")
i, _ := strconv.Atoi(servingSmfIndexStr)
i, err := strconv.Atoi(servingSmfIndexStr)
if err != nil {
logger.ConsumerLog.Errorf("Could not convert %s to int: %v", servingSmfIndexStr, err)
}
servingSmfIndexInt := i + 1
servingSmfIndex = servingSmfIndexInt % smfNum
os.Setenv("SERVING_SMF_INDEX", strconv.Itoa(servingSmfIndex))
if err := os.Setenv("SERVING_SMF_INDEX", strconv.Itoa(servingSmfIndex)); err != nil {
logger.ConsumerLog.Errorf("Could not set env SERVING_SMF_INDEX: %v", err)
}
return
}

Expand Down
4 changes: 3 additions & 1 deletion context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ func (ran *AmfRan) Remove() {
NfStatus: mi.NfStatusDisconnected, NfName: ran.GnbId,
},
}
metrics.StatWriter.PublishNfStatusEvent(gnbStatus)
if err := metrics.StatWriter.PublishNfStatusEvent(gnbStatus); err != nil {
ran.Log.Errorf("Could not publish NfStatusEvent: %v", err)
}

ran.SetRanStats(RanDisconnected)
ran.Log.Infof("Remove RAN Context[ID: %+v]", ran.RanID())
Expand Down
13 changes: 10 additions & 3 deletions context/amf_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,10 @@ func (ue *AmfUe) UnmarshalJSON(data []byte) error {
}
}
for key, val := range aux.SmCtxList {
keyVal, _ := strconv.ParseInt(key, 10, 32)
keyVal, err := strconv.ParseInt(key, 10, 32)
if err != nil {
logger.ContextLog.Errorf("Error parsing int from %s: %v", key, err)
}
ue.StoreSmContext(int32(keyVal), &val)
}
sqn := uint8(aux.ULCount & 0x000000ff)
Expand Down Expand Up @@ -486,7 +489,9 @@ func (ue *AmfUe) Remove() {
}

// tmsiGenerator.FreeID(int64(ue.Tmsi))
AMF_Self().Drsm.ReleaseInt32ID(ue.Tmsi)
if err := AMF_Self().Drsm.ReleaseInt32ID(ue.Tmsi); err != nil {
logger.ContextLog.Errorf("Error releasing RanUe: %v", err)
}

if len(ue.Supi) > 0 {
AMF_Self().UePool.Delete(ue.Supi)
Expand Down Expand Up @@ -1066,5 +1071,7 @@ func (ueContext *AmfUe) PublishUeCtxtInfo() {
kafkaSmCtxt.UeState = string(ueState[0].CmState)

// Send to stream
metrics.GetWriter().PublishUeCtxtEvent(kafkaSmCtxt, op)
if err := metrics.GetWriter().PublishUeCtxtEvent(kafkaSmCtxt, op); err != nil {
logger.ContextLog.Errorf("Could not publish Ue Context Event: %v", err)
}
}
18 changes: 14 additions & 4 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ func (context *AMFContext) AllocateGutiToUe(ue *AmfUe) {
func (context *AMFContext) ReAllocateGutiToUe(ue *AmfUe) {
servedGuami := context.ServedGuamiList[0]

context.Drsm.ReleaseInt32ID(ue.Tmsi)
if err := context.Drsm.ReleaseInt32ID(ue.Tmsi); err != nil {
logger.ContextLog.Errorf("Errro releasing tmsi: %v", err)
}
// tmsiGenerator.FreeID(int64(ue.Tmsi))

ue.Tmsi = context.TmsiAllocate()
Expand All @@ -168,7 +170,10 @@ func (context *AMFContext) AllocateRegistrationArea(ue *AmfUe, anType models.Acc
taiList := make([]models.Tai, len(context.SupportTaiLists))
copy(taiList, context.SupportTaiLists)
for i := range taiList {
tmp, _ := strconv.ParseUint(taiList[i].Tac, 10, 32)
tmp, err := strconv.ParseUint(taiList[i].Tac, 10, 32)
if err != nil {
logger.ContextLog.Errorf("Could not convert TAC to int: %v", err)
}
taiList[i].Tac = fmt.Sprintf("%06x", tmp)
logger.ContextLog.Infof("Supported Tai List in AMF Plmn: %v, Tac: %v", taiList[i].PlmnId, taiList[i].Tac)
}
Expand Down Expand Up @@ -209,7 +214,9 @@ func (context *AMFContext) DeleteAMFStatusSubscription(subscriptionID string) {
logger.ContextLog.Error(err)
} else {
// amfStatusSubscriptionIDGenerator.FreeID(id)
context.Drsm.ReleaseInt32ID(int32(id))
if err := context.Drsm.ReleaseInt32ID(int32(id)); err != nil {
logger.ContextLog.Error(err)
}
}
}

Expand Down Expand Up @@ -431,7 +438,10 @@ func (context *AMFContext) InPlmnSupportList(snssai models.Snssai) bool {
}

func mapToByte(data map[string]interface{}) (ret []byte) {
ret, _ = json.Marshal(data)
ret, err := json.Marshal(data)
if err != nil {
logger.ContextLog.Error(err)
}
return
}

Expand Down
9 changes: 7 additions & 2 deletions context/ran_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (ranUe *RanUe) Remove() error {
self := AMF_Self()
self.RanUePool.Delete(ranUe.AmfUeNgapId)
// amfUeNGAPIDGenerator.FreeID(ranUe.AmfUeNgapId)
self.Drsm.ReleaseInt32ID(int32(ranUe.AmfUeNgapId))
if err := self.Drsm.ReleaseInt32ID(int32(ranUe.AmfUeNgapId)); err != nil {
logger.ContextLog.Errorf("Error releasing UE: %v", err)
}
return nil
}

Expand Down Expand Up @@ -243,7 +245,10 @@ func (ranUe *RanUe) UpdateLocation(userLocationInformation *ngapType.UserLocatio
ranUe.Location.N3gaLocation.PortNumber = ngapConvert.PortNumberToInt(port)
// N3GPP TAI is operator-specific
// TODO: define N3GPP TAI
tmp, _ := strconv.ParseUint(amfSelf.SupportTaiLists[0].Tac, 10, 32)
tmp, err := strconv.ParseUint(amfSelf.SupportTaiLists[0].Tac, 10, 32)
if err != nil {
logger.ContextLog.Errorf("Error parsing TAC: %v", err)
}
tac := fmt.Sprintf("%06x", tmp)
ranUe.Location.N3gaLocation.N3gppTai = &models.Tai{
PlmnId: amfSelf.SupportTaiLists[0].PlmnId,
Expand Down
4 changes: 3 additions & 1 deletion gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ func transport5GSMMessage(ue *context.AmfUe, anType models.AccessType,

if !smContextExist {
msg := new(nas.Message)
msg.PlainNasDecode(&smMessage)
if err := msg.PlainNasDecode(&smMessage); err != nil {
ue.GmmLog.Errorf("Could not decode Nas message: %v", err)
}
if msg.GsmMessage != nil && msg.GsmMessage.Status5GSM != nil {
ue.GmmLog.Warningf("SmContext doesn't exist, 5GSM Status message received from UE with cause %v", msg.GsmMessage.Status5GSM.Cause5GSM)
return nil
Expand Down
29 changes: 22 additions & 7 deletions gmm/sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func DeRegistered(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
case NwInitiatedDeregistrationEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
accessType := args[ArgAccessType].(models.AccessType)
NetworkInitiatedDeregistrationProcedure(amfUe, accessType)
if err := NetworkInitiatedDeregistrationProcedure(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
}
case StartAuthEvent:
logger.GmmLog.Debugln(event)
case fsm.ExitEvent:
Expand Down Expand Up @@ -138,7 +140,9 @@ func Registered(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
case NwInitiatedDeregistrationEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
accessType := args[ArgAccessType].(models.AccessType)
NetworkInitiatedDeregistrationProcedure(amfUe, accessType)
if err := NetworkInitiatedDeregistrationProcedure(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
}
/*TODO */
case SliceInfoAddEvent:
case SliceInfoDeleteEvent:
Expand Down Expand Up @@ -222,11 +226,15 @@ func Authentication(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
amfUe := args[ArgAmfUe].(*context.AmfUe)
accessType := args[ArgAccessType].(models.AccessType)
logger.GmmLog.Debugln(event)
HandleAuthenticationError(amfUe, accessType)
if err := HandleAuthenticationError(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
}
case NwInitiatedDeregistrationEvent:
amfUe := args[ArgAmfUe].(*context.AmfUe)
accessType := args[ArgAccessType].(models.AccessType)
NetworkInitiatedDeregistrationProcedure(amfUe, accessType)
if err := NetworkInitiatedDeregistrationProcedure(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
}
case fsm.ExitEvent:
// clear authentication related data at exit
amfUe := args[ArgAmfUe].(*context.AmfUe)
Expand Down Expand Up @@ -268,11 +276,14 @@ func SecurityMode(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
// Generate KnasEnc, KnasInt
amfUe.DerivateAlgKey()
if amfUe.CipheringAlg == security.AlgCiphering128NEA0 && amfUe.IntegrityAlg == security.AlgIntegrity128NIA0 {
GmmFSM.SendEvent(state, SecuritySkipEvent, fsm.ArgsType{
err := GmmFSM.SendEvent(state, SecuritySkipEvent, fsm.ArgsType{
ArgAmfUe: amfUe,
ArgAccessType: accessType,
ArgNASMessage: amfUe.RegistrationRequest,
})
if err != nil {
logger.GmmLog.Errorln(err)
}
} else {
gmm_message.SendSecurityModeCommand(amfUe.RanUe[accessType], eapSuccess, eapMessage)
}
Expand Down Expand Up @@ -340,7 +351,9 @@ func SecurityMode(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
accessType := args[ArgAccessType].(models.AccessType)
amfUe.T3560.Stop()
amfUe.T3560 = nil
NetworkInitiatedDeregistrationProcedure(amfUe, accessType)
if err := NetworkInitiatedDeregistrationProcedure(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
}
case SecurityModeSuccessEvent:
logger.GmmLog.Debugln(event)
case SecurityModeFailEvent:
Expand Down Expand Up @@ -440,7 +453,9 @@ func ContextSetup(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
amfUe.T3550.Stop()
amfUe.T3550 = nil
amfUe.State[accessType].Set(context.Registered)
NetworkInitiatedDeregistrationProcedure(amfUe, accessType)
if err := NetworkInitiatedDeregistrationProcedure(amfUe, accessType); err != nil {
logger.GmmLog.Errorln(err)
}
case ContextSetupFailEvent:
logger.GmmLog.Debugln(event)
case fsm.ExitEvent:
Expand Down
8 changes: 6 additions & 2 deletions metrics/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func (writer Writer) PublishUeCtxtEvent(ctxt mi.CoreSubscriber, op mi.Subscriber
return err
} else {
logger.KafkaLog.Debugf("publishing ue context event[%s] ", msg)
StatWriter.SendMessage(msg)
if err := StatWriter.SendMessage(msg); err != nil {
logger.KafkaLog.Errorf("Could not publish ue context event, error [%v]", err.Error())
}
}
return nil
}
Expand Down Expand Up @@ -102,7 +104,9 @@ func (writer Writer) PublishNfStatusEvent(msgEvent mi.MetricEvent) error {
return err
} else {
logger.KafkaLog.Debugf("publishing nf status event[%s] ", msg)
StatWriter.SendMessage(msg)
if err := StatWriter.SendMessage(msg); err != nil {
logger.KafkaLog.Errorf("Error publishing nf status event: %v", err)
}
}
return nil
}
5 changes: 4 additions & 1 deletion metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"fmt"
"net/http"

"github.com/omec-project/amf/logger"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
Expand Down Expand Up @@ -64,7 +65,9 @@ func init() {
// InitMetrics initialises AMF stats
func InitMetrics() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(":9089", nil)
if err := http.ListenAndServe(":9089", nil); err != nil {
logger.InitLog.Errorf("Could not open metrics port: %v", err)
}
}

// IncrementNgapMsgStats increments message level stats
Expand Down
9 changes: 7 additions & 2 deletions nas/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ func HandleNAS(ue *context.RanUe, procedureCode int64, nasPdu []byte) {
} else {
if amfSelf.EnableSctpLb {
/* checking the guti-ue belongs to this amf instance */
id, _ := amfSelf.Drsm.FindOwnerInt32ID(int32(ue.AmfUe.Tmsi))
id, err := amfSelf.Drsm.FindOwnerInt32ID(int32(ue.AmfUe.Tmsi))
if err != nil {
logger.NasLog.Errorf("Error checking guti-ue: %v", err)
}
if id != nil && id.PodName != os.Getenv("HOSTNAME") {
rsp := &sdcoreAmfServer.AmfMessage{}
rsp.VerboseMsg = "Redirecting Msg From AMF Pod !"
Expand All @@ -49,7 +52,9 @@ func HandleNAS(ue *context.RanUe, procedureCode int64, nasPdu []byte) {
if ue != nil && ue.AmfUe != nil {
ue.AmfUe.Remove()
} else if ue != nil {
ue.Remove()
if err := ue.Remove(); err != nil {
logger.NasLog.Errorf("Error removing ue: %v", err)
}
}
ue.Ran.Amf2RanMsgChan <- rsp
return
Expand Down
8 changes: 5 additions & 3 deletions ngap/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func DispatchLb(sctplbMsg *sdcoreAmfServer.SctplbMessage, Amf2RanMsgChan chan *s
//ranUe.Log.Debugln("RanUe RanNgapId AmfNgapId: ", ranUe.RanUeNgapId, ranUe.AmfUeNgapId)
/* checking whether same AMF instance can handle this message */
/* redirect it to correct owner if required */
id, _ := amfSelf.Drsm.FindOwnerInt32ID(int32(ngapId.Value))
if id == nil {
id, err := amfSelf.Drsm.FindOwnerInt32ID(int32(ngapId.Value))
if id == nil || err != nil {
ran.Log.Warningf("DispatchLb, Couldn't find owner for amfUeNgapid: %v", ngapId.Value)
} else if id != nil && id.PodName != os.Getenv("HOSTNAME") {
rsp := &sdcoreAmfServer.AmfMessage{}
Expand All @@ -86,7 +86,9 @@ func DispatchLb(sctplbMsg *sdcoreAmfServer.SctplbMessage, Amf2RanMsgChan chan *s
ranUe.AmfUe.Remove()
}
if ranUe != nil {
ranUe.Remove()
if err := ranUe.Remove(); err != nil {
ran.Log.Errorf("Could not remove ranUe: %v", err)
}
}
return
} else {
Expand Down
13 changes: 10 additions & 3 deletions ngap/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ func HandleNGSetupRequest(ran *context.AmfRan, message *ngapType.NGAPPDU) {
NfStatus: mi.NfStatusConnected, NfName: ran.GnbId,
},
}
metrics.StatWriter.PublishNfStatusEvent(gnbStatus)
if err := metrics.StatWriter.PublishNfStatusEvent(gnbStatus); err != nil {
ran.Log.Errorf("Could not publish NfStatusEvent: %v", err)
}
} else {
ngap_message.SendNGSetupFailure(ran, cause)
}
Expand Down Expand Up @@ -1520,7 +1522,10 @@ func HandleInitialUEMessage(ran *context.AmfRan, message *ngapType.NGAPPDU, sctp
} else {
ranUe.Log.Tracef("find AmfUe [GUTI: %s]", guti)
/* checking the guti-ue belongs to this amf instance */
id, _ := amfSelf.Drsm.FindOwnerInt32ID(int32(amfUe.Tmsi))
id, err := amfSelf.Drsm.FindOwnerInt32ID(int32(amfUe.Tmsi))
if err != nil {
ranUe.Log.Errorf("Error checking the guti-ue in this instance: %v", err)
}
if id != nil && id.PodName != os.Getenv("HOSTNAME") && amfSelf.EnableSctpLb {
rsp := &sdcoreAmfServer.AmfMessage{}
rsp.VerboseMsg = "Redirect Msg From AMF Pod !"
Expand All @@ -1533,7 +1538,9 @@ func HandleInitialUEMessage(ran *context.AmfRan, message *ngapType.NGAPPDU, sctp
if ranUe != nil && ranUe.AmfUe != nil {
ranUe.AmfUe.Remove()
} else if ranUe != nil {
ranUe.Remove()
if err := ranUe.Remove(); err != nil {
ranUe.Log.Errorf("Could not remove ranUe: %v", err)
}
}
ran.Amf2RanMsgChan <- rsp
return
Expand Down
5 changes: 4 additions & 1 deletion producer/oam.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ func HandleOAMPurgeUEContextRequest(supi, reqUri string, msg interface{}) (inter
ue.Remove()
case context.Registered:
logger.ProducerLog.Info("Deregistration triggered for the UE : ", ue.Supi)
gmm.GmmFSM.SendEvent(ue.State[models.AccessType__3_GPP_ACCESS], gmm.NwInitiatedDeregistrationEvent, fsm.ArgsType{
err := gmm.GmmFSM.SendEvent(ue.State[models.AccessType__3_GPP_ACCESS], gmm.NwInitiatedDeregistrationEvent, fsm.ArgsType{
gmm.ArgAmfUe: ue,
gmm.ArgAccessType: models.AccessType__3_GPP_ACCESS,
})
if err != nil {
logger.ProducerLog.Errorf("Error sending deregistration event: %v", err)
}
}
}
return nil, "", nil, nil
Expand Down