diff options
author | Chris Stockton <cstockton@godaddy.com> | 2017-05-31 08:37:09 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-05-31 08:37:09 +0900 |
commit | b529f81ed7d8428200a3f5dcf99a57db9f9f769e (patch) | |
tree | 03f9916f6e26307f8226a158e72d1c8b71ec35d4 /table/destination.go | |
parent | b4831ce8e91e6f27e3b241efd0c3fdfd8feca43a (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.go | 20 |
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 } |