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 <gran@vmware.com>
  • Loading branch information
gran-vmv committed May 13, 2024
1 parent 4ec2bdd commit 58dbcc3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 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
27 changes: 27 additions & 0 deletions pkg/agent/util/net_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +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)
}
// Fix #6301
// In some new Linux versions which support AltName, if there is only one valid value in AlternativeNamesPolicy
// which is also occupied by 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.
removeInterfaceAltName(to, from)
return nil
}

Expand Down Expand Up @@ -378,6 +384,27 @@ func renameHostInterface(oriName string, newName string) error {
return nil
}

func removeInterfaceAltName(name string, altName string) error {
link, err := netlinkUtil.LinkByName(name)
if err != nil {
return err
}
match := false
for _, existAltName := range link.Attrs().AltNames {
if existAltName == altName {
match = true
break
}
}
if !match {
return nil
}
if err := netlinkUtil.LinkDelAltName(link, altName); err != nil {
return err
}
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
4 changes: 4 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,8 @@ 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{"test1"}}, nil)
mockNetlink.LinkDelAltName(mockLink{name: "test2", altNames: []string{"test1"}}, "test1").Return(nil)
},
},
{
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 58dbcc3

Please sign in to comment.