Skip to content

Commit

Permalink
Optimize pool4
Browse files Browse the repository at this point in the history
Added a new by-address index so there's no need to iterate
sequentially over anything now.

The new pool4 is unit-tested and looking stable, but there are two
TODOs preventing the code from being usable:

1. The API changed a little and I still need to tweak the callers.
2. I can't use RCU anymore and all the locking code is commented out.

Progress on #214.
  • Loading branch information
ydahhrk committed May 12, 2016
1 parent fb756c2 commit 877ddb7
Show file tree
Hide file tree
Showing 8 changed files with 912 additions and 357 deletions.
1 change: 1 addition & 0 deletions include/nat64/mod/common/tags.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* help me review the code.
*
* Feel free to purge this if the code leaves my care.
* TODO remove?
*/

/**
Expand Down
9 changes: 5 additions & 4 deletions include/nat64/mod/stateful/pool4/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ struct pool4;
* Write functions (Caller must prevent concurrence)
*/

int pool4db_init(struct pool4 **pool, unsigned int capacity);
int pool4db_init(struct pool4 **pool);
void pool4db_get(struct pool4 *pool);
void pool4db_put(struct pool4 *pool);

Expand All @@ -29,19 +29,20 @@ int pool4db_add_str(struct pool4 *pool, char *prefix_strs[], int prefix_count);
int pool4db_rm(struct pool4 *pool, const __u32 mark, enum l4_protocol proto,
struct ipv4_prefix *prefix, struct port_range *ports);
int pool4db_rm_usr(struct pool4 *pool, struct pool4_entry_usr *entry);
int pool4db_flush(struct pool4 *pool);
void pool4db_flush(struct pool4 *pool);

/*
* Read functions (Legal to use anywhere)
*/

bool pool4db_contains(struct pool4 *pool, struct net *ns,
enum l4_protocol proto, struct ipv4_transport_addr *addr);
bool pool4db_is_empty(struct pool4 *pool);
/* This doesn't need to be public now. */
/* bool pool4db_is_empty(struct pool4 *pool); */
void pool4db_count(struct pool4 *pool, __u32 *tables, __u64 *samples,
__u64 *taddrs);

int pool4db_foreach_sample(struct pool4 *pool,
int pool4db_foreach_sample(struct pool4 *pool, l4_protocol proto,
int (*cb)(struct pool4_sample *, void *), void *arg,
struct pool4_sample *offset);
int pool4db_foreach_taddr4(struct pool4 *pool, struct net *ns,
Expand Down
20 changes: 0 additions & 20 deletions include/nat64/mod/stateful/pool4/entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,7 @@

#include "nat64/common/types.h"

struct pool4_ports {
struct port_range range;
/* Links this pool4_ports to its address's "ports" list. */
struct list_head list_hook;
};

/**
* An address within the pool, along with its ports.
*/
struct pool4_addr {
struct in_addr addr;
/**
* The port ranges from the addresses the user reserved for Jool to use.
* It links elements of type pool4_ports.
* TODO (performance) maybe we could break some iterations early if
* this was sorted.
*/
struct list_head ports;

struct list_head list_hook;
};

struct pool4_ports *pool4_ports_create(const __u16 min, const __u16 max);

Expand Down
11 changes: 2 additions & 9 deletions mod/common/nl/pool4.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,25 +82,18 @@ static int handle_pool4_rm(struct xlator *jool, struct genl_info *info,
static int handle_pool4_flush(struct xlator *jool, struct genl_info *info,
union request_pool4 *request)
{
int error;

if (verify_superpriv())
return nlcore_respond(info, -EPERM);

log_debug("Flushing pool4.");
error = pool4db_flush(jool->nat64.pool4);

/*
* Well, pool4db_flush() only errors on memory allocation failures,
* so I guess clearing BIB and session even if pool4db_flush fails
* is a good idea.
*/
pool4db_flush(jool->nat64.pool4);
if (xlat_is_nat64() && !request->flush.quick) {
sessiondb_flush(jool->nat64.session);
bibdb_flush(jool->nat64.bib);
}

return nlcore_respond(info, error);
return nlcore_respond(info, 0);
}

static int handle_pool4_count(struct pool4 *pool, struct genl_info *info)
Expand Down
6 changes: 6 additions & 0 deletions mod/common/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ bool port_range_equals(const struct port_range *r1,
return (r1->min == r2->min) && (r1->max == r2->max);
}

/**
* Range [1,3] touches [2,6].
* Range [1,3] touches [3,6].
* Range [1,3] touches [4,6].
* Range [1,3] does not touch [5,6].
*/
bool port_range_touches(const struct port_range *r1,
const struct port_range *r2)
{
Expand Down
Loading

0 comments on commit 877ddb7

Please sign in to comment.