Skip to content

Instantly share code, notes, and snippets.

@LionelJouin
Last active November 15, 2024 06:58
Show Gist options
  • Save LionelJouin/37ed49f95256cc95456a50cee4277373 to your computer and use it in GitHub Desktop.
Save LionelJouin/37ed49f95256cc95456a50cee4277373 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net"
"github.com/vishvananda/netlink"
)
func main() {
nexthops := []*netlink.NexthopInfo{}
for i := 1; i < 254; i++ {
nexthops = append(nexthops, &netlink.NexthopInfo{
Gw: net.ParseIP(fmt.Sprintf("172.18.0.%d", i)),
})
}
_, ipNet, _ := net.ParseCIDR("20.0.0.1/32")
route := &netlink.Route{
Dst: ipNet,
MultiPath: nexthops,
Family: netlink.FAMILY_V4,
Table: 2500,
}
err := netlink.RouteReplace(route)
fmt.Println(err)
routeList, err := netlink.RouteListFiltered(netlink.FAMILY_ALL, &netlink.Route{Table: 2500}, netlink.RT_FILTER_TABLE)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(routeList)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment