Skip to content

Commit

Permalink
Merge pull request #48 from coroot/net_device_filter
Browse files Browse the repository at this point in the history
node: do not ignore `em*`, `bond*`, `p*p*`, and `enx*` network devices
  • Loading branch information
def authored Nov 9, 2023
2 parents 44dcc73 + fab4a7d commit ade6728
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 6 additions & 3 deletions node/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -68,5 +72,4 @@ func NetDevices() ([]NetDeviceInfo, error) {
res = append(res, info)
}
return res, nil

}
32 changes: 32 additions & 0 deletions node/net_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit ade6728

Please sign in to comment.