diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2023-11-29 10:36:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-29 10:36:30 +0200 |
| commit | fc8a07433f64194aaa445e16e0854f3439247c89 (patch) | |
| tree | e79394ba902f8788ba71ebdad7022028b601e686 /tests/topotests/ospfapi/test_ospf_clientapi.py | |
| parent | c3b314654e8a82d191a77b33211026ae5c67aab5 (diff) | |
| parent | 5993c4aef923700bd606c4d105da39a3c66523c3 (diff) | |
Merge pull request #14886 from LabNConsulting/aceelindem/ospf-link-local-fix
ospfd: Fix OSPF link-local opaque LSA crash and opaque memory corruption
Diffstat (limited to 'tests/topotests/ospfapi/test_ospf_clientapi.py')
| -rw-r--r-- | tests/topotests/ospfapi/test_ospf_clientapi.py | 191 |
1 files changed, 163 insertions, 28 deletions
diff --git a/tests/topotests/ospfapi/test_ospf_clientapi.py b/tests/topotests/ospfapi/test_ospf_clientapi.py index 7a7ea85e2f..41c18df7d3 100644 --- a/tests/topotests/ospfapi/test_ospf_clientapi.py +++ b/tests/topotests/ospfapi/test_ospf_clientapi.py @@ -1205,7 +1205,10 @@ def _test_opaque_interface_disable(tgen, apibin): } } test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf interface json", r1_interface_without_opaque + topotest.router_json_cmp, + r1, + "show ip ospf interface json", + r1_interface_without_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF interface doesn't have opaque capability disabled" @@ -1232,7 +1235,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 4 in test_ospf_opaque_interface_disable and STEP 59 in CI tests step("Verify that the r1 neighbor options don't include opaque") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf neighbor detail json", r1_neighbor_without_opaque + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_without_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF neighbor has opaque option in optionsList" @@ -1241,7 +1247,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 5 in test_ospf_opaque_interface_disable and STEP 60 in CI tests step("Verify that the r1 neighbor options don't include opaque") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf neighbor detail json", r2_neighbor_without_opaque + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_without_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF neighbor has opaque option in optionsList" @@ -1282,7 +1291,10 @@ def _test_opaque_interface_disable(tgen, apibin): } } test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf interface json", r2_interface_with_opaque + topotest.router_json_cmp, + r2, + "show ip ospf interface json", + r2_interface_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF interface has opaque capability disabled" @@ -1338,19 +1350,17 @@ def _test_opaque_interface_disable(tgen, apibin): "asExternalOpaqueLsaCount": 1, } opaque_area_empty_database = { - "routerId":"2.0.0.0", - "areaLocalOpaqueLsa":{ - "areas":{ - "1.2.3.4":[ - ] - } - } + "routerId": "2.0.0.0", + "areaLocalOpaqueLsa": {"areas": {"1.2.3.4": []}}, } # STEP 9 in test_ospf_opaque_interface_disable and STEP 64 in CI tests step("Check that LSAs are added on r1") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf database json", opaque_LSAs_in_database + topotest.router_json_cmp, + r1, + "show ip ospf database json", + opaque_LSAs_in_database, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF database doesn't contain opaque LSAs" @@ -1359,8 +1369,11 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 10 in test_ospf_opaque_interface_disable and STEP 65 in CI tests step("Check that LSAs are not added on r2") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf database opaque-area json", - opaque_area_empty_database, True + topotest.router_json_cmp, + r2, + "show ip ospf database opaque-area json", + opaque_area_empty_database, + True, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF area database contains opaque LSAs" @@ -1382,7 +1395,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 13 in test_ospf_opaque_interface_disable and STEP 68 in CI tests step("Verify the ospf opaque option is applied to the r1 interface") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf interface json", r1_interface_with_opaque + topotest.router_json_cmp, + r1, + "show ip ospf interface json", + r1_interface_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF interface doesn't have opaque capability disabled" @@ -1409,7 +1425,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 14 in test_ospf_opaque_interface_disable and STEP 69 in CI tests step("Verify that the r1 neighbor options include opaque") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf neighbor detail json", r1_neighbor_with_opaque + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF neighbor doesn't have opaque option in optionsList" @@ -1418,7 +1437,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 15 in test_ospf_opaque_interface_disable and STEP 70 in CI tests step("Verify that the r2 neighbor options include opaque") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf neighbor detail json", r2_neighbor_with_opaque + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF neighbor doesn't have opaque option in optionsList" @@ -1427,7 +1449,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 16 in test_ospf_opaque_interface_disable and STEP 71 in CI tests step("Check that LSAs are now added to r2") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf database json", opaque_LSAs_in_database + topotest.router_json_cmp, + r2, + "show ip ospf database json", + opaque_LSAs_in_database, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF database doesn't contains opaque LSAs" @@ -1463,7 +1488,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 20 in test_ospf_opaque_interface_disable and STEP 75 in CI tests step("Verify the ospf opaque option is not applied to the r2 interface") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf interface json", r2_interface_without_opaque + topotest.router_json_cmp, + r2, + "show ip ospf interface json", + r2_interface_without_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF interface doesn't have opaque capability disabled" @@ -1472,7 +1500,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 21 in test_ospf_opaque_interface_disable and STEP 76 in CI tests step("Verify that the r1 neighbor options don't include opaque") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf neighbor detail json", r1_neighbor_without_opaque + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_without_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF neighbor has opaque option in optionsList" @@ -1481,7 +1512,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 22 in test_ospf_opaque_interface_disable and STEP 77 in CI tests step("Verify that the r2 neighbor options don't include opaque") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf neighbor detail json", r2_neighbor_without_opaque + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_without_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF neighbor has opaque option in optionsList" @@ -1490,7 +1524,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 23 in test_ospf_opaque_interface_disable and STEP 78 in CI tests step("Verify that r1 still has the opaque LSAs") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf database json", opaque_LSAs_in_database + topotest.router_json_cmp, + r1, + "show ip ospf database json", + opaque_LSAs_in_database, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF database doesn't contain opaque LSAs" @@ -1499,8 +1536,11 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 24 in test_ospf_opaque_interface_disable and STEP 79 in CI tests step("Verify that r2 doesn't have the opaque LSAs") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf database opaque-area json", - opaque_area_empty_database, True + topotest.router_json_cmp, + r2, + "show ip ospf database opaque-area json", + opaque_area_empty_database, + True, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF area database contains opaque LSAs" @@ -1524,7 +1564,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 27 in test_ospf_opaque_interface_disable and STEP 82 in CI tests step("Verify the ospf opaque option is applied to the r2 interface") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf interface json", r2_interface_with_opaque + topotest.router_json_cmp, + r2, + "show ip ospf interface json", + r2_interface_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF interface doesn't have opaque capability disabled" @@ -1533,7 +1576,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 28 in test_ospf_opaque_interface_disable and STEP 83 in CI tests step("Verify that the r2 neighbor options include opaque") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf neighbor detail json", r2_neighbor_with_opaque + topotest.router_json_cmp, + r2, + "show ip ospf neighbor detail json", + r2_neighbor_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF neighbor doesn't have opaque option in optionsList" @@ -1542,7 +1588,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 29 in test_ospf_opaque_interface_disable and STEP 84 in CI tests step("Verify that the r1 neighbor options include opaque") test_func = partial( - topotest.router_json_cmp, r1, "show ip ospf neighbor detail json", r1_neighbor_with_opaque + topotest.router_json_cmp, + r1, + "show ip ospf neighbor detail json", + r1_neighbor_with_opaque, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r1 OSPF neighbor doesn't have opaque option in optionsList" @@ -1551,7 +1600,10 @@ def _test_opaque_interface_disable(tgen, apibin): # STEP 30 in test_ospf_opaque_interface_disable and STEP 85 in CLI tests step("Verify that r2 now has the opaque LSAs") test_func = partial( - topotest.router_json_cmp, r2, "show ip ospf database json", opaque_LSAs_in_database + topotest.router_json_cmp, + r2, + "show ip ospf database json", + opaque_LSAs_in_database, ) _, result = topotest.run_and_expect(test_func, None, count=60, wait=1) assertmsg = "r2 OSPF database doesn't contain opaque LSAs" @@ -1581,6 +1633,89 @@ def test_ospf_opaque_interface_disable(tgen): _test_opaque_interface_disable(tgen, apibin) +def _test_opaque_link_local_lsa_crash(tgen, apibin): + "Test disabling opaque capability on an interface" + + r1 = tgen.gears["r1"] + r2 = tgen.gears["r2"] + tc_name = "opaque_interface_disable" + + p = None + # Log to our stdin, stderr + pout = open(os.path.join(r1.net.logdir, "r1/intf-disable.log"), "a+") + try: + step("Add a link-local opaque LSA for r1-eth0") + pread = r1.popen([apibin, "-v", "add,9,10.0.1.1,230,1,feedaceedeadbeef"]) + + input_dict = { + "linkLocalOpaqueLsa": { + "areas": { + "1.2.3.4": [ + { + "linkStateId": "230.0.0.1", + "advertisingRouter": "1.0.0.0", + "lsaSeqNumber": "80000001", + "opaqueData": "feedaceedeadbeef", + }, + ], + } + }, + } + + # verify content + json_cmd = "show ip ospf da opaque-link json" + assert verify_ospf_database(tgen, r1, input_dict, json_cmd) is None + + step("Shut down r1-eth0 and verify there is no crash") + r1.vtysh_multicmd("conf t\ninterface r1-eth0\nshut") + time.sleep(2) + + step("Bring r1-eth0 back up and verify there is no crash") + r1.vtysh_multicmd("conf t\ninterface r1-eth0\nno shut") + + step("Add another link-local opaque LSA for r1-eth0") + pread = r1.popen([apibin, "-v", "add,9,10.0.1.1,230,1,feedaceecafebeef"]) + + input_dict = { + "linkLocalOpaqueLsa": { + "areas": { + "1.2.3.4": [ + { + "linkStateId": "230.0.0.1", + "advertisingRouter": "1.0.0.0", + "lsaSeqNumber": "80000001", + "opaqueData": "feedaceecafebeef", + }, + ], + } + }, + } + # verify content + json_cmd = "show ip ospf da opaque-link json" + assert verify_ospf_database(tgen, r1, input_dict, json_cmd) is None + + except Exception: + if p: + p.terminate() + if p.wait(): + comm_error(p) + p = None + raise + finally: + if p: + p.terminate() + p.wait() + p = None + + +@pytest.mark.parametrize("tgen", [2], indirect=True) +def test_ospf_opaque_link_local_lsa_crash(tgen): + apibin = os.path.join(CLIENTDIR, "ospfclient.py") + rc, o, e = tgen.gears["r2"].net.cmd_status([apibin, "--help"]) + logging.debug("%s --help: rc: %s stdout: '%s' stderr: '%s'", apibin, rc, o, e) + _test_opaque_link_local_lsa_crash(tgen, apibin) + + if __name__ == "__main__": args = ["-s"] + sys.argv[1:] sys.exit(pytest.main(args)) |
