summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--api/grpc_server.go4
-rw-r--r--table/policy.go26
2 files changed, 24 insertions, 6 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index f167c13f..9fc66bde 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -1001,12 +1001,12 @@ func (s *Server) DeleteNeighbor(ctx context.Context, arg *DeleteNeighborRequest)
}
func NewPrefixFromApiStruct(a *Prefix) (*table.Prefix, error) {
- addr, prefix, err := net.ParseCIDR(a.IpPrefix)
+ _, prefix, err := net.ParseCIDR(a.IpPrefix)
if err != nil {
return nil, err
}
rf := bgp.RF_IPv4_UC
- if addr.To4() == nil {
+ if strings.Contains(a.IpPrefix, ":") {
rf = bgp.RF_IPv6_UC
}
return &table.Prefix{
diff --git a/table/policy.go b/table/policy.go
index fe1dcaf8..edaf3a3e 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -285,14 +285,32 @@ func (lhs *Prefix) Equal(rhs *Prefix) bool {
return lhs.Prefix.String() == rhs.Prefix.String() && lhs.MasklengthRangeMin == rhs.MasklengthRangeMin && lhs.MasklengthRangeMax == rhs.MasklengthRangeMax
}
+func (p *Prefix) PrefixString() string {
+ isZeros := func(p net.IP) bool {
+ for i := 0; i < len(p); i++ {
+ if p[i] != 0 {
+ return false
+ }
+ }
+ return true
+ }
+
+ ip := p.Prefix.IP
+ if p.AddressFamily == bgp.RF_IPv6_UC && isZeros(ip[0:10]) && ip[10] == 0xff && ip[11] == 0xff {
+ m, _ := p.Prefix.Mask.Size()
+ return fmt.Sprintf("::FFFF:%s/%d", ip.To16(), m)
+ }
+ return p.Prefix.String()
+}
+
func NewPrefix(c config.Prefix) (*Prefix, error) {
- addr, prefix, err := net.ParseCIDR(c.IpPrefix)
+ _, prefix, err := net.ParseCIDR(c.IpPrefix)
if err != nil {
return nil, err
}
rf := bgp.RF_IPv4_UC
- if addr.To4() == nil {
+ if strings.Contains(c.IpPrefix, ":") {
rf = bgp.RF_IPv6_UC
}
p := &Prefix{
@@ -420,7 +438,7 @@ func (s *PrefixSet) List() []string {
s.tree.Walk(func(s string, v interface{}) bool {
ps := v.([]*Prefix)
for _, p := range ps {
- list = append(list, fmt.Sprintf("%s %d..%d", p.Prefix.String(), p.MasklengthRangeMin, p.MasklengthRangeMax))
+ list = append(list, fmt.Sprintf("%s %d..%d", p.PrefixString(), p.MasklengthRangeMin, p.MasklengthRangeMax))
}
return false
})
@@ -432,7 +450,7 @@ func (s *PrefixSet) ToConfig() *config.PrefixSet {
s.tree.Walk(func(s string, v interface{}) bool {
ps := v.([]*Prefix)
for _, p := range ps {
- list = append(list, config.Prefix{IpPrefix: p.Prefix.String(), MasklengthRange: fmt.Sprintf("%d..%d", p.MasklengthRangeMin, p.MasklengthRangeMax)})
+ list = append(list, config.Prefix{IpPrefix: p.PrefixString(), MasklengthRange: fmt.Sprintf("%d..%d", p.MasklengthRangeMin, p.MasklengthRangeMax)})
}
return false
})