static bool assert_session_entry_equals(struct session_entry* expected, struct session_entry* actual, char* test_name) { if (expected == actual) return true; if (!expected) { log_err("Test '%s' failed: Expected null, obtained " SESSION_PRINT_KEY ".", test_name, PRINT_SESSION(actual)); return false; } if (!actual) { log_err("Test '%s' failed: Expected " SESSION_PRINT_KEY ", got null.", test_name, PRINT_SESSION(expected)); return false; } if (expected->l4_proto != actual->l4_proto || !ipv6_transport_addr_equals(&expected->remote6, &actual->remote6) || !ipv6_transport_addr_equals(&expected->local6, &actual->local6) || !ipv4_transport_addr_equals(&expected->local4, &actual->local4) || !ipv4_transport_addr_equals(&expected->remote4, &actual->remote4)) { log_err("Test '%s' failed: Expected " SESSION_PRINT_KEY ", got " SESSION_PRINT_KEY ".", test_name, PRINT_SESSION(expected), PRINT_SESSION(actual)); return false; } return true; }
static bool assert_bib_entry_equals(struct bib_entry* expected, struct bib_entry* actual, char* test_name) { if (expected == actual) return true; if (!expected) { log_err("Test '%s' failed: Expected null, got " BIB_PRINT_KEY ".", test_name, PRINT_BIB(actual)); return false; } if (!actual) { log_err("Test '%s' failed: Expected " BIB_PRINT_KEY ", got null.", test_name, PRINT_BIB(expected)); return false; } if (!ipv4_transport_addr_equals(&expected->ipv4, &actual->ipv4) || !ipv6_transport_addr_equals(&expected->ipv6, &actual->ipv6)) { log_err("Test '%s' failed: Expected " BIB_PRINT_KEY " got " BIB_PRINT_KEY ".", test_name, PRINT_BIB(expected), PRINT_BIB(actual)); return false; } return true; }
int delete_static_route(struct request_bib *req) { struct bib_entry *bib; int error = 0; if (req->remove.addr6_set) { error = bibdb_get_by_ipv6(&req->remove.addr6, req->l4_proto, &bib); } else if (req->remove.addr4_set) { error = bibdb_get_by_ipv4(&req->remove.addr4, req->l4_proto, &bib); } else { log_err("You need to provide an address so I can find the entry you want to remove."); return -EINVAL; } if (error == -ESRCH) { log_err("Could not find the BIB entry requested by the user."); return error; } if (error) return error; if (req->remove.addr6_set && req->remove.addr4_set) { if (!ipv4_transport_addr_equals(&bib->ipv4, &req->remove.addr4)) { log_err("There's no BIB entry with BOTH of the addresses you requested."); bib_return(bib); return -ESRCH; } } /* Remove the fake user. */ if (bib->is_static) { bib_return(bib); bib->is_static = false; } /* Remove bib's sessions and their references. */ error = sessiondb_delete_by_bib(bib); if (error) { bib_return(bib); return error; } /* Remove our own reference. If it was the last one, the entry should be no more. */ if (bib_return(bib) == 0) { log_err("Looks like some packet was using the BIB entry, " "so it couldn't be deleted immediately. If the entry still exists, " "you might want to try again."); return -EAGAIN; } return 0; }
int delete_static_route(struct request_bib *request) { struct ipv4_transport_addr *req4 = &request->rm.addr4; struct ipv6_transport_addr *req6 = &request->rm.addr6; struct bib_entry *bib; int error = 0; if (request->rm.addr6_set) { error = bibdb_get6(req6, request->l4_proto, &bib); } else if (request->rm.addr4_set) { error = bibdb_get4(req4, request->l4_proto, &bib); } else { log_err("You need to provide an address so I can find the " "entry you want to remove."); return -EINVAL; } if (error == -ESRCH) { log_err("The entry wasn't in the database."); return error; } if (error) return error; if (request->rm.addr6_set && request->rm.addr4_set) { if (!ipv4_transport_addr_equals(&bib->ipv4, req4)) { log_err("%pI6c#%u is mapped to %pI4#%u, not %pI4#%u.", &bib->ipv6.l3, bib->ipv6.l4, &bib->ipv4.l3, bib->ipv4.l4, &req4->l3, req4->l4); bibdb_return(bib); return -ESRCH; } } /* Remove the fake user. */ if (bib->is_static) { bibdb_return(bib); bib->is_static = false; } /* Remove bib's sessions and their references. */ error = sessiondb_delete_by_bib(bib); if (error) { bibdb_return(bib); return error; } /* Remove our own reference. */ bibdb_return(bib); return 0; }