summaryrefslogtreecommitdiffhomepage
path: root/table/destination.go
diff options
context:
space:
mode:
authorChris Stockton <cstockton@godaddy.com>2017-05-31 08:37:09 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-05-31 08:37:09 +0900
commitb529f81ed7d8428200a3f5dcf99a57db9f9f769e (patch)
tree03f9916f6e26307f8226a158e72d1c8b71ec35d4 /table/destination.go
parentb4831ce8e91e6f27e3b241efd0c3fdfd8feca43a (diff)
table: reduce allocs in NewDestination
In NewDestination we add additional path to AddrToRadixkey to check the concrete type of nlri.
Diffstat (limited to 'table/destination.go')
-rw-r--r--table/destination.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/table/destination.go b/table/destination.go
index 3535bbfe..9664fdbc 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -64,6 +64,24 @@ func CidrToRadixkey(cidr string) string {
return IpToRadixkey(n.IP, uint8(ones))
}
+func AddrToRadixkey(addr bgp.AddrPrefixInterface) string {
+ var (
+ ip net.IP
+ size uint8
+ )
+ switch T := addr.(type) {
+ case *bgp.IPAddrPrefix:
+ mask := net.CIDRMask(int(T.Length), net.IPv4len*8)
+ ip, size = T.Prefix.Mask(mask).To4(), uint8(T.Length)
+ case *bgp.IPv6AddrPrefix:
+ mask := net.CIDRMask(int(T.Length), net.IPv6len*8)
+ ip, size = T.Prefix.Mask(mask).To16(), uint8(T.Length)
+ default:
+ return CidrToRadixkey(addr.String())
+ }
+ return IpToRadixkey(ip, size)
+}
+
type PeerInfo struct {
AS uint32
ID net.IP
@@ -140,7 +158,7 @@ func NewDestination(nlri bgp.AddrPrefixInterface, known ...*Path) *Destination {
}
switch d.routeFamily {
case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC, bgp.RF_IPv4_MPLS, bgp.RF_IPv6_MPLS:
- d.RadixKey = CidrToRadixkey(nlri.String())
+ d.RadixKey = AddrToRadixkey(nlri)
}
return d
}