From 80d441219256e8cd78d6a55a68b681687ffe3d93 Mon Sep 17 00:00:00 2001 From: vvhuang-ll <13680846391@163.com> Date: Tue, 10 Dec 2024 17:59:48 +0800 Subject: [PATCH] Fix: Enhance default interface detection logic - Updated 'LookupDefaultIfaceName' to support additional naming conventions: - Added support for interfaces like 'ens[0-9]+.*' and 'eth[0-9]+'. --- pkg/skoop/netstack/link.go | 4 ++-- pkg/skoop/netstack/link_test.go | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/skoop/netstack/link.go b/pkg/skoop/netstack/link.go index c2a853bf..febb833a 100644 --- a/pkg/skoop/netstack/link.go +++ b/pkg/skoop/netstack/link.go @@ -71,8 +71,8 @@ func LookupDefaultIfaceName(ifaces []Interface) string { } } - // find first interfaces matched enp[0-9]+s[0-9]+.* - regex := regexp.MustCompile("^enp[0-9]+s[0-9]+.*$") + // find first interfaces matched (enp[0-9]+s[0-9]+.*|eth[0-9]+|ens[0-9]+)$") + regex := regexp.MustCompile("^(enp[0-9]+s[0-9]+.*|eth[0-9]+|ens[0-9]+)$") filtered := lo.Filter(ifaces, func(i Interface, _ int) bool { return regex.MatchString(i.Name) }) diff --git a/pkg/skoop/netstack/link_test.go b/pkg/skoop/netstack/link_test.go index 0bd5214c..36ef1335 100644 --- a/pkg/skoop/netstack/link_test.go +++ b/pkg/skoop/netstack/link_test.go @@ -24,6 +24,10 @@ func TestLookupDefaultIfaceName(t *testing.T) { ifaces: []string{"wg0", "ipvs0", "cni0", "aaenp1s1"}, expected: "", }, + { + ifaces: []string{"ens160", "cali85f094c216c", "vxlan.calico", "calie92c3084733"}, + expected: "ens160", + }, } for _, c := range testcases {