Skip to content

Commit e9218ae

Browse files
committed
Fix issue caused by different iptables versions
A backport of "nft: Optimize class-based IP prefix matches" from newer iptables versions broke the hairpin mode detection of ipv6nat. This is caused by newer versions on the host create optimized ipt rules, which will be interpreted different by older versions of iptables. This can be spotted when you dump the rules on the host and compare it to the rules dumped inside the ipv6nat container. The outside rule contains the correct subnet for the detection, 127.0.0.0/8 while inside it is displayed as 127.0.0.0/32 which causes the detection (code in manager.go) to fail. As this is only a display issue (the rule is correct), accepting both versions should be fine to get around this issue. Big thanks to Phil Sutter who provided me the code to implement my idea to cover old and new versions to be matched, as it is very hard to ensure the same iptables version to be used inside and outside the container. A test build is available on docker hub at geektoor/ipv6nat-devel. Closes: robbertkl#67 Cc: Phil Sutter <[email protected]> Signed-off-by: Sven Michels <[email protected]>
1 parent 4cd961e commit e9218ae

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

manager.go

+10
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ func detectHairpinMode() (bool, error) {
9999
return false, nil
100100
}
101101

102+
// Old iptables misinterprets prefix matches in new iptables
103+
hairpinModeOffRulespec[2] = "127.0.0.0/32"
104+
105+
hairpinModeOff, err = ipt.Exists(TableNat, ChainOutput, hairpinModeOffRulespec...)
106+
if err != nil {
107+
return false, err
108+
} else if hairpinModeOff {
109+
return false, nil
110+
}
111+
102112
return false, errors.New("unable to detect hairpin mode (is the docker daemon running?)")
103113
}
104114

0 commit comments

Comments
 (0)