diff options
-rw-r--r-- | gobgp/cmd/policy.go | 7 | ||||
-rw-r--r-- | table/policy.go | 8 |
2 files changed, 10 insertions, 5 deletions
diff --git a/gobgp/cmd/policy.go b/gobgp/cmd/policy.go index 2eba8951..c58bbf53 100644 --- a/gobgp/cmd/policy.go +++ b/gobgp/cmd/policy.go @@ -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 diff --git a/table/policy.go b/table/policy.go index 2a8c759f..8a174284 100644 --- a/table/policy.go +++ b/table/policy.go @@ -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 } } |