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

fix: fix golangci error #4

Merged
merged 2 commits into from
Apr 18, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ linters-settings:
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 120
line-length: 140
# tab width in spaces. Default to 1.
tab-width: 1
maligned:
Expand Down
2 changes: 1 addition & 1 deletion internal/gre/gre.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func SetupGreTunnel(greIfaceName, parentIfaceName string, ueTunnelAddr, n3iwfTun

logger.AppLog.Infof("GRE Key Field: 0x%x", greKeyField)

if err := netlink.LinkAdd(newGRETunnel); err != nil {
if err = netlink.LinkAdd(newGRETunnel); err != nil {
return nil, err
}

Expand Down
8 changes: 6 additions & 2 deletions internal/nwucp/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ func Dispatch(conn net.Conn, nasEnv []byte) {
n3ueSelf := context.N3UESelf()

// Decap Nas envelope
nasEnv, _ = ngapPacket.DecapNasPduFromEnvelope(nasEnv[:len((nasEnv))])
nasMsg, err := n3ue_security.NASDecode(n3ueSelf.RanUeContext, nas.SecurityHeaderTypeIntegrityProtectedAndCiphered, nasEnv[:len((nasEnv))])
nasEnv, _ = ngapPacket.DecapNasPduFromEnvelope(nasEnv[:])
nasMsg, err := n3ue_security.NASDecode(
n3ueSelf.RanUeContext,
nas.SecurityHeaderTypeIntegrityProtectedAndCiphered,
nasEnv[:],
)
if err != nil {
naslog.Errorf("NAS Decode Fail: %+v", err)
return
Expand Down
8 changes: 7 additions & 1 deletion internal/nwucp/handler/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import (
)

func SendNasMsg(ue *security.RanUeContext, conn net.Conn, msg []byte) {
pdu, err := ngapPacket.EncodeNasPduInEnvelopeWithSecurity(ue, msg, nas.SecurityHeaderTypeIntegrityProtectedAndCiphered, true, false)
pdu, err := ngapPacket.EncodeNasPduInEnvelopeWithSecurity(
ue,
msg,
nas.SecurityHeaderTypeIntegrityProtectedAndCiphered,
true,
false,
)
if err != nil {
naslog.Errorf("EncodeNasPduWithSecurity: %+v", err)
return
Expand Down
3 changes: 1 addition & 2 deletions internal/nwucp/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ func init() {
func Run() error {
n3ueSelf := context.N3UESelf()

var errChan chan error
errChan = make(chan error)
errChan := make(chan error)

go serveConn(n3ueSelf, errChan)
if err, ok := <-errChan; ok {
Expand Down
12 changes: 10 additions & 2 deletions internal/packet/nasPacket/nasPduDl.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,21 @@ import (
"github.com/free5gc/nas/nasMessage"
)

func DecodePDUSessionEstablishmentAccept(ue *n3ue_security.RanUeContext, length int, buffer []byte) (*nas.Message, error) {
func DecodePDUSessionEstablishmentAccept(
ue *n3ue_security.RanUeContext,
length int,
buffer []byte,
) (*nas.Message, error) {
if length == 0 {
return nil, fmt.Errorf("Empty buffer")
}

nasEnv, n := ngapPacket.DecapNasPduFromEnvelope(buffer[:length])
nasMsg, err := n3ue_security.NASDecode(ue, nas.SecurityHeaderTypeIntegrityProtectedAndCiphered, nasEnv[:n])
nasMsg, err := n3ue_security.NASDecode(
ue,
nas.SecurityHeaderTypeIntegrityProtectedAndCiphered,
nasEnv[:n],
)
if err != nil {
return nil, fmt.Errorf("NAS Decode Fail: %+v", err)
}
Expand Down
39 changes: 29 additions & 10 deletions internal/packet/nasPacket/nasPduUl.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,17 @@ func GetPduSessionEstablishmentRequest(pduSessionId uint8) []byte {
pduSessionEstablishmentRequest.IntegrityProtectionMaximumDataRate.
SetMaximumDataRatePerUEForUserPlaneIntegrityProtectionForUpLink(0xff)

pduSessionEstablishmentRequest.PDUSessionType = nasType.NewPDUSessionType(nasMessage.PDUSessionEstablishmentRequestPDUSessionTypeType)
pduSessionEstablishmentRequest.PDUSessionType = nasType.NewPDUSessionType(
nasMessage.PDUSessionEstablishmentRequestPDUSessionTypeType,
)
pduSessionEstablishmentRequest.PDUSessionType.SetPDUSessionTypeValue(uint8(0x01)) // IPv4 type

pduSessionEstablishmentRequest.SSCMode = nasType.NewSSCMode(nasMessage.PDUSessionEstablishmentRequestSSCModeType)
pduSessionEstablishmentRequest.SSCMode.SetSSCMode(uint8(0x01)) // SSC Mode 1

pduSessionEstablishmentRequest.ExtendedProtocolConfigurationOptions = nasType.NewExtendedProtocolConfigurationOptions(
nasMessage.PDUSessionEstablishmentRequestExtendedProtocolConfigurationOptionsType)
nasMessage.PDUSessionEstablishmentRequestExtendedProtocolConfigurationOptionsType,
)
protocolConfigurationOptions := nasConvert.NewProtocolConfigurationOptions()
protocolConfigurationOptions.AddIPAddressAllocationViaNASSignallingUL()
protocolConfigurationOptions.AddDNSServerIPv4AddressRequest()
Expand Down Expand Up @@ -154,7 +157,9 @@ func GetUlNasTransport_PduSessionEstablishmentRequest(pduSessionId uint8, reques
ulNasTransport.SNSSAI.SetSD(sdTemp)
}

ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(nasMessage.PayloadContainerTypeN1SMInfo)
ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(
nasMessage.PayloadContainerTypeN1SMInfo,
)
ulNasTransport.PayloadContainer.SetLen(uint16(len(pduSessionEstablishmentRequest)))
ulNasTransport.PayloadContainer.SetPayloadContainerContents(pduSessionEstablishmentRequest)

Expand Down Expand Up @@ -207,7 +212,9 @@ func GetUlNasTransport_PduSessionModificationRequest(pduSessionId uint8, request
ulNasTransport.SNSSAI.SetSD(sdTemp)
}

ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(nasMessage.PayloadContainerTypeN1SMInfo)
ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(
nasMessage.PayloadContainerTypeN1SMInfo,
)
ulNasTransport.PayloadContainer.SetLen(uint16(len(pduSessionModificationRequest)))
ulNasTransport.PayloadContainer.SetPayloadContainerContents(pduSessionModificationRequest)

Expand Down Expand Up @@ -422,7 +429,9 @@ func GetUlNasTransport_PduSessionCommonData(pduSessionId uint8, types string) []
ulNasTransport.PduSessionID2Value.SetIei(nasMessage.ULNASTransportPduSessionID2ValueType)
ulNasTransport.PduSessionID2Value.SetPduSessionID2Value(pduSessionId)

ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(nasMessage.PayloadContainerTypeN1SMInfo)
ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(
nasMessage.PayloadContainerTypeN1SMInfo,
)
ulNasTransport.PayloadContainer.SetLen(uint16(len(payload)))
ulNasTransport.PayloadContainer.SetPayloadContainerContents(payload)

Expand Down Expand Up @@ -733,7 +742,9 @@ func GetDeregistrationRequest(accessType uint8, switchOff uint8, ngKsi uint8,
deregistrationRequest.NgksiAndDeregistrationType.SetTSC(ngKsi)
deregistrationRequest.NgksiAndDeregistrationType.SetNasKeySetIdentifiler(ngKsi)
deregistrationRequest.MobileIdentity5GS.SetLen(mobileIdentity5GS.GetLen())
deregistrationRequest.MobileIdentity5GS.SetMobileIdentity5GSContents(mobileIdentity5GS.GetMobileIdentity5GSContents())
deregistrationRequest.MobileIdentity5GS.SetMobileIdentity5GSContents(
mobileIdentity5GS.GetMobileIdentity5GSContents(),
)

m.GmmMessage.DeregistrationRequestUEOriginatingDeregistration = deregistrationRequest

Expand Down Expand Up @@ -776,7 +787,9 @@ func GetStatus5GMM(cause uint8) []byte {
m.GmmHeader.SetMessageType(nas.MsgTypeStatus5GMM)

status5GMM := nasMessage.NewStatus5GMM(0)
status5GMM.ExtendedProtocolDiscriminator.SetExtendedProtocolDiscriminator(nasMessage.Epd5GSMobilityManagementMessage)
status5GMM.ExtendedProtocolDiscriminator.SetExtendedProtocolDiscriminator(
nasMessage.Epd5GSMobilityManagementMessage,
)
status5GMM.SpareHalfOctetAndSecurityHeaderType.SetSecurityHeaderType(nas.SecurityHeaderTypePlainNas)
status5GMM.SpareHalfOctetAndSecurityHeaderType.SetSpareHalfOctet(0)
status5GMM.STATUSMessageIdentity5GMM.SetMessageType(nas.MsgTypeStatus5GMM)
Expand Down Expand Up @@ -832,7 +845,9 @@ func GetUlNasTransport_Status5GSM(pduSessionId uint8, cause uint8) []byte {
ulNasTransport.PduSessionID2Value.SetIei(nasMessage.ULNASTransportPduSessionID2ValueType)
ulNasTransport.PduSessionID2Value.SetPduSessionID2Value(pduSessionId)

ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(nasMessage.PayloadContainerTypeN1SMInfo)
ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(
nasMessage.PayloadContainerTypeN1SMInfo,
)
ulNasTransport.PayloadContainer.SetLen(uint16(len(payload)))
ulNasTransport.PayloadContainer.SetPayloadContainerContents(payload)

Expand Down Expand Up @@ -863,7 +878,9 @@ func GetUlNasTransport_PduSessionReleaseRequest(pduSessionId uint8) []byte {
ulNasTransport.PduSessionID2Value.SetIei(nasMessage.ULNASTransportPduSessionID2ValueType)
ulNasTransport.PduSessionID2Value.SetPduSessionID2Value(pduSessionId)

ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(nasMessage.PayloadContainerTypeN1SMInfo)
ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(
nasMessage.PayloadContainerTypeN1SMInfo,
)
ulNasTransport.PayloadContainer.SetLen(uint16(len(pduSessionReleaseRequest)))
ulNasTransport.PayloadContainer.SetPayloadContainerContents(pduSessionReleaseRequest)

Expand Down Expand Up @@ -916,7 +933,9 @@ func GetUlNasTransport_PduSessionReleaseComplete(pduSessionId uint8, requestType
ulNasTransport.SNSSAI.SetSD(sdTemp)
}

ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(nasMessage.PayloadContainerTypeN1SMInfo)
ulNasTransport.SpareHalfOctetAndPayloadContainerType.SetPayloadContainerType(
nasMessage.PayloadContainerTypeN1SMInfo,
)
ulNasTransport.PayloadContainer.SetLen(uint16(len(pduSessionReleaseRequest)))
ulNasTransport.PayloadContainer.SetPayloadContainerContents(pduSessionReleaseRequest)

Expand Down
Loading
Loading