From fd3c4e039f6bd1de25e2cf5bdca017d64bf2d16b Mon Sep 17 00:00:00 2001
From: L6NqLW <64205544+L6NqLW@users.noreply.github.com>
Date: Tue, 2 Jun 2020 13:28:03 +0200
Subject: bonding: T2476: fix mac address override for bond member interfaces

---
 scripts/vyatta-interfaces.pl | 44 ++++++++++++++++++++++++++------------------
 1 file changed, 26 insertions(+), 18 deletions(-)

(limited to 'scripts')

diff --git a/scripts/vyatta-interfaces.pl b/scripts/vyatta-interfaces.pl
index f6fa717a..6f29c4c2 100755
--- a/scripts/vyatta-interfaces.pl
+++ b/scripts/vyatta-interfaces.pl
@@ -258,24 +258,32 @@ sub update_mac {
   my $intf = new Vyatta::Interface($name);
   $intf or die "Unknown interface name/type: $name\n";
 
-  # maybe nothing needs to change
-  my $oldmac = $intf->hw_address();
-  exit 0 if (lc($oldmac) eq lc($mac));
-
-  # try the direct approach
-  if (system("sudo ip link set $name address $mac") == 0) {
-    exit 0;
-  } elsif ($intf->up()) {
-
-    # some hardware can not change MAC address if up
-    system "sudo ip link set $name down"
-      and die "Could not set $name down\n";
-    system "sudo ip link set $name address $mac"
-      and die "Could not set $name address\n";
-    system "sudo ip link set $name up"
-      and die "Could not set $name up\n";
-  } else {
-    die "Could not set mac address for $name\n";
+  my $config = new Vyatta::Config;
+  $config->setLevel($intf->path());
+  my $bond = $config->returnValue("bond-group");
+
+  # we need to skip this for bond member interfaces
+  if (!defined($bond)) {
+
+    # maybe nothing needs to change
+    my $oldmac = $intf->hw_address();
+    exit 0 if (lc($oldmac) eq lc($mac));
+
+    # try the direct approach
+    if (system("sudo ip link set $name address $mac") == 0) {
+      exit 0;
+    } elsif ($intf->up()) {
+
+      # some hardware can not change MAC address if up
+      system "sudo ip link set $name down"
+        and die "Could not set $name down\n";
+      system "sudo ip link set $name address $mac"
+        and die "Could not set $name address\n";
+      system "sudo ip link set $name up"
+        and die "Could not set $name up\n";
+    } else {
+      die "Could not set mac address for $name\n";
+    }
   }
 
   exit 0;
-- 
cgit v1.2.3