[1/2] network-functions.pl: Add MAC address compare function

Message ID 20210324164716.387-1-hofmann@leo-andres.de
State Accepted
Commit 92d8c1f73c548c61b0c2a33c76d66c9b917d5122
Headers
Series [1/2] network-functions.pl: Add MAC address compare function |

Commit Message

Leo-Andres Hofmann March 24, 2021, 4:47 p.m. UTC
  Signed-off-by: Leo-Andres Hofmann <hofmann@leo-andres.de>
---
 config/cfgroot/network-functions.pl | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Patch

diff --git a/config/cfgroot/network-functions.pl b/config/cfgroot/network-functions.pl
index e94404f05..9908ee8ab 100644
--- a/config/cfgroot/network-functions.pl
+++ b/config/cfgroot/network-functions.pl
@@ -431,6 +431,18 @@  sub valid_mac($) {
 	return $mac =~ /^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$/;
 }
 
+# Compares two MAC addresses and returns true if they are equal
+sub is_mac_equal {
+	my $mac_1 = uc shift; # convert to upper case
+	my $mac_2 = uc shift;
+
+	if(valid_mac($mac_1) && valid_mac($mac_2) && ($mac_1 eq $mac_2)) {
+		return 1;
+	}
+
+	return 0;
+}
+
 sub random_mac {
 	my $address = "02";