Skip to content

Commit

Permalink
Promote feature gate CleanupStaleUDPSvcConntrack to Beta
Browse files Browse the repository at this point in the history
This is a subsequent PR for antrea-io#5112. It fixes the issue that AntreaProxy could
unintentionally delete conntrack entries in zone 0 As mentioned in antrea-io#5112:

> Due to the restriction of the go library 'netlink', there is no API to specify a
  target zone. As a result, when deleting a stale conntrack entry with a
  destination port (such as NodePort), not only will the conntrack entry whose
  destination port is the port added by AntreaProxy be deleted, but also the
  conntrack entry that is not added by AntreaProxy will be deleted. This behavior
  is unexpected, as only the conntrack entries added by AntreaProxy should be
  deleted.

This PR resolves the issue by integrating a CT zone filter, now available in
the latest Go library `netlink`. Leveraging this feature, AntreaProxy can
accurately delete stale UDP conntrack entries. Consequently, we are promoting
the feature gate `CleanupStaleUDPSvcConntrack` to Beta.

Signed-off-by: Hongliang Liu <[email protected]>
  • Loading branch information
hongliangl committed Apr 11, 2024
1 parent 3ac87f6 commit bb6ba90
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 17 deletions.
4 changes: 2 additions & 2 deletions docs/feature-gates.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ edit the Agent configuration in the
## List of Available Features
| Feature Name | Component | Default | Stage | Alpha Release | Beta Release | GA Release | Extra Requirements | Notes |
| ----------------------------- | ------------------ | ------- | ----- | ------------- | ------------ | ---------- | ------------------ | --------------------------------------------- |
|-------------------------------|--------------------|---------|-------|---------------|--------------|------------|--------------------|-----------------------------------------------|
| `AntreaProxy` | Agent | `true` | GA | v0.8 | v0.11 | v1.14 | Yes | Must be enabled for Windows. |
| `EndpointSlice` | Agent | `true` | GA | v0.13.0 | v1.11 | v1.14 | Yes | |
| `TopologyAwareHints` | Agent | `true` | Beta | v1.8 | v1.12 | N/A | Yes | |
| `CleanupStaleUDPSvcConntrack` | Agent | `false` | Alpha | v1.13 | N/A | N/A | Yes | |
| `CleanupStaleUDPSvcConntrack` | Agent | `true` | Alpha | v1.13 | v2.0 | N/A | Yes | |
| `LoadBalancerModeDSR` | Agent | `false` | Alpha | v1.13 | N/A | N/A | Yes | |
| `AntreaPolicy` | Agent + Controller | `true` | Beta | v0.8 | v1.0 | N/A | No | Agent side config required from v0.9.0+. |
| `Traceflow` | Agent + Controller | `true` | Beta | v0.8 | v0.11 | N/A | Yes | |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
github.com/ti-mo/conntrack v0.5.0
github.com/vishvananda/netlink v1.2.1-beta.2
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240410182734-f4e6e3d5d507
github.com/vmware/go-ipfix v0.9.0
go.uber.org/mock v0.4.0
golang.org/x/crypto v0.22.0
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,8 @@ github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljT
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
github.com/vishvananda/netlink v1.1.1-0.20211101163509-b10eb8fe5cf6/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
github.com/vishvananda/netlink v1.2.1-beta.2 h1:Llsql0lnQEbHj0I1OuKyp8otXp0r3q0mPkuhwHfStVs=
github.com/vishvananda/netlink v1.2.1-beta.2/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240410182734-f4e6e3d5d507 h1:bm/1ktLjnn0F9lq4xXsYs+dVCQtkVS8MRzshrzxzWmI=
github.com/vishvananda/netlink v1.2.1-beta.2.0.20240410182734-f4e6e3d5d507/go.mod h1:whJevzBpTrid75eZy99s3DqCmy05NfibNaF2Ol5Ox5A=
github.com/vishvananda/netns v0.0.0-20200728191858-db3c7e526aae/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
github.com/vishvananda/netns v0.0.4 h1:Oeaw1EM2JMxD51g9uhtC0D7erkIjgmj8+JZc26m1YX8=
github.com/vishvananda/netns v0.0.4/go.mod h1:SpkAiCQRtJ6TvvxPnOSyH3BMl6unz3xZlaprSwhNNJM=
Expand Down Expand Up @@ -943,6 +943,7 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down
8 changes: 4 additions & 4 deletions hack/update-checksum-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ CONTAINERD_CONF_FILES="${WINDOWS_DIR}/containerd/conf/Install-WindowsCNI-Contain
CONTAINERD_WITH_OVS_CONF_FILES="${WINDOWS_DIR}/containerd-with-ovs/conf/Run-AntreaOVS-Containerd.ps1 \
${WINDOWS_DIR}/containerd-with-ovs/conf/VMSwitchExtension-AntreaAgent-Containerd.ps1"

checksum_windows_config=$(cat ${BASE_CONF_FILES} | sha256sum | cut -d " " -f 1)
checksum_windows_config=$(cat ${BASE_CONF_FILES} | shasum -a 256 | cut -d " " -f 1)

checksum_default=$(cat ${DEFAULT_CONF_FILES} | sha256sum | cut -d " " -f 1)
checksum_default=$(cat ${DEFAULT_CONF_FILES} | shasum -a 256 | cut -d " " -f 1)

checksum_containerd=$( cat ${CONTAINERD_CONF_FILES} | sha256sum | cut -d " " -f 1)
checksum_containerd=$( cat ${CONTAINERD_CONF_FILES} | shasum -a 256 | cut -d " " -f 1)

checksum_containerd_with_ovs=$(cat ${CONTAINERD_CONF_FILES} ${CONTAINERD_WITH_OVS_CONF_FILES} | sha256sum | cut -d " " -f 1)
checksum_containerd_with_ovs=$(cat ${CONTAINERD_CONF_FILES} ${CONTAINERD_WITH_OVS_CONF_FILES} | shasum -a 256 | cut -d " " -f 1)

for file in ${MANIFESTS[@]}; do
sed -i.bak "s/windows-config-checksum-placeholder/${checksum_windows_config}/g" ${file}
Expand Down
9 changes: 9 additions & 0 deletions pkg/agent/route/route_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
utilnet "k8s.io/utils/net"

"antrea.io/antrea/pkg/agent/config"
"antrea.io/antrea/pkg/agent/openflow"
"antrea.io/antrea/pkg/agent/servicecidr"
"antrea.io/antrea/pkg/agent/types"
"antrea.io/antrea/pkg/agent/util/ipset"
Expand Down Expand Up @@ -1919,28 +1920,36 @@ func (c *Client) DeleteRouteForLink(cidr *net.IPNet, linkIndex int) error {
func (c *Client) ClearConntrackEntryForService(svcIP net.IP, svcPort uint16, endpointIP net.IP, protocol binding.Protocol) error {
var protoVar uint8
var ipFamily netlink.InetFamily
var zone uint16
switch protocol {
case binding.ProtocolTCP:
ipFamily = unix.AF_INET
protoVar = unix.IPPROTO_TCP
zone = openflow.CtZone
case binding.ProtocolTCPv6:
ipFamily = unix.AF_INET6
protoVar = unix.IPPROTO_TCP
zone = openflow.CtZoneV6
case binding.ProtocolUDP:
ipFamily = unix.AF_INET
protoVar = unix.IPPROTO_UDP
zone = openflow.CtZone
case binding.ProtocolUDPv6:
ipFamily = unix.AF_INET6
protoVar = unix.IPPROTO_UDP
zone = openflow.CtZoneV6
case binding.ProtocolSCTP:
ipFamily = unix.AF_INET
protoVar = unix.IPPROTO_SCTP
zone = openflow.CtZone
case binding.ProtocolSCTPv6:
ipFamily = unix.AF_INET6
protoVar = unix.IPPROTO_SCTP
zone = openflow.CtZoneV6
}
filter := &netlink.ConntrackFilter{}
filter.AddProtocol(protoVar)
filter.AddZone(zone)
if svcIP != nil {
filter.AddIP(netlink.ConntrackOrigDstIP, svcIP)
}
Expand Down
86 changes: 79 additions & 7 deletions pkg/agent/route/route_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ import (
"github.com/stretchr/testify/assert"
"github.com/vishvananda/netlink"
"go.uber.org/mock/gomock"
"golang.org/x/sys/unix"
"k8s.io/apimachinery/pkg/util/sets"

"antrea.io/antrea/pkg/agent/config"
"antrea.io/antrea/pkg/agent/openflow"
servicecidrtest "antrea.io/antrea/pkg/agent/servicecidr/testing"
"antrea.io/antrea/pkg/agent/types"
"antrea.io/antrea/pkg/agent/util/ipset"
ipsettest "antrea.io/antrea/pkg/agent/util/ipset/testing"
"antrea.io/antrea/pkg/agent/util/iptables"
iptablestest "antrea.io/antrea/pkg/agent/util/iptables/testing"
netlinktest "antrea.io/antrea/pkg/agent/util/netlink/testing"
"antrea.io/antrea/pkg/ovs/openflow"
binding "antrea.io/antrea/pkg/ovs/openflow"
"antrea.io/antrea/pkg/ovs/ovsconfig"
"antrea.io/antrea/pkg/util/ip"
)
Expand Down Expand Up @@ -1322,7 +1324,7 @@ func TestAddNodePort(t *testing.T) {
name string
nodePortAddresses []net.IP
port uint16
protocol openflow.Protocol
protocol binding.Protocol
expectedCalls func(ipset *ipsettest.MockInterfaceMockRecorder)
}{
{
Expand All @@ -1332,7 +1334,7 @@ func TestAddNodePort(t *testing.T) {
net.ParseIP("1.1.2.2"),
},
port: 30000,
protocol: openflow.ProtocolTCP,
protocol: binding.ProtocolTCP,
expectedCalls: func(ipset *ipsettest.MockInterfaceMockRecorder) {
ipset.AddEntry(antreaNodePortIPSet, "1.1.1.1,tcp:30000")
ipset.AddEntry(antreaNodePortIPSet, "1.1.2.2,tcp:30000")
Expand All @@ -1345,7 +1347,7 @@ func TestAddNodePort(t *testing.T) {
net.ParseIP("fd00:1234:5678:dead:beaf::2"),
},
port: 30001,
protocol: openflow.ProtocolUDPv6,
protocol: binding.ProtocolUDPv6,
expectedCalls: func(ipset *ipsettest.MockInterfaceMockRecorder) {
ipset.AddEntry(antreaNodePortIP6Set, "fd00:1234:5678:dead:beaf::1,udp:30001")
ipset.AddEntry(antreaNodePortIP6Set, "fd00:1234:5678:dead:beaf::2,udp:30001")
Expand All @@ -1368,7 +1370,7 @@ func TestDeleteNodePort(t *testing.T) {
name string
nodePortAddresses []net.IP
port uint16
protocol openflow.Protocol
protocol binding.Protocol
expectedCalls func(ipset *ipsettest.MockInterfaceMockRecorder)
}{
{
Expand All @@ -1378,7 +1380,7 @@ func TestDeleteNodePort(t *testing.T) {
net.ParseIP("1.1.2.2"),
},
port: 30000,
protocol: openflow.ProtocolTCP,
protocol: binding.ProtocolTCP,
expectedCalls: func(ipset *ipsettest.MockInterfaceMockRecorder) {
ipset.DelEntry(antreaNodePortIPSet, "1.1.1.1,tcp:30000")
ipset.DelEntry(antreaNodePortIPSet, "1.1.2.2,tcp:30000")
Expand All @@ -1391,7 +1393,7 @@ func TestDeleteNodePort(t *testing.T) {
net.ParseIP("fd00:1234:5678:dead:beaf::2"),
},
port: 30001,
protocol: openflow.ProtocolUDPv6,
protocol: binding.ProtocolUDPv6,
expectedCalls: func(ipset *ipsettest.MockInterfaceMockRecorder) {
ipset.DelEntry(antreaNodePortIP6Set, "fd00:1234:5678:dead:beaf::1,udp:30001")
ipset.DelEntry(antreaNodePortIP6Set, "fd00:1234:5678:dead:beaf::2,udp:30001")
Expand Down Expand Up @@ -2156,3 +2158,73 @@ COMMIT
})
}
}

func TestClearConntrackEntryForService(t *testing.T) {
testCases := []struct {
name string
svcIP net.IP
svcPort uint16
endpointIP net.IP
protocol binding.Protocol
expectedCalls func(mockNetlink *netlinktest.MockInterfaceMockRecorder)
}{
{
name: "TCPv4 with all parameters",
svcIP: net.ParseIP("192.168.1.1"),
svcPort: 80,
endpointIP: net.ParseIP("10.10.0.2"),
protocol: binding.ProtocolTCP,
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
filter := &netlink.ConntrackFilter{}
filter.AddProtocol(unix.AF_INET)
filter.AddZone(openflow.CtZone)
filter.AddIP(netlink.ConntrackOrigDstIP, net.ParseIP("192.168.1.1"))
filter.AddPort(netlink.ConntrackOrigDstPort, 80)
filter.AddIP(netlink.ConntrackReplySrcIP, net.ParseIP("10.10.0.2"))
mockNetlink.ConntrackDeleteFilter(netlink.ConntrackTable, unix.AF_INET, filter).Times(1)
},
},
{
name: "UDPv4 with svcIP and svcPort",
svcIP: net.ParseIP("192.168.1.1"),
svcPort: 53,
endpointIP: nil,
protocol: binding.ProtocolUDP,
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
filter := &netlink.ConntrackFilter{}
filter.AddProtocol(unix.AF_INET)
filter.AddZone(openflow.CtZone)
filter.AddIP(netlink.ConntrackOrigDstIP, net.ParseIP("192.168.1.1"))
filter.AddPort(netlink.ConntrackOrigDstPort, 53)
mockNetlink.ConntrackDeleteFilter(netlink.ConntrackTable, unix.AF_INET, filter).Times(1)
},
},
{
name: "SCTPv6 with endpointIP",
svcIP: nil,
svcPort: 0,
endpointIP: net.ParseIP("10.10.0.2"),
protocol: binding.ProtocolSCTPv6,
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
filter := &netlink.ConntrackFilter{}
filter.AddProtocol(unix.AF_INET6)
filter.AddZone(openflow.CtZone)
filter.AddIP(netlink.ConntrackOrigDstIP, net.ParseIP("10.10.0.2"))
mockNetlink.ConntrackDeleteFilter(netlink.ConntrackTable, unix.AF_INET6, filter).Times(1)
},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
mockNetlink := netlinktest.NewMockInterface(ctrl)
c := &Client{
netlink: mockNetlink,
}
tc.expectedCalls(mockNetlink.EXPECT())

assert.NoError(t, c.ClearConntrackEntryForService(tc.svcIP, tc.svcPort, tc.endpointIP, tc.protocol))
})
}
}
3 changes: 2 additions & 1 deletion pkg/features/antrea_features.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
TopologyAwareHints featuregate.Feature = "TopologyAwareHints"

// alpha: v1.13
// beta: v2.0
// Enable support for cleaning up stale UDP Service conntrack connections in AntreaProxy.
CleanupStaleUDPSvcConntrack featuregate.Feature = "CleanupStaleUDPSvcConntrack"

Expand Down Expand Up @@ -177,7 +178,7 @@ var (
Egress: {Default: true, PreRelease: featuregate.Beta},
EndpointSlice: {Default: true, PreRelease: featuregate.GA},
TopologyAwareHints: {Default: true, PreRelease: featuregate.Beta},
CleanupStaleUDPSvcConntrack: {Default: false, PreRelease: featuregate.Alpha},
CleanupStaleUDPSvcConntrack: {Default: false, PreRelease: featuregate.Beta},
Traceflow: {Default: true, PreRelease: featuregate.Beta},
AntreaIPAM: {Default: false, PreRelease: featuregate.Alpha},
FlowExporter: {Default: false, PreRelease: featuregate.Alpha},
Expand Down

0 comments on commit bb6ba90

Please sign in to comment.