Trying to print a list of routes from within a network namespace. The netlink.RouteList function requires an Interface type. A list of all interfaces is gathered by LinkList().
I'm trying to call RouteList with every interface and print it's output. RouteList returns type Route where I'm trying to print the int LinkIndex.
It appears as if my loop
for j := range rt {
log.Printf("Route: %d : %d",rt[j].LinkIndex)
}
Isn't executing for some reason, running another Printf test in there yields nothing.
Why wouldn't this loop be called?
func (h *NSHandle) showInts() {
nh := (*netlink.Handle)(h) //cast required
int, err := nh.LinkList()
if err != nil {
log.Fatal(err)
}
log.Printf("Namespace Ints:")
for i, r := range int {
log.Printf("%d: %s", i, r.Attrs().Name)
rt, err := netlink.RouteList(r,-1)
if err != nil {
log.Fatal(err)
}
for j := range rt {
log.Printf("Route: %d : %d",rt[j].LinkIndex)
}
}
}