freebsd join, checkin, and leave functional

This commit is contained in:
afeiszli
2021-11-09 23:44:39 +00:00
parent 317a639bf5
commit c4303d2499
4 changed files with 35 additions and 7 deletions

View File

@@ -19,7 +19,9 @@ func SetIPForwarding() error {
var err error
switch os {
case "linux":
err = SetIPForwardingLinux()
err = SetIPForwardingUnix()
case "freebsd":
err = SetIPForwardingFreeBSD()
case "darwin":
err = SetIPForwardingMac()
default:
@@ -29,7 +31,7 @@ func SetIPForwarding() error {
}
// SetIPForwardingLinux - sets the ipforwarding for linux
func SetIPForwardingLinux() error {
func SetIPForwardingUnix() error {
out, err := ncutils.RunCmd("sysctl net.ipv4.ip_forward", true)
if err != nil {
log.Println("WARNING: Error encountered setting ip forwarding. This can break functionality.")
@@ -47,6 +49,25 @@ func SetIPForwardingLinux() error {
return nil
}
// SetIPForwardingLinux - sets the ipforwarding for linux
func SetIPForwardingFreeBSD() error {
out, err := ncutils.RunCmd("sysctl net.inet.ip.forwarding", true)
if err != nil {
log.Println("WARNING: Error encountered setting ip forwarding. This can break functionality.")
return err
} else {
s := strings.Fields(string(out))
if s[1] != "1" {
_, err = ncutils.RunCmd("sysctl -w net.inet.ip.forwarding=1", true)
if err != nil {
log.Println("WARNING: Error encountered setting ip forwarding. You may want to investigate this.")
return err
}
}
}
return nil
}
// SetIPForwardingMac - sets ip forwarding for mac
func SetIPForwardingMac() error {
_, err := ncutils.RunCmd("sysctl -w net.inet.ip.forwarding=1", true)