diff --git a/cmd/jailhost.go b/cmd/jailhost.go index 4d0ad2b..2ab43f0 100644 --- a/cmd/jailhost.go +++ b/cmd/jailhost.go @@ -4,6 +4,8 @@ import ( "fmt" "golang.org/x/net/route" "net" + "regexp" + "strings" ) var defaultRoute4 = [4]byte{0, 0, 0, 0} @@ -103,3 +105,22 @@ func (jh *JailHost) GetDefaultGateway6() string { } return jh.default_gateway6 } + +func getHostInUseIPv4() ([]string, error) { + var ips []string + + re := regexp.MustCompile(ifconfigipv4re) + + out, err := executeCommand("/sbin/ifconfig") + if err != nil { + return ips, fmt.Errorf("ERROR executing \"/sbin/ifconfig\": %s", err) + } + + for _, line := range strings.Split(out, "\n") { + if re.MatchString(line) { + ips = append(ips, re.FindStringSubmatch(line)[1]) + } + } + + return ips, nil +} diff --git a/cmd/start.go b/cmd/start.go index f728268..27e0256 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -229,12 +229,6 @@ func prepareJailedZfsDatasets(jail *Jail) error { return nil } -type NatDesc struct { - Proto string - JailPort string - HostPort string -} - // tcp(80:8080),tcp(3300-3310:33060-33070) func getNatForwardsArray(nat_forwards string, decompose_range bool) ([]NatDesc, error) { var res []NatDesc @@ -282,24 +276,6 @@ func getNatForwardsArray(nat_forwards string, decompose_range bool) ([]NatDesc, return res, nil } -func enableRcKeyValue(rcconfpath string, key string, value string) error { - cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s %s=%s", rcconfpath, key, value) - _, err := executeCommand(cmd) - if err != nil { - return err - } - return nil -} - -func disableRcKey(rcconfpath string, key string) error { - cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s -x %s", rcconfpath, key) - _, err := executeCommand(cmd) - if err != nil { - return err - } - return nil -} - /***************************************************************************** * Enable or disables DHCP or accept_rtadv for interfaces declared with this * option @@ -433,25 +409,6 @@ func getJailsInUseIPv4() ([]string, error) { return ips, nil } -func getHostInUseIPv4() ([]string, error) { - var ips []string - - re := regexp.MustCompile(ifconfigipv4re) - - out, err := executeCommand("/sbin/ifconfig") - if err != nil { - return ips, fmt.Errorf("ERROR executing \"/sbin/ifconfig\": %s", err) - } - - for _, line := range strings.Split(out, "\n") { - if re.MatchString(line) { - ips = append(ips, re.FindStringSubmatch(line)[1]) - } - } - - return ips, nil -} - func genNatIpv4(jail *Jail) ([]string, error) { var ippair []string diff --git a/cmd/struct.go b/cmd/struct.go index f2c5fdc..47b2bbe 100644 --- a/cmd/struct.go +++ b/cmd/struct.go @@ -9,6 +9,12 @@ const ( IPv6 = 1 ) +type NatDesc struct { + Proto string + JailPort string + HostPort string +} + // To allow sorting, just duplicate fields in JailSort below type Jail struct { Name string diff --git a/cmd/utils.go b/cmd/utils.go index 77bf1ce..0b1beab 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -214,6 +214,29 @@ func executeCommandInJail(jail *Jail, cmdline string) (string, error) { return string(out), err } +/***************************************************************************** + * + * rc.conf management + * + *****************************************************************************/ +func enableRcKeyValue(rcconfpath string, key string, value string) error { + cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s %s=%s", rcconfpath, key, value) + _, err := executeCommand(cmd) + if err != nil { + return err + } + return nil +} + +func disableRcKey(rcconfpath string, key string) error { + cmd := fmt.Sprintf("/usr/sbin/sysrc -f %s -x %s", rcconfpath, key) + _, err := executeCommand(cmd) + if err != nil { + return err + } + return nil +} + /***************************************************************************** * Parse an fstab file, returning an array of Mount *****************************************************************************/