diff --git a/node/net.go b/node/net.go index 04f5d0b..30f5201 100644 --- a/node/net.go +++ b/node/net.go @@ -8,7 +8,11 @@ import ( "regexp" ) -var includeNetDev = regexp.MustCompile(`^(enp\d+s\d+(f\d+)?|eth\d+|eno\d+|ens\d+)`) +var netDeviceFilterRe = regexp.MustCompile(`^(enp\d+s\d+(f\d+)?|eth\d+|eno\d+|ens\d+|em\d+|bond\d+|p\d+p\d+|enx[0-9a-f]{12})`) + +func netDeviceFilter(name string) bool { + return netDeviceFilterRe.MatchString(name) +} type NetDeviceInfo struct { Name string @@ -38,7 +42,7 @@ func NetDevices() ([]NetDeviceInfo, error) { var res []NetDeviceInfo for _, link := range links { attrs := link.Attrs() - if !includeNetDev.MatchString(attrs.Name) { + if !netDeviceFilter(attrs.Name) { continue } info := NetDeviceInfo{ @@ -68,5 +72,4 @@ func NetDevices() ([]NetDeviceInfo, error) { res = append(res, info) } return res, nil - } diff --git a/node/net_test.go b/node/net_test.go new file mode 100644 index 0000000..42e7669 --- /dev/null +++ b/node/net_test.go @@ -0,0 +1,32 @@ +package node + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestNetDeviceFilter(t *testing.T) { + cases := map[string]bool{ + "eth0": true, + "eth0@if699": true, + "enp2s0": true, + "bond0": true, + "ens1": true, + "p1p1": true, + "eno2": true, + "em1": true, + "enx78e7d1ea46da": true, + + "dummy0": false, + "docker0": false, + "kube-ipvs0": false, + "veth1b0c947@if2": false, + "flannel.1": false, + "cni0": false, + "lxc00aa@if698": false, + } + + for name, ok := range cases { + assert.Equal(t, ok, netDeviceFilter(name), name) + } +}