Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit e925dec

Browse files
committed
Fix iptables for old systems
The iptables args list needs to include all fields as they are eventually spit out by iptables-save. This is because some systems do not support the 'iptables -C' arg, and so fall back on parsing iptables-save output. If this does not match, it will not pass the check. For example: adding the /32 on the destination IP arg is not strictly required, but causes this list to not match the final iptables-save output. This is fragile and I hope one day we can stop supporting such old iptables versions.
1 parent b614f22 commit e925dec

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

pkg/proxy/proxier.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,20 @@ var localhostIPv6 = net.ParseIP("::1")
578578

579579
// Build a slice of iptables args for a portal rule.
580580
func iptablesPortalArgs(destIP net.IP, destPort int, protocol api.Protocol, proxyIP net.IP, proxyPort int, service string) []string {
581+
// This list needs to include all fields as they are eventually spit out
582+
// by iptables-save. This is because some systems do not support the
583+
// 'iptables -C' arg, and so fall back on parsing iptables-save output.
584+
// If this does not match, it will not pass the check. For example:
585+
// adding the /32 on the destination IP arg is not strictly required,
586+
// but causes this list to not match the final iptables-save output.
587+
// This is fragile and I hope one day we can stop supporting such old
588+
// iptables versions.
581589
args := []string{
582590
"-m", "comment",
583591
"--comment", service,
584592
"-p", strings.ToLower(string(protocol)),
585-
"-d", destIP.String(),
593+
"-m", strings.ToLower(string(protocol)),
594+
"-d", fmt.Sprintf("%s/32", destIP.String()),
586595
"--dport", fmt.Sprintf("%d", destPort),
587596
}
588597
// This is tricky. If the proxy is bound (see Proxier.listenAddress)

pkg/util/iptables/iptables.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (runner *runner) checkRule(table Table, chain Chain, args ...string) (bool,
189189
// Executes the rule check without using the "-C" flag, instead parsing iptables-save.
190190
// Present for compatibility with <1.4.11 versions of iptables.
191191
func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...string) (bool, error) {
192+
glog.V(1).Infof("running iptables-save -t %s", string(table))
192193
out, err := runner.exec.Command("iptables-save", "-t", string(table)).CombinedOutput()
193194
if err != nil {
194195
return false, fmt.Errorf("error checking rule: %v", err)
@@ -206,6 +207,7 @@ func (runner *runner) checkRuleWithoutCheck(table Table, chain Chain, args ...st
206207
if util.NewStringSet(fields...).IsSuperset(argset) {
207208
return true, nil
208209
}
210+
glog.V(5).Infof("DBG: fields is not a superset of args: fields=%v args=%v", fields, args)
209211
}
210212
}
211213

0 commit comments

Comments
 (0)