Skip to content

Commit 5eb06eb

Browse files
authored
Merge pull request #2351 from daym/fewer-modprobes
Use fewer modprobes
2 parents 3fb133e + 9ae9394 commit 5eb06eb

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

iptables/iptables.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ func (e ChainError) Error() string {
7272
}
7373

7474
func probe() {
75-
if out, err := exec.Command("modprobe", "-va", "nf_nat").CombinedOutput(); err != nil {
76-
logrus.Warnf("Running modprobe nf_nat failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
75+
path, err := exec.LookPath("iptables")
76+
if err != nil {
77+
logrus.Warnf("Failed to find iptables: %v", err)
78+
return
7779
}
78-
if out, err := exec.Command("modprobe", "-va", "xt_conntrack").CombinedOutput(); err != nil {
79-
logrus.Warnf("Running modprobe xt_conntrack failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
80+
if out, err := exec.Command(path, "--wait", "-t", "nat", "-L", "-n").CombinedOutput(); err != nil {
81+
logrus.Warnf("Running iptables --wait -t nat -L -n failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
8082
}
8183
}
8284

ns/init_linux.go

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,8 @@ func NlHandle() *netlink.Handle {
7676
func getSupportedNlFamilies() []int {
7777
fams := []int{syscall.NETLINK_ROUTE}
7878
// NETLINK_XFRM test
79-
if err := loadXfrmModules(); err != nil {
80-
if checkXfrmSocket() != nil {
81-
logrus.Warnf("Could not load necessary modules for IPSEC rules: %v", err)
82-
} else {
83-
fams = append(fams, syscall.NETLINK_XFRM)
84-
}
79+
if err := checkXfrmSocket(); err != nil {
80+
logrus.Warnf("Could not load necessary modules for IPSEC rules: %v", err)
8581
} else {
8682
fams = append(fams, syscall.NETLINK_XFRM)
8783
}
@@ -99,16 +95,6 @@ func getSupportedNlFamilies() []int {
9995
return fams
10096
}
10197

102-
func loadXfrmModules() error {
103-
if out, err := exec.Command("modprobe", "-va", "xfrm_user").CombinedOutput(); err != nil {
104-
return fmt.Errorf("Running modprobe xfrm_user failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
105-
}
106-
if out, err := exec.Command("modprobe", "-va", "xfrm_algo").CombinedOutput(); err != nil {
107-
return fmt.Errorf("Running modprobe xfrm_algo failed with message: `%s`, error: %v", strings.TrimSpace(string(out)), err)
108-
}
109-
return nil
110-
}
111-
11298
// API check on required xfrm modules (xfrm_user, xfrm_algo)
11399
func checkXfrmSocket() error {
114100
fd, err := syscall.Socket(syscall.AF_NETLINK, syscall.SOCK_RAW, syscall.NETLINK_XFRM)

0 commit comments

Comments
 (0)