/** * Inserts a single entry, validates it, removes it, validates again. * Does not touch the session tables. */ bool simple_bib(void) { struct bib_entry *bib; bool success = true; bib = create_bib_entry(0, 0); if (!assert_not_null(bib, "Allocation of test BIB entry")) return false; success &= assert_equals_int(0, bib_add(bib, IPPROTO_TCP), "BIB insertion call"); success &= assert_bib("BIB insertion state", bib, false, true, false); if (!success) /* * Rather have a slight memory leak than corrupted memory. Because of the error, the table * might or might not have a reference to the entry, and if it does, it will try to kfree * it during bib_destroy(). Hence, better not free it here. */ return false; success &= assert_true(bib_remove(bib, IPPROTO_TCP), "BIB removal call"); success &= assert_bib("BIB removal state", bib, false, false, false); if (!success) return false; kfree(bib); return success; }
/** * Inserts a single entry, validates it, removes it, validates again. * Does not touch the session tables. */ static bool simple_bib(void) { struct ipv4_transport_addr addr = addr4[0]; struct bib_entry *bib; bool success = true; if (is_error(pool4_get_any_port(L4PROTO_TCP, &addr.l3, &addr.l4))) return false; bib = bib_create(&addr, &addr6[0], false, L4PROTO_TCP); if (!assert_not_null(bib, "Allocation of test BIB entry")) return false; success &= assert_equals_int(0, bibdb_add(bib), "BIB insertion call"); success &= assert_bib("BIB insertion state", bib, false, true, false); if (!success) return false; success &= assert_equals_int(0, bibdb_remove(bib, false), "BIB removal call"); success &= assert_bib("BIB removal state", bib, false, false, false); if (!success) return false; bib_kfree(bib); return success; }
/** * Inserts a single entry, validates it, removes it, validates again. * Does not touch the session tables. */ bool simple_bib(void) { // Init struct bib_entry *bib = create_bib_entry(0, 0); if (!bib) { log_warning("Could not allocate a BIB entry."); return false; } // Add if (!bib_add(bib, IPPROTO_TCP)) { log_warning("Test 'BIB insertion' failed: Call returned false."); return false; } if (!assert_bib("BIB insertion", bib, false, true, false)) return false; // Remove if (!bib_remove(bib, IPPROTO_TCP)) { log_warning("Test 'BIB removal' failed: Call returned false."); return false; } if (!assert_bib("BIB removal", bib, false, false, false)) return false; // Quit return true; }
bool simple_bib_session(void) { struct bib_entry *bib; struct session_entry *session; bib = create_bib_entry(0, 0); if (!bib) { log_warning("Could not allocate a BIB entry."); return false; } session = create_session_entry(1, 0, 1, 0, bib, IPPROTO_TCP, 12345); if (!session) { log_warning("Could not allocate a Session entry."); return false; } // Insert the BIB entry. if (!bib_add(bib, IPPROTO_TCP)) { log_warning("Test 'BIB insertion' failed: Call returned false."); return false; } if (!assert_bib("BIB insertion", bib, false, true, false)) return false; // Insert the session entry. if (!session_add(session)) { log_warning("Test 'Session insertion' failed: Call returned false."); return false; } if (!assert_session("Session insertion", session, false, true, false)) return false; // The BIB entry has a session entry, so it shouldn't be removable. if (bib_remove(bib, IPPROTO_TCP)) { log_warning("Test 'Bib removal' failed: Removal shouldn't have succeeded."); return false; } if (!assert_bib("Bib removal (bib table)", bib, false, true, false)) return false; if (!assert_session("BIB removal (session table)", session, false, true, false)) return false; // Remove the session entry. // Because the BIB entry no longer has sessions, it should be automatically removed as well. if (!session_remove(session)) { log_warning("Test 'Session removal' failed: Call returned false."); return false; } if (!assert_bib("Session removal (bib table)", bib, false, false, false)) return false; if (!assert_session("Session removal (session table)", session, false, false, false)) return false; // Quit. return true; }