Beispiel #1
0
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;
}
Beispiel #2
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;
}