From 35edcff88479ec2568fcb560f905f1af27454e33 Mon Sep 17 00:00:00 2001 From: Pim van Pelt Date: Sat, 9 Apr 2022 20:47:23 +0000 Subject: [PATCH] Allow mac to be set up loopbacks, iff not multicast --- config/loopback.py | 4 ++++ schema.yaml | 1 + unittest/yaml/error-loopback2.yaml | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 unittest/yaml/error-loopback2.yaml diff --git a/config/loopback.py b/config/loopback.py index 09fe243..9890c03 100644 --- a/config/loopback.py +++ b/config/loopback.py @@ -14,6 +14,7 @@ import logging import config.lcp as lcp import config.address as address +import config.mac as mac def get_loopbacks(yaml): """ Return a list of all loopbacks. """ @@ -73,5 +74,8 @@ def validate_loopbacks(yaml): if not address.is_allowed(yaml, ifname, iface['addresses'], a): msgs.append("loopback %s IP address %s conflicts with another" % (ifname, a)) result = False + if 'mac' in iface and mac.is_multicast(iface['mac']): + msgs.append("loopback %s MAC address %s cannot be multicast" % (ifname, iface['mac'])) + result = False return result, msgs diff --git a/schema.yaml b/schema.yaml index 41037b4..0732ecc 100644 --- a/schema.yaml +++ b/schema.yaml @@ -29,6 +29,7 @@ bridgedomain-settings: --- loopback: description: str(exclude='\'"',len=64,required=False) + mac: mac(required=False) lcp: str(max=15,matches='[a-z]+[a-z0-9-]*',required=False) mtu: int(min=128,max=9216,required=False) addresses: list(ip_interface(),min=1,max=6,required=False) diff --git a/unittest/yaml/error-loopback2.yaml b/unittest/yaml/error-loopback2.yaml new file mode 100644 index 0000000..c9c3845 --- /dev/null +++ b/unittest/yaml/error-loopback2.yaml @@ -0,0 +1,17 @@ +test: + description: "Loopback MAC address can't be multicast" + errors: + expected: + - "loopback .* MAC address .* cannot be multicast" + count: 1 +--- +loopbacks: + loop0: + description: "Cool, local MACs are fine" + mac: 02:00:00:00:00:00 + loop1: + description: "Cool, global unicast MACs are fine" + mac: 04:00:00:00:00:00 + loop2: + description: "Not cool, multicast MACs" + mac: 01:00:00:00:00:00