From a6415394afd2940a387f6822965400f05975e12f Mon Sep 17 00:00:00 2001 From: wlan0 Date: Wed, 25 Mar 2015 14:57:48 -0700 Subject: [PATCH] match network interfaces by MAC addresses --- cmd/network/network.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/network/network.go b/cmd/network/network.go index 3978aa26..03217284 100644 --- a/cmd/network/network.go +++ b/cmd/network/network.go @@ -1,11 +1,13 @@ package network import ( + "bytes" "errors" "fmt" "net" "os" "os/exec" + "strings" log "github.com/Sirupsen/logrus" @@ -48,6 +50,18 @@ func applyNetworkConfigs(cfg *config.Config) error { continue } + if len(netConf.Match) > 4 && strings.ToLower(netConf.Match[:3]) == "mac" { + haAddr, err := net.ParseMAC(netConf.Match[4:]) + if err != nil { + return err + } + if bytes.Compare(haAddr, link.Attrs().HardwareAddr) == 0 { + // MAC address match is used over all other matches + match = netConf + break + } + } + // "" means match has not been found if match.Match == "" && matches(linkName, netConf.Match) { match = netConf