Skip to content

Commit

Permalink
Add GHA for staticcheck given that golangci-lint does not cover e…
Browse files Browse the repository at this point in the history
…verything that `staticcheck` covers (#282)

Signed-off-by: Arrobo, Gabriel <[email protected]>
  • Loading branch information
gab-arrobo committed Aug 16, 2024
1 parent b3ce51c commit a7dcc60
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 43 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ jobs:
dockerfile: Dockerfile
ignore: DL3008,DL3018

staticcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: WillAbides/[email protected]
with:
go-version-file: 'go.mod'

- uses: dominikh/[email protected]
with:
version: latest
install-go: false

license-check:
runs-on: ubuntu-latest
steps:
Expand Down
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -239,7 +239,6 @@ linters:
- gofmt
- govet
- errcheck
- staticcheck
- unused
- gosimple
- ineffassign
Expand Down
2 changes: 1 addition & 1 deletion amf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion communication/api_individual_ue_context_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion communication/api_n1_n2_message_collection_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion consumer/nf_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion consumer/nf_mangement.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion context/amf_ran.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
34 changes: 17 additions & 17 deletions gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion nas/dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions nas/nas_security/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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())
}
}

Expand Down
6 changes: 3 additions & 3 deletions ngap/message/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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] {
Expand Down
7 changes: 3 additions & 4 deletions producer/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit a7dcc60

Please sign in to comment.