From 7aab4a99d3581abbe909c31ffd8cefdc8deab9d9 Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Wed, 6 Feb 2019 18:58:20 +0100 Subject: [PATCH] probe media before applying new settings, exclude vlan's (align to configure_interface_hardware()). for https://github.com/opnsense/core/issues/3198 We could debate that media is hardware setting and thus should move to configure_interface_hardware(), but seems to be the case for more settings in interface_configure(). Maybe it's an idea to move all of these things to a single point later, so legacy_interface_details() only needs to be called once. --- src/etc/inc/interfaces.inc | 23 +++++++++++++++-------- src/etc/inc/interfaces.lib.inc | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/etc/inc/interfaces.inc b/src/etc/inc/interfaces.inc index 769a93f8f..f9afcbcfb 100644 --- a/src/etc/inc/interfaces.inc +++ b/src/etc/inc/interfaces.inc @@ -2406,16 +2406,23 @@ function interface_configure($verbose = false, $interface = 'wan', $reload = fal } } - /* media */ - if (!empty($wancfg['media']) || !empty($wancfg['mediaopt'])) { - $cmd = "/sbin/ifconfig " . escapeshellarg($realhwif); - if (!empty($wancfg['media'])) { - $cmd .= " media " . escapeshellarg($wancfg['media']); - } + /* skip vlans for media setup and only apply when changed */ + if (!stristr($realhwif, "_vlan") && (!empty($wancfg['media']) || !empty($wancfg['mediaopt']))) { + $intf_details = legacy_interface_details($realhwif); + $media_changed = stripos($intf_details['media_raw'], $wancfg['media']) == false; if (!empty($wancfg['mediaopt'])) { - $cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']); + $media_changed |= stripos($intf_details['media_raw'], $wancfg['mediaopt']) == false; + } + if ($media_changed) { + $cmd = "/sbin/ifconfig " . escapeshellarg($realhwif); + if (!empty($wancfg['media'])) { + $cmd .= " media " . escapeshellarg($wancfg['media']); + } + if (!empty($wancfg['mediaopt'])) { + $cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']); + } + mwexec($cmd); } - mwexec($cmd); } // apply interface hardware settings (tso, lro, ..) configure_interface_hardware($realhwif); diff --git a/src/etc/inc/interfaces.lib.inc b/src/etc/inc/interfaces.lib.inc index c49aa8a6b..373554433 100644 --- a/src/etc/inc/interfaces.lib.inc +++ b/src/etc/inc/interfaces.lib.inc @@ -301,6 +301,7 @@ function legacy_interfaces_details($intf = null) if (preg_match("/media: .*? \((.*?)\)/", $line, $matches)) { $result[$current_interface]['media'] = $matches[1]; } + $result[$current_interface]['media_raw'] = substr(trim($line), 7); } elseif (preg_match("/status: (.*)$/", $line, $matches)) { $result[$current_interface]['status'] = $matches[1]; } elseif (preg_match("/channel (\S*)/", $line, $matches)) {