Skip to content

Commit

Permalink
Drop eth0 packets in PREROUTING on Kind Nodes
Browse files Browse the repository at this point in the history
According to the OVS documentation:
On Linux, when a physical interface is in use by the userspace datapath,
packets received on the interface still also pass into the kernel TCP/IP
stack. This can cause surprising and incorrect behavior. You can use
"iptables" to avoid this behavior, by using it to drop received packets.

The OVS documentation suggests dropping packets in the INPUT and FORWARD
chains. However, this is not sufficient for some edge cases. For
example, when receiving a TCP RST packet, the packet will clear the
conntrack entry for the TCP connection before it can be dropped, which
can cause the "second" TCP RST packet (the one processed by OVS
userspace) to be marked as invalid when going through conntrack.

So instead we drop the packet in PREROUTING:
iptables -t raw -A PREROUTING -i eth0 -j DROP
This rule is added to the start_ovs_netdev script.

By adding this rule, we no longer need to skip TCP e2e tests for the
Reject NetworkPolicy Action in Kind clusters.

It's possible that this is also going to help with various connectivity
issues we observed with Antrea in Kind over time. For example, I believe
we may also be able to remove the hack which reduces the value of the
tcp_retries2 sysctl parameter. I need to run tests to confirm.

Fixes antrea-io#2025

Signed-off-by: Antonin Bas <abas@vmware.com>
  • Loading branch information
antoninbas committed Jun 4, 2021
1 parent 2b0f6e3 commit 7f8574e
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 18 deletions.
2 changes: 2 additions & 0 deletions build/images/scripts/start_ovs_netdev
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function add_br_phy {
ip addr flush dev eth0 2>/dev/null
ip link set eth0 up
ip route add default via "$gw" dev br-phy
iptables -t raw -A PREROUTING -i eth0 -j DROP
}

function del_br_phy {
Expand All @@ -44,6 +45,7 @@ function del_br_phy {
ip addr add "$inet" dev eth0
ip link set eth0 up
ip route add default via "$gw" dev eth0
iptables -t raw -D PREROUTING -i eth0 -j DROP
}

function start_ovs {
Expand Down
2 changes: 0 additions & 2 deletions hack/kind-fix-networking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,4 @@ for node in "$@"; do
peerName=$(docker run --net=host antrea/ethtool:latest ip link | grep ^"$peerIdx": | awk -F[:@] '{ print $2 }' | cut -c 2-)
echo "Disabling TX checksum offload for node $node ($peerName)"
docker run --net=host --privileged antrea/ethtool:latest ethtool -K "$peerName" tx off
# Workaround for https://github.com/antrea-io/antrea/issues/324
docker exec "$node" sysctl -w net.ipv4.tcp_retries2=4
done
6 changes: 0 additions & 6 deletions test/e2e/antreapolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/wait"

"antrea.io/antrea/pkg/agent/config"
crdv1alpha1 "antrea.io/antrea/pkg/apis/crd/v1alpha1"
crdv1alpha2 "antrea.io/antrea/pkg/apis/crd/v1alpha2"
crdv1alpha3 "antrea.io/antrea/pkg/apis/crd/v1alpha3"
Expand Down Expand Up @@ -1796,11 +1795,6 @@ func testACNPRejectEgress(t *testing.T) {

// testACNPRejectIngress tests that a ACNP is able to reject egress traffic from pods labelled A to namespace Z.
func testACNPRejectIngress(t *testing.T, data *TestData, protocol v1.Protocol) {
// TCP rejection can't work on Kind when the traffic mode is noEncap. Skip it.
// https://github.com/antrea-io/antrea/issues/2025
if protocol == v1.ProtocolTCP {
skipIfEncapModeIsNotAndProviderIs(t, data, config.TrafficEncapModeEncap, "kind")
}
builder := &ClusterNetworkPolicySpecBuilder{}
builder = builder.SetName("acnp-reject-a-from-z-ingress").
SetPriority(1.0).
Expand Down
10 changes: 0 additions & 10 deletions test/e2e/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,6 @@ func skipIfEncapModeIsNot(tb testing.TB, data *TestData, encapMode config.Traffi
}
}

func skipIfEncapModeIsNotAndProviderIs(tb testing.TB, data *TestData, encapMode config.TrafficEncapModeType, name string) {
currentEncapMode, err := data.GetEncapMode()
if err != nil {
tb.Fatalf("Failed to get encap mode: %v", err)
}
if currentEncapMode != encapMode && testOptions.providerName == name {
tb.Skipf("Skipping test when encap mode is '%s' and provider is '%s', test requires '%s'", currentEncapMode.String(), name, encapMode.String())
}
}

func skipIfHasWindowsNodes(tb testing.TB) {
if len(clusterInfo.windowsNodes) != 0 {
tb.Skipf("Skipping test as the cluster has Windows Nodes")
Expand Down

0 comments on commit 7f8574e

Please sign in to comment.