diff options
-rw-r--r-- | packet/bgp/validate.go | 15 | ||||
-rw-r--r-- | packet/bgp/validate_test.go | 15 |
2 files changed, 30 insertions, 0 deletions
diff --git a/packet/bgp/validate.go b/packet/bgp/validate.go index da7aa5fc..5cf2afbb 100644 --- a/packet/bgp/validate.go +++ b/packet/bgp/validate.go @@ -159,6 +159,21 @@ func ValidateAttribute(a PathAttributeInterface, rfs map[RouteFamily]bool, doCon } } } + case *PathAttributeLargeCommunities: + uniq := make([]*LargeCommunity, 0, len(p.Values)) + for _, x := range p.Values { + found := false + for _, y := range uniq { + if x.String() == y.String() { + found = true + break + } + } + if !found { + uniq = append(uniq, x) + } + } + p.Values = uniq case *PathAttributeUnknown: if p.GetFlags()&BGP_ATTR_FLAG_OPTIONAL == 0 { diff --git a/packet/bgp/validate_test.go b/packet/bgp/validate_test.go index 66eb56d5..225f941d 100644 --- a/packet/bgp/validate_test.go +++ b/packet/bgp/validate_test.go @@ -384,3 +384,18 @@ func Test_Validate_flowspec(t *testing.T) { _, err = ValidateAttribute(a, m, false) assert.NotNil(err) } + +func TestValidateLargeCommunities(t *testing.T) { + assert := assert.New(t) + c1, err := ParseLargeCommunity("10:10:10") + assert.Nil(err) + c2, err := ParseLargeCommunity("10:10:10") + assert.Nil(err) + c3, err := ParseLargeCommunity("10:10:20") + assert.Nil(err) + a := NewPathAttributeLargeCommunities([]*LargeCommunity{c1, c2, c3}) + assert.True(len(a.Values) == 3) + _, err = ValidateAttribute(a, nil, false) + assert.Nil(err) + assert.True(len(a.Values) == 2) +} |