diff options
Diffstat (limited to 'packet/bgp/bgp.go')
-rw-r--r-- | packet/bgp/bgp.go | 89 |
1 files changed, 43 insertions, 46 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 361da392..b882f9a6 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -289,13 +289,13 @@ func (c BGPCapabilityCode) String() string { var ( // Used parsing RouteDistinguisher - _regexpRouteDistinguisher = regexp.MustCompile("^((\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)|((\\d+)\\.)?(\\d+)|([\\w]+:[\\w:]*:[\\w]+)):(\\d+)$") + _regexpRouteDistinguisher = regexp.MustCompile(`^((\d+)\.(\d+)\.(\d+)\.(\d+)|((\d+)\.)?(\d+)|([\w]+:[\w:]*:[\w]+)):(\d+)$`) // Used for operator and value for the FlowSpec numeric type // Example: // re.FindStringSubmatch("&==80") // >>> ["&==80" "&" "==" "80"] - _regexpFlowSpecNumericType = regexp.MustCompile("(&?)(==|=|>|>=|<|<=|!|!=|=!)?(\\d+|-\\d|true|false)") + _regexpFlowSpecNumericType = regexp.MustCompile(`(&?)(==|=|>|>=|<|<=|!|!=|=!)?(\d+|-\d|true|false)`) // - "=!" is used in the old style format of "tcp-flags" and "fragment". // - The value field should be one of the followings: @@ -303,8 +303,8 @@ var ( // * Combination of the small letters, decimals, "-" and "+" // (e.g., tcp, ipv4, is-fragment+first-fragment) // * Capital letters (e.g., SA) - _regexpFlowSpecOperator = regexp.MustCompile("&|=|>|<|!|[\\w\\-+]+") - _regexpFlowSpecOperatorValue = regexp.MustCompile("[\\w\\-+]+") + _regexpFlowSpecOperator = regexp.MustCompile(`&|=|>|<|!|[\w\-+]+`) + _regexpFlowSpecOperatorValue = regexp.MustCompile(`[\w\-+]+`) // Note: "(-*)" and "(.*)" catch the invalid flags // Example: In this case, "Z" is unsupported flag type. @@ -315,13 +315,13 @@ var ( // Note: "(.*)" catches the invalid flags // re.FindStringSubmatch("&!=+first-fragment+last-fragment+invalid-fragment") // >>> ["&!=+first-fragment+last-fragment+invalid-fragment" "&" "!=" "+first-fragment+last-fragment" "+last-fragment" "+" "last" "+invalid-fragment"] - _regexpFlowSpecFragment = regexp.MustCompile("(&?)(==|=|!|!=|=!)?(((\\+)?(dont|is|first|last|not-a)-fragment)+)(.*)") + _regexpFlowSpecFragment = regexp.MustCompile(`(&?)(==|=|!|!=|=!)?(((\+)?(dont|is|first|last|not-a)-fragment)+)(.*)`) // re.FindStringSubmatch("192.168.0.0/24") // >>> ["192.168.0.0/24" "192.168.0.0" "/24" "24"] // re.FindStringSubmatch("192.168.0.1") // >>> ["192.168.0.1" "192.168.0.1" "" ""] - _regexpFindIPv4Prefix = regexp.MustCompile("^([\\d.]+)(/(\\d{1,2}))?") + _regexpFindIPv4Prefix = regexp.MustCompile(`^([\d.]+)(/(\d{1,2}))?`) // re.FindStringSubmatch("2001:dB8::/64") // >>> ["2001:dB8::/64" "2001:dB8::" "/64" "64" "" ""] @@ -329,7 +329,7 @@ var ( // >>> ["2001:dB8::/64/8" "2001:dB8::" "/64" "64" "/8" "8"] // re.FindStringSubmatch("2001:dB8::1") // >>> ["2001:dB8::1" "2001:dB8::1" "" "" "" ""] - _regexpFindIPv6Prefix = regexp.MustCompile("^([a-fA-F\\d:.]+)(/(\\d{1,3}))?(/(\\d{1,3}))?") + _regexpFindIPv6Prefix = regexp.MustCompile(`^([a-fA-F\d:.]+)(/(\d{1,3}))?(/(\d{1,3}))?`) ) type ParameterCapabilityInterface interface { @@ -1572,7 +1572,8 @@ func (l *MPLSLabelStack) DecodeFromBytes(data []byte) error { break } } - if foundBottom == false { + + if foundBottom { l.Labels = []uint32{} return nil } @@ -2161,7 +2162,7 @@ func ParseEthernetSegmentIdentifier(args []string) (EthernetSegmentIdentifier, e } invalidEsiValuesError := fmt.Errorf("invalid esi values for type %s: %s", esi.Type.String(), args[1:]) - esi.Value = make([]byte, 9, 9) + esi.Value = make([]byte, 9) switch esi.Type { case ESI_LACP: fallthrough @@ -2196,7 +2197,7 @@ func ParseEthernetSegmentIdentifier(args []string) (EthernetSegmentIdentifier, e if err != nil { return esi, invalidEsiValuesError } - iBuf := make([]byte, 4, 4) + iBuf := make([]byte, 4) binary.BigEndian.PutUint32(iBuf, uint32(i)) copy(esi.Value[6:9], iBuf[1:4]) case ESI_ROUTERID: @@ -2278,7 +2279,7 @@ func labelSerialize(label uint32) ([]byte, error) { if label > 0xffffff { return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, fmt.Sprintf("Out of range Label: %d", label)) } - buf := make([]byte, 3, 3) + buf := make([]byte, 3) buf[0] = byte((label >> 16) & 0xff) buf[1] = byte((label >> 8) & 0xff) buf[2] = byte(label & 0xff) @@ -3951,13 +3952,10 @@ func (v *FlowSpecComponentItem) Len() int { } func (v *FlowSpecComponentItem) Serialize() ([]byte, error) { - if v.Value < 0 { - return nil, fmt.Errorf("invalid value size(too small): %d", v.Value) - } - if v.Op < 0 || v.Op > math.MaxUint8 { + if v.Op > math.MaxUint8 { return nil, fmt.Errorf("invalid op size: %d", v.Op) - } + order := uint32(math.Log2(float64(v.Len()))) buf := make([]byte, 1+(1<<order)) buf[0] = byte(uint32(v.Op) | order<<4) @@ -5488,7 +5486,7 @@ func (p *PathAttributeAsPath) DecodeFromBytes(data []byte, options ...*Marshalli } for len(value) > 0 { var tuple AsPathParamInterface - if isAs4 == true { + if isAs4 { tuple = &As4PathParam{} } else { tuple = &AsPathParam{} @@ -5498,9 +5496,6 @@ func (p *PathAttributeAsPath) DecodeFromBytes(data []byte, options ...*Marshalli return err } p.Value = append(p.Value, tuple) - if tuple.Len() > len(value) { - - } value = value[tuple.Len():] } return nil @@ -5877,19 +5872,19 @@ type WellKnownCommunity uint32 const ( COMMUNITY_INTERNET WellKnownCommunity = 0x00000000 - COMMUNITY_PLANNED_SHUT = 0xffff0000 - COMMUNITY_ACCEPT_OWN = 0xffff0001 - COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 = 0xffff0002 - COMMUNITY_ROUTE_FILTER_v4 = 0xffff0003 - COMMUNITY_ROUTE_FILTER_TRANSLATED_v6 = 0xffff0004 - COMMUNITY_ROUTE_FILTER_v6 = 0xffff0005 - COMMUNITY_LLGR_STALE = 0xffff0006 - COMMUNITY_NO_LLGR = 0xffff0007 - COMMUNITY_BLACKHOLE = 0xffff029a - COMMUNITY_NO_EXPORT = 0xffffff01 - COMMUNITY_NO_ADVERTISE = 0xffffff02 - COMMUNITY_NO_EXPORT_SUBCONFED = 0xffffff03 - COMMUNITY_NO_PEER = 0xffffff04 + COMMUNITY_PLANNED_SHUT WellKnownCommunity = 0xffff0000 + COMMUNITY_ACCEPT_OWN WellKnownCommunity = 0xffff0001 + COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 WellKnownCommunity = 0xffff0002 + COMMUNITY_ROUTE_FILTER_v4 WellKnownCommunity = 0xffff0003 + COMMUNITY_ROUTE_FILTER_TRANSLATED_v6 WellKnownCommunity = 0xffff0004 + COMMUNITY_ROUTE_FILTER_v6 WellKnownCommunity = 0xffff0005 + COMMUNITY_LLGR_STALE WellKnownCommunity = 0xffff0006 + COMMUNITY_NO_LLGR WellKnownCommunity = 0xffff0007 + COMMUNITY_BLACKHOLE WellKnownCommunity = 0xffff029a + COMMUNITY_NO_EXPORT WellKnownCommunity = 0xffffff01 + COMMUNITY_NO_ADVERTISE WellKnownCommunity = 0xffffff02 + COMMUNITY_NO_EXPORT_SUBCONFED WellKnownCommunity = 0xffffff03 + COMMUNITY_NO_PEER WellKnownCommunity = 0xffffff04 ) var WellKnownCommunityNameMap = map[WellKnownCommunity]string{ @@ -5996,7 +5991,7 @@ func (p *PathAttributeOriginatorId) MarshalJSON() ([]byte, error) { } func (p *PathAttributeOriginatorId) Serialize(options ...*MarshallingOption) ([]byte, error) { - buf := make([]byte, 4, 4) + buf := make([]byte, 4) copy(buf, p.Value) return p.PathAttribute.Serialize(buf, options...) } @@ -6710,7 +6705,7 @@ type ValidationExtended struct { } func (e *ValidationExtended) Serialize() ([]byte, error) { - buf := make([]byte, 8, 8) + buf := make([]byte, 8) typ, subType := e.GetTypes() buf[0] = byte(typ) buf[1] = byte(subType) @@ -6750,7 +6745,7 @@ type ColorExtended struct { } func (e *ColorExtended) Serialize() ([]byte, error) { - buf := make([]byte, 8, 8) + buf := make([]byte, 8) typ, subType := e.GetTypes() buf[0] = byte(typ) buf[1] = byte(subType) @@ -6790,7 +6785,7 @@ type EncapExtended struct { } func (e *EncapExtended) Serialize() ([]byte, error) { - buf := make([]byte, 8, 8) + buf := make([]byte, 8) typ, subType := e.GetTypes() buf[0] = byte(typ) buf[1] = byte(subType) @@ -6850,7 +6845,7 @@ type DefaultGatewayExtended struct { } func (e *DefaultGatewayExtended) Serialize() ([]byte, error) { - buf := make([]byte, 8, 8) + buf := make([]byte, 8) typ, subType := e.GetTypes() buf[0] = byte(typ) buf[1] = byte(subType) @@ -6889,7 +6884,7 @@ func (e *OpaqueExtended) Serialize() ([]byte, error) { if len(e.Value) != 7 { return nil, fmt.Errorf("invalid value length for opaque extended community: %d", len(e.Value)) } - buf := make([]byte, 8, 8) + buf := make([]byte, 8) if e.IsTransitive { buf[0] = byte(EC_TYPE_TRANSITIVE_OPAQUE) } else { @@ -6900,7 +6895,7 @@ func (e *OpaqueExtended) Serialize() ([]byte, error) { } func (e *OpaqueExtended) String() string { - buf := make([]byte, 8, 8) + buf := make([]byte, 8) copy(buf[1:], e.Value) return fmt.Sprintf("%d", binary.BigEndian.Uint64(buf)) } @@ -6931,7 +6926,7 @@ func (e *OpaqueExtended) MarshalJSON() ([]byte, error) { } func NewOpaqueExtended(isTransitive bool, value []byte) *OpaqueExtended { - v := make([]byte, 7, 7) + v := make([]byte, 7) copy(v, value) return &OpaqueExtended{ IsTransitive: isTransitive, @@ -7552,7 +7547,7 @@ func (e *UnknownExtended) Serialize() ([]byte, error) { if len(e.Value) != 7 { return nil, fmt.Errorf("invalid value length for unknown extended community: %d", len(e.Value)) } - buf := make([]byte, 8, 8) + buf := make([]byte, 8) buf[0] = uint8(e.Type) copy(buf[1:], e.Value) return buf, nil @@ -7587,7 +7582,7 @@ func (e *UnknownExtended) GetTypes() (ExtendedCommunityAttrType, ExtendedCommuni } func NewUnknownExtended(typ ExtendedCommunityAttrType, value []byte) *UnknownExtended { - v := make([]byte, 7, 7) + v := make([]byte, 7) copy(v, value) return &UnknownExtended{ Type: typ, @@ -7731,9 +7726,11 @@ func (p *PathAttributeAs4Path) DecodeFromBytes(data []byte, options ...*Marshall if err != nil { return err } - if isAs4 == false { + + if !isAs4 { return NewMessageError(eCode, eSubCode, nil, "AS4 PATH param is malformed") } + for len(value) > 0 { tuple := &As4PathParam{} tuple.DecodeFromBytes(value) @@ -8149,7 +8146,7 @@ func (p *TunnelEncapTLV) Serialize() ([]byte, error) { } func (p *TunnelEncapTLV) String() string { - tlvList := make([]string, len(p.Value), len(p.Value)) + tlvList := make([]string, len(p.Value)) for i, v := range p.Value { tlvList[i] = v.String() } @@ -8208,7 +8205,7 @@ func (p *PathAttributeTunnelEncap) Serialize(options ...*MarshallingOption) ([]b } func (p *PathAttributeTunnelEncap) String() string { - tlvList := make([]string, len(p.Value), len(p.Value)) + tlvList := make([]string, len(p.Value)) for i, v := range p.Value { tlvList[i] = v.String() } |