Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IPv6] Bug fix in adding iptable rules #2469

Merged
merged 2 commits into from Aug 5, 2021

Conversation

lzhecheng
Copy link
Contributor

@lzhecheng lzhecheng commented Jul 26, 2021

  • bug fix in EnsureRule()
  • refactor iptables methods

Signed-off-by: Zhecheng Li lzhecheng@vmware.com

@lzhecheng
Copy link
Contributor Author

/test-e2e /test-conformance /test-networkpolicy /test-ipv6-e2e

@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2021

Codecov Report

Merging #2469 (15437d1) into main (cdc8453) will increase coverage by 5.12%.
The diff coverage is 37.03%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2469      +/-   ##
==========================================
+ Coverage   59.82%   64.95%   +5.12%     
==========================================
  Files         284      281       -3     
  Lines       22168    25534    +3366     
==========================================
+ Hits        13263    16586    +3323     
+ Misses       7483     7403      -80     
- Partials     1422     1545     +123     
Flag Coverage Δ
e2e-tests 55.83% <37.03%> (?)
kind-e2e-tests 47.09% <26.15%> (+0.01%) ⬆️
unit-tests 42.22% <0.00%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/agent/nodeportlocal/portcache/port_table.go 64.94% <0.00%> (+3.22%) ⬆️
pkg/agent/nodeportlocal/rules/rules.go 100.00% <ø> (ø)
pkg/agent/route/route_linux.go 50.59% <33.33%> (+5.91%) ⬆️
pkg/agent/util/iptables/iptables.go 43.55% <35.59%> (+6.15%) ⬆️
pkg/agent/nodeportlocal/rules/iptable_rule.go 59.72% <47.05%> (+7.17%) ⬆️
pkg/agent/agent_linux.go 80.00% <0.00%> (-20.00%) ⬇️
pkg/controller/egress/ipallocator/allocator.go 67.82% <0.00%> (-15.16%) ⬇️
pkg/controller/networkpolicy/endpoint_querier.go 77.64% <0.00%> (-13.79%) ⬇️
pkg/apis/controlplane/v1beta1/conversion.go 72.44% <0.00%> (-11.89%) ⬇️
pkg/util/ip/ip.go 68.67% <0.00%> (-11.63%) ⬇️
... and 273 more

@lzhecheng lzhecheng force-pushed the e2e-fix-ds-upgrade branch 6 times, most recently from b6105a8 to 789e384 Compare July 28, 2021 02:41
@lzhecheng
Copy link
Contributor Author

/test-e2e /test-conformance /test-networkpolicy /test-ipv6-e2e /test-ipv6-only-e2e

@lzhecheng
Copy link
Contributor Author

@antoninbas @tnqn I refactored some iptables methods. PTAL.

test/e2e/flowaggregator_test.go Outdated Show resolved Hide resolved
test/e2e/networkpolicy_test.go Outdated Show resolved Hide resolved
pkg/agent/route/route_linux.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Show resolved Hide resolved
@lzhecheng lzhecheng force-pushed the e2e-fix-ds-upgrade branch 8 times, most recently from 9cb186a to a2b8df9 Compare July 29, 2021 08:31
@lzhecheng
Copy link
Contributor Author

/test-e2e /test-conformance /test-networkpolicy /test-ipv6-e2e /test-ipv6-only-e2e

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest changes look good to me overall

pkg/agent/nodeportlocal/rules/iptable_rule.go Outdated Show resolved Hide resolved
pkg/agent/nodeportlocal/rules/iptable_rule.go Outdated Show resolved Hide resolved
@lzhecheng lzhecheng force-pushed the e2e-fix-ds-upgrade branch 3 times, most recently from b0c0e9b to cc394bb Compare July 30, 2021 01:12
@lzhecheng
Copy link
Contributor Author

/test-all /test-ipv6-all /test-ipv6-only-all

@antoninbas
Copy link
Contributor

@tnqn PTAL

@lzhecheng please cherry-pick this as needed (at least v1.2, but potentially all the way back to v0.13 if appropriate)

pkg/agent/nodeportlocal/rules/iptable_rule.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
for idx := range c.ipts {
err := c.ipts[idx].ClearChain(table, chain)
// DeleteMatchingChains deletes all rules from chains in all tables and then delete the chains.
func (c *Client) DeleteMatchingChains(table string, chain string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

The comment about "delete all rules from chains in all tables" is incorrect.

I think if we specify "protocol" like EnsureChain, AppendRule and InsertRule, it will make same to name the delete method DeleteChain and DeleteRule? @antoninbas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment is updated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antoninbas please take a look at @tnqn 's suggestion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes if we pass the protocol like for the insertion functions, we can use the same naming scheme I think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

pkg/agent/route/route_linux.go Outdated Show resolved Hide resolved
@lzhecheng
Copy link
Contributor Author

/test-e2e /test-conformance /test-networkpolicy /test-ipv6-all /test-ipv6-only-all

pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
pkg/agent/util/iptables/iptables.go Outdated Show resolved Hide resolved
@lzhecheng
Copy link
Contributor Author

/test-all /test-ipv6-all /test-ipv6-only-all

Copy link
Contributor

@antoninbas antoninbas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, save for the typo

@@ -771,5 +772,5 @@ func (c *Client) DeleteSNATRule(mark uint32) error {
}
c.markToSNATIP.Delete(mark)
snatIP := value.(net.IP)
return c.ipt.DeleteRule(iptables.NATTable, antreaPostRoutingChain, c.snatRuleSpec(snatIP, mark))
return c.ipt.DeleteRules(iptables.ProtocolDual, iptables.NATTable, antreaPostRoutingChain, c.snatRuleSpec(snatIP, mark))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should still be DeleteRule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for catching this. Updated.

* bug fix in EnsureRule()
* refactor iptables methods

Signed-off-by: Zhecheng Li <lzhecheng@vmware.com>
@lzhecheng
Copy link
Contributor Author

lzhecheng commented Aug 5, 2021

/test-all /test-ipv6-all /test-ipv6-only-all

if !exists {
return nil
if err := ipt.table.DeleteChain(iptables.ProtocolIPv4, iptables.NATTable, NodePortLocalChain); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a test, deleting a chain which was still referenced by another rule always fails with "Too many links" error, so this would introduce a regression. Is this method covered by any test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you do it manually? "Too many links" is expected in this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, it seems DeleteChain is only used in DeleteAllRules and DeleteAllRules is used by no one. I am going to delete them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's expected. The original code deletes the chain at last so it ensures the chain is not referenced by any rule when deleting it. This patch changes to delete the chain in the beginning so it would introduce a regression. I'm not why there there is an orphaned method here, maybe it's left for historical reason, or maybe it's planed for future usage. Anyway it's beyond the scope of this PR. I would sugges to keep it as is if you want to merge this earlier. Otherwise I would invite the feature owner to comment whether deleting it is expected. If you keep the method, I would expect it wouldn't introduce a bug by this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DeleteAllRules and ChainExists are reverted.

@lzhecheng lzhecheng force-pushed the e2e-fix-ds-upgrade branch 2 times, most recently from 8a9aabf to 896c590 Compare August 5, 2021 10:47
Signed-off-by: Zhecheng Li <lzhecheng@vmware.com>
Copy link
Member

@tnqn tnqn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tnqn
Copy link
Member

tnqn commented Aug 5, 2021

/test-all

@tnqn tnqn merged commit f0a44d5 into antrea-io:main Aug 5, 2021
antoninbas added a commit that referenced this pull request Aug 6, 2021
* [IPv6] Bug fix in adding iptable rules
* bug fix in EnsureRule()
* refactor iptables methods

Signed-off-by: Zhecheng Li <lzhecheng@vmware.com>
antoninbas pushed a commit that referenced this pull request Aug 10, 2021
* Bug fix in adding iptable rules * bug fix in EnsureRule() * refactor iptables methods

Signed-off-by: Zhecheng Li <lzhecheng@vmware.com>

* Revert ChainExists() and DeleteAllRules()

Signed-off-by: Zhecheng Li <lzhecheng@vmware.com>
@lzhecheng lzhecheng deleted the e2e-fix-ds-upgrade branch October 26, 2021 02:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants