Skip to content

Commit

Permalink
gremlin: fix nexthop for IP being default and destination
Browse files Browse the repository at this point in the history
  • Loading branch information
safchain committed Aug 1, 2019
1 parent b1ac319 commit 5034336
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions topology/nexthop.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,47 @@ func GetNextHop(node *graph.Node, ip net.IP) (*NextHop, error) {
for _, t := range *rts {
var defaultRouteIP net.IP
var defaultIfIndex int64
var nh *NextHop

getNeighbor := func(ip net.IP) string {
if neighbors != nil {
return neighbors.getMAC(ip)
}
return ""
}

for _, r := range t.Routes {
ipnet := net.IPNet(r.Prefix)
if r.Prefix.IsDefaultRoute() {
defaultRouteIP = r.NextHops[0].IP
defaultIfIndex = r.NextHops[0].IfIndex
} else if ipnet.Contains(ip) {
nextIP := r.NextHops[0].IP
nh := &NextHop{IfIndex: r.NextHops[0].IfIndex}
if nextIP != nil {
nh.IP = nextIP
if neighbors != nil {
nh.MAC = neighbors.getMAC(nextIP)
}
nh = &NextHop{IfIndex: r.NextHops[0].IfIndex}

if r.NextHops[0].IP != nil {
nh.IP = r.NextHops[0].IP
nh.MAC = getNeighbor(nh.IP)

// dedicated NH so return here
return nh, nil
}
return nh, nil

// same network but maybe a dedicated route, keep checking
nh.IP = ip
nh.MAC = getNeighbor(nh.IP)
}
}

// one route found
if nh != nil {
return nh, nil
}

// no route found try with the default
if defaultRouteIP != nil {
nh := &NextHop{IP: defaultRouteIP, IfIndex: defaultIfIndex}
if neighbors != nil {
nh.MAC = neighbors.getMAC(defaultRouteIP)
}
nh.MAC = getNeighbor(nh.IP)

return nh, nil
}
}
Expand Down

0 comments on commit 5034336

Please sign in to comment.