Skip to content

Commit

Permalink
Follow golangci advices
Browse files Browse the repository at this point in the history
  • Loading branch information
wmnsk committed Apr 19, 2024
1 parent ee72707 commit d19107c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 50 deletions.
6 changes: 2 additions & 4 deletions gtpv1/ie/uli.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func (i *IE) CGI() (uint16, error) {
return 0, io.ErrUnexpectedEOF
}

switch i.Payload[0] {
case locTypeCGI:
if i.Payload[0] == locTypeCGI {
if len(i.Payload) < 8 {
return 0, io.ErrUnexpectedEOF
}
Expand All @@ -125,8 +124,7 @@ func (i *IE) SAC() (uint16, error) {
return 0, io.ErrUnexpectedEOF
}

switch i.Payload[0] {
case locTypeSAI:
if i.Payload[0] == locTypeSAI {
if len(i.Payload) < 8 {
return 0, io.ErrUnexpectedEOF
}
Expand Down
34 changes: 21 additions & 13 deletions gtpv1/message/create-pdp-context-req.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2019-2024 go-gtp authors. All rights reserved.
// Copyright 2019-2023 go-gtp authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.

Expand Down Expand Up @@ -79,11 +79,13 @@ func NewCreatePDPContextRequest(teid uint32, seq uint16, ies ...*ie.IE) *CreateP
case ie.NSAPI:
if c.NSAPI == nil {
c.NSAPI = i
} else if c.LinkedNSAPI == nil {
continue
}
if c.LinkedNSAPI == nil {
c.LinkedNSAPI = i
} else {
c.AdditionalIEs = append(c.AdditionalIEs, i)
continue
}
c.AdditionalIEs = append(c.AdditionalIEs, i)
case ie.ChargingCharacteristics:
c.ChargingCharacteristics = i
case ie.TraceReference:
Expand All @@ -99,11 +101,13 @@ func NewCreatePDPContextRequest(teid uint32, seq uint16, ies ...*ie.IE) *CreateP
case ie.GSNAddress:
if c.SGSNAddressForSignalling == nil {
c.SGSNAddressForSignalling = i
} else if c.SGSNAddressForUserTraffic == nil {
continue
}
if c.SGSNAddressForUserTraffic == nil {
c.SGSNAddressForUserTraffic = i
} else {
c.AdditionalIEs = append(c.AdditionalIEs, i)
continue
}
c.AdditionalIEs = append(c.AdditionalIEs, i)
case ie.MSISDN:
c.MSISDN = i
case ie.QoSProfile:
Expand Down Expand Up @@ -471,11 +475,13 @@ func (c *CreatePDPContextRequest) UnmarshalBinary(b []byte) error {
case ie.NSAPI:
if c.NSAPI == nil {
c.NSAPI = i
} else if c.LinkedNSAPI == nil {
continue
}
if c.LinkedNSAPI == nil {
c.LinkedNSAPI = i
} else {
c.AdditionalIEs = append(c.AdditionalIEs, i)
continue
}
c.AdditionalIEs = append(c.AdditionalIEs, i)
case ie.ChargingCharacteristics:
c.ChargingCharacteristics = i
case ie.TraceReference:
Expand All @@ -491,11 +497,13 @@ func (c *CreatePDPContextRequest) UnmarshalBinary(b []byte) error {
case ie.GSNAddress:
if c.SGSNAddressForSignalling == nil {
c.SGSNAddressForSignalling = i
} else if c.SGSNAddressForUserTraffic == nil {
continue
}
if c.SGSNAddressForUserTraffic == nil {
c.SGSNAddressForUserTraffic = i
} else {
c.AdditionalIEs = append(c.AdditionalIEs, i)
continue
}
c.AdditionalIEs = append(c.AdditionalIEs, i)
case ie.MSISDN:
c.MSISDN = i
case ie.QoSProfile:
Expand Down
28 changes: 18 additions & 10 deletions gtpv1/message/create-pdp-context-res.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ func NewCreatePDPContextResponse(teid uint32, seq uint16, ies ...*ie.IE) *Create
case ie.GSNAddress:
if c.GGSNAddressForCPlane == nil {
c.GGSNAddressForCPlane = i
} else if c.GGSNAddressForUserTraffic == nil {
continue
}
if c.GGSNAddressForUserTraffic == nil {
c.GGSNAddressForUserTraffic = i
} else if c.AltGGSNAddressForCPlane == nil {
continue
}
if c.AltGGSNAddressForCPlane == nil {
c.AltGGSNAddressForCPlane = i
} else if c.AltGGSNAddressForUserTraffic == nil {
c.AltGGSNAddressForUserTraffic = i
continue
}
c.AltGGSNAddressForUserTraffic = i
case ie.QoSProfile:
c.QoSProfile = i
case ie.ChargingGatewayAddress:
Expand Down Expand Up @@ -365,21 +369,25 @@ func (c *CreatePDPContextResponse) UnmarshalBinary(b []byte) error {
case ie.GSNAddress:
if c.GGSNAddressForCPlane == nil {
c.GGSNAddressForCPlane = i
} else if c.GGSNAddressForUserTraffic == nil {
continue
}
if c.GGSNAddressForUserTraffic == nil {
c.GGSNAddressForUserTraffic = i
} else if c.AltGGSNAddressForCPlane == nil {
continue
}
if c.AltGGSNAddressForCPlane == nil {
c.AltGGSNAddressForCPlane = i
} else if c.AltGGSNAddressForUserTraffic == nil {
c.AltGGSNAddressForUserTraffic = i
continue
}
c.AltGGSNAddressForUserTraffic = i
case ie.QoSProfile:
c.QoSProfile = i
case ie.ChargingGatewayAddress:
if c.ChargingGatewayAddress == nil {
c.ChargingGatewayAddress = i
} else if c.AltChargingGatewayAddress == nil {
c.AltChargingGatewayAddress = i
continue
}
c.AltChargingGatewayAddress = i
case ie.CommonFlags:
c.CommonFlags = i
case ie.APNRestriction:
Expand Down
24 changes: 16 additions & 8 deletions gtpv1/message/update-pdp-context-req.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,17 @@ func NewUpdatePDPContextRequest(teid uint32, seq uint16, ies ...*ie.IE) *UpdateP
case ie.GSNAddress:
if u.SGSNAddressForCPlane == nil {
u.SGSNAddressForCPlane = i
} else if u.SGSNAddressForUserTraffic == nil {
continue
}
if u.SGSNAddressForUserTraffic == nil {
u.SGSNAddressForUserTraffic = i
} else if u.AlternativeSGSNAddressForCPlane == nil {
continue
}
if u.AlternativeSGSNAddressForCPlane == nil {
u.AlternativeSGSNAddressForCPlane = i
} else if u.AlternativeSGSNAddressForUserTraffic == nil {
u.AlternativeSGSNAddressForUserTraffic = i
continue
}
u.AlternativeSGSNAddressForUserTraffic = i
case ie.QoSProfile:
u.QoSProfile = i
case ie.TrafficFlowTemplate:
Expand Down Expand Up @@ -399,13 +403,17 @@ func (u *UpdatePDPContextRequest) UnmarshalBinary(b []byte) error {
case ie.GSNAddress:
if u.SGSNAddressForCPlane == nil {
u.SGSNAddressForCPlane = i
} else if u.SGSNAddressForUserTraffic == nil {
continue
}
if u.SGSNAddressForUserTraffic == nil {
u.SGSNAddressForUserTraffic = i
} else if u.AlternativeSGSNAddressForCPlane == nil {
continue
}
if u.AlternativeSGSNAddressForCPlane == nil {
u.AlternativeSGSNAddressForCPlane = i
} else if u.AlternativeSGSNAddressForUserTraffic == nil {
u.AlternativeSGSNAddressForUserTraffic = i
continue
}
u.AlternativeSGSNAddressForUserTraffic = i
case ie.QoSProfile:
u.QoSProfile = i
case ie.TrafficFlowTemplate:
Expand Down
24 changes: 16 additions & 8 deletions gtpv1/message/update-pdp-context-res.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,17 @@ func NewUpdatePDPContextResponse(teid uint32, seq uint16, ies ...*ie.IE) *Update
case ie.GSNAddress:
if u.GGSNAddressForCPlane == nil {
u.GGSNAddressForCPlane = i
} else if u.GGSNAddressForUserTraffic == nil {
continue
}
if u.GGSNAddressForUserTraffic == nil {
u.GGSNAddressForUserTraffic = i
} else if u.AltGGSNAddressForCPlane == nil {
continue
}
if u.AltGGSNAddressForCPlane == nil {
u.AltGGSNAddressForCPlane = i
} else if u.AltGGSNAddressForUserTraffic == nil {
u.AltGGSNAddressForUserTraffic = i
continue
}
u.AltGGSNAddressForUserTraffic = i
case ie.QoSProfile:
u.QoSProfile = i
case ie.ChargingGatewayAddress:
Expand Down Expand Up @@ -305,13 +309,17 @@ func (u *UpdatePDPContextResponse) UnmarshalBinary(b []byte) error {
case ie.GSNAddress:
if u.GGSNAddressForCPlane == nil {
u.GGSNAddressForCPlane = i
} else if u.GGSNAddressForUserTraffic == nil {
continue
}
if u.GGSNAddressForUserTraffic == nil {
u.GGSNAddressForUserTraffic = i
} else if u.AltGGSNAddressForCPlane == nil {
continue
}
if u.AltGGSNAddressForCPlane == nil {
u.AltGGSNAddressForCPlane = i
} else if u.AltGGSNAddressForUserTraffic == nil {
u.AltGGSNAddressForUserTraffic = i
continue
}
u.AltGGSNAddressForUserTraffic = i
case ie.QoSProfile:
u.QoSProfile = i
case ie.ChargingGatewayAddress:
Expand Down
3 changes: 1 addition & 2 deletions gtpv1/u-conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ func newPktConn(laddr net.Addr) (pktConn, error) {
udpConn: pktC.(*net.UDPConn),
PacketConn: ipv6.NewPacketConn(pktC),
}, nil
} else {
return nil, fmt.Errorf("laddr must refer to an IP address")
}
return nil, fmt.Errorf("laddr must refer to an IP address")
}

// UPlaneConn represents a U-Plane Connection of GTPv1.
Expand Down
3 changes: 1 addition & 2 deletions gtpv2/message/create-bearer-res.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ func (c *CreateBearerResponse) UnmarshalBinary(b []byte) error {
c.WLANLocationInformation = i
}
case ie.TWANIdentifierTimestamp:
switch i.Instance() {
case 1:
if i.Instance() == 1 {
c.WLANLocationTimestamp = i
}
case ie.OverloadControlInformation:
Expand Down
5 changes: 2 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ func EncodePLMN(mcc, mnc string) ([]byte, error) {
}

// 2-digit
b := make([]byte, 3)
if len(mnc) == 2 {
b = append(c, n...)
return b, nil
return append(c, n...), nil
}

// 3-digit
b := make([]byte, 3)
b[0] = c[0]
b[1] = (c[1] & 0x0f) | (n[1] << 4 & 0xf0)
b[2] = n[0]
Expand Down

0 comments on commit d19107c

Please sign in to comment.