summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDon Slice <dslice@nvidia.com>2021-03-19 20:10:14 +0100
committerDon Slice <dslice@nvidia.com>2021-03-31 18:38:59 +0200
commit00302a580c57fce0bb45d3fd6af9d4408a417ceb (patch)
tree591123af13564ea33852d8352a0c5880d8552a92
parenttools: frr-reload.py changes to make black happy (diff)
downloadfrr-00302a580c57fce0bb45d3fd6af9d4408a417ceb.tar.xz
frr-00302a580c57fce0bb45d3fd6af9d4408a417ceb.zip
tools: frr-reload fixes for deleting vrf static routes
Problems reported that in certain cases, frr-reload.py would delete vrf static routes inadvertantly due to two different reasons. First, vrf statics with null0 or Null0 nexthops would fail the match since rendered as blackholes. This was already fixed for non-vrf statics so added for vrf-based. Second, frr-reload would fail to match due to different formats for adding the command. If entered in the old way "ip route x.x.x.x/x y.y.y.y vrf NAME" and rendered in the new sway "vrf NAME\nip route x.x.x.x/x y.y.y.y" it would fail to match do an inadvertant delete. Ticket: 2570270 Signed-off-by: Don Slice <dslice@nvidia.com>
-rwxr-xr-xtools/frr-reload.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/frr-reload.py b/tools/frr-reload.py
index 75d6b62d4..cfc745d43 100755
--- a/tools/frr-reload.py
+++ b/tools/frr-reload.py
@@ -279,6 +279,35 @@ class Config(object):
if ":" in line:
line = get_normalized_mac_ip_line(line)
+ """
+ vrf static routes can be added in two ways. The old way is:
+
+ "ip route x.x.x.x/x y.y.y.y vrf <vrfname>"
+
+ but it's rendered in the configuration as the new way::
+
+ vrf <vrf-name>
+ ip route x.x.x.x/x y.y.y.y
+ exit-vrf
+
+ this difference causes frr-reload to not consider them a
+ match and delete vrf static routes incorrectly.
+ fix the old way to match new "show running" output so a
+ proper match is found.
+ """
+ if (
+ line.startswith("ip route ") or line.startswith("ipv6 route ")
+ ) and " vrf " in line:
+ newline = line.split(" ")
+ vrf_index = newline.index("vrf")
+ vrf_ctx = newline[vrf_index] + " " + newline[vrf_index + 1]
+ del newline[vrf_index : vrf_index + 2]
+ newline = " ".join(newline)
+ self.lines.append(vrf_ctx)
+ self.lines.append(newline)
+ self.lines.append("exit-vrf")
+ line = "end"
+
self.lines.append(line)
self.load_contexts()
@@ -460,6 +489,23 @@ class Config(object):
):
key[0] = re.sub(r"\s+null0(\s*$)", " Null0", key[0])
+ """
+ Similar to above, but when the static is in a vrf, it turns into a
+ blackhole nexthop for both null0 and Null0. Fix it accordingly
+ """
+ if lines and key[0].startswith("vrf "):
+ newlines = []
+ for line in lines:
+ if line.startswith("ip route ") or line.startswith("ipv6 route "):
+ if "null0" in line:
+ line = re.sub(r"\s+null0(\s*$)", " blackhole", line)
+ elif "Null0" in line:
+ line = re.sub(r"\s+Null0(\s*$)", " blackhole", line)
+ newlines.append(line)
+ else:
+ newlines.append(line)
+ lines = newlines
+
if lines:
if tuple(key) not in self.contexts:
ctx = Context(tuple(key), lines)