diff --git a/network/interface.go b/network/interface.go index 6bad7a2..cc0eec2 100644 --- a/network/interface.go +++ b/network/interface.go @@ -82,7 +82,11 @@ func (i *logicalInterface) Netdev() string { } func (i *logicalInterface) Filename() string { - return fmt.Sprintf("%02x-%s", i.configDepth, i.name) + name := i.name + if name == "" { + name = i.hwaddr.String() + } + return fmt.Sprintf("%02x-%s", i.configDepth, name) } func (i *logicalInterface) Children() []networkInterface { diff --git a/network/interface_test.go b/network/interface_test.go index 51d9458..c2ec3dc 100644 --- a/network/interface_test.go +++ b/network/interface_test.go @@ -344,6 +344,8 @@ func TestFilename(t *testing.T) { {logicalInterface{name: "iface", configDepth: 9}, "09-iface"}, {logicalInterface{name: "iface", configDepth: 10}, "0a-iface"}, {logicalInterface{name: "iface", configDepth: 53}, "35-iface"}, + {logicalInterface{hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), configDepth: 1}, "01-01:23:45:67:89:ab"}, + {logicalInterface{name: "iface", hwaddr: net.HardwareAddr([]byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab}), configDepth: 1}, "01-iface"}, } { if tt.i.Filename() != tt.f { t.Fatalf("bad filename (%q): got %q, want %q", tt.i, tt.i.Filename(), tt.f)