@@ -1649,6 +1649,39 @@ func (proxier *Proxier) writeIptablesRules() {
16491649 )
16501650 }
16511651
1652+ // Install the kubernetes-specific postrouting rules. We use a whole chain for
1653+ // this so that it is easier to flush and change, for example if the mark
1654+ // value should ever change.
1655+ // NB: THIS MUST MATCH the corresponding code in the kubelet
1656+ writeLine (proxier .natRules , []string {
1657+ "-A" , string (kubePostroutingChain ),
1658+ "-m" , "mark" , "!" , "--mark" , fmt .Sprintf ("%s/%s" , proxier .masqueradeMark , proxier .masqueradeMark ),
1659+ "-j" , "RETURN" ,
1660+ }... )
1661+ // Clear the mark to avoid re-masquerading if the packet re-traverses the network stack.
1662+ writeLine (proxier .natRules , []string {
1663+ "-A" , string (kubePostroutingChain ),
1664+ // XOR proxier.masqueradeMark to unset it
1665+ "-j" , "MARK" , "--xor-mark" , proxier .masqueradeMark ,
1666+ }... )
1667+ masqRule := []string {
1668+ "-A" , string (kubePostroutingChain ),
1669+ "-m" , "comment" , "--comment" , `"kubernetes service traffic requiring SNAT"` ,
1670+ "-j" , "MASQUERADE" ,
1671+ }
1672+ if proxier .iptables .HasRandomFully () {
1673+ masqRule = append (masqRule , "--random-fully" )
1674+ }
1675+ writeLine (proxier .natRules , masqRule ... )
1676+
1677+ // Install the kubernetes-specific masquerade mark rule. We use a whole chain for
1678+ // this so that it is easier to flush and change, for example if the mark
1679+ // value should ever change.
1680+ writeLine (proxier .natRules , []string {
1681+ "-A" , string (KubeMarkMasqChain ),
1682+ "-j" , "MARK" , "--or-mark" , proxier .masqueradeMark ,
1683+ }... )
1684+
16521685 // Write the end-of-table markers.
16531686 writeLine (proxier .filterRules , "COMMIT" )
16541687 writeLine (proxier .natRules , "COMMIT" )
@@ -1707,41 +1740,6 @@ func (proxier *Proxier) createAndLinkeKubeChain() {
17071740 }
17081741 }
17091742
1710- // Install the kubernetes-specific postrouting rules. We use a whole chain for
1711- // this so that it is easier to flush and change, for example if the mark
1712- // value should ever change.
1713- // NB: THIS MUST MATCH the corresponding code in the kubelet
1714- writeLine (proxier .natRules , []string {
1715- "-A" , string (kubePostroutingChain ),
1716- "-m" , "mark" , "!" , "--mark" , fmt .Sprintf ("%s/%s" , proxier .masqueradeMark , proxier .masqueradeMark ),
1717- "-j" , "RETURN" ,
1718- }... )
1719- // Clear the mark to avoid re-masquerading if the packet re-traverses the network stack.
1720- writeLine (proxier .natRules , []string {
1721- "-A" , string (kubePostroutingChain ),
1722- // XOR proxier.masqueradeMark to unset it
1723- "-j" , "MARK" , "--xor-mark" , proxier .masqueradeMark ,
1724- }... )
1725- masqRule := []string {
1726- "-A" , string (kubePostroutingChain ),
1727- "-m" , "comment" , "--comment" , `"kubernetes service traffic requiring SNAT"` ,
1728- "-j" , "MASQUERADE" ,
1729- }
1730- if proxier .iptables .HasRandomFully () {
1731- masqRule = append (masqRule , "--random-fully" )
1732- klog .V (3 ).Info ("Using `--random-fully` in the MASQUERADE rule for iptables" )
1733- } else {
1734- klog .V (2 ).Info ("Not using `--random-fully` in the MASQUERADE rule for iptables because the local version of iptables does not support it" )
1735- }
1736- writeLine (proxier .natRules , masqRule ... )
1737-
1738- // Install the kubernetes-specific masquerade mark rule. We use a whole chain for
1739- // this so that it is easier to flush and change, for example if the mark
1740- // value should ever change.
1741- writeLine (proxier .natRules , []string {
1742- "-A" , string (KubeMarkMasqChain ),
1743- "-j" , "MARK" , "--or-mark" , proxier .masqueradeMark ,
1744- }... )
17451743}
17461744
17471745// getExistingChains get iptables-save output so we can check for existing chains and rules.
0 commit comments