@@ -24,6 +24,8 @@ import (
2424 "github.com/coreos/go-iptables/iptables"
2525 "github.com/moby/ipvs"
2626 "github.com/vishvananda/netlink"
27+ "golang.org/x/net/ipv4"
28+ "golang.org/x/net/ipv6"
2729 v1 "k8s.io/api/core/v1"
2830 discoveryv1 "k8s.io/api/discovery/v1"
2931 "k8s.io/client-go/kubernetes"
@@ -104,6 +106,8 @@ const (
104106 tunnelInterfaceType = "tunnel"
105107
106108 gracefulTermServiceTickTime = 5 * time .Second
109+
110+ tcpHeaderMinLen = 20
107111)
108112
109113// NetworkServicesController enables local node as network service proxy through IPVS/LVS.
@@ -147,7 +151,7 @@ type NetworkServicesController struct {
147151 gracefulTermination bool
148152 syncChan chan int
149153 dsr * dsrOpt
150- dsrTCPMSS int
154+ mtu int
151155
152156 iptablesCmdHandlers map [v1.IPFamily ]utils.IPTablesHandler
153157 ipSetHandlers map [v1.IPFamily ]utils.IPSetHandler
@@ -1537,14 +1541,16 @@ func changedIpvsSchedFlags(svc *ipvs.Service, s schedFlags) bool {
15371541}
15381542
15391543// setupMangleTableRule: sets up iptables rule to FWMARK the traffic to external IP vip
1540- func (nsc * NetworkServicesController ) setupMangleTableRule (ip string , protocol string , port string , fwmark string ,
1541- tcpMSS int ) error {
1544+ func (nsc * NetworkServicesController ) setupMangleTableRule (ip string , protocol string , port string , fwmark string ) error {
15421545 var iptablesCmdHandler utils.IPTablesHandler
1546+ tcpMSS := nsc .mtu
15431547 parsedIP := net .ParseIP (ip )
15441548 if parsedIP .To4 () != nil {
15451549 iptablesCmdHandler = nsc .iptablesCmdHandlers [v1 .IPv4Protocol ]
1550+ tcpMSS -= 2 * ipv4 .HeaderLen + tcpHeaderMinLen
15461551 } else {
15471552 iptablesCmdHandler = nsc .iptablesCmdHandlers [v1 .IPv6Protocol ]
1553+ tcpMSS -= 2 * ipv6 .HeaderLen + tcpHeaderMinLen
15481554 }
15491555
15501556 args := []string {"-d" , ip , "-m" , protocol , "-p" , protocol , "--dport" , port , "-j" , "MARK" , "--set-mark" , fwmark }
@@ -1592,13 +1598,16 @@ func (nsc *NetworkServicesController) setupMangleTableRule(ip string, protocol s
15921598}
15931599
15941600func (nsc * NetworkServicesController ) cleanupMangleTableRule (ip string , protocol string , port string ,
1595- fwmark string , tcpMSS int ) error {
1601+ fwmark string ) error {
15961602 var iptablesCmdHandler utils.IPTablesHandler
1603+ tcpMSS := nsc .mtu
15971604 parsedIP := net .ParseIP (ip )
15981605 if parsedIP .To4 () != nil {
15991606 iptablesCmdHandler = nsc .iptablesCmdHandlers [v1 .IPv4Protocol ]
1607+ tcpMSS -= 2 * ipv4 .HeaderLen + tcpHeaderMinLen
16001608 } else {
16011609 iptablesCmdHandler = nsc .iptablesCmdHandlers [v1 .IPv6Protocol ]
1610+ tcpMSS -= 2 * ipv6 .HeaderLen + tcpHeaderMinLen
16021611 }
16031612
16041613 args := []string {"-d" , ip , "-m" , protocol , "-p" , protocol , "--dport" , port , "-j" , "MARK" , "--set-mark" , fwmark }
@@ -2026,11 +2035,8 @@ func NewNetworkServicesController(clientset kubernetes.Interface,
20262035 if err != nil {
20272036 return nil , err
20282037 }
2029- // Sets it to 60 bytes less than the auto-detected MTU to account for additional ip-ip headers needed for DSR, above
2030- // method GetMTUFromNodeIP() already accounts for the overhead of ip-ip overlay networking, so we need to
2031- // remove 60 bytes (internet headers and additional ip-ip because MTU includes internet headers. MSS does not.)
2032- // This needs also a condition to deal with auto-mtu=false
2033- nsc .dsrTCPMSS = automtu - utils .IPInIPHeaderLength * 3
2038+ // Store MTU only. Code setting MSS will handle address family, and calculate correct MSS.
2039+ nsc .mtu = automtu
20342040
20352041 nsc .podLister = podInformer .GetIndexer ()
20362042
0 commit comments