From 502aaa06537e1c802ac73fbbdbb7b4ad492ae712 Mon Sep 17 00:00:00 2001 From: "liarsa.localdomain" Date: Mon, 4 Mar 2024 14:01:15 +0800 Subject: [PATCH] fix 'LsTLVIPReachability Prefix Set Value' bug --- pkg/packet/bgp/bgp.go | 55 +++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index fad11c1f4..ee0b9c117 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -64,6 +64,7 @@ func IsAddPathEnabled(decode bool, f RouteFamily, options []*MarshallingOption) } return false } + func IsAttributePresent(attr BGPAttrType, options []*MarshallingOption) bool { for _, opt := range options { if opt == nil { @@ -685,8 +686,10 @@ func (c *CapGracefulRestart) DecodeFromBytes(data []byte) error { c.Tuples = make([]*CapGracefulRestartTuple, 0, valueLen/4) for i := valueLen; i >= 4; i -= 4 { - t := &CapGracefulRestartTuple{binary.BigEndian.Uint16(data[0:2]), - data[2], data[3]} + t := &CapGracefulRestartTuple{ + binary.BigEndian.Uint16(data[0:2]), + data[2], data[3], + } c.Tuples = append(c.Tuples, t) data = data[4:] } @@ -1875,8 +1878,10 @@ func ContainsCIDR(n1, n2 *net.IPNet) bool { // // The label information carried (as part of NLRI) in the Withdrawn // Routes field should be set to 0x800000. -const WITHDRAW_LABEL = uint32(0x800000) -const ZERO_LABEL = uint32(0) // some platform uses this as withdraw label +const ( + WITHDRAW_LABEL = uint32(0x800000) + ZERO_LABEL = uint32(0) // some platform uses this as withdraw label +) type MPLSLabelStack struct { Labels []uint32 @@ -3257,7 +3262,6 @@ func (er *EVPNIPMSIRoute) Len() int { } func (er *EVPNIPMSIRoute) DecodeFromBytes(data []byte) error { - er.RD = GetRouteDistinguisher(data[0:8]) data = data[er.RD.Len():] @@ -3318,7 +3322,6 @@ func (er *EVPNIPMSIRoute) rd() RouteDistinguisherInterface { } func NewEVPNIPMSIRoute(rd RouteDistinguisherInterface, etag uint32, ec ExtendedCommunityInterface) *EVPNNLRI { - return NewEVPNNLRI(EVPN_I_PMSI, &EVPNIPMSIRoute{ RD: rd, ETag: etag, @@ -4588,7 +4591,6 @@ func NewFlowSpecComponent(typ BGPFlowSpecType, items []*FlowSpecComponentItem) * } else { v.Op &^= 0x80 } - } return &FlowSpecComponent{ Items: items, @@ -4838,7 +4840,6 @@ func (n *FlowSpecNLRI) MarshalJSON() ([]byte, error) { }{ Value: n.Value, }) - } // CompareFlowSpecNLRI(n, m) returns @@ -5694,7 +5695,7 @@ func NewLsPrefixTLVs(pd *LsPrefixDescriptor) []LsTLVInterface { Length: lenIpReach, }, PrefixLength: uint8(prefixSize), - Prefix: []byte(ip)[:((lenIpPrefix-1)/8 + 1)], + Prefix: []byte(ip), } } else if ipReach.IP.To16() != nil { ip := ipReach.IP.To16() @@ -5704,7 +5705,7 @@ func NewLsPrefixTLVs(pd *LsPrefixDescriptor) []LsTLVInterface { Length: lenIpReach, }, PrefixLength: uint8(prefixSize), - Prefix: []byte(ip)[:((lenIpPrefix-1)/8 + 1)], + Prefix: []byte(ip), } } lsTLVs = append(lsTLVs, tlv) @@ -8972,7 +8973,6 @@ type LsNodeDescriptor struct { } func (l *LsNodeDescriptor) String() string { - if l.BGPRouterID == nil { return fmt.Sprintf("{ASN: %v, BGP LS ID: %v, OSPF AREA: %v, IGP ROUTER ID: %v}", l.Asn, l.BGPLsID, l.OspfAreaID, l.IGPRouterID) } @@ -9090,7 +9090,6 @@ func NewLsTLVNodeDescriptor(nd *LsNodeDescriptor, tlvType LsTLVType) LsTLVNodeDe }, SubTLVs: subTLVs, } - } type LsAddrPrefix struct { @@ -9906,7 +9905,8 @@ func (c NotificationErrorCode) String() string { UNDEFINED, "connection not synchronized", "bad message length", - "bad message type"} + "bad message type", + } case BGP_ERROR_OPEN_MESSAGE_ERROR: codeStr = "open" subcodeList = []string{ @@ -9917,7 +9917,8 @@ func (c NotificationErrorCode) String() string { "unsupported optional parameter", "deprecated authentication failure", "unacceptable hold time", - "unsupported capability"} + "unsupported capability", + } case BGP_ERROR_UPDATE_MESSAGE_ERROR: codeStr = "update" subcodeList = []string{ @@ -9932,19 +9933,22 @@ func (c NotificationErrorCode) String() string { "invalid next hop attribute", "optional attribute error", "invalid network field", - "sub malformed as path"} + "sub malformed as path", + } case BGP_ERROR_HOLD_TIMER_EXPIRED: codeStr = "hold timer expired" subcodeList = []string{ UNDEFINED, - "hold timer expired"} + "hold timer expired", + } case BGP_ERROR_FSM_ERROR: codeStr = "fsm" subcodeList = []string{ UNDEFINED, "receive unexpected message in opensent state", "receive unexpected message in openconfirm state", - "receive unexpected message in established state"} + "receive unexpected message in established state", + } case BGP_ERROR_CEASE: codeStr = "cease" subcodeList = []string{ @@ -9956,7 +9960,8 @@ func (c NotificationErrorCode) String() string { "connection rejected", "other configuration change", "connection collision resolution", - "out of resources"} + "out of resources", + } case BGP_ERROR_ROUTE_REFRESH_MESSAGE_ERROR: codeStr = "route refresh" subcodeList = []string{"invalid message length"} @@ -11035,7 +11040,6 @@ type PathAttributeMpReachNLRI struct { } func (p *PathAttributeMpReachNLRI) DecodeFromBytes(data []byte, options ...*MarshallingOption) error { - value, err := p.PathAttribute.DecodeFromBytes(data, options...) if err != nil { return err @@ -11933,8 +11937,7 @@ func NewEncapExtended(tunnelType TunnelType) *EncapExtended { } } -type DefaultGatewayExtended struct { -} +type DefaultGatewayExtended struct{} func (e *DefaultGatewayExtended) Serialize() ([]byte, error) { buf := make([]byte, 8) @@ -14647,8 +14650,7 @@ func NewBGPNotificationMessage(errcode uint8, errsubcode uint8, data []byte) *BG } } -type BGPKeepAlive struct { -} +type BGPKeepAlive struct{} func (msg *BGPKeepAlive) DecodeFromBytes(data []byte, options ...*MarshallingOption) error { return nil @@ -15031,24 +15033,31 @@ func (p *IPAddrPrefixDefault) Flat() map[string]string { func (l *EVPNNLRI) Flat() map[string]string { return map[string]string{} } + func (l *RouteTargetMembershipNLRI) Flat() map[string]string { return map[string]string{} } + func (l *FlowSpecIPv4Unicast) Flat() map[string]string { return map[string]string{} } + func (l *FlowSpecIPv4VPN) Flat() map[string]string { return map[string]string{} } + func (l *FlowSpecIPv6Unicast) Flat() map[string]string { return map[string]string{} } + func (l *FlowSpecIPv6VPN) Flat() map[string]string { return map[string]string{} } + func (l *FlowSpecL2VPN) Flat() map[string]string { return map[string]string{} } + func (l *OpaqueNLRI) Flat() map[string]string { return map[string]string{} }