@@ -1787,6 +1787,39 @@ func (proxier *Proxier) writeIptablesRules() {
1787
1787
"-j" , "ACCEPT" ,
1788
1788
)
1789
1789
1790
+ // Install the kubernetes-specific postrouting rules. We use a whole chain for
1791
+ // this so that it is easier to flush and change, for example if the mark
1792
+ // value should ever change.
1793
+ // NB: THIS MUST MATCH the corresponding code in the kubelet
1794
+ writeLine (proxier .natRules , []string {
1795
+ "-A" , string (kubePostroutingChain ),
1796
+ "-m" , "mark" , "!" , "--mark" , fmt .Sprintf ("%s/%s" , proxier .masqueradeMark , proxier .masqueradeMark ),
1797
+ "-j" , "RETURN" ,
1798
+ }... )
1799
+ // Clear the mark to avoid re-masquerading if the packet re-traverses the network stack.
1800
+ writeLine (proxier .natRules , []string {
1801
+ "-A" , string (kubePostroutingChain ),
1802
+ // XOR proxier.masqueradeMark to unset it
1803
+ "-j" , "MARK" , "--xor-mark" , proxier .masqueradeMark ,
1804
+ }... )
1805
+ masqRule := []string {
1806
+ "-A" , string (kubePostroutingChain ),
1807
+ "-m" , "comment" , "--comment" , `"kubernetes service traffic requiring SNAT"` ,
1808
+ "-j" , "MASQUERADE" ,
1809
+ }
1810
+ if proxier .iptables .HasRandomFully () {
1811
+ masqRule = append (masqRule , "--random-fully" )
1812
+ }
1813
+ writeLine (proxier .natRules , masqRule ... )
1814
+
1815
+ // Install the kubernetes-specific masquerade mark rule. We use a whole chain for
1816
+ // this so that it is easier to flush and change, for example if the mark
1817
+ // value should ever change.
1818
+ writeLine (proxier .natRules , []string {
1819
+ "-A" , string (KubeMarkMasqChain ),
1820
+ "-j" , "MARK" , "--or-mark" , proxier .masqueradeMark ,
1821
+ }... )
1822
+
1790
1823
// Write the end-of-table markers.
1791
1824
writeLine (proxier .filterRules , "COMMIT" )
1792
1825
writeLine (proxier .natRules , "COMMIT" )
@@ -1845,38 +1878,6 @@ func (proxier *Proxier) createAndLinkeKubeChain() {
1845
1878
}
1846
1879
}
1847
1880
1848
- // Install the kubernetes-specific postrouting rules. We use a whole chain for
1849
- // this so that it is easier to flush and change, for example if the mark
1850
- // value should ever change.
1851
- // NB: THIS MUST MATCH the corresponding code in the kubelet
1852
- writeLine (proxier .natRules , []string {
1853
- "-A" , string (kubePostroutingChain ),
1854
- "-m" , "mark" , "!" , "--mark" , fmt .Sprintf ("%s/%s" , proxier .masqueradeMark , proxier .masqueradeMark ),
1855
- "-j" , "RETURN" ,
1856
- }... )
1857
- // Clear the mark to avoid re-masquerading if the packet re-traverses the network stack.
1858
- writeLine (proxier .natRules , []string {
1859
- "-A" , string (kubePostroutingChain ),
1860
- // XOR proxier.masqueradeMark to unset it
1861
- "-j" , "MARK" , "--xor-mark" , proxier .masqueradeMark ,
1862
- }... )
1863
- masqRule := []string {
1864
- "-A" , string (kubePostroutingChain ),
1865
- "-m" , "comment" , "--comment" , `"kubernetes service traffic requiring SNAT"` ,
1866
- "-j" , "MASQUERADE" ,
1867
- }
1868
- if proxier .iptables .HasRandomFully () {
1869
- masqRule = append (masqRule , "--random-fully" )
1870
- }
1871
- writeLine (proxier .natRules , masqRule ... )
1872
-
1873
- // Install the kubernetes-specific masquerade mark rule. We use a whole chain for
1874
- // this so that it is easier to flush and change, for example if the mark
1875
- // value should ever change.
1876
- writeLine (proxier .natRules , []string {
1877
- "-A" , string (KubeMarkMasqChain ),
1878
- "-j" , "MARK" , "--or-mark" , proxier .masqueradeMark ,
1879
- }... )
1880
1881
}
1881
1882
1882
1883
// getExistingChains get iptables-save output so we can check for existing chains and rules.
0 commit comments