Skip to content

Commit

Permalink
Testing, random bugfixes
Browse files Browse the repository at this point in the history
- Update dkms.conf
- Update xlator.c comments
- Prevent atomic configuration from changing a translator's framework
- Fix several bugs involving the NAT64 timeout global config values
- Patch xlator_init() so it receives enough arguments to fully initalize
  the instance
  • Loading branch information
ydahhrk committed Nov 5, 2018
1 parent 95ad600 commit fb5c8e9
Show file tree
Hide file tree
Showing 26 changed files with 214 additions and 180 deletions.
2 changes: 1 addition & 1 deletion dkms.conf
Expand Up @@ -33,7 +33,7 @@ if test ! -e "${VERSIONFILE}"; then
eval "$(sed -n '/^#define *JOOL_VERSION_\(MAJOR\|MINOR\|REV\) / {
s/^#define *//;
s/ */=/p;
}' ${SRCDIR}/src/include/jool/common/xlat.h)"
}' ${SRCDIR}/src/common/xlat.h)"

if test ! -z "$JOOL_VERSION_MAJOR" -a ! -z "$JOOL_VERSION_MINOR" -a \
! -z "$JOOL_VERSION_REV"; then
Expand Down
23 changes: 19 additions & 4 deletions src/common/common-global.c
Expand Up @@ -7,6 +7,7 @@
#define print_bool NULL
#define print_u8 NULL
#define print_u32 NULL
#define print_timeout NULL
#define print_plateaus NULL
#define print_prefix6 NULL
#define print_prefix4 NULL
Expand All @@ -16,13 +17,15 @@
#define parse_bool NULL
#define parse_u8 NULL
#define parse_u32 NULL
#define parse_timeout NULL
#define parse_plateaus NULL
#define parse_prefix6 NULL
#define parse_prefix4 NULL
#define parse_hairpin_mode NULL

int validate_u8(struct global_field *field, void *value, bool force);
int validate_u32(struct global_field *field, void *value, bool force);
int validate_timeout(struct global_field *field, void *value, bool force);
int validate_pool6(struct global_field *field, void *value, bool force);
int validate_plateaus(struct global_field *field, void *value, bool force);
int validate_prefix6(struct global_field *field, void *value, bool force);
Expand All @@ -35,6 +38,7 @@ int validate_hairpin_mode(struct global_field *field, void *value, bool force);
void print_bool(void *value, bool csv);
void print_u8(void *value, bool csv);
void print_u32(void *value, bool csv);
void print_timeout(void *value, bool csv);
void print_plateaus(void *value, bool csv);
void print_prefix6(void *value, bool csv);
void print_prefix4(void *value, bool csv);
Expand All @@ -44,13 +48,15 @@ void print_fargs(void *value, bool csv);
int parse_bool(struct global_field *field, char *str, void *result);
int parse_u8(struct global_field *field, char *str, void *result);
int parse_u32(struct global_field *field, char *str, void *result);
int parse_timeout(struct global_field *field, char *str, void *result);
int parse_plateaus(struct global_field *field, char *str, void *result);
int parse_prefix6(struct global_field *field, char *str, void *result);
int parse_prefix4(struct global_field *field, char *str, void *result);
int parse_hairpin_mode(struct global_field *field, char *str, void *result);

#define validate_u8 NULL
#define validate_u32 NULL
#define validate_timeout NULL
#define validate_pool6 NULL
#define validate_plateaus NULL
#define validate_prefix6 NULL
Expand Down Expand Up @@ -86,6 +92,15 @@ static struct global_type gt_uint32 = {
.validate = validate_u32,
};

static struct global_type gt_timeout = {
.id = GTI_TIMEOUT,
.name = "32-bit unsigned integer",
.size = sizeof(__u32),
.print = print_timeout,
.parse = parse_timeout,
.validate = validate_timeout,
};

static struct global_type gt_plateaus = {
.id = GTI_PLATEAUS,
.name = "List of 16-bit unsigned integers separated by commas",
Expand Down Expand Up @@ -218,31 +233,31 @@ static struct global_field global_fields[] = {
.xt = XT_NAT64,
}, {
.name = "udp-timeout",
.type = &gt_uint32,
.type = &gt_timeout,
.doc = "Set the UDP session lifetime (in seconds).",
.offset = offsetof(struct globals, nat64.bib.ttl.udp),
.xt = XT_NAT64,
.min = UDP_MIN,
.max = MAX_U32 / 1000,
}, {
.name = "icmp-timeout",
.type = &gt_uint32,
.type = &gt_timeout,
.doc = "Set the timeout for ICMP sessions (in seconds).",
.offset = offsetof(struct globals, nat64.bib.ttl.icmp),
.xt = XT_NAT64,
.min = 0,
.max = MAX_U32 / 1000,
}, {
.name = "tcp-est-timeout",
.type = &gt_uint32,
.type = &gt_timeout,
.doc = "Set the TCP established session lifetime (in seconds).",
.offset = offsetof(struct globals, nat64.bib.ttl.tcp_est),
.xt = XT_NAT64,
.min = TCP_EST,
.max = MAX_U32 / 1000,
}, {
.name = "tcp-trans-timeout",
.type = &gt_uint32,
.type = &gt_timeout,
.doc = "Set the TCP transitory session lifetime (in seconds).",
.offset = offsetof(struct globals, nat64.bib.ttl.tcp_trans),
.xt = XT_NAT64,
Expand Down
1 change: 1 addition & 0 deletions src/common/common-global.h
Expand Up @@ -12,6 +12,7 @@ typedef enum global_type_id {
GTI_BOOL,
GTI_NUM8,
GTI_NUM32,
GTI_TIMEOUT,
GTI_PLATEAUS,
GTI_PREFIX6,
GTI_PREFIX4,
Expand Down
7 changes: 3 additions & 4 deletions src/common/config.h
Expand Up @@ -459,7 +459,7 @@ struct session_entry_usr {
struct ipv6_transport_addr dst6;
struct ipv4_transport_addr src4;
struct ipv4_transport_addr dst4;
__u64 dying_time;
__u32 dying_time;
__u8 state;
};

Expand Down Expand Up @@ -489,6 +489,7 @@ struct mtu_plateaus {
};

struct bib_config {
/* These values are always measured in milliseconds. */
struct {
__u32 tcp_est;
__u32 tcp_trans;
Expand All @@ -507,8 +508,6 @@ struct bib_config {
__u32 max_stored_pkts;
};

/* This has to be <= 32. */
#define JOOLD_MULTICAST_GROUP 30
#define JOOLD_MAX_PAYLOAD 2048

struct joold_config {
Expand All @@ -533,7 +532,7 @@ struct joold_config {

/**
* The timer forcibly flushes the queue if this hasn't happened after
* this amount of jiffies, regardless of the ACK and @flush_asap.
* this amount of milliseconds, regardless of the ACK and @flush_asap.
* This helps if an ACK is lost for some reason.
*/
__u32 flush_deadline;
Expand Down
5 changes: 1 addition & 4 deletions src/common/constants.h
Expand Up @@ -43,9 +43,6 @@
/** Default session lifetime for ICMP bindings, in seconds. */
#define ICMP_DEFAULT (1 * 60)

/** Default time interval fragments are allowed to arrive in. In seconds. */
#define FRAGMENT_MIN (2)

/*
* The timers will never sleep less than this amount of jiffies. This is because
* I don't think we need to interrupt the kernel too much.
Expand Down Expand Up @@ -87,7 +84,7 @@
1006, 508, 296, 68 }
#define DEFAULT_JOOLD_ENABLED false
#define DEFAULT_JOOLD_FLUSH_ASAP true
#define DEFAULT_JOOLD_DEADLINE msecs_to_jiffies(2000)
#define DEFAULT_JOOLD_DEADLINE 2
#define DEFAULT_JOOLD_CAPACITY 512
/**
* typical MTU minus max(20, 40) minus the UDP header. (1500 - 40 - 8)
Expand Down
6 changes: 1 addition & 5 deletions src/mod/common/atomic_config.c
Expand Up @@ -129,11 +129,7 @@ static int get_candidate(char *iname, struct config_candidate **result)
* fw and pool6 are basic configuration that we can't populate yet.
* Those must be handled later.
*/

candidate->xlator.ns = ns;
strcpy(candidate->xlator.iname, iname);
candidate->xlator.fw = 0;
error = xlator_init(&candidate->xlator, NULL);
error = xlator_init(&candidate->xlator, ns, 0, iname, NULL);
if (error) {
wkfree(struct config_candidate, candidate);
put_net(ns);
Expand Down
27 changes: 26 additions & 1 deletion src/mod/common/common-global.c
Expand Up @@ -27,10 +27,35 @@ int validate_u8(struct global_field *field, void *value, bool force)

int validate_u32(struct global_field *field, void *value, bool force)
{
__u8 value32 = *((__u32 *)value);
__u32 value32 = *((__u32 *)value);
return validate_uint(field, value32);
}

int validate_timeout(struct global_field *field, void *value, bool force)
{
__u32 timeout = *((__u32 *)value);

/*
* Can't reuse validate_uint() for now because @field->min and
* @field->max are not the same unit as @timeout.
*/

if (timeout < 1000 * field->min) {
log_err("%u is too small for the range of %s [%llu-%llu].",
timeout / 1000, field->name,
field->min, field->max);
return -EINVAL;
}
if (timeout > 1000 * field->max) {
log_err("%u is too big for the range of %s [%llu-%llu].",
timeout / 1000, field->name,
field->min, field->max);
return -EINVAL;
}

return 0;
}

static int validate_pool6_len(__u8 len)
{
if (len == 32 || len == 40 || len == 48)
Expand Down
25 changes: 5 additions & 20 deletions src/mod/common/config.c
Expand Up @@ -47,10 +47,10 @@ struct global_config *config_alloc(struct config_prefix6 *pool6)
config->nat64.f_args = DEFAULT_F_ARGS;
config->nat64.handle_rst_during_fin_rcv = DEFAULT_HANDLE_FIN_RCV_RST;

config->nat64.bib.ttl.tcp_est = TCP_EST;
config->nat64.bib.ttl.tcp_trans = TCP_TRANS;
config->nat64.bib.ttl.udp = UDP_DEFAULT;
config->nat64.bib.ttl.icmp = ICMP_DEFAULT;
config->nat64.bib.ttl.tcp_est = 1000 * TCP_EST;
config->nat64.bib.ttl.tcp_trans = 1000 * TCP_TRANS;
config->nat64.bib.ttl.udp = 1000 * UDP_DEFAULT;
config->nat64.bib.ttl.icmp = 1000 * ICMP_DEFAULT;
config->nat64.bib.bib_logging = DEFAULT_BIB_LOGGING;
config->nat64.bib.session_logging = DEFAULT_SESSION_LOGGING;
config->nat64.bib.drop_by_addr = DEFAULT_ADDR_DEPENDENT_FILTERING;
Expand All @@ -59,7 +59,7 @@ struct global_config *config_alloc(struct config_prefix6 *pool6)

config->nat64.joold.enabled = DEFAULT_JOOLD_ENABLED;
config->nat64.joold.flush_asap = DEFAULT_JOOLD_FLUSH_ASAP;
config->nat64.joold.flush_deadline = DEFAULT_JOOLD_DEADLINE;
config->nat64.joold.flush_deadline = 1000 * DEFAULT_JOOLD_DEADLINE;
config->nat64.joold.capacity = DEFAULT_JOOLD_CAPACITY;
config->nat64.joold.max_payload = DEFAULT_JOOLD_MAX_PAYLOAD;
}
Expand Down Expand Up @@ -93,20 +93,5 @@ void config_copy(struct globals *from, struct globals *to)
RCUTAG_FREE
void prepare_config_for_userspace(struct globals *config, bool pools_empty)
{
struct bib_config *bib;
struct joold_config *joold;

config->status = config->enabled && !pools_empty;

if (xlat_is_siit())
return;

bib = &config->nat64.bib;
bib->ttl.tcp_est = jiffies_to_msecs(bib->ttl.tcp_est);
bib->ttl.tcp_trans = jiffies_to_msecs(bib->ttl.tcp_trans);
bib->ttl.udp = jiffies_to_msecs(bib->ttl.udp);
bib->ttl.icmp = jiffies_to_msecs(bib->ttl.icmp);

joold = &config->nat64.joold;
joold->flush_deadline = jiffies_to_msecs(joold->flush_deadline);
}
2 changes: 0 additions & 2 deletions src/mod/common/nl/global.c
Expand Up @@ -11,8 +11,6 @@
#include "mod/nat64/bib/db.h"
#include "mod/siit/eam.h"

/* TODO (NOW) transform jiffies to milliseconds in globals */

static int handle_global_display(struct xlator *jool, struct genl_info *info)
{
struct globals config;
Expand Down

0 comments on commit fb5c8e9

Please sign in to comment.