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

Fix dumping OVS flows of a NetworkPolicy #3335

Merged
merged 1 commit into from
Feb 25, 2022

Conversation

jainpulkit22
Copy link
Contributor

Fixes #3306.

This PR fixes the nil pointer dereference error while dumping the ovsflows of NetworkPolicy, by adding a nil check on the NetworkPolicyReference attribute of the policyRuleConjunction Object

Signed-off-by: Pulkit Jain jainpu@vmware.com

@codecov-commenter
Copy link

codecov-commenter commented Feb 21, 2022

Codecov Report

Merging #3335 (687dfb0) into main (0ffcfc9) will decrease coverage by 8.48%.
The diff coverage is 41.09%.

❗ Current head 687dfb0 differs from pull request most recent head b6389fb. Consider uploading reports for the commit b6389fb to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3335      +/-   ##
==========================================
- Coverage   62.13%   53.65%   -8.49%     
==========================================
  Files         266      239      -27     
  Lines       26519    34037    +7518     
==========================================
+ Hits        16477    18261    +1784     
- Misses       8222    13996    +5774     
+ Partials     1820     1780      -40     
Flag Coverage Δ
e2e-tests 53.65% <41.09%> (?)
kind-e2e-tests ?
unit-tests ?

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

Impacted Files Coverage Δ
pkg/agent/controller/networkpolicy/packetin.go 68.34% <ø> (+1.19%) ⬆️
pkg/agent/ipassigner/responder/ndp_responder.go 0.00% <0.00%> (ø)
pkg/agent/openflow/network_policy.go 64.38% <0.00%> (-18.87%) ⬇️
pkg/agent/openflow/pipeline_other.go 3.44% <0.00%> (+1.27%) ⬆️
pkg/agent/openflow/pipeline.go 66.37% <16.66%> (-7.43%) ⬇️
pkg/agent/proxy/proxier.go 49.90% <16.66%> (-13.24%) ⬇️
pkg/agent/openflow/client.go 59.77% <28.57%> (+5.74%) ⬆️
pkg/controller/networkpolicy/validate.go 62.94% <33.33%> (+21.75%) ⬆️
pkg/agent/ipassigner/ip_assigner_linux.go 52.55% <43.83%> (-7.72%) ⬇️
pkg/agent/ipassigner/responder/arp_responder.go 63.52% <63.52%> (ø)
... and 270 more

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.

It's good to add a test when fixing a bug like this one.

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.

The title of the PR/commit should mention it's fixing it, i.e. "Fix dumping OVS flows of a NetworkPolicy"

@@ -1455,6 +1455,11 @@ func (c *client) GetNetworkPolicyFlowKeys(npName, npNamespace string) []string {

for _, conjObj := range c.policyCache.List() {
conj := conjObj.(*policyRuleConjunction)
// If the NetworkPolicyReference in the policyRuleConjunction is nil then that entry in client's
// policyCache should be ignored because here we need to dump flows of NetworkPolicy.
if conj.npRef == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Better to explain why the reference could be nil in the comment of this field in the struct.

@tnqn tnqn added the action/release-note Indicates a PR that should be included in release notes. label Feb 23, 2022
@jainpulkit22 jainpulkit22 changed the title Dumping OVS flows of a NetworkPolicy Fix dumping OVS flows of a NetworkPolicy Feb 23, 2022
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.

Could you squash the two commits to one?

@@ -525,7 +525,8 @@ type policyRuleConjunction struct {
serviceClause *clause
actionFlows []binding.Flow
metricFlows []binding.Flow
// NetworkPolicy reference information for debugging usage.
// NetworkPolicy reference information for debugging usage, its' value can be nil
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// NetworkPolicy reference information for debugging usage, its' value can be nil
// NetworkPolicy reference information for debugging usage, its value can be nil
Suggested change
// NetworkPolicy reference information for debugging usage, its' value can be nil
// NetworkPolicy reference information for debugging usage, its' value can be nil

@@ -525,7 +525,8 @@ type policyRuleConjunction struct {
serviceClause *clause
actionFlows []binding.Flow
metricFlows []binding.Flow
// NetworkPolicy reference information for debugging usage.
// NetworkPolicy reference information for debugging usage, its' value can be nil
// when a new DNS Conjunction is added to the policyCache.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// when a new DNS Conjunction is added to the policyCache.
// for conjunctions that are not built for a specific NetworkPolicy, e.g. DNS packetin Conjunction.

// dnsID will store the ID for New DNS packet, that is created,
// to test for nil NetworkPolicyReference.
dnsID := uint32(107)
c.NewDNSpacketInConjunction(dnsID)
Copy link
Member

Choose a reason for hiding this comment

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

Better to call this function in the begining of the test to be similar with the actual code. It should check error is nil to ensure it takes effect.

@@ -222,6 +222,10 @@ func TestInstallPolicyRuleFlows(t *testing.T) {
assert.Equal(t, 3, getChangedFlowOPCount(matchFlows2, insertion))
err = c.applyConjunctiveMatchFlows(ctxChanges2)
require.Nil(t, err)
// dnsID will store the ID for New DNS packet, that is created,
Copy link
Member

Choose a reason for hiding this comment

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

The comment doesn't reflect the real meaning of the ID, which is the OVS rule ID of the DNS response intercept rule. Here I would suggest to just pass 1 as the ID and comment:

Create a policyRuleConjunction for the dns response interception flows to ensure nil NetworkPolicyReference is handled correctly by GetNetworkPolicyFlowKeys.

@jainpulkit22 jainpulkit22 force-pushed the networkPolicy-flowDump-fix branch 2 times, most recently from f4791e5 to a6c1efa Compare February 24, 2022 07:56
tnqn
tnqn previously approved these changes Feb 24, 2022
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, thanks

@tnqn tnqn requested a review from antoninbas February 24, 2022 08:34
antoninbas
antoninbas previously approved these changes Feb 24, 2022
Comment on lines 165 to 166
err := c.NewDNSpacketInConjunction(dnsID)
require.Nil(t, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

require.NoError(t, c.NewDNSpacketInConjunction(dnsID))

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 the suggestion.

tnqn
tnqn previously approved these changes Feb 25, 2022
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 Feb 25, 2022

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

@tnqn
Copy link
Member

tnqn commented Feb 25, 2022

===> Installing Golangci-lint <===
golangci/golangci-lint info checking GitHub for tag 'v1.41.1'
golangci/golangci-lint info found version: 1.41.1 for v1.41.1/linux/amd64
golangci/golangci-lint info installed .golangci-bin/golangci-lint
===> Running golangci (linux) <===
pkg/agent/openflow/network_policy_test.go:162: File is not `gofmt`-ed with `-s` (gofmt)
	// Create a policyRuleConjunction for the dns response interception flows 
make: *** [Makefile:252: golangci] Error 1
Error: Process completed with exit code 2.

@jainpulkit22 golangci-lint check failed because the comment is not gofmted.

Fixes antrea-io#3306.

This commit fixes the nil pointer dereference error while dumping
ovsflows of NetworkPolicy, and adds a test to validate the changes.

Signed-off-by: Pulkit Jain <jainpu@vmware.com>
@tnqn
Copy link
Member

tnqn commented Feb 25, 2022

/test-all

@tnqn
Copy link
Member

tnqn commented Feb 25, 2022

/test-integration

@tnqn tnqn merged commit 7692426 into antrea-io:main Feb 25, 2022
bangqipropel pushed a commit to bangqipropel/antrea that referenced this pull request Mar 2, 2022
Fixes antrea-io#3306.

This commit fixes the nil pointer dereference error while dumping
ovsflows of NetworkPolicy, and adds a test to validate the changes.

Signed-off-by: Pulkit Jain <jainpu@vmware.com>
@jainpulkit22 jainpulkit22 deleted the networkPolicy-flowDump-fix branch March 21, 2022 05:45
@jainpulkit22 jainpulkit22 restored the networkPolicy-flowDump-fix branch March 21, 2022 05:45
@jainpulkit22 jainpulkit22 deleted the networkPolicy-flowDump-fix branch March 21, 2022 05:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/release-note Indicates a PR that should be included in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dumping OVS flows of a NetworkPolicy is not working
4 participants