From a7dcc6078e7c1e0d725e01fed9690f88a627e801 Mon Sep 17 00:00:00 2001 From: gab-arrobo Date: Fri, 16 Aug 2024 14:46:26 -0700 Subject: [PATCH] Add GHA for `staticcheck` given that `golangci-lint` does not cover everything that `staticcheck` covers (#282) Signed-off-by: Arrobo, Gabriel --- .github/workflows/master.yml | 14 ++++++++ .golangci.yml | 3 +- amf.go | 2 +- .../api_individual_ue_context_document.go | 2 +- .../api_n1_n2_message_collection_document.go | 2 +- consumer/nf_discovery.go | 2 +- consumer/nf_mangement.go | 2 +- context/amf_ran.go | 2 +- factory/factory.go | 2 +- gmm/handler.go | 34 +++++++++---------- nas/dispatch.go | 2 +- nas/nas_security/security.go | 18 +++++----- ngap/message/build.go | 6 ++-- producer/callback.go | 7 ++-- 14 files changed, 55 insertions(+), 43 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index c179ca2c..de7852b8 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -64,6 +64,20 @@ jobs: dockerfile: Dockerfile ignore: DL3008,DL3018 + staticcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: WillAbides/setup-go-faster@v1.14.0 + with: + go-version-file: 'go.mod' + + - uses: dominikh/staticcheck-action@v1.3.1 + with: + version: latest + install-go: false + license-check: runs-on: ubuntu-latest steps: diff --git a/.golangci.yml b/.golangci.yml index 9a1e32fc..e3cbb29e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,7 +2,7 @@ # Copyright 2019 free5GC.org # # SPDX-License-Identifier: Apache-2.0 -# +# # This file contains all available configuration options # with their default values. @@ -239,7 +239,6 @@ linters: - gofmt - govet - errcheck - - staticcheck - unused - gosimple - ineffassign diff --git a/amf.go b/amf.go index a2eff3e1..6be59a1b 100644 --- a/amf.go +++ b/amf.go @@ -40,7 +40,7 @@ func main() { func action(c *cli.Context) error { if err := AMF.Initialize(c); err != nil { logger.CfgLog.Errorf("%+v", err) - return fmt.Errorf("Failed to initialize !!") + return fmt.Errorf("failed to initialize") } AMF.WatchConfig() diff --git a/communication/api_individual_ue_context_document.go b/communication/api_individual_ue_context_document.go index 4b3262a8..1a2d485d 100644 --- a/communication/api_individual_ue_context_document.go +++ b/communication/api_individual_ue_context_document.go @@ -54,7 +54,7 @@ func HTTPCreateUEContext(c *gin.Context) { case "multipart/related": err = openapi.Deserialize(&createUeContextRequest, requestBody, contentType) default: - err = fmt.Errorf("Wrong content type") + err = fmt.Errorf("wrong content type") } if err != nil { diff --git a/communication/api_n1_n2_message_collection_document.go b/communication/api_n1_n2_message_collection_document.go index 4f15852e..b92d1fc5 100644 --- a/communication/api_n1_n2_message_collection_document.go +++ b/communication/api_n1_n2_message_collection_document.go @@ -54,7 +54,7 @@ func HTTPN1N2MessageTransfer(c *gin.Context) { case "multipart/related": err = openapi.Deserialize(&n1n2MessageTransferRequest, requestBody, contentType) default: - err = fmt.Errorf("Wrong content type") + err = fmt.Errorf("wrong content type") } if err != nil { diff --git a/consumer/nf_discovery.go b/consumer/nf_discovery.go index c0d7f60e..95928640 100644 --- a/consumer/nf_discovery.go +++ b/consumer/nf_discovery.go @@ -38,7 +38,7 @@ func SendNfDiscoveryToNrf(nrfUri string, targetNfType, requestNfType models.NfTy result, res, err := client.NFInstancesStoreApi.SearchNFInstances(context.TODO(), targetNfType, requestNfType, param) if res != nil && res.StatusCode == http.StatusTemporaryRedirect { - err = fmt.Errorf("Temporary Redirect For Non NRF Consumer") + err = fmt.Errorf("temporary Redirect For Non NRF Consumer") } defer func() { if bodyCloseErr := res.Body.Close(); bodyCloseErr != nil { diff --git a/consumer/nf_mangement.go b/consumer/nf_mangement.go index b5c2a6a0..dbbf688a 100644 --- a/consumer/nf_mangement.go +++ b/consumer/nf_mangement.go @@ -35,7 +35,7 @@ func BuildNFInstance(context *amf_context.AMFContext) (profile models.NfProfile, } amfInfo := models.AmfInfo{} if len(context.ServedGuamiList) == 0 { - err = fmt.Errorf("Gumai List is Empty in AMF") + err = fmt.Errorf("gumai List is Empty in AMF") return profile, err } regionId, setId, _, err1 := util.SeperateAmfId(context.ServedGuamiList[0].AmfId) diff --git a/context/amf_ran.go b/context/amf_ran.go index b96c94f6..44ec10f4 100644 --- a/context/amf_ran.go +++ b/context/amf_ran.go @@ -98,7 +98,7 @@ func (ran *AmfRan) NewRanUe(ranUeNgapID int64) (*RanUe, error) { amfUeNgapID, err := self.AllocateAmfUeNgapID() if err != nil { ran.Log.Errorln("Alloc Amf ue ngap id failed", err) - return nil, fmt.Errorf("Allocate AMF UE NGAP ID error: %+v", err) + return nil, fmt.Errorf("allocate AMF UE NGAP ID error: %+v", err) } ranUe.AmfUeNgapId = amfUeNgapID ranUe.RanUeNgapId = ranUeNgapID diff --git a/factory/factory.go b/factory/factory.go index 46a54707..693992a1 100644 --- a/factory/factory.go +++ b/factory/factory.go @@ -128,7 +128,7 @@ func CheckConfigVersion() error { currentVersion := AmfConfig.GetVersion() if currentVersion != AMF_EXPECTED_CONFIG_VERSION { - return fmt.Errorf("config version is [%s], but expected is [%s].", + return fmt.Errorf("config version is [%s], but expected is [%s]", currentVersion, AMF_EXPECTED_CONFIG_VERSION) } diff --git a/gmm/handler.go b/gmm/handler.go index 102b12c7..5954c036 100644 --- a/gmm/handler.go +++ b/gmm/handler.go @@ -215,7 +215,7 @@ func transport5GSMMessage(ue *context.AmfUe, anType models.AccessType, if allowedNssai, ok := ue.AllowedNssai[anType]; ok { snssai = *allowedNssai[0].AllowedSnssai } else { - return errors.New("Ue doesn't have allowedNssai") + return errors.New("ue doesn't have allowedNssai") } } @@ -249,7 +249,7 @@ func transport5GSMMessage(ue *context.AmfUe, anType models.AccessType, return nil } else if problemDetail != nil { // TODO: error handling - return fmt.Errorf("Failed to Create smContext[pduSessionID: %d], Error[%v]", pduSessionID, problemDetail) + return fmt.Errorf("failed to Create smContext[pduSessionID: %d], Error[%v]", pduSessionID, problemDetail) } else if errResponse != nil { ue.GmmLog.Warnf("PDU Session Establishment Request is rejected by SMF[pduSessionId:%d]", pduSessionID) @@ -368,7 +368,7 @@ func forward5GSMMessageToSMF( ngap_message.AppendPDUSessionResourceToReleaseListRelCmd(&list, pduSessionID, n2SmInfo) ngap_message.SendPDUSessionResourceReleaseCommand(ue.RanUe[accessType], n1Msg, list) default: - return fmt.Errorf("Error N2 SM information type[%s]", responseData.N2SmInfoType) + return fmt.Errorf("error N2 SM information type[%s]", responseData.N2SmInfoType) } } else if n1Msg != nil { ue.GmmLog.Debugf("AMF forward Only N1 SM Message to UE") @@ -438,7 +438,7 @@ func HandleRegistrationRequest(ue *context.AmfUe, anType models.AccessType, proc messageType := m.GmmMessage.GmmHeader.GetMessageType() if messageType != nas.MsgTypeRegistrationRequest { - return errors.New("The payload of NAS Message Container is not Registration Request") + return errors.New("the payload of NAS Message Container is not Registration Request") } // TS 24.501 4.4.6: The AMF shall consider the NAS message that is obtained from the NAS message container // IE as the initial NAS message that triggered the procedure @@ -458,7 +458,7 @@ func HandleRegistrationRequest(ue *context.AmfUe, anType models.AccessType, proc case nasMessage.RegistrationType5GSPeriodicRegistrationUpdating: ue.GmmLog.Debugf("RegistrationType: Periodic Registration Updating") case nasMessage.RegistrationType5GSEmergencyRegistration: - return fmt.Errorf("Not Supportted RegistrationType: Emergency Registration") + return fmt.Errorf("not Supportted RegistrationType: Emergency Registration") case nasMessage.RegistrationType5GSReserved: ue.RegistrationType5GS = nasMessage.RegistrationType5GSInitialRegistration ue.GmmLog.Debugf("RegistrationType: Reserved") @@ -526,7 +526,7 @@ func HandleRegistrationRequest(ue *context.AmfUe, anType models.AccessType, proc } if !context.InTaiList(ue.Tai, taiList) { gmm_message.SendRegistrationReject(ue.RanUe[anType], nasMessage.Cause5GMMTrackingAreaNotAllowed, "") - return fmt.Errorf("Registration Reject[Tracking area not allowed]") + return fmt.Errorf("registration reject[Tracking area not allowed]") } if registrationRequest.UESecurityCapability != nil { @@ -607,7 +607,7 @@ func HandleInitialRegistration(ue *context.AmfUe, anType models.AccessType) erro ngap_message.SendUEContextReleaseCommand(ue.RanUe[anType], context.UeContextN2NormalRelease, ngapType.CausePresentNas, ngapType.CauseNasPresentNormalRelease) ue.Remove() - return fmt.Errorf("Allowed Nssai List is nil") + return fmt.Errorf("allowed nssai list is nil") } //TODO: this is commented because Radysis USIM is not sending this IE @@ -952,7 +952,7 @@ func HandleMobilityAndPeriodicRegistrationUpdating(ue *context.AmfUe, anType mod smContext, exist := ue.SmContextFindByPDUSessionID(requestData.PduSessionId) if !exist { ue.N1N2Message = nil - return fmt.Errorf("Pdu Session Id not Exists") + return fmt.Errorf("pdu session id does not exist") } if smContext.AccessType() == models.AccessType_NON_3_GPP_ACCESS { @@ -1210,7 +1210,7 @@ func handleRequestedNssai(ue *context.AmfUe, anType models.AccessType) error { if ue.RegistrationRequest.RequestedNSSAI != nil { requestedNssai, err := nasConvert.RequestedNssaiToModels(ue.RegistrationRequest.RequestedNSSAI) if err != nil { - return fmt.Errorf("Decode failed at RequestedNSSAI[%s]", err) + return fmt.Errorf("decode failed at RequestedNSSAI[%s]", err) } ue.GmmLog.Infof("RequestedNssai: %+v", requestedNssai) @@ -1250,11 +1250,11 @@ func handleRequestedNssai(ue *context.AmfUe, anType models.AccessType) error { if problemDetails != nil { ue.GmmLog.Errorf("NSSelection Get Failed Problem[%+v]", problemDetails) gmm_message.SendRegistrationReject(ue.RanUe[anType], nasMessage.Cause5GMMProtocolErrorUnspecified, "") - return fmt.Errorf("Handle Requested Nssai of UE failed") + return fmt.Errorf("handle Requested Nssai of UE failed") } else if err != nil { ue.GmmLog.Errorf("NSSelection Get Error[%+v]", err) gmm_message.SendRegistrationReject(ue.RanUe[anType], nasMessage.Cause5GMMProtocolErrorUnspecified, "") - return fmt.Errorf("Handle Requested Nssai of UE failed") + return fmt.Errorf("handle Requested Nssai of UE failed") } // Step 5: Initial AMF send Namf_Communication_RegistrationCompleteNotify to old AMF @@ -1553,7 +1553,7 @@ func AuthenticationProcedure(ue *context.AmfUe, accessType models.AccessType) (b return false, errors.New("Authentication procedure failed") } else if problemDetails != nil { ue.GmmLog.Errorf("Nausf_UEAU Authenticate Request Failed: %+v", problemDetails) - return false, errors.New("Error Response from AUSF") + return false, errors.New("error response from AUSF") } ue.AuthenticationCtx = response ue.ABBA = []uint8{0x00, 0x00} // set ABBA value as described at TS 33.501 Annex A.7.1 @@ -1743,7 +1743,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, messageType := m.GmmMessage.GmmHeader.GetMessageType() if messageType != nas.MsgTypeServiceRequest { - return errors.New("The payload of NAS message Container is not service request") + return errors.New("the payload of NAS message Container is not service request") } // TS 24.501 4.4.6: The AMF shall consider the NAS message that is obtained from the NAS message container // IE as the initial NAS message that triggered the procedure @@ -1787,7 +1787,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, targetPduSessionId = requestData.N2InfoContainer.SmInfo.PduSessionId } else { ue.N1N2Message = nil - return fmt.Errorf("Service Request triggered by Network has not implemented about non SM N2Info") + return fmt.Errorf("service request triggered by Network has not implemented about non SM N2Info") } } } @@ -1891,7 +1891,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, smContext, exist := ue.SmContextFindByPDUSessionID(requestData.PduSessionId) if !exist { ue.N1N2Message = nil - return fmt.Errorf("Service Request triggered by Network error for pduSessionId does not exist") + return fmt.Errorf("service request triggered by Network error for pduSessionId does not exist") } if smContext.AccessType() == models.AccessType_NON_3_GPP_ACCESS { @@ -2005,7 +2005,7 @@ func HandleServiceRequest(ue *context.AmfUe, anType models.AccessType, } } default: - return fmt.Errorf("Service Type[%d] is not supported", serviceType) + return fmt.Errorf("service type[%d] is not supported", serviceType) } if len(errPduSessionId) != 0 { ue.GmmLog.Info(errPduSessionId, errCause) @@ -2057,7 +2057,7 @@ func HandleAuthenticationResponse(ue *context.AmfUe, accessType models.AccessTyp } if ue.AuthenticationCtx == nil { - return fmt.Errorf("Ue Authentication Context is nil") + return fmt.Errorf("ue authentication context is nil") } switch ue.AuthenticationCtx.AuthType { diff --git a/nas/dispatch.go b/nas/dispatch.go index 1bf0cb7d..9da0e089 100644 --- a/nas/dispatch.go +++ b/nas/dispatch.go @@ -18,7 +18,7 @@ import ( func Dispatch(ue *context.AmfUe, accessType models.AccessType, procedureCode int64, msg *nas.Message) error { if msg.GmmMessage == nil { - return errors.New("Gmm Message is nil") + return errors.New("gmm message is nil") } if msg.GsmMessage != nil { diff --git a/nas/nas_security/security.go b/nas/nas_security/security.go index 99ce37ff..2ac527d2 100644 --- a/nas/nas_security/security.go +++ b/nas/nas_security/security.go @@ -28,7 +28,7 @@ func Encode(ue *context.AmfUe, msg *nas.Message) ([]byte, error) { return nil, fmt.Errorf("amfUe is nil") } if msg == nil { - return nil, fmt.Errorf("Nas Message is empty") + return nil, fmt.Errorf("nas message is empty") } // Plain NAS message @@ -49,13 +49,13 @@ func Encode(ue *context.AmfUe, msg *nas.Message) ([]byte, error) { ue.ULCount.Set(0, 0) ue.DLCount.Set(0, 0) default: - return nil, fmt.Errorf("Wrong security header type: 0x%0x", msg.SecurityHeader.SecurityHeaderType) + return nil, fmt.Errorf("wrong security header type: 0x%0x", msg.SecurityHeader.SecurityHeaderType) } // encode plain nas first payload, err := msg.PlainNasEncode() if err != nil { - return nil, fmt.Errorf("Plain NAS encode error: %+v", err) + return nil, fmt.Errorf("plain NAS encode error: %+v", err) } ue.NASLog.Tracef("plain payload:\n%+v", hex.Dump(payload)) @@ -65,7 +65,7 @@ func Encode(ue *context.AmfUe, msg *nas.Message) ([]byte, error) { ue.NASLog.Tracef("NAS ciphering key: %0x", ue.KnasEnc) if err = security.NASEncrypt(ue.CipheringAlg, ue.KnasEnc, ue.DLCount.Get(), security.Bearer3GPP, security.DirectionDownlink, payload); err != nil { - return nil, fmt.Errorf("Encrypt error: %+v", err) + return nil, fmt.Errorf("encrypt error: %+v", err) } } @@ -193,7 +193,7 @@ func Decode(ue *context.AmfUe, accessType models.AccessType, payload []byte) (*n return nil, fmt.Errorf("amfUe is nil") } if payload == nil { - return nil, fmt.Errorf("Nas payload is empty") + return nil, fmt.Errorf("nas payload is empty") } msg := new(nas.Message) @@ -210,7 +210,7 @@ func Decode(ue *context.AmfUe, accessType models.AccessType, payload []byte) (*n } if msg.GmmMessage == nil { - return nil, fmt.Errorf("Gmm Message is nil") + return nil, fmt.Errorf("gmm message is nil") } // TS 24.501 4.4.4.3: Except the messages listed below, no NAS signalling messages shall be processed @@ -263,7 +263,7 @@ func Decode(ue *context.AmfUe, accessType models.AccessType, payload []byte) (*n ciphered = true ue.ULCount.Set(0, 0) default: - return nil, fmt.Errorf("Wrong security header type: 0x%0x", msg.SecurityHeader.SecurityHeaderType) + return nil, fmt.Errorf("wrong security header type: 0x%0x", msg.SecurityHeader.SecurityHeaderType) } if ue.ULCount.SQN() > sequenceNumber { @@ -296,7 +296,7 @@ func Decode(ue *context.AmfUe, accessType models.AccessType, payload []byte) (*n // decrypt payload without sequence number (payload[1]) if err = security.NASEncrypt(ue.CipheringAlg, ue.KnasEnc, ue.ULCount.Get(), security.Bearer3GPP, security.DirectionUplink, payload[1:]); err != nil { - return nil, fmt.Errorf("Encrypt error: %+v", err) + return nil, fmt.Errorf("encrypt error: %+v", err) } } @@ -327,7 +327,7 @@ func Decode(ue *context.AmfUe, accessType models.AccessType, payload []byte) (*n case nas.MsgTypeDeregistrationAcceptUETerminatedDeregistration: return msg, nil default: - return nil, fmt.Errorf("Mac Verification for the nas message [%v] failed", msg.GmmHeader.GetMessageType()) + return nil, fmt.Errorf("mac verification for the nas message [%v] failed", msg.GmmHeader.GetMessageType()) } } diff --git a/ngap/message/build.go b/ngap/message/build.go index e265abf5..745cfea7 100644 --- a/ngap/message/build.go +++ b/ngap/message/build.go @@ -487,7 +487,7 @@ func BuildUEContextReleaseCommand( } switch causePresent { case ngapType.CausePresentNothing: - return nil, fmt.Errorf("Cause Present is Nothing") + return nil, fmt.Errorf("cause present is nothing") case ngapType.CausePresentRadioNetwork: ngapCause.RadioNetwork = new(ngapType.CauseRadioNetwork) ngapCause.RadioNetwork.Value = cause @@ -504,7 +504,7 @@ func BuildUEContextReleaseCommand( ngapCause.Misc = new(ngapType.CauseMisc) ngapCause.Misc.Value = cause default: - return nil, fmt.Errorf("Cause Present is Unknown") + return nil, fmt.Errorf("cause present is unknown") } ie.Value.Cause = &ngapCause @@ -2205,7 +2205,7 @@ func BuildPaging( taiListForPaging := ie.Value.TAIListForPaging if ue.RegistrationArea[models.AccessType__3_GPP_ACCESS] == nil { - err = fmt.Errorf("Registration Area of Ue[%s] is empty", ue.Supi) + err = fmt.Errorf("registration area of ue[%s] is empty", ue.Supi) return nil, err } else { for _, tai := range ue.RegistrationArea[models.AccessType__3_GPP_ACCESS] { diff --git a/producer/callback.go b/producer/callback.go index 330a2258..b6bc643c 100644 --- a/producer/callback.go +++ b/producer/callback.go @@ -15,7 +15,6 @@ import ( "github.com/mohae/deepcopy" "github.com/omec-project/amf/consumer" "github.com/omec-project/amf/context" - amf_context "github.com/omec-project/amf/context" gmm_message "github.com/omec-project/amf/gmm/message" "github.com/omec-project/amf/logger" "github.com/omec-project/amf/nas" @@ -471,11 +470,11 @@ func NfSubscriptionStatusNotifyProcedure(notificationData models.NotificationDat // If nrf caching is enabled, go ahead and delete the entry from the cache. // This will force the amf to do nf discovery and get the updated nf profile from the nrf. if notificationData.Event == models.NotificationEventType_DEREGISTERED { - if amf_context.AMF_Self().EnableNrfCaching { + if context.AMF_Self().EnableNrfCaching { ok := nrfCache.RemoveNfProfileFromNrfCache(nfInstanceId) logger.ProducerLog.Tracef("nfinstance %v deleted from cache: %v", nfInstanceId, ok) } - if subscriptionId, ok := amf_context.AMF_Self().NfStatusSubscriptions.Load(nfInstanceId); ok { + if subscriptionId, ok := context.AMF_Self().NfStatusSubscriptions.Load(nfInstanceId); ok { logger.ConsumerLog.Debugf("SubscriptionId of nfInstance %v is %v", nfInstanceId, subscriptionId.(string)) problemDetails, err := consumer.SendRemoveSubscription(subscriptionId.(string)) if problemDetails != nil { @@ -484,7 +483,7 @@ func NfSubscriptionStatusNotifyProcedure(notificationData models.NotificationDat logger.ConsumerLog.Errorf("Remove NF Subscription Error[%+v]", err) } else { logger.ConsumerLog.Infoln("[AMF] Remove NF Subscription successful") - amf_context.AMF_Self().NfStatusSubscriptions.Delete(nfInstanceId) + context.AMF_Self().NfStatusSubscriptions.Delete(nfInstanceId) } } else { logger.ProducerLog.Infof("nfinstance %v not found in map", nfInstanceId)