netmaker/netclient/local/routes_freebsd.go

38 lines
1.1 KiB
Go
Raw Normal View History

2022-02-04 08:55:12 +08:00
package local
import (
"net"
2022-04-26 01:22:56 +08:00
"github.com/gravitl/netmaker/logger"
2022-02-04 08:55:12 +08:00
"github.com/gravitl/netmaker/netclient/ncutils"
2022-04-26 01:22:56 +08:00
"github.com/seancfoley/ipaddress-go/ipaddr"
2022-02-04 08:55:12 +08:00
)
func setRoute(iface string, addr *net.IPNet, address string) error {
var err error
2022-02-06 04:00:26 +08:00
_, _ = ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
2022-02-04 08:55:12 +08:00
return err
}
func deleteRoute(iface string, addr *net.IPNet, address string) error {
var err error
2022-02-08 00:29:10 +08:00
_, _ = ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, false)
2022-02-04 08:55:12 +08:00
return err
}
func setCidr(iface, address string, addr *net.IPNet) {
2022-04-20 04:18:03 +08:00
cidr := ipaddr.NewIPAddressString(addr.String()).GetAddress()
if cidr.IsIPv4() {
ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
} else if cidr.IsIPv6() {
ncutils.RunCmd("route add -net -inet6 "+addr.String()+" -interface "+iface, false)
} else {
logger.Log(1, "could not parse address: "+addr.String())
}
2022-02-06 04:00:26 +08:00
ncutils.RunCmd("route add -net "+addr.String()+" -interface "+iface, false)
}
func removeCidr(iface string, addr *net.IPNet, address string) {
ncutils.RunCmd("route delete -net "+addr.String()+" -interface "+iface, false)
}