Skip to content

Commit

Permalink
🐛 fix net interface sort (#4672)
Browse files Browse the repository at this point in the history
Signed-off-by: cuisongliu <cuisongliu@qq.com>
  • Loading branch information
cuisongliu committed Apr 12, 2024
1 parent e3c82b4 commit c3fa80d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/utils/iputils/iputils_v2.go
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"math/big"
"net"
"sort"
"strings"

"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -105,6 +106,9 @@ func ListLocalHostAddrs() (*[]net.Addr, error) {
logger.Warn("net.Interfaces failed, err:", err.Error())
return nil, err
}
sort.Slice(netInterfaces, func(i, j int) bool {
return netInterfaces[i].Index < netInterfaces[j].Index
})
var allAddrs []net.Addr
for i := 0; i < len(netInterfaces); i++ {
if (netInterfaces[i].Flags & net.FlagUp) == 0 {
Expand Down

0 comments on commit c3fa80d

Please sign in to comment.