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 Traceflow implementation for external IPs and gateway IP #1884

Conversation

antoninbas
Copy link
Contributor

@antoninbas antoninbas commented Feb 18, 2021

PR #1883 fixes a panic in libOpenflow triggered when OVS receives reply
traffic for a Traceflow request with a valid dataplane tag as the ToS
field and the Linux packet mark set. However, it should be noted that
reply packets for Traceflow requests are generally meaningless and
should be ignored. In encapMode, The Traceflow implementation should
also not timeout when a Traceflow request leaves the overlay: as soon as
the request is forwarded through the gateway port, we should consider
the request complete, and ignore any potential reply packet. So we
include the following changes:

  • add a new "ForwardedOutOfOverlay" Traceflow action when a request is
    forwarded out of the network managed by Antrea in encapMode. The
    Controller can then mark the request as "succeeded". In theory,
    something similar could be done for other traffic modes, but it would
    be much more complex.
  • add support for Traceflow requests for which the destination is the
    gateway's IP, by reporting a "Delivered" action.
  • add an OVS flow in charge of dropping reply traffic for Traceflow
    requests (using the conntrack state to match this traffic), thus
    ensuring it is not sent to the Agent. In our testing, this is
    especially useful when the destination IP is the local Node's IP, as
    the IP ToS field seems to be preseved in that case, causing the reply
    packet to be treated as a Traceflow request.

We add end-to-end tests for both cases (external destination IP and
Antrea gateway destination IP).

See #1878

ob.TunnelDstIP = tunnelDstIP
ob.Action = opsv1alpha1.Forwarded
} else if ipDst == gatewayIP.String() && outputPort == config.HostGatewayOFPort {
ob.Action = opsv1alpha1.Delivered
} else if c.networkConfig.TrafficEncapMode.SupportsEncap() && outputPort == config.HostGatewayOFPort {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we check if ipDst in Pod CIDR here? Current we support to trace inter-Node packet without encapsulation, but this behavior is changed in this PR.
Otherwise the e2e test will fail: https://github.com/vmware-tanzu/antrea/pull/1884/checks?check_run_id=1924336861

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I can see that I forgot an if case here. Added it back.

@codecov-io
Copy link

codecov-io commented Feb 18, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@f389d2e). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1884   +/-   ##
=======================================
  Coverage        ?   53.48%           
=======================================
  Files           ?      200           
  Lines           ?    17272           
  Branches        ?        0           
=======================================
  Hits            ?     9238           
  Misses          ?     6873           
  Partials        ?     1161           
Flag Coverage Δ
e2e-tests 43.52% <0.00%> (?)
kind-e2e-tests 50.12% <0.00%> (?)

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

@gran-vmv
Copy link
Contributor

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

Copy link
Contributor

@jianjuns jianjuns left a comment

Choose a reason for hiding this comment

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

The new behavior sound good to me.

Action().SendToController(uint8(PacketInReasonTF)).
Cookie(c.cookieAllocator.Request(category).Raw()).
Done())
// Only SendToController if output port is local gateway.
Copy link
Contributor

Choose a reason for hiding this comment

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

If we still output when kube-proxy is used, could we still trace the Service traffic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory, we do not support tracing Service traffic when AntreaProxy is disabled. It is documented (https://github.com/vmware-tanzu/antrea/blob/main/docs/traceflow-guide.md#prerequisites) and the following error will be logged by the agent: Error: using Service destination requires AntreaProxy feature enabled. However, it dates back to before we started using DSCP to carry the Traceflow dataplane tag. Now that we do, it may be possible to lift the restriction, since iptables will preserve the DSCP field. I commented out the error in the agent code, and this is what I get for a Traceflow request from a Pod to a Service, when AntreaProxy is disabled:

name: default-toolbox-jvmv5-to-kube-system-kube-dns-xs25d865
phase: Succeeded
source: default/toolbox-jvmv5
destination: kube-system/kube-dns
results:
- node: k8s-node-worker-1
  timestamp: 1613785297
  observations:
  - component: Forwarding
    componentInfo: Classification
    action: Received
  - component: Forwarding
    componentInfo: Output
    action: Delivered
- node: k8s-node-control-plane
  timestamp: 1613785297
  observations:
  - component: SpoofGuard
    action: Forwarded
  - component: Forwarding
    componentInfo: Output
    action: Forwarded
    tunnelDstIP: 192.168.77.101
- node: k8s-node-control-plane
  timestamp: 1613785297
  observations:
  - component: SpoofGuard
    action: Forwarded
  - component: Forwarding
    componentInfo: Output
    action: Forwarded

This is definitely not as straightforward as the one when AntreaProxy is enabled (although it is accurate):

name: default-toolbox-jvmv5-to-kube-system-kube-dns-m489kxwk
phase: Succeeded
source: default/toolbox-jvmv5
destination: kube-system/kube-dns
results:
- node: k8s-node-control-plane
  timestamp: 1613785535
  observations:
  - component: SpoofGuard
    action: Forwarded
  - component: LB
    action: Forwarded
    pod: kube-system/coredns-74ff55c5b-vc7z7
    translatedDstIP: 10.10.1.2
  - component: Forwarding
    componentInfo: Output
    action: Forwarded
    tunnelDstIP: 192.168.77.101
- node: k8s-node-worker-1
  timestamp: 1613785535
  observations:
  - component: Forwarding
    componentInfo: Classification
    action: Received
  - component: Forwarding
    componentInfo: Output
    action: Delivered

I am personally not sure it is worth lifting the restriction, but I can open a PR to do it and update the documentation. I don't know if there is any edge case I am missing. @jianjuns what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right. Probably not worthwhile, given AntreaProxy is enabled by default now.

tnqn
tnqn previously approved these changes Feb 24, 2021
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, just a typo

test/e2e/framework.go Outdated Show resolved Hide resolved
antoninbas and others added 4 commits February 24, 2021 18:08
PR antrea-io#1883 fixes a panic in libOpenflow triggered when OVS receives reply
traffic for a Traceflow request with a valid dataplane tag as the ToS
field and the Linux packet mark set. However, it should be noted that
reply packets for Traceflow requests are generally meaningless and
should be ignored. In encapMode, The Traceflow implementation should
also not timeout when a Traceflow request leaves the overlay: as soon as
the request is forwarded through the gateway port, we should consider
the request complete, and ignore any potential reply packet. So we
include the following changes:

* add a new "ForwardedOutOfOverlay" Traceflow action when a request is
  forwarded out of the network managed by Antrea in encapMode. The
  Controller can then mark the request as "succeeded". In theory,
  something similar could be done for other traffic modes, but it would
  be much more complex.
* add support for Traceflow requests for which the destination is the
  gateway's IP, by reporting a "Delivered" action.
* add an OVS flow in charge of dropping reply traffic for Traceflow
  requests (using the conntrack state to match this traffic), thus
  ensuring it is not set to the Agent. In our testing, this is
  especially useful when the destination IP is the local Node's IP, as
  the IP ToS field seems to be preseved in that case, causing the reply
  packet to be treated as a Traceflow request.

We add end-to-end tests for both cases (external destination IP and
Antrea gateway destination IP).

See antrea-io#1878
Co-authored-by: Quan Tian <[email protected]>
@antoninbas antoninbas force-pushed the fix-traceflow-for-destination-external-IPs-and-gateway-IP branch from a778c0a to 95f43fd Compare February 25, 2021 02:12
@antoninbas antoninbas requested a review from tnqn February 25, 2021 02:13
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

@antoninbas
Copy link
Contributor Author

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

@antoninbas
Copy link
Contributor Author

/test-conformance

@antoninbas antoninbas merged commit 8038935 into antrea-io:main Feb 26, 2021
@antoninbas antoninbas deleted the fix-traceflow-for-destination-external-IPs-and-gateway-IP branch February 26, 2021 02:42
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.

6 participants