1
0
mirror of https://github.com/rancher/os.git synced 2025-08-19 15:26:49 +00:00

Fixed a regression bug where wildcard MAC matching would match bond and vlan interface.

This commit is contained in:
Morten Møller Riis 2019-04-08 10:41:23 +02:00 committed by niusmallnan
parent 2249a897f1
commit 6126091822
2 changed files with 35 additions and 4 deletions

View File

@ -113,7 +113,11 @@ func findMatch(link netlink.Link, netCfg *NetworkConfig) (InterfaceConfig, bool)
if strings.HasPrefix(netConf.Match, "mac") { if strings.HasPrefix(netConf.Match, "mac") {
if strings.Contains(netConf.Match, "*") { if strings.Contains(netConf.Match, "*") {
// If selector contains wildcard * and MAC address matches wildcard then return // If selector contains wildcard * and MAC address matches wildcard then return
return netConf, glob.Glob(netConf.Match[4:], link.Attrs().HardwareAddr.String()) // Don't match mac address of a bond or VLAN interface because it is the same address as the slave or parent.
if glob.Glob(netConf.Match[4:], link.Attrs().HardwareAddr.String()) && link.Attrs().Name != netConf.Bond && link.Type() != "vlan" {
return netConf, true
}
continue
} }
haAddr, err := net.ParseMAC(netConf.Match[4:]) haAddr, err := net.ParseMAC(netConf.Match[4:])

View File

@ -9,6 +9,7 @@ import (
type mockLink struct { type mockLink struct {
attrs netlink.LinkAttrs attrs netlink.LinkAttrs
t string
} }
func (l mockLink) Attrs() *netlink.LinkAttrs { func (l mockLink) Attrs() *netlink.LinkAttrs {
@ -16,33 +17,57 @@ func (l mockLink) Attrs() *netlink.LinkAttrs {
} }
func (l mockLink) Type() string { func (l mockLink) Type() string {
return "fake" return l.t
} }
func TestFindMatch(t *testing.T) { func TestFindMatch(t *testing.T) {
testCases := []struct { testCases := []struct {
match string match string
mac string mac string
t string
name string
bond string
expected bool expected bool
}{ }{
{ {
"mac:aa:bb:cc:dd:ee:ff", "mac:aa:bb:cc:dd:ee:ff",
"aa:bb:cc:dd:ee:ff", "aa:bb:cc:dd:ee:ff",
"fake",
"eth0",
"bond0",
true, true,
}, },
{ {
"mac:aa:bb:cc:*", "mac:aa:bb:cc:*",
"aa:bb:cc:12:34:56", "aa:bb:cc:12:34:56",
"fake",
"eth0",
"bond0",
true, true,
}, },
{ {
"mac:aa:bb:cc:*", "mac:aa:bb:cc:*",
"11:bb:cc:dd:ee:ff", "11:bb:cc:dd:ee:ff",
"fake",
"eth0",
"bond0",
false, false,
}, },
{ {
"mac:aa:bb:cc:dd:ee:ff", "mac:aa:bb:cc:dd:ee:ff",
"aa:bb:cc:dd:ee:11", "aa:bb:cc:dd:ee:11",
"fake",
"eth0",
"bond0",
false,
},
// This is a bond eg. bond0
{
"mac:aa:bb:*",
"aa:bb:cc:dd:ee:11",
"bond",
"bond0",
"bond0",
false, false,
}, },
} }
@ -50,14 +75,15 @@ func TestFindMatch(t *testing.T) {
for i, tt := range testCases { for i, tt := range testCases {
netCfg := NetworkConfig{ netCfg := NetworkConfig{
Interfaces: map[string]InterfaceConfig{ Interfaces: map[string]InterfaceConfig{
"eth0": InterfaceConfig{ tt.name: InterfaceConfig{
Match: tt.match, Match: tt.match,
Bond: tt.bond,
}, },
}, },
} }
linkAttrs := netlink.NewLinkAttrs() linkAttrs := netlink.NewLinkAttrs()
linkAttrs.Name = "eth0" linkAttrs.Name = tt.name
linkAttrs.HardwareAddr, _ = net.ParseMAC(tt.mac) linkAttrs.HardwareAddr, _ = net.ParseMAC(tt.mac)
link := mockLink{attrs: linkAttrs} link := mockLink{attrs: linkAttrs}
@ -67,4 +93,5 @@ func TestFindMatch(t *testing.T) {
t.Errorf("Test case %d failed: mac: '%s' match '%s' expected: '%v' got: '%v'", i, tt.mac, tt.match, tt.expected, match) t.Errorf("Test case %d failed: mac: '%s' match '%s' expected: '%v' got: '%v'", i, tt.mac, tt.match, tt.expected, match)
} }
} }
} }