From 1b57495ae934b639d103fdb18dd672de69af153c Mon Sep 17 00:00:00 2001 From: Thomas Rosenstein Date: Fri, 8 Feb 2019 12:31:56 +0100 Subject: Fix listing of prefix set in gobgp cli --- cmd/gobgp/policy.go | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/cmd/gobgp/policy.go b/cmd/gobgp/policy.go index 8c720578..05695878 100644 --- a/cmd/gobgp/policy.go +++ b/cmd/gobgp/policy.go @@ -178,19 +178,35 @@ func formatDefinedSet(head bool, typ string, indent int, list []*api.DefinedSet) buff.WriteString(fmt.Sprintf(format, "NAME", typ)) } for _, s := range list { - l := s.GetList() - if len(l) == 0 { - buff.WriteString(fmt.Sprintf(format, s.GetName(), "")) - } - for i, x := range l { - if typ == "COMMUNITY" || typ == "EXT-COMMUNITY" || typ == "LARGE-COMMUNITY" { - x = _regexpCommunity.ReplaceAllString(x, "$1") + if typ == "PREFIX" { + l := s.GetPrefixes() + if len(l) == 0 { + buff.WriteString(fmt.Sprintf(format, s.GetName(), "")) } - if i == 0 { - buff.WriteString(fmt.Sprintf(format, s.GetName(), x)) - } else { - buff.WriteString(fmt.Sprint(sIndent)) - buff.WriteString(fmt.Sprintf(format, "", x)) + for i, x := range l { + prefix := fmt.Sprintf("%s (%d - %d)", x.GetIpPrefix(), x.GetMaskLengthMin(), x.GetMaskLengthMax()) + if i == 0 { + buff.WriteString(fmt.Sprintf(format, s.GetName(), prefix)) + } else { + buff.WriteString(fmt.Sprint(sIndent)) + buff.WriteString(fmt.Sprintf(format, "", prefix)) + } + } + } else { + l := s.GetList() + if len(l) == 0 { + buff.WriteString(fmt.Sprintf(format, s.GetName(), "")) + } + for i, x := range l { + if typ == "COMMUNITY" || typ == "EXT-COMMUNITY" || typ == "LARGE-COMMUNITY" { + x = _regexpCommunity.ReplaceAllString(x, "$1") + } + if i == 0 { + buff.WriteString(fmt.Sprintf(format, s.GetName(), x)) + } else { + buff.WriteString(fmt.Sprint(sIndent)) + buff.WriteString(fmt.Sprintf(format, "", x)) + } } } } -- cgit v1.2.3