Merge pull request #253 from Erdnusschokolade/fix/vlan-mgmt-filter

Fix conf_overwrite filter removing vlan mgmt entries
This commit is contained in:
René van Dorst
2026-06-21 18:52:59 +00:00
committed by GitHub
+7 -3
View File
@@ -14,6 +14,7 @@ const conf_cmds = [
/^pvid\s+\d{1,2}\s+\d{1,4}$/, /^pvid\s+\d{1,2}\s+\d{1,4}$/,
/^ingress(\s+\d{1,2}[tua])+$/, /^ingress(\s+\d{1,2}[tua])+$/,
/^ingress\s+[tua]$/, /^ingress\s+[tua]$/,
/^port\s+\d{1,2}\s+(10m|100m|1g|2g5|5g|10g|auto|on|off)(\s+(half|full))?$/,
/^port\s+\d{1,2}\s+name\s+\S+$/, /^port\s+\d{1,2}\s+name\s+\S+$/,
/^eee(\s+\d{1,2})?\s+(on|off)$/, /^eee(\s+\d{1,2})?\s+(on|off)$/,
/^mirror(\s+\d{1,2})(\s+\d{1,2}[tr]?)+$/, /^mirror(\s+\d{1,2})(\s+\d{1,2}[tr]?)+$/,
@@ -36,6 +37,7 @@ const conf_overwrite = [
/^vlan\s+\d{1,4}(?!\s+mgmt\b)/, /^vlan\s+\d{1,4}(?!\s+mgmt\b)/,
/^pvid\s+\d{1,2}\b/, /^pvid\s+\d{1,2}\b/,
/^ingress\b/, /^ingress\b/,
/^port\s+\d{1,2}(?!\s+name\b)/,
/^port\s+\d{1,2}\s+name\b/, /^port\s+\d{1,2}\s+name\b/,
/^eee\s+\d{1,2}\b/, /^eee\s+\d{1,2}\b/,
/^eee\b/, /^eee\b/,
@@ -57,8 +59,7 @@ function parseConf(s){
const deleteMatch = line.match(/^vlan\s+(\d{1,4})\s+d$/); const deleteMatch = line.match(/^vlan\s+(\d{1,4})\s+d$/);
if (deleteMatch) { if (deleteMatch) {
const prefix = "vlan " + deleteMatch[1] + " "; const prefix = "vlan " + deleteMatch[1] + " ";
configuration = configuration.filter(c => configuration = configuration.filter(c => !c.startsWith(prefix));
c !== "vlan " + deleteMatch[1] && !c.startsWith(prefix));
continue; continue;
} }
console.log(l + ' --> ' + line); console.log(l + ' --> ' + line);
@@ -71,10 +72,13 @@ function parseConf(s){
let m = line.match(x); let m = line.match(x);
let matchStr = m[0]; let matchStr = m[0];
configuration = configuration.filter(item => configuration = configuration.filter(item =>
!(item === matchStr || item.startsWith(matchStr + " "))); !(item === matchStr || (item.startsWith(matchStr + " ") && !item.endsWith(" mgmt") && !item.startsWith(matchStr + " name "))));
break; break;
} }
} }
// Only one management VLAN can be active, so drop any previous mgmt entry
if (/^vlan\s+\d{1,4}\s+mgmt$/.test(line))
configuration = configuration.filter(item => !/^vlan\s+\d{1,4}\s+mgmt$/.test(item));
configuration.push(line); configuration.push(line);
} }
console.log("Configuration now:"); console.log("Configuration now:");