From 985f90458bb6552f5cbf29294c70fcd3bb1a6385 Mon Sep 17 00:00:00 2001 From: ming-hsien Date: Wed, 27 Nov 2024 03:52:50 +0000 Subject: [PATCH 1/3] fix: qos id identical in pdu session establishment accept message error --- internal/context/gsm_build.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/context/gsm_build.go b/internal/context/gsm_build.go index 44e93968..186e7f61 100644 --- a/internal/context/gsm_build.go +++ b/internal/context/gsm_build.go @@ -36,9 +36,12 @@ func BuildGSMPDUSessionEstablishmentAccept(smContext *SMContext) ([]byte, error) pDUSessionEstablishmentAccept.SessionAMBR = nasConvert.ModelsToSessionAMBR(sessRule.AuthSessAmbr) pDUSessionEstablishmentAccept.SessionAMBR.SetLen(uint8(len(pDUSessionEstablishmentAccept.SessionAMBR.Octet))) - qoSRules := nasType.QoSRules{ - { - Identifier: 0x01, + qoSRules := nasType.QoSRules{} + if defRuleID, err := smContext.QoSRuleIDGenerator.Allocate(); err != nil { + return nil, err + } else { + qosRule := nasType.QoSRule{ + Identifier: uint8(defRuleID), DQR: true, Operation: nasType.OperationCodeCreateNewQoSRule, Precedence: 255, @@ -52,7 +55,8 @@ func BuildGSMPDUSessionEstablishmentAccept(smContext *SMContext) ([]byte, error) }, }, }, - }, + } + qoSRules = append(qoSRules, qosRule) } for _, pccRule := range smContext.PCCRules { From bfc2192ea194fef445fa6a82769a9c1c0f44046c Mon Sep 17 00:00:00 2001 From: ming-hsien Date: Wed, 27 Nov 2024 07:35:23 +0000 Subject: [PATCH 2/3] feat: add defruleid for smcontext and allocate id when construct new smcontext --- internal/context/gsm_build.go | 12 ++++-------- internal/context/sm_context.go | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/context/gsm_build.go b/internal/context/gsm_build.go index 186e7f61..fb56534c 100644 --- a/internal/context/gsm_build.go +++ b/internal/context/gsm_build.go @@ -36,12 +36,9 @@ func BuildGSMPDUSessionEstablishmentAccept(smContext *SMContext) ([]byte, error) pDUSessionEstablishmentAccept.SessionAMBR = nasConvert.ModelsToSessionAMBR(sessRule.AuthSessAmbr) pDUSessionEstablishmentAccept.SessionAMBR.SetLen(uint8(len(pDUSessionEstablishmentAccept.SessionAMBR.Octet))) - qoSRules := nasType.QoSRules{} - if defRuleID, err := smContext.QoSRuleIDGenerator.Allocate(); err != nil { - return nil, err - } else { - qosRule := nasType.QoSRule{ - Identifier: uint8(defRuleID), + qoSRules := nasType.QoSRules{ + { + Identifier: smContext.defRuleID, DQR: true, Operation: nasType.OperationCodeCreateNewQoSRule, Precedence: 255, @@ -55,8 +52,7 @@ func BuildGSMPDUSessionEstablishmentAccept(smContext *SMContext) ([]byte, error) }, }, }, - } - qoSRules = append(qoSRules, qosRule) + }, } for _, pccRule := range smContext.PCCRules { diff --git a/internal/context/sm_context.go b/internal/context/sm_context.go index d8ac995e..eb2b3fd1 100644 --- a/internal/context/sm_context.go +++ b/internal/context/sm_context.go @@ -182,6 +182,7 @@ type SMContext struct { SelectedSessionRuleID string // QoS + defRuleID uint8 QoSRuleIDGenerator *idgenerator.IDGenerator PacketFilterIDGenerator *idgenerator.IDGenerator QFIGenerator *idgenerator.IDGenerator @@ -299,6 +300,9 @@ func NewSMContext(id string, pduSessID int32) *SMContext { smContext.Tunnel = NewUPTunnel() smContext.QoSRuleIDGenerator = idgenerator.NewGenerator(1, 255) + defRuleID, _ := smContext.QoSRuleIDGenerator.Allocate() + smContext.defRuleID = uint8(defRuleID) + smContext.PacketFilterIDGenerator = idgenerator.NewGenerator(1, 255) smContext.QFIGenerator = idgenerator.NewGenerator(2, 63) // 1 always reserve for default Qos smContext.PCCRuleIDToQoSRuleID = make(map[string]uint8) From 8de73b92fece2542a3a1223f9e7e2b7bb15c294b Mon Sep 17 00:00:00 2001 From: ming-hsien Date: Wed, 27 Nov 2024 08:07:58 +0000 Subject: [PATCH 3/3] fix: golangci lint error --- internal/context/sm_context.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/context/sm_context.go b/internal/context/sm_context.go index eb2b3fd1..f2ce2c14 100644 --- a/internal/context/sm_context.go +++ b/internal/context/sm_context.go @@ -300,8 +300,11 @@ func NewSMContext(id string, pduSessID int32) *SMContext { smContext.Tunnel = NewUPTunnel() smContext.QoSRuleIDGenerator = idgenerator.NewGenerator(1, 255) - defRuleID, _ := smContext.QoSRuleIDGenerator.Allocate() - smContext.defRuleID = uint8(defRuleID) + if defRuleID, err := smContext.QoSRuleIDGenerator.Allocate(); err != nil { + logger.CtxLog.Warnln("Create Default QoS rule error ", err) + } else { + smContext.defRuleID = uint8(defRuleID) + } smContext.PacketFilterIDGenerator = idgenerator.NewGenerator(1, 255) smContext.QFIGenerator = idgenerator.NewGenerator(2, 63) // 1 always reserve for default Qos