Skip to content

Commit

Permalink
Fix that AntreaProxy could unintentionally delete conntrack entries i…
Browse files Browse the repository at this point in the history
…n zone 0

This is a subsequent PR for #5112. As mentioned in #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 is to fix the issue by incorporating a ct zone filter, which is provided by
the latest go libray `netlink`.

Signed-off-by: Hongliang Liu <lhongliang@vmware.com>
  • Loading branch information
hongliangl committed Apr 11, 2024
1 parent 3ac87f6 commit 6fd4aec
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
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
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

0 comments on commit 6fd4aec

Please sign in to comment.