public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Moayad Almalat <m.almalat@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH pve-cluster v3] fix #2685: datacenter: allow 4-bit suffix in mac_prefix
Date: Tue, 24 Feb 2026 17:14:18 +0100	[thread overview]
Message-ID: <20260224161418.320892-1-m.almalat@proxmox.com> (raw)

---
 src/PVE/DataCenterConfig.pm |  2 +-
 src/test/Makefile           |  9 ++++++++-
 src/test/test_mac_prefix.pl | 24 ++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 2 deletions(-)
 create mode 100644 src/test/test_mac_prefix.pl

diff --git a/src/PVE/DataCenterConfig.pm b/src/PVE/DataCenterConfig.pm
index 514c867..d88b167 100644
--- a/src/PVE/DataCenterConfig.pm
+++ b/src/PVE/DataCenterConfig.pm
@@ -224,7 +224,7 @@ PVE::JSONSchema::register_format('mac-prefix', \&pve_verify_mac_prefix);
 sub pve_verify_mac_prefix {
     my ($mac_prefix, $noerr) = @_;
 
-    if ($mac_prefix !~ m/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}:?$/i) {
+    if ($mac_prefix !~ m/^[a-f0-9][02468ace](?::[a-f0-9]{2}){0,2}(?::[a-f0-9]?)?$/i) {
         return undef if $noerr;
         die "value is not a valid unicast MAC address prefix\n";
     }
diff --git a/src/test/Makefile b/src/test/Makefile
index 757f35f..cdd37d0 100644
--- a/src/test/Makefile
+++ b/src/test/Makefile
@@ -4,8 +4,15 @@ cpgtest: cpgtest.c
 	gcc -Wall cpgtest.c $(shell pkg-config --cflags --libs libcpg libqb) -o cpgtest
 
 .PHONY: check install clean distclean
-check:
+check: corosync-parser-test test-mac-prefix
+
+.PHONY: corosync-parser-test
+corosync-parser-test:
 	./corosync_parser_test.pl
 
+.PHONY: test-mac-prefix
+test-mac-prefix:
+	perl test_mac_prefix.pl
+
 distclean: clean
 clean:
diff --git a/src/test/test_mac_prefix.pl b/src/test/test_mac_prefix.pl
new file mode 100644
index 0000000..631874c
--- /dev/null
+++ b/src/test/test_mac_prefix.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+
+use Test::More;
+
+use lib ('.', '..');
+
+use PVE::DataCenterConfig;
+
+my $longest_prefix_len = 10;
+my $prefix = "00:00:00:00:00:00";
+
+# test that all sub-strings of $prefix longer than "00" and strictly shorter than
+# "00:00:00:00" are OK
+for (my $i = 0; $i <= length($prefix); $i++) {
+    my $sub_prefix = substr($prefix, 0, $i);
+    if (2 <= $i && $i <= $longest_prefix_len) {
+        ok(PVE::DataCenterConfig::pve_verify_mac_prefix($sub_prefix), "$sub_prefix is a valid mac prefix");
+    } else {
+        is(PVE::DataCenterConfig::pve_verify_mac_prefix($sub_prefix, 1), undef, "$sub_prefix is not valid mac prefix");
+    }
+}
+
+done_testing();
-- 
2.47.3




                 reply	other threads:[~2026-02-24 16:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260224161418.320892-1-m.almalat@proxmox.com \
    --to=m.almalat@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal