routes_freebsd.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package local
  2. import (
  3. "net"
  4. "github.com/c-robinson/iplib"
  5. "github.com/gravitl/netmaker/logger"
  6. "github.com/gravitl/netmaker/netclient/ncutils"
  7. )
  8. func setRoute(iface string, addr *net.IPNet, address string) error {
  9. var err error
  10. _, _ = ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
  11. return err
  12. }
  13. func deleteRoute(iface string, addr *net.IPNet, address string) error {
  14. var err error
  15. _, _ = ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, false)
  16. return err
  17. }
  18. func setCidr(iface, address string, addr *net.IPNet) {
  19. if iplib.Version(addr.IP) == 4 {
  20. ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
  21. } else if iplib.Version(addr.IP) == 6 {
  22. ncutils.RunCmd("route add -net -inet6 "+addr.String()+" -interface "+iface, false)
  23. } else {
  24. logger.Log(1, "could not parse address: "+addr.String())
  25. }
  26. ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
  27. }
  28. func removeCidr(iface string, addr *net.IPNet, address string) {
  29. ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, false)
  30. }