diff --git a/protocols/bgp/packet/large_community.go b/protocols/bgp/packet/large_community.go index 7547fd60c1dce29886d917ae72b889613b898617..5b3f7788b16c921f114880ac36d04e8868938627 100644 --- a/protocols/bgp/packet/large_community.go +++ b/protocols/bgp/packet/large_community.go @@ -2,13 +2,10 @@ package packet import ( "fmt" - "regexp" "strconv" "strings" ) -var largeCommunityRegEx = regexp.MustCompile("^\\(?\\d+,\\d+,\\d+\\)?$") - type LargeCommunity struct { GlobalAdministrator uint32 DataPart1 uint32 @@ -20,12 +17,13 @@ func (c LargeCommunity) String() string { } func ParseLargeCommunityString(s string) (com LargeCommunity, err error) { - if !largeCommunityRegEx.Match([]byte(s)) { - return com, fmt.Errorf("malformed large community string %s", s) - } s = strings.Trim(s, "()") t := strings.Split(s, ",") + if len(t) != 3 { + return com, fmt.Errorf("can not parse large community %s", s) + } + v, err := strconv.ParseUint(t[0], 10, 32) if err != nil { return com, err