Skip to content

Commit 36b3356

Browse files
committed
fix: don't use stale chains. add comments. minor style change
Signed-off-by: Hunter Gregory <[email protected]>
1 parent c149095 commit 36b3356

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

npm/pkg/dataplane/policies/chain-management_linux.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
335335
klog.Info("detected nft iptables. cleaning up legacy iptables")
336336
util.SetIptablesToLegacy()
337337
} else {
338-
klog.Info("detected legacy iptables. cleaning up legacy iptables")
338+
klog.Info("detected legacy iptables. cleaning up nft iptables")
339339
util.SetIptablesToNft()
340340
}
341341

@@ -352,25 +352,25 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
352352
deletedJumpRule := false
353353

354354
// 1.1. delete the deprecated jump to AZURE-NPM
355-
deprecatedErrCode, deprecatedErr := pMgr.ignoreErrorsAndRunIPTablesCommand(removeDeprecatedJumpIgnoredErrors, util.IptablesDeletionFlag, deprecatedJumpFromForwardToAzureChainArgs...)
356-
if deprecatedErrCode == 0 {
355+
errCode, err := pMgr.ignoreErrorsAndRunIPTablesCommand(removeDeprecatedJumpIgnoredErrors, util.IptablesDeletionFlag, deprecatedJumpFromForwardToAzureChainArgs...)
356+
if errCode == 0 {
357357
klog.Infof("deleted deprecated jump rule from FORWARD chain to AZURE-NPM chain")
358358
deletedJumpRule = true
359-
} else if deprecatedErr != nil {
359+
} else if err != nil {
360360
metrics.SendErrorLogAndMetric(util.IptmID,
361361
"[cleanup] failed to delete deprecated jump rule from FORWARD chain to AZURE-NPM chain for unexpected reason with exit code %d and error: %s",
362-
deprecatedErrCode, deprecatedErr.Error())
362+
errCode, err.Error())
363363
}
364364

365365
// 1.2. delete the jump to AZURE-NPM
366-
deprecatedErrCode, deprecatedErr = pMgr.ignoreErrorsAndRunIPTablesCommand(removeDeprecatedJumpIgnoredErrors, util.IptablesDeletionFlag, jumpFromForwardToAzureChainArgs...)
367-
if deprecatedErrCode == 0 {
366+
errCode, err = pMgr.ignoreErrorsAndRunIPTablesCommand(removeDeprecatedJumpIgnoredErrors, util.IptablesDeletionFlag, jumpFromForwardToAzureChainArgs...)
367+
if errCode == 0 {
368368
deletedJumpRule = true
369369
klog.Infof("deleted deprecated jump rule from FORWARD chain to AZURE-NPM chain")
370-
} else if deprecatedErr != nil {
370+
} else if err != nil {
371371
metrics.SendErrorLogAndMetric(util.IptmID,
372372
"[cleanup] failed to delete jump rule from FORWARD chain to AZURE-NPM chain for unexpected reason with exit code %d and error: %s",
373-
deprecatedErrCode, deprecatedErr.Error())
373+
errCode, err.Error())
374374
}
375375

376376
// 2. get current chains
@@ -430,6 +430,9 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
430430

431431
errCode, err := pMgr.runIPTablesCommand(util.IptablesFlushFlag, chain)
432432
if err != nil && errCode != doesNotExistErrorCode {
433+
// NOTE: if we fail to flush or delete the chain, then we will never clean it up in the future.
434+
// This is zero-day behavior since NPM supported nft (we used to mark the chain stale, but this would not have worked as expected).
435+
// NPM currently has no mechanism for retrying flush/delete for a chain from the other iptables version (other than the AZURE-NPM chain which is handled above).
433436
currentErrString := fmt.Sprintf("failed to flush chain %s with err [%v]", chain, err)
434437
if aggregateError == nil {
435438
aggregateError = npmerrors.SimpleError(currentErrString)
@@ -451,8 +454,9 @@ func (pMgr *PolicyManager) cleanupOtherIptables() error {
451454
for _, chain := range chains {
452455
errCode, err := pMgr.runIPTablesCommand(util.IptablesDestroyFlag, chain)
453456
if err != nil && errCode != doesNotExistErrorCode {
454-
// add to staleChains if it's not one of the iptablesAzureChains
455-
pMgr.staleChains.add(chain)
457+
// NOTE: if we fail to flush or delete the chain, then we will never clean it up in the future.
458+
// This is zero-day behavior since NPM supported nft (we used to mark the chain stale, but this would not have worked as expected).
459+
// NPM currently has no mechanism for retrying flush/delete for a chain from the other iptables version (other than the AZURE-NPM chain which is handled above).
456460
currentErrString := fmt.Sprintf("failed to delete chain %s with err [%v]", chain, err)
457461
if aggregateError == nil {
458462
aggregateError = npmerrors.SimpleError(currentErrString)

0 commit comments

Comments
 (0)