summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortamihiro <dead6oy@gmail.com>2016-04-18 17:03:39 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-04-20 12:19:35 +0900
commite06bb04f14bc24eddf24e40aa340a8a05a99c637 (patch)
tree40dc58e25c44e2b9f3dc181e40f259350d3abd39
parent4e07254d0a0d52099d1cc12b4a3fcd6cb97132bd (diff)
fix community-set match all evaluation and remove regexp special chars from cli output of community strings
-rw-r--r--gobgp/cmd/policy.go7
-rw-r--r--table/policy.go8
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
}
}