Exemple #1
0
/**
 * 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;
}
Exemple #2
0
int add_static_route(struct request_bib *request)
{
	struct bib_entry *bib = NULL;
	int error;

	if (!pool4db_contains(request->l4_proto, &request->add.addr4)) {
		log_err("The transport address '%pI4#%u' does not belong to "
				"the IPv4 pool. Please add it there first.",
				&request->add.addr4.l3, request->add.addr4.l4);
		return -EINVAL;
	}

	error = bibdb_get4(&request->add.addr4, request->l4_proto, &bib);
	error = validate_bib(error, bib);
	if (error)
		return error;

	error = bibdb_get6(&request->add.addr6, request->l4_proto, &bib);
	error = validate_bib(error, bib);
	if (error)
		return error;

	bib = bibentry_create(&request->add.addr4, &request->add.addr6, true,
			request->l4_proto);
	if (!bib) {
		log_err("Could not allocate the BIB entry.");
		return -ENOMEM;
	}

	error = bibdb_add(bib);
	if (error) {
		log_err("The BIB entry could not be added to the database, "
				"despite validations. This can happen if a "
				"conflicting entry appeared while I was "
				"trying to insert. Try again.");
		bibentry_kfree(bib);
		return error;
	}

	/*
	 * We do not call bib_return(bib) here, because we want the entry to
	 * hold a fake user so the timer doesn't delete it.
	 */

	return 0;
}
Exemple #3
0
int add_static_route(struct request_bib *req)
{
	struct bib_entry *bib = NULL;
	int error;

	error = pool4_get(req->l4_proto, &req->add.addr4);
	if (error) {
		log_err("The IPv4 address and port could not be reserved from the pool. "
				"Maybe the IPv4 address you provided does not belong to the pool. "
				"Or maybe they're being used by some other BIB entry?");
		return error;
	}

	bib = bib_create(&req->add.addr4, &req->add.addr6, true, req->l4_proto);
	if (!bib) {
		log_err("Could not allocate the BIB entry.");
		error = -ENOMEM;
		goto bib_error;
	}

	error = bibdb_add(bib);
	if (error) {
		log_err("The BIB entry could not be added to the database. Maybe an entry with the "
				"same IPv4 and/or IPv6 transport address already exists?");
		bib_kfree(bib);
		goto bib_error;
	}

	/*
	 * We do not call bib_return(bib) here, because we want the entry to hold a fake user so the
	 * timer doesn't delete it.
	 */

	return 0;

bib_error:
	pool4_return(req->l4_proto, &req->add.addr4);
	return error;
}