From 9f379021c19b1dbd4946f4904592af53fe099968 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 11 Oct 2022 22:36:26 +0300 Subject: [PATCH] tools: Handle sequence numbers for BGP community (large/ext) in frr-reload.py If we add/modify community/large/ext lists without sequence numbers, and doing frr-reload.py, then rules with sequence numbers (show running-config always adds sequence numbers) will be deleted and new ones will be re-added. This could lead to blackholing for some time. Signed-off-by: Donatas Abraitis (cherry picked from commit 8bcbee1999176a46cd82b80002e4111c2cdd5084) --- tools/frr-reload.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/frr-reload.py b/tools/frr-reload.py index 743d32d5e2..5839fd69a4 100755 --- a/tools/frr-reload.py +++ b/tools/frr-reload.py @@ -1376,6 +1376,37 @@ def ignore_delete_re_add_lines(lines_to_add, lines_to_del): lines_to_add.append((add_cmd, None)) lines_to_del_to_del.append((ctx_keys, None)) + # bgp community-list, large-community-list, extcommunity-list can be + # specified without a seq number. However, the running config always + # adds `seq X` (sequence number). So, ignore such lines as well. + # Examples: + # bgp community-list standard clist seq 5 permit 222:213 + # bgp large-community-list standard llist seq 5 permit 65001:65001:1 + # bgp extcommunity-list standard elist seq 5 permit soo 123:123 + re_bgp_lists = re.search( + "^(bgp )(community-list|large-community-list|extcommunity-list)(\s+\S+\s+)(\S+\s+)(seq \d+\s+)(permit|deny)(.*)$", + ctx_keys[0], + ) + if re_bgp_lists: + found = False + tmpline = ( + re_bgp_lists.group(1) + + re_bgp_lists.group(2) + + re_bgp_lists.group(3) + + re_bgp_lists.group(4) + + re_bgp_lists.group(6) + + re_bgp_lists.group(7) + ) + for ctx in lines_to_add: + if ctx[0][0] == tmpline: + lines_to_del_to_del.append((ctx_keys, None)) + lines_to_add_to_del.append(((tmpline,), None)) + found = True + if found is False: + add_cmd = ("no " + ctx_keys[0],) + lines_to_add.append((add_cmd, None)) + lines_to_del_to_del.append((ctx_keys, None)) + if ( len(ctx_keys) == 3 and ctx_keys[0].startswith("router bgp") -- 2.39.5