Skip to content

Commit

Permalink
fix 'LsTLVIPReachability Prefix Set Value' bug
Browse files Browse the repository at this point in the history
  • Loading branch information
eviltomorrow committed Mar 4, 2024
1 parent d67f568 commit 502aaa0
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:]
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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():]
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -4588,7 +4591,6 @@ func NewFlowSpecComponent(typ BGPFlowSpecType, items []*FlowSpecComponentItem) *
} else {
v.Op &^= 0x80
}

}
return &FlowSpecComponent{
Items: items,
Expand Down Expand Up @@ -4838,7 +4840,6 @@ func (n *FlowSpecNLRI) MarshalJSON() ([]byte, error) {
}{
Value: n.Value,
})

}

// CompareFlowSpecNLRI(n, m) returns
Expand Down Expand Up @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -9090,7 +9090,6 @@ func NewLsTLVNodeDescriptor(nd *LsNodeDescriptor, tlvType LsTLVType) LsTLVNodeDe
},
SubTLVs: subTLVs,
}

}

type LsAddrPrefix struct {
Expand Down Expand Up @@ -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{
Expand All @@ -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{
Expand All @@ -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{
Expand All @@ -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"}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{}
}
Expand Down

0 comments on commit 502aaa0

Please sign in to comment.