Last active
November 15, 2024 06:58
-
-
Save LionelJouin/37ed49f95256cc95456a50cee4277373 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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