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

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