disable sloppy_tcp if there is no DSR & Maglev service

This commit is contained in:
Anupam Ghosh 2025-08-03 13:52:25 +05:30 committed by Aaron U'Ren
parent 98e38e9e66
commit bbb8f3b0d9
2 changed files with 10 additions and 7 deletions

View File

@ -406,23 +406,24 @@ func (nsc *NetworkServicesController) setupExternalIPServices(serviceInfoMap ser
}
func (nsc *NetworkServicesController) setupSloppyTCP(serviceInfoMap serviceInfoMap) {
enableSloppyTCP := false
var sloppyTCPVal int8 = 0
for _, svc := range serviceInfoMap {
// Enable sloppy TCP if any DSR service with Maglev hashing is configured
if svc.directServerReturn && svc.scheduler == IpvsMaglevHashing {
enableSloppyTCP = true
sloppyTCPVal = 1
break
}
}
// set sloppy_tcp to 1 if not already set
// enable/disable sloppy_tcp sysctl based on sloppyTCPVal
sloppyTCP := nsc.krNode.SloppyTCP()
if enableSloppyTCP && sloppyTCP.CachedVal() == 0 {
sysctlErr := sloppyTCP.WriteVal(1)
if sloppyTCP.CachedVal() != sloppyTCPVal {
sysctlErr := sloppyTCP.WriteVal(sloppyTCPVal)
if sysctlErr != nil {
klog.Errorf("Failed to enable IPVS sloppy TCP: %s", sysctlErr.Error())
} else {
klog.Infof("IPVS sloppy TCP enabled")
return
}
klog.Infof("IPVS sloppy TCP set to %d", sloppyTCPVal)
}
}

View File

@ -251,6 +251,8 @@ func NewKRNode(node *apiv1.Node, linkQ LocalLinkQuerier, enableIPv4, enableIPv6
},
linkQ: linkQ,
NodeInterfaceName: nodeInterfaceName,
// Purposefully set the value of sloppyTCP to 0. This ensures the machine's sloppy_tcp setting remains
// unchanged when there are no services with both Maglev and DSR enabled.
sloppyTCP: SysctlConfig{
name: IPv4IPVSSloppyTCP,
value: 0,