From 859cedf4771364458b283a351b04326232d549b6 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Thu, 20 Aug 2015 13:42:38 +0900 Subject: server: fix for sorting adj-in/out routes Signed-off-by: FUJITA Tomonori --- table/destination.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'table') diff --git a/table/destination.go b/table/destination.go index f669cced..55c90b53 100644 --- a/table/destination.go +++ b/table/destination.go @@ -41,6 +41,16 @@ const ( BPR_ROUTER_ID = "Router ID" ) +func CidrToRadixkey(cidr string) string { + _, n, _ := net.ParseCIDR(cidr) + ones, _ := n.Mask.Size() + var buffer bytes.Buffer + for i := 0; i < len(n.IP) && i < ones; i++ { + buffer.WriteString(fmt.Sprintf("%08b", n.IP[i])) + } + return buffer.String()[:ones] +} + type PeerInfo struct { AS uint32 ID net.IP @@ -84,15 +94,7 @@ func NewDestination(nlri bgp.AddrPrefixInterface) *Destination { newPathList: make([]*Path, 0), } if d.routeFamily == bgp.RF_IPv4_UC { - d.RadixKey = func(cidr string) string { - _, n, _ := net.ParseCIDR(cidr) - ones, _ := n.Mask.Size() - var buffer bytes.Buffer - for i := 0; i < len(n.IP) && i < ones; i++ { - buffer.WriteString(fmt.Sprintf("%08b", n.IP[i])) - } - return buffer.String()[:ones] - }(nlri.String()) + d.RadixKey = CidrToRadixkey(nlri.String()) } return d } -- cgit v1.2.3