]> git.puffer.fish Git - matthieu/frr.git/commitdiff
tools: frr-reload strip interface vrf ctx line
authorChirag Shah <chirag@nvidia.com>
Tue, 9 Apr 2024 00:14:48 +0000 (17:14 -0700)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Wed, 17 Apr 2024 07:42:49 +0000 (07:42 +0000)
if frr.conf file contains 'interface x vrf <name> config
it causes protocol (like ospf) neighbor session flap,
as it deletes interface base config line ('interface x') from
running config and readds with 'interface x vrf <name>'
line from frr.conf.
This deletion and readdition of lines leads to neighborship
flaps.

This issue is by product of (PR-10411 | https://github.com/FRRouting/frr/pull/10411)
(commit id: 788a036fdb)
where running config for interface config no loger displays associated
vrf line.

Ticket: #3858146
Testing:

frr.conf
interface swp1.2 vrf vrf1012
ip ospf network point-to-point

running-config:
interface swp1.2
 ip ospf network point-to-point
 exit

Before fix:
frr-reload logs:

2024-04-09 00:28:31,096  INFO: Executed "interface swp1.2  no ip ospf
network point-to-point exit"

 'interface swp1.2 vrf vrf1012\n ip ospf network
 point-to-point\nexit\n',

After fix:
frr-reload strips vrf line, thus no config change between
frr.conf and running config.

Signed-off-by: Chirag Shah <chirag@nvidia.com>
(cherry picked from commit c1356f0e85e7b8480295d38b843a729d4a491d41)

tools/frr-reload.py

index 73479c634bc4f09a0e4fbc9110f3f7f3ada4bdb3..9c20d0099f4b7f01348d013112ed4e6cfcbf0fd4 100755 (executable)
@@ -220,6 +220,23 @@ def get_normalized_mac_ip_line(line):
     return line
 
 
+def get_normalized_interface_vrf(line):
+    """
+    If 'interface <int_name> vrf <vrf_name>' is present in file,
+    we need to remove the explicit "vrf <vrf_name>"
+    so that the context information is created
+    correctly and configurations are matched appropriately.
+    """
+
+    intf_vrf = re.search("interface (\S+) vrf (\S+)", line)
+    if intf_vrf:
+        old_line = "vrf %s" % intf_vrf.group(2)
+        new_line = line.replace(old_line, "").strip()
+        return new_line
+
+    return line
+
+
 # This dictionary contains a tree of all commands that we know start a
 # new multi-line context. All other commands are treated either as
 # commands inside a multi-line context or as single-line contexts. This
@@ -295,6 +312,10 @@ class Config(object):
             # Compress duplicate whitespaces
             line = " ".join(line.split())
 
+            # Remove 'vrf <vrf_name>' from 'interface <x> vrf <vrf_name>'
+            if line.startswith("interface ") and "vrf" in line:
+                line = get_normalized_interface_vrf(line)
+
             if ":" in line:
                 line = get_normalized_mac_ip_line(line)