Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Session timer enhancement #257

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
56 changes: 54 additions & 2 deletions include/nat64/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ enum config_mode {
MODE_SESSION = (1 << 4),
/** The current message is talking about log times for benchmark. */
MODE_LOGTIME = (1 << 5),
/** The user requested performance status. */
MODE_TIMESTAMPS = (1 << 12),
/** The current message is talking about the JSON configuration file */
MODE_PARSE_FILE = (1 << 9),
/** The current message is talking about synchronization entries.*/
Expand Down Expand Up @@ -85,6 +87,7 @@ char *configmode_to_string(enum config_mode mode);
#define SESSION_OPS (OP_DISPLAY | OP_COUNT)
#define JOOLD_OPS (OP_ADVERTISE | OP_TEST)
#define LOGTIME_OPS (OP_DISPLAY)
#define TIMESTAMPS_OPS (OP_DISPLAY)
#define INSTANCE_OPS (OP_ADD | OP_REMOVE)
/**
* @}
Expand Down Expand Up @@ -151,10 +154,11 @@ enum parse_section {
#define UPDATE_MODES (MODE_GLOBAL | MODE_POOL4 | MODE_PARSE_FILE)

#define SIIT_MODES (MODE_GLOBAL | MODE_POOL6 | MODE_BLACKLIST | MODE_RFC6791 \
| MODE_EAMT | MODE_LOGTIME | MODE_PARSE_FILE | MODE_INSTANCE)
| MODE_EAMT | MODE_LOGTIME | MODE_PARSE_FILE | MODE_INSTANCE \
| MODE_TIMESTAMPS)
#define NAT64_MODES (MODE_GLOBAL | MODE_POOL6 | MODE_POOL4 | MODE_BIB \
| MODE_SESSION | MODE_LOGTIME | MODE_PARSE_FILE \
| MODE_INSTANCE | MODE_JOOLD)
| MODE_INSTANCE | MODE_JOOLD | MODE_TIMESTAMPS)
/**
* @}
*/
Expand Down Expand Up @@ -467,6 +471,54 @@ struct logtime_entry_usr {

#endif

typedef enum timestamp_type {
TST64_FULL_TRANSLATION,
TST_PKT6_INIT,

TST46_FULL_TRANSLATION,
TST_PKT4_INIT,

TST_DIT, /* determine incoming tuple */
TST_FAU, /* filtering and updating */
TST_COT, /* compute outgoing tuple */
TST_TTP, /* translating the packet */
TST_HH, /* handling hairpinning */
TST_SP, /* send packet */

TST_FAU64_VALIDATIONS,
TST_FAU46_VALIDATIONS,
TST_FAU64_MDS, /* Mask domain search */

TST64_SESSION_GENERIC_OLD,
TST64_SESSION_GENERIC_NEW,
TST46_SESSION_GENERIC,
TST64_SESSION_TCP_OLD,
TST64_SESSION_TCP_NEW,
TST46_SESSION_TCP,
TST_SESSION_OLD,
TST_SESSION_NEW,
TST_SESSION_TIMER,
TST_SESSION_PROBE,
TST_SESSION_MASK,

TST_ICMP6,
TST_ICMP4,

TST_LENGTH,
} timestamp_type;

struct timestamps_entry_usr {
__u32 success_count;
__u32 success_min;
__u32 success_avg;
__u32 success_max;

__u32 failure_count;
__u32 failure_min;
__u32 failure_avg;
__u32 failure_max;
};

/**
* A BIB entry, from the eyes of userspace.
*
Expand Down
2 changes: 1 addition & 1 deletion include/nat64/common/xlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define JOOL_VERSION_MAJOR 3
#define JOOL_VERSION_MINOR 5
#define JOOL_VERSION_REV 5
#define JOOL_VERSION_DEV 0
#define JOOL_VERSION_DEV 1

/** See http://stackoverflow.com/questions/195975 */
#define STR_VALUE(arg) #arg
Expand Down
8 changes: 8 additions & 0 deletions include/nat64/mod/common/nl/timestamp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef MOD_COMMON_NL_TIMESTAMP_H_
#define MOD_COMMON_NL_TIMESTAMP_H_

#include <net/genetlink.h>

int handle_timestamp(struct genl_info *info);

#endif /* MOD_COMMON_NL_TIMESTAMPS_H_ */
51 changes: 51 additions & 0 deletions include/nat64/mod/common/timestamp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef INCLUDE_NAT64_MOD_COMMON_TIMESTAMP_H_
#define INCLUDE_NAT64_MOD_COMMON_TIMESTAMP_H_

#include "nat64/common/config.h"

/*
* Ehh... this should be private. Feel free to ignore it if you're reading the
* API... --U
*/
#define TS_BATCH_COUNT 1

#if defined(TIMESTAMP_JIFFIES)

typedef unsigned long timestamp;
#define TIMESTAMP_DECLARE_START(name) timestamp name = jiffies
#define TIMESTAMP_DECLARE(name) timestamp name
#define TIMESTAMP_START(name) name = jiffies
#define TIMESTAMP_STOP(a, b, c) timestamp_stop(a, b, c)

#elif defined(TIMESTAMP_TIMESPEC)

#include <linux/time.h>
#include <linux/time64.h>
#include <linux/ktime.h>
#include <linux/timekeeping.h>
typedef struct timespec64 timestamp;
#define TIMESTAMP_DECLARE_START(name) timestamp name; getnstimeofday64(&name)
#define TIMESTAMP_DECLARE(name) timestamp name
#define TIMESTAMP_START(name) getnstimeofday64(&name)
#define TIMESTAMP_STOP(a, b, c) timestamp_stop(a, b, c)

#else

#define timestamp int /* Whatevs */
#define TIMESTAMP_DECLARE_START(name) /* Empty */
#define TIMESTAMP_DECLARE(name) /* Empty */
#define TIMESTAMP_START(name) /* Empty */
#define TIMESTAMP_STOP(a, b, c) /* Empty */

#endif

void timestamp_stop(timestamp ts, timestamp_type type, bool success);

struct timestamp_foreach_func {
int (*cb)(struct timestamps_entry_usr *, void *);
void *arg;
};

int timestamp_foreach(struct timestamp_foreach_func *func, void *args);

#endif /* INCLUDE_NAT64_MOD_COMMON_TIMESTAMP_H_ */
3 changes: 1 addition & 2 deletions include/nat64/mod/stateful/bib/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ enum session_fate {
int bib_init(void);
void bib_destroy(void);

struct bib *bib_create(void);
struct bib *bib_create(struct net *ns);
void bib_get(struct bib *db);
void bib_put(struct bib *db);

Expand Down Expand Up @@ -96,7 +96,6 @@ int bib_find(struct bib *db, struct tuple *tuple,
struct bib_session *result);
int bib_add_session(struct bib *db, struct session_entry *new,
struct collision_cb *cb);
void bib_clean(struct bib *db, struct net *ns);

/* These are used by userspace request handling. */

Expand Down
3 changes: 2 additions & 1 deletion include/nat64/mod/stateful/bib/pkt_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ void pktqueue_put_node(struct pktqueue_session *node);
* outside.
*/
unsigned int pktqueue_prepare_clean(struct pktqueue *queue,
struct list_head *probes);
struct list_head *probes, u64 *max_session_rm, u64 *sessions_rm,
bool *pending_rm);
/**
* Sends the ICMP errors contained in the @probe list.
*/
Expand Down
13 changes: 13 additions & 0 deletions include/nat64/mod/stateful/global_timer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _JOOL_MOD_GLOBAL_TIMER_H
#define _JOOL_MOD_GLOBAL_TIMER_H

/**
* @file
* Timer used to trigger some of Jool's events. Always runs, as long as Jool
* is modprobed. At time of writing, this induces fragment expiration.
*/

int global_timer_init(void);
void global_timer_destroy(void);

#endif /* _JOOL_MOD_GLOBAL_TIMER_H */
17 changes: 0 additions & 17 deletions include/nat64/mod/stateful/timer.h

This file was deleted.

1 change: 1 addition & 0 deletions include/nat64/usr/argp/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum argp_flags {
ARGP_BLACKLIST = 7000,
ARGP_RFC6791 = 6791,
ARGP_LOGTIME = 'l',
ARGP_TIMESTAMPS = 7003,
ARGP_GLOBAL = 'g',
ARGP_PARSE_FILE = 'p',
ARGP_INSTANCE = 7001,
Expand Down
6 changes: 6 additions & 0 deletions include/nat64/usr/timestamp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef INCLUDE_NAT64_USR_TIMESTAMP_H_
#define INCLUDE_NAT64_USR_TIMESTAMP_H_

int timestamp_display(void);

#endif /* INCLUDE_NAT64_USR_TIMESTAMP_H_ */
71 changes: 56 additions & 15 deletions mod/common/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "nat64/mod/common/config.h"
#include "nat64/mod/common/handling_hairpinning.h"
#include "nat64/mod/common/xlator.h"
#include "nat64/mod/common/timestamp.h"
#include "nat64/mod/common/translation_state.h"
#include "nat64/mod/common/rfc6145/core.h"
#include "nat64/mod/stateful/compute_outgoing_tuple.h"
Expand All @@ -14,31 +15,40 @@
#include <net/netfilter/ipv4/nf_defrag_ipv4.h>
#include <net/netfilter/ipv6/nf_defrag_ipv6.h>

#define EXECUTE(action, tst) ({\
TIMESTAMP_START(timer); \
result = action; \
TIMESTAMP_STOP(timer, tst, result == VERDICT_CONTINUE); \
result; \
})

static verdict core_common(struct xlation *state)

static verdict core_common(struct xlation *state, bool *success)
{
verdict result;
TIMESTAMP_DECLARE(timer);

if (xlat_is_nat64()) {
result = determine_in_tuple(state);
result = EXECUTE(determine_in_tuple(state), TST_DIT);
if (result != VERDICT_CONTINUE)
goto end;
result = filtering_and_updating(state);
result = EXECUTE(filtering_and_updating(state), TST_FAU);
if (result != VERDICT_CONTINUE)
goto end;
result = compute_out_tuple(state);
result = EXECUTE(compute_out_tuple(state), TST_COT);
if (result != VERDICT_CONTINUE)
goto end;
}
result = translating_the_packet(state);

result = EXECUTE(translating_the_packet(state), TST_TTP);
if (result != VERDICT_CONTINUE)
goto end;

if (is_hairpin(state)) {
result = handling_hairpinning(state);
result = EXECUTE(handling_hairpinning(state), TST_HH);
kfree_skb(state->out.skb); /* Put this inside of hh()? */
} else {
result = sendpkt_send(state);
result = EXECUTE(sendpkt_send(state), TST_SP);
/* sendpkt_send() releases out's skb regardless of verdict. */
}

Expand All @@ -56,6 +66,7 @@ static verdict core_common(struct xlation *state)
*/
kfree_skb(state->in.skb);
result = VERDICT_STOLEN;
*success = true;
/* Fall through. */

end:
Expand All @@ -64,11 +75,24 @@ static verdict core_common(struct xlation *state)
return result;
}

static int init_pkt4(struct packet *pkt, struct sk_buff *skb)
{
int error;
TIMESTAMP_DECLARE_START(timer);

error = pkt_init_ipv4(pkt, skb);

TIMESTAMP_STOP(timer, TST_PKT4_INIT, !error);
return error;
}

unsigned int core_4to6(struct sk_buff *skb, const struct net_device *dev)
{
struct xlation state;
struct iphdr *hdr = ip_hdr(skb);
bool success = false;
verdict result;
TIMESTAMP_DECLARE_START(timer);

xlation_init(&state);

Expand All @@ -83,21 +107,36 @@ unsigned int core_4to6(struct sk_buff *skb, const struct net_device *dev)
log_debug("Catching IPv4 packet: %pI4->%pI4", &hdr->saddr, &hdr->daddr);

/* Reminder: This function might change pointers. */
if (pkt_init_ipv4(&state.in, skb) != 0) {
if (init_pkt4(&state.in, skb)) {
xlation_put(&state);
return NF_DROP;
}

result = core_common(&state);
result = core_common(&state, &success);

xlation_put(&state);
TIMESTAMP_STOP(timer, TST46_FULL_TRANSLATION, success);
return result;
}

static int init_pkt6(struct packet *pkt, struct sk_buff *skb)
{
int error;
TIMESTAMP_DECLARE_START(timer);

error = pkt_init_ipv6(pkt, skb);

TIMESTAMP_STOP(timer, TST_PKT6_INIT, !error);
return error;
}

unsigned int core_6to4(struct sk_buff *skb, const struct net_device *dev)
{
struct xlation state;
struct ipv6hdr *hdr = ipv6_hdr(skb);
bool success = false;
verdict result;
TIMESTAMP_DECLARE_START(timer);

xlation_init(&state);

Expand All @@ -115,7 +154,7 @@ unsigned int core_6to4(struct sk_buff *skb, const struct net_device *dev)
&hdr->daddr);

/* Reminder: This function might change pointers. */
if (pkt_init_ipv6(&state.in, skb) != 0) {
if (init_pkt6(&state.in, skb)) {
xlation_put(&state);
return NF_DROP;
}
Expand All @@ -124,13 +163,15 @@ unsigned int core_6to4(struct sk_buff *skb, const struct net_device *dev)

if (xlat_is_nat64()) {
result = fragdb_handle(state.jool.nat64.frag, &state.in);
if (result != VERDICT_CONTINUE)
goto end;
if (result != VERDICT_CONTINUE) {
xlation_put(&state);
return result;
}
}

result = core_common(&state);
/* Fall through. */
end:
result = core_common(&state, &success);

xlation_put(&state);
TIMESTAMP_STOP(timer, TST64_FULL_TRANSLATION, success);
return result;
}
Loading