Skip to content

Commit

Permalink
Merge pull request #2351 from daym/fewer-modprobes
Browse files Browse the repository at this point in the history
Use fewer modprobes
  • Loading branch information
selansen authored Jul 25, 2019
2 parents 3fb133e + 9ae9394 commit 5eb06eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
10 changes: 6 additions & 4 deletions iptables/iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ func (e ChainError) Error() string {
}

func probe() {
if out, err := exec.Command("modprobe", "-va", "nf_nat").CombinedOutput(); err != nil {
logrus.Warnf("Running modprobe nf_nat failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
path, err := exec.LookPath("iptables")
if err != nil {
logrus.Warnf("Failed to find iptables: %v", err)
return
}
if out, err := exec.Command("modprobe", "-va", "xt_conntrack").CombinedOutput(); err != nil {
logrus.Warnf("Running modprobe xt_conntrack failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
if out, err := exec.Command(path, "--wait", "-t", "nat", "-L", "-n").CombinedOutput(); err != nil {
logrus.Warnf("Running iptables --wait -t nat -L -n failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
}
}

Expand Down
18 changes: 2 additions & 16 deletions ns/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,8 @@ func NlHandle() *netlink.Handle {
func getSupportedNlFamilies() []int {
fams := []int{syscall.NETLINK_ROUTE}
// NETLINK_XFRM test
if err := loadXfrmModules(); err != nil {
if checkXfrmSocket() != nil {
logrus.Warnf("Could not load necessary modules for IPSEC rules: %v", err)
} else {
fams = append(fams, syscall.NETLINK_XFRM)
}
if err := checkXfrmSocket(); err != nil {
logrus.Warnf("Could not load necessary modules for IPSEC rules: %v", err)
} else {
fams = append(fams, syscall.NETLINK_XFRM)
}
Expand All @@ -99,16 +95,6 @@ func getSupportedNlFamilies() []int {
return fams
}

func loadXfrmModules() error {
if out, err := exec.Command("modprobe", "-va", "xfrm_user").CombinedOutput(); err != nil {
return fmt.Errorf("Running modprobe xfrm_user failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
}
if out, err := exec.Command("modprobe", "-va", "xfrm_algo").CombinedOutput(); err != nil {
return fmt.Errorf("Running modprobe xfrm_algo failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
}
return nil
}

// API check on required xfrm modules (xfrm_user, xfrm_algo)
func checkXfrmSocket() error {
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_XFRM)
Expand Down

0 comments on commit 5eb06eb

Please sign in to comment.