Skip to content

Commit f997e4a

Browse files
committed
fix(NSC): pass fwmark to traffic director as an int
It used to be when we were using iproute2's CLI we needed to have the fwmark as a hex number so we were passing it as a string in that format. However, now that we use the netlink library directly, we already have the fwmark in the condition that we need it. So instead of doing all of these string <-> int conversions, lets just keep this simpler.
1 parent fff99ea commit f997e4a

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

pkg/controllers/proxy/network_services_controller.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,25 +1730,14 @@ func (nsc *NetworkServicesController) cleanupMangleTableRule(ip string, protocol
17301730
// For DSR it is required that we dont assign the VIP to any interface to avoid martian packets
17311731
// http://www.austintek.com/LVS/LVS-HOWTO/HOWTO/LVS-HOWTO.routing_to_VIP-less_director.html
17321732
// routeVIPTrafficToDirector: setups policy routing so that FWMARKed packets are delivered locally
1733-
func routeVIPTrafficToDirector(fwmark string, family v1.IPFamily) error {
1733+
func routeVIPTrafficToDirector(fwmark uint32, family v1.IPFamily) error {
17341734
nFamily := netlink.FAMILY_V4
17351735
if family == v1.IPv6Protocol {
17361736
nFamily = netlink.FAMILY_V6
17371737
}
17381738

1739-
iFWMark, err := strconv.Atoi(fwmark)
1740-
if err != nil {
1741-
return fmt.Errorf("failed to convert fwmark to integer due to: %v", err)
1742-
}
1743-
1744-
// Convert to uint32 safely
1745-
uFWMark, err := safecast.ToUint32(iFWMark)
1746-
if err != nil {
1747-
return fmt.Errorf("failed to convert fwmark to uint32: %v", err)
1748-
}
1749-
17501739
nRule := netlink.NewRule()
1751-
nRule.Mark = uFWMark
1740+
nRule.Mark = fwmark
17521741
nRule.Table = customDSRRouteTableID
17531742
nRule.Priority = defaultTrafficDirectorRulePriority
17541743

pkg/controllers/proxy/service_endpoints_sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ func (nsc *NetworkServicesController) setupExternalIPForDSRService(svcIn *servic
557557
}
558558

559559
// do policy routing to deliver the packet locally so that IPVS can pick the packet
560-
err = routeVIPTrafficToDirector("0x"+fmt.Sprintf("%x", fwMark), family)
560+
err = routeVIPTrafficToDirector(fwMark, family)
561561
if err != nil {
562562
return fmt.Errorf("failed to setup ip rule to lookup traffic to external IP: %s through custom "+
563563
"route table due to %v", externalIP, err)

0 commit comments

Comments
 (0)