@@ -1595,6 +1595,57 @@ func (nsc *NetworkServicesController) setupMangleTableRule(ip string, protocol s
15951595 }
15961596 }
15971597
1598+ // Clean up old IPv6 rules that were created with the incorrect MSS value (MTU-60 instead of MTU-100).
1599+ // Prior to commit ee0940b8, IPv6 rules incorrectly used the same MSS calculation as IPv4 (MTU-60),
1600+ // resulting in IPv6 rules with MSS=1440 instead of the correct MSS=1400 (for MTU=1500).
1601+ // This cleanup ensures these old incorrect rules are removed during upgrades.
1602+ // TODO: remove after v2.4.X or above
1603+ if parsedIP .To4 () == nil && protocol == tcpProtocol {
1604+ // Calculate what the old incorrect MSS would have been (using IPv4 calculation for IPv6)
1605+ oldIncorrectIPv6MSS := nsc .mtu - 2 * ipv4 .HeaderLen - tcpHeaderMinLen
1606+
1607+ // Only proceed if the old incorrect value differs from the current correct value
1608+ if oldIncorrectIPv6MSS != tcpMSS {
1609+ klog .V (2 ).Infof ("checking for old incorrect IPv6 TCPMSS rules with MSS %d (correct is %d)" ,
1610+ oldIncorrectIPv6MSS , tcpMSS )
1611+
1612+ // Check for old-style rules (POSTROUTING with -s, PREROUTING with -d)
1613+ for firstArg , chain := range map [string ]string {"-s" : "POSTROUTING" , "-d" : "PREROUTING" } {
1614+ oldIncorrectArgs := []string {firstArg , ip , "-m" , tcpProtocol , "-p" , tcpProtocol ,
1615+ "--tcp-flags" , "SYN,RST" , "SYN" , "-j" , "TCPMSS" , "--set-mss" , strconv .Itoa (oldIncorrectIPv6MSS )}
1616+ exists , err := iptablesCmdHandler .Exists ("mangle" , chain , oldIncorrectArgs ... )
1617+ if err != nil {
1618+ return fmt .Errorf ("failed to check for old incorrect IPv6 TCPMSS rule in %s due to %v" , chain , err )
1619+ }
1620+ if exists {
1621+ klog .V (2 ).Infof ("removing old incorrect IPv6 TCPMSS rule with MSS %d: ip6tables -D %s -t mangle %v" ,
1622+ oldIncorrectIPv6MSS , chain , oldIncorrectArgs )
1623+ err = iptablesCmdHandler .Delete ("mangle" , chain , oldIncorrectArgs ... )
1624+ if err != nil {
1625+ return fmt .Errorf ("failed to delete old incorrect IPv6 TCPMSS rule from %s due to %v" , chain , err )
1626+ }
1627+ }
1628+ }
1629+
1630+ // Check for current-style rule format with incorrect MSS
1631+ currentFormatOldMSS := []string {"-s" , ip , "-m" , tcpProtocol , "-p" , tcpProtocol , "--sport" , port ,
1632+ "-i" , "kube-bridge" , "--tcp-flags" , "SYN,RST" , "SYN" , "-j" , "TCPMSS" ,
1633+ "--set-mss" , strconv .Itoa (oldIncorrectIPv6MSS )}
1634+ exists , err := iptablesCmdHandler .Exists ("mangle" , "PREROUTING" , currentFormatOldMSS ... )
1635+ if err != nil {
1636+ return fmt .Errorf ("failed to check for old incorrect IPv6 TCPMSS rule (current format) due to %v" , err )
1637+ }
1638+ if exists {
1639+ klog .V (2 ).Infof ("removing old incorrect IPv6 TCPMSS rule (current format) with MSS %d" ,
1640+ oldIncorrectIPv6MSS )
1641+ err = iptablesCmdHandler .Delete ("mangle" , "PREROUTING" , currentFormatOldMSS ... )
1642+ if err != nil {
1643+ return fmt .Errorf ("failed to delete old incorrect IPv6 TCPMSS rule (current format) due to %v" , err )
1644+ }
1645+ }
1646+ }
1647+ }
1648+
15981649 return nil
15991650}
16001651
0 commit comments