summaryrefslogtreecommitdiffhomepage
path: root/pkg/packet
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-07-14 19:45:35 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-07-24 09:57:49 +0900
commit3dc23d3075f13f2976afd255ef2fd9b1410acc77 (patch)
treef019ead108469eeb8fe5064c051607f14c954eb6 /pkg/packet
parent1cf93d5acfd9ed16ad798c98142291bdb7688d84 (diff)
pkg/packet/bgp: fix ParsePmsiTunnel() and NewPathAttributePmsiTunnel() crash
Once we create an object, we should not mutate it. This fixes the following in a different way. https://github.com/osrg/gobgp/pull/1778 Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'pkg/packet')
-rw-r--r--pkg/packet/bgp/bgp.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go
index 01251167..1be42ec5 100644
--- a/pkg/packet/bgp/bgp.go
+++ b/pkg/packet/bgp/bgp.go
@@ -8443,6 +8443,9 @@ func (p *PathAttributePmsiTunnel) MarshalJSON() ([]byte, error) {
}
func NewPathAttributePmsiTunnel(typ PmsiTunnelType, isLeafInfoRequired bool, label uint32, id PmsiTunnelIDInterface) *PathAttributePmsiTunnel {
+ if id == nil {
+ return nil
+ }
// Flags(1) + TunnelType(1) + Label(3) + TunnelID(variable)
l := 5 + id.Len()
t := BGP_ATTR_TYPE_PMSI_TUNNEL
@@ -8466,22 +8469,22 @@ func ParsePmsiTunnel(args []string) (*PathAttributePmsiTunnel, error) {
return nil, fmt.Errorf("invalid pmsi tunnel arguments: %s", args)
}
- pmsi := NewPathAttributePmsiTunnel(0, false, 0, nil)
-
+ var tunnelType PmsiTunnelType
+ var isLeafInfoRequired bool
switch args[0] {
case "ingress-repl":
- pmsi.TunnelType = PMSI_TUNNEL_TYPE_INGRESS_REPL
+ tunnelType = PMSI_TUNNEL_TYPE_INGRESS_REPL
default:
typ, err := strconv.ParseUint(args[0], 10, 8)
if err != nil {
return nil, fmt.Errorf("invalid pmsi tunnel type: %s", args[0])
}
- pmsi.TunnelType = PmsiTunnelType(typ)
+ tunnelType = PmsiTunnelType(typ)
}
indx := 1
if args[indx] == "leaf-info-required" {
- pmsi.IsLeafInfoRequired = true
+ isLeafInfoRequired = true
indx++
}
@@ -8489,21 +8492,21 @@ func ParsePmsiTunnel(args []string) (*PathAttributePmsiTunnel, error) {
if err != nil {
return nil, fmt.Errorf("invalid pmsi tunnel label: %s", args[indx])
}
- pmsi.Label = uint32(label)
indx++
- switch pmsi.TunnelType {
+ var id PmsiTunnelIDInterface
+ switch tunnelType {
case PMSI_TUNNEL_TYPE_INGRESS_REPL:
ip := net.ParseIP(args[indx])
if ip == nil {
return nil, fmt.Errorf("invalid pmsi tunnel identifier: %s", args[indx])
}
- pmsi.TunnelID = &IngressReplTunnelID{Value: ip}
+ id = &IngressReplTunnelID{Value: ip}
default:
- pmsi.TunnelID = &DefaultPmsiTunnelID{Value: []byte(args[indx])}
+ id = &DefaultPmsiTunnelID{Value: []byte(args[indx])}
}
- return pmsi, nil
+ return NewPathAttributePmsiTunnel(tunnelType, isLeafInfoRequired, uint32(label), id), nil
}
type PathAttributeIP6ExtendedCommunities struct {