Skip to content

Commit

Permalink
Remove unexpected AltName after rename interface
Browse files Browse the repository at this point in the history
Fix #6301

Signed-off-by: gran <[email protected]>
Co-authored-by: Lan <[email protected]>
  • Loading branch information
gran-vmv and luolanzone committed May 16, 2024
1 parent 4ec2bdd commit 43a83cd
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,5 @@ require (
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
)

replace github.com/vishvananda/netlink => github.com/vishvananda/netlink v0.0.0-20240425164735-856e190dd707
7 changes: 3 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,8 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
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 v0.0.0-20240425164735-856e190dd707 h1:upojxMEa64PkbMGs2PfcjOlSwx5rwj9Hte6R7jq1Yls=
github.com/vishvananda/netlink v0.0.0-20240425164735-856e190dd707/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 @@ -916,7 +915,6 @@ golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602100848-8d3cce7afc34/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200728102440-3e129f6d46b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201118182958-a01c418693c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -942,6 +940,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.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
Expand Down
21 changes: 20 additions & 1 deletion pkg/agent/util/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,12 @@ func RenameInterface(from, to string) error {
if pollErr != nil {
return fmt.Errorf("failed to rename host interface name %s to %s", from, to)
}
return nil
// Fix for the issue https://github.com/antrea-io/antrea/issues/6301.
// In some new Linux versions which support AltName, if there is only one valid value in AlternativeNamesPolicy
// which is also occupied by an interface name, after the interface name changed from generated value to another one,
// the interface altname will be set to previous name immediately.
// This altname must be removed to avoid unexpected conflict.
return removeInterfaceAltName(to, from)
}

func RemoveLinkIPs(link netlink.Link) error {
Expand Down Expand Up @@ -378,6 +383,20 @@ func renameHostInterface(oriName string, newName string) error {
return nil
}

// removeInterfaceAltName removes altName on interface with provided name. altName not found will return nil.
func removeInterfaceAltName(name string, altName string) error {
link, err := netlinkUtil.LinkByName(name)
if err != nil {
return err
}
for _, existAltName := range link.Attrs().AltNames {
if existAltName == altName {
return netlinkUtil.LinkDelAltName(link, altName)
}
}
return nil
}

// PrepareHostInterfaceConnection prepares host interface connection to the OVS bridge client by:
// 1. Renaming the host interface (a bridged suffix will be added to it).
// 2. Creating an internal port (original name of the host interface will be used here).
Expand Down
25 changes: 25 additions & 0 deletions pkg/agent/util/net_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type mockLink struct {
name string
masterIndex int
hardwareAddr net.HardwareAddr
altNames []string
}

func (l mockLink) Attrs() *netlink.LinkAttrs {
Expand All @@ -44,6 +45,7 @@ func (l mockLink) Attrs() *netlink.LinkAttrs {
Name: l.name,
MasterIndex: l.masterIndex,
HardwareAddr: l.hardwareAddr,
AltNames: l.altNames,
}
}

Expand Down Expand Up @@ -569,6 +571,18 @@ func TestRenameInterface(t *testing.T) {
mockNetlink.LinkSetDown(mockLink{name: "test1"}).Return(nil)
mockNetlink.LinkSetName(mockLink{name: "test1"}, "test2").Return(nil)
mockNetlink.LinkSetUp(mockLink{name: "test1"}).Return(nil)
mockNetlink.LinkByName("test2").Return(mockLink{name: "test2", altNames: []string{}}, nil)
},
},
{
name: "Rename Interface Success with AltName",
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
mockNetlink.LinkByName("test1").Return(mockLink{name: "test1"}, nil)
mockNetlink.LinkSetDown(mockLink{name: "test1"}).Return(nil)
mockNetlink.LinkSetName(mockLink{name: "test1"}, "test2").Return(nil)
mockNetlink.LinkSetUp(mockLink{name: "test1"}).Return(nil)
mockNetlink.LinkByName("test2").Return(mockLink{name: "test2", altNames: []string{"test1"}}, nil)
mockNetlink.LinkDelAltName(mockLink{name: "test2", altNames: []string{"test1"}}, "test1").Return(nil)
},
},
{
Expand Down Expand Up @@ -605,6 +619,17 @@ func TestRenameInterface(t *testing.T) {
},
wantErr: renameFailErr,
},
{
name: "Remove AltName Err",
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
mockNetlink.LinkByName("test1").Return(mockLink{name: "test1"}, nil)
mockNetlink.LinkSetDown(mockLink{name: "test1"}).Return(nil)
mockNetlink.LinkSetName(mockLink{name: "test1"}, "test2").Return(nil)
mockNetlink.LinkSetUp(mockLink{name: "test1"}).Return(nil)
mockNetlink.LinkByName("test2").Return(mockLink{name: "test2", altNames: []string{"test1"}}, nil)
mockNetlink.LinkDelAltName(mockLink{name: "test2", altNames: []string{"test1"}}, "test1").Return(testInvalidErr)
},
},
}

for _, tc := range tests {
Expand Down
4 changes: 4 additions & 0 deletions pkg/agent/util/netlink/netlink_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ type Interface interface {

LinkSetName(link netlink.Link, name string) error

LinkAddAltName(link netlink.Link, name string) error

LinkDelAltName(link netlink.Link, name string) error

LinkSetUp(link netlink.Link) error

ConntrackDeleteFilter(table netlink.ConntrackTableType, family netlink.InetFamily, filter netlink.CustomConntrackFilter) (uint, error)
Expand Down
30 changes: 29 additions & 1 deletion pkg/agent/util/netlink/testing/mock_netlink_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 43a83cd

Please sign in to comment.