fix community-set match all evaluation and remove regexp special chars from cli output of community strings

This commit is contained in:
tamihiro
2016-04-20 12:19:35 +09:00
committed by FUJITA Tomonori
parent 4e07254d0a
commit e06bb04f14
2 changed files with 10 additions and 5 deletions
+6 -1
View File
@@ -119,6 +119,10 @@ func formatDefinedSet(head bool, typ string, indent int, list []*api.DefinedSet)
buff.WriteString(fmt.Sprintf(format, s.Name, ""))
}
for i, x := range s.List {
if typ == "COMMUNITY" || typ == "EXT-COMMUNITY" {
exp := regexp.MustCompile("\\^(\\S+)\\$")
x = exp.ReplaceAllString(x, "$1")
}
if i == 0 {
buff.WriteString(fmt.Sprintf(format, s.Name, x))
} else {
@@ -446,7 +450,8 @@ func printStatement(indent int, s *api.Statement) {
formatComAction := func(c *api.CommunityAction) string {
option := c.Type.String()
if len(c.Communities) != 0 {
communities := strings.Join(c.Communities, ",")
exp := regexp.MustCompile("[\\^\\$]")
communities := exp.ReplaceAllString(strings.Join(c.Communities, ","), "")
option = fmt.Sprintf("%s[%s]", c.Type, communities)
}
return option
+4 -4
View File
@@ -1345,10 +1345,10 @@ func (c *CommunityCondition) ToApiStruct() *api.MatchSet {
func (c *CommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
cs := path.GetCommunities()
result := false
for _, x := range cs {
for _, x := range c.set.list {
result = false
for _, y := range c.set.list {
if y.MatchString(fmt.Sprintf("%d:%d", x>>16, x&0x0000ffff)) {
for _, y := range cs {
if x.MatchString(fmt.Sprintf("%d:%d", y>>16, y&0x0000ffff)) {
result = true
break
}
@@ -1356,7 +1356,7 @@ func (c *CommunityCondition) Evaluate(path *Path, _ *PolicyOptions) bool {
if c.option == MATCH_OPTION_ALL && !result {
break
}
if c.option == MATCH_OPTION_ANY && result {
if (c.option == MATCH_OPTION_ANY || c.option == MATCH_OPTION_INVERT) && result {
break
}
}