Blame SOURCES/0011-reload-bfd-profile.patch

b57a21
diff --git a/tools/frr-reload.py b/tools/frr-reload.py
b57a21
index 9979c8b..1c24f90 100755
b57a21
--- a/tools/frr-reload.py
b57a21
+++ b/tools/frr-reload.py
b57a21
@@ -785,6 +785,48 @@ def line_exist(lines, target_ctx_keys, target_line, exact_match=True):
b57a21
                     return True
b57a21
     return False
b57a21
 
b57a21
+def delete_bgp_bfd(lines_to_add, lines_to_del):
b57a21
+    """
b57a21
+    When 'neighbor <peer> bfd profile <profile>' is present without a
b57a21
+    'neighbor <peer> bfd' line, FRR explicitily adds it to the running
b57a21
+    configuration. When the new configuration drops the bfd profile
b57a21
+    line, the user's intent is to delete any bfd configuration on the
b57a21
+    peer. On reload, deleting the bfd profile line after the bfd line
b57a21
+    will re-enable BFD with the default BFD profile. Move the bfd line
b57a21
+    to the end, if it exists in the new configuration.
b57a21
+
b57a21
+    Example:
b57a21
+
b57a21
+     neighbor 10.0.0.1 bfd
b57a21
+     neighbor 10.0.0.1 bfd profile bfd-profile-1
b57a21
+
b57a21
+     Move to end:
b57a21
+     neighbor 10.0.0.1 bfd profile bfd-profile-1
b57a21
+     ...
b57a21
+
b57a21
+     neighbor 10.0.0.1 bfd
b57a21
+
b57a21
+    """
b57a21
+    lines_to_del_to_app = []
b57a21
+    for (ctx_keys, line) in lines_to_del:
b57a21
+        if (
b57a21
+            ctx_keys[0].startswith("router bgp")
b57a21
+            and line
b57a21
+            and line.startswith("neighbor ")
b57a21
+        ):
b57a21
+            # 'no neighbor [peer] bfd>'
b57a21
+            nb_bfd = "neighbor (\S+) .*bfd$"
b57a21
+            re_nb_bfd = re.search(nb_bfd, line)
b57a21
+            if re_nb_bfd:
b57a21
+                lines_to_del_to_app.append((ctx_keys, line))
b57a21
+
b57a21
+    for (ctx_keys, line) in lines_to_del_to_app:
b57a21
+        lines_to_del.remove((ctx_keys, line))
b57a21
+        lines_to_del.append((ctx_keys, line))
b57a21
+
b57a21
+    return (lines_to_add, lines_to_del)
b57a21
+
b57a21
+
b57a21
 def check_for_exit_vrf(lines_to_add, lines_to_del):
b57a21
 
b57a21
     # exit-vrf is a bit tricky.  If the new config is missing it but we
b57a21
@@ -1248,6 +1290,7 @@ def compare_context_objects(newconf, running):
b57a21
             for line in newconf_ctx.lines:
b57a21
                 lines_to_add.append((newconf_ctx_keys, line))
b57a21
 
b57a21
+    (lines_to_add, lines_to_del) = delete_bgp_bfd(lines_to_add, lines_to_del)
b57a21
     (lines_to_add, lines_to_del) = check_for_exit_vrf(lines_to_add, lines_to_del)
b57a21
     (lines_to_add, lines_to_del) = ignore_delete_re_add_lines(lines_to_add, lines_to_del)
b57a21
     (lines_to_add, lines_to_del) = ignore_unconfigurable_lines(lines_to_add, lines_to_del)
b57a21
diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c
b57a21
index b566b0e..1bd6249 100644
b57a21
--- a/bgpd/bgp_bfd.c
b57a21
+++ b/bgpd/bgp_bfd.c
b57a21
@@ -686,9 +686,9 @@ void bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, char *addr)
b57a21
 
b57a21
 	if (!CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG)
b57a21
 	    && (bfd_info->type == BFD_TYPE_NOT_CONFIGURED)) {
b57a21
-		vty_out(vty, " neighbor %s bfd", addr);
b57a21
+		vty_out(vty, " neighbor %s bfd\n", addr);
b57a21
 		if (bfd_info->profile[0])
b57a21
-			vty_out(vty, " profile %s", bfd_info->profile);
b57a21
+			vty_out(vty, " neighbor %s bfd profile %s", addr, bfd_info->profile);
b57a21
 		vty_out(vty, "\n");
b57a21
 	}
b57a21