-
Notifications
You must be signed in to change notification settings - Fork 370
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
Bugfix: TCP src port is unset on the TCP DNS response flow #5078
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1381,6 +1381,7 @@ func networkPolicyInitFlows(externalNodeEnabled, l7NetworkPolicyEnabled bool) [] | |
} | ||
return initFlows | ||
} | ||
|
||
func Test_featureNetworkPolicy_initFlows(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
|
@@ -1416,3 +1417,70 @@ func Test_featureNetworkPolicy_initFlows(t *testing.T) { | |
}) | ||
} | ||
} | ||
|
||
func Test_NewDNSPacketInConjunction(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great test. I assume it will fail without the patch, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is failed before the change. |
||
for _, tc := range []struct { | ||
name string | ||
enableIPv4 bool | ||
enableIPv6 bool | ||
conjID uint32 | ||
expectedFlows []string | ||
}{ | ||
{ | ||
name: "IPv4 only", | ||
enableIPv4: true, | ||
enableIPv6: false, | ||
conjID: 1, | ||
expectedFlows: []string{ | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,conj_id=1 actions=controller(id=32776,reason=no_match,userdata=02,max_len=128),goto_table:IngressMetric", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,udp,tp_src=53 actions=conjunction(1,1/2)", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,tcp,tp_src=53,tcp_flags=+psh+ack actions=conjunction(1,1/2)", | ||
}, | ||
}, | ||
{ | ||
name: "IPv6 only", | ||
enableIPv4: false, | ||
enableIPv6: true, | ||
conjID: 1, | ||
expectedFlows: []string{ | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,conj_id=1 actions=controller(id=32776,reason=no_match,userdata=02,max_len=128),goto_table:IngressMetric", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,udp6,tp_src=53 actions=conjunction(1,1/2)", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,tcp6,tp_src=53,tcp_flags=+psh+ack actions=conjunction(1,1/2)", | ||
}, | ||
}, | ||
{ | ||
name: "dual stack", | ||
enableIPv4: true, | ||
enableIPv6: true, | ||
conjID: 1, | ||
expectedFlows: []string{ | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,conj_id=1 actions=controller(id=32776,reason=no_match,userdata=02,max_len=128),goto_table:IngressMetric", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,udp,tp_src=53 actions=conjunction(1,1/2)", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,tcp,tp_src=53,tcp_flags=+psh+ack actions=conjunction(1,1/2)", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,udp6,tp_src=53 actions=conjunction(1,1/2)", | ||
"cookie=0x1020000000000, table=AntreaPolicyIngressRule, priority=64991,tcp6,tp_src=53,tcp_flags=+psh+ack actions=conjunction(1,1/2)", | ||
}, | ||
}, | ||
} { | ||
t.Run(tc.name, func(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
m := oftest.NewMockOFEntryOperations(ctrl) | ||
bridge := mocks.NewMockBridge(ctrl) | ||
fc := newFakeClient(m, tc.enableIPv4, tc.enableIPv6, config.K8sNode, config.TrafficEncapModeEncap) | ||
defer resetPipelines() | ||
fc.featureNetworkPolicy.bridge = bridge | ||
actualFlows := make([]string, 0) | ||
m.EXPECT().AddAll(gomock.Any()).Do(func(flowMessages []*openflow15.FlowMod) { | ||
flowStrings := getFlowStrings(flowMessages) | ||
actualFlows = append(actualFlows, flowStrings...) | ||
}).Return(nil).AnyTimes() | ||
bridge.EXPECT().AddFlowsInBundle(gomock.Any(), gomock.Any(), gomock.Any()).Do(func(addflows, modFlows, delFlows []*openflow15.FlowMod) { | ||
flowStrings := getFlowStrings(addflows) | ||
actualFlows = append(actualFlows, flowStrings...) | ||
}).Return(nil).Times(1) | ||
err := fc.NewDNSPacketInConjunction(tc.conjID) | ||
assert.NoError(t, err) | ||
assert.ElementsMatch(t, tc.expectedFlows, actualFlows) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finding the root cause of this issue.
I think you can simply fix it by changing
matchPairs
here tomatchPairs: append(dnsTCPMatchPair, tcpFlagsMatchPair),
Before adding source port support,
dnsTCPMatchPair
only has one item inside. Now, for a service with a source port match,getServiceMatchPairs
will generate two pairs. One is for the destination port, matching port 0(match all) and the other is for the source port, matching the port we provided.cc @Dyanngg since he is the owner of source port support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The truth is we only care about TCP source port and TCP flags, why it is a must to add a match for dst port value 0 although it does not work on OVS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, from my understanding, that part could be improved. Let's see @Dyanngg 's opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we could refine the logic for matchPairs. We do not have to add the match for dst port if src port matching is the only "filter" we have on the traffic. The code is written in the current way simply because dst port matching is a much common case and I wanted to simplify the implementation (instead of explicitly covering cases for src port matching only, dst port matching only and src dst port matching).