Skip to content

Commit

Permalink
Merge branch 'issue410'
Browse files Browse the repository at this point in the history
  • Loading branch information
ydahhrk committed Jun 22, 2024
2 parents 082f83d + b1e5021 commit b073d34
Show file tree
Hide file tree
Showing 18 changed files with 386 additions and 74 deletions.
13 changes: 10 additions & 3 deletions docs/en/usr-flags-global.md
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ Watch out for this message in the kernel logs:

joold: Too many sessions deferred! I need to drop some; sorry.

If you want to find out how many sessions have been lost, query the `JSTAT_JOOLD_SSS_ENOSPC` [stat](https://nicmx.github.io/Jool/en/usr-flags-stats.html):

```
$ jool stats display --all | grep JSTAT_JOOLD_SSS_ENOSPC
JSTAT_JOOLD_SSS_ENOSPC: 0
```

### `ss-max-payload`

- Type: Integer
Expand All @@ -685,7 +692,7 @@ Deprecated; does nothing as of Jool 4.1.11.
### `ss-max-sessions-per-packet`

- Type: Integer
- Default: 10
- Default: 27
- Modes: Stateful NAT64 only
- Source: [Issue 113]({{ site.repository-url }}/issues/113), [issue 410]({{ site.repository-url }}/issues/410)

Expand Down Expand Up @@ -714,13 +721,13 @@ $ make
$ sudo make test | head
...
Jool: Netlink attribute header size: 4
Jool: Serialized session size: 140
Jool: Serialized session size: 52
...
```

So the default value came out of

```
floor((1500 - max(20, 40) - 8 - 4) / 140)
floor((1500 - max(20, 40) - 8 - 4) / 52)
```

1 change: 1 addition & 0 deletions src/common/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ enum joolnl_attr_bib {

extern struct nla_policy joolnl_bib_entry_policy[JNLAB_COUNT];

/* TODO (fine) Most of these fields are obsolete; rm them in a minor release. */
enum joolnl_attr_session {
JNLASE_SRC6 = 1,
JNLASE_DST6,
Expand Down
17 changes: 17 additions & 0 deletions src/common/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ enum jool_stat_id {

JSTAT_ICMPEXT_BIG,

JSTAT_JOOLD_EMPTY,
JSTAT_JOOLD_TIMEOUT,
JSTAT_JOOLD_MISSING_ACK,
JSTAT_JOOLD_AD_ONGOING,
JSTAT_JOOLD_FLUSH_ASAP,
JSTAT_JOOLD_PKT_FULL,
JSTAT_JOOLD_QUEUING,

JSTAT_JOOLD_SSS_QUEUED,
JSTAT_JOOLD_SSS_SENT,
JSTAT_JOOLD_SSS_RCVD,
JSTAT_JOOLD_SSS_ENOSPC,
JSTAT_JOOLD_PKT_SENT,
JSTAT_JOOLD_PKT_RCVD,
JSTAT_JOOLD_ADS,
JSTAT_JOOLD_ACKS,

/* These 3 need to be last, and in this order. */
JSTAT_UNKNOWN, /* "WTF was that" errors only. */
JSTAT_PADDING,
Expand Down
2 changes: 1 addition & 1 deletion src/common/xlat.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define JOOL_VERSION_MAJOR 4
#define JOOL_VERSION_MINOR 1
#define JOOL_VERSION_REV 11
#define JOOL_VERSION_DEV 0
#define JOOL_VERSION_DEV 1

/** See http://stackoverflow.com/questions/195975 */
#define STR_VALUE(arg) #arg
Expand Down
53 changes: 42 additions & 11 deletions src/mod/common/joold.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,39 @@ static bool should_send(struct xlator *jool)

queue = jool->nat64.joold;

if (queue->deferred.count == 0)
if (queue->deferred.count == 0) {
jstat_inc(jool->stats, JSTAT_JOOLD_EMPTY);
return false;
}

deadline = msecs_to_jiffies(GLOBALS(jool).flush_deadline);
if (time_before(queue->last_flush_time + deadline, jiffies))
if (time_before(queue->last_flush_time + deadline, jiffies)) {
jstat_inc(jool->stats, JSTAT_JOOLD_TIMEOUT);
return true;
}

if (!(queue->flags & JQF_ACK_RECEIVED))
if (!(queue->flags & JQF_ACK_RECEIVED)) {
jstat_inc(jool->stats, JSTAT_JOOLD_MISSING_ACK);
return false;
}

if (queue->flags & JQF_AD_ONGOING)
if (queue->flags & JQF_AD_ONGOING) {
jstat_inc(jool->stats, JSTAT_JOOLD_AD_ONGOING);
return true;
}

if (GLOBALS(jool).flush_asap) {
jstat_inc(jool->stats, JSTAT_JOOLD_FLUSH_ASAP);
return true;
}

if (GLOBALS(jool).flush_asap)
if (queue->deferred.count >= GLOBALS(jool).max_sessions_per_pkt) {
jstat_inc(jool->stats, JSTAT_JOOLD_PKT_FULL);
return true;
}

return queue->deferred.count >= GLOBALS(jool).max_sessions_per_pkt;
jstat_inc(jool->stats, JSTAT_JOOLD_QUEUING);
return false;
}

static bool too_many_sessions(struct xlator *jool)
Expand Down Expand Up @@ -166,6 +182,8 @@ static void send_to_userspace_prepare(struct xlator *jool,
if (session) {
if (too_many_sessions(jool)) {
log_warn_once("joold: Too many sessions deferred! I need to drop some; sorry.");
jstat_inc(jool->stats, JSTAT_JOOLD_SSS_ENOSPC);
FREE_DEFERRED(session);
} else {
list_add_tail(&session->lh, &queue->deferred.list);
queue->deferred.count++;
Expand Down Expand Up @@ -209,7 +227,7 @@ static void send_to_userspace(struct xlator *jool, struct list_head *sessions)
struct joolnlhdr *jhdr;
struct nlattr *root;
struct deferred_session *session;
unsigned int count;
int count;
int error;

if (list_empty(sessions))
Expand All @@ -236,14 +254,17 @@ static void send_to_userspace(struct xlator *jool, struct list_head *sessions)
count = 0;
while (!list_empty(sessions)) {
session = first_deferred(sessions);
error = jnla_put_session(skb, JNLAL_ENTRY, &session->session);
error = jnla_put_session_joold(skb, JNLAL_ENTRY, &session->session);
if (WARN(error, "jnla_put_session() returned %d", error))
goto revert_skb;
list_del(&session->lh);
FREE_DEFERRED(session);
count++;
}

jstat_add(jool->stats, JSTAT_JOOLD_SSS_SENT, count);
jstat_inc(jool->stats, JSTAT_JOOLD_PKT_SENT);

nla_nest_end(skb, root);
genlmsg_end(skb, jhdr);
sendpkt_multicast(jool, skb);
Expand Down Expand Up @@ -333,6 +354,7 @@ void joold_add(struct xlator *jool, struct session_entry *_session)
spin_unlock_bh(&queue->lock);

send_to_userspace(jool, &prepared);
jstat_inc(jool->stats, JSTAT_JOOLD_SSS_QUEUED);
}

struct add_params {
Expand All @@ -353,7 +375,7 @@ static enum session_fate collision_cb(struct session_entry *old, void *arg)
return FATE_TIMER_SLOW;
}

log_err("We're out of sync: Incoming session entry " SEPP
log_warn_once("We're out of sync: Incoming session entry " SEPP
" collides with DB entry " SEPP ".",
SEPA(new), SEPA(old));
params->success = false;
Expand All @@ -368,7 +390,7 @@ static bool add_new_session(struct xlator *jool, struct nlattr *attr)

__log_debug(jool, "Adding session!");

error = jnla_get_session(attr, "joold session",
error = jnla_get_session_joold(attr, "joold session",
&jool->globals.nat64.bib, &params.new);
if (error)
return false;
Expand Down Expand Up @@ -409,14 +431,21 @@ int joold_sync(struct xlator *jool, struct nlattr *root)
{
struct nlattr *attr;
int rem;
int rcvd;
bool success;

if (joold_disabled(jool))
return -EINVAL;

success = true;
nla_for_each_nested(attr, root, rem)
rcvd = 0;
nla_for_each_nested(attr, root, rem) {
success &= add_new_session(jool, attr);
rcvd++;
}

jstat_add(jool->stats, JSTAT_JOOLD_SSS_RCVD, rcvd);
jstat_inc(jool->stats, JSTAT_JOOLD_PKT_RCVD);

__log_debug(jool, "Done.");
return success ? 0 : -EINVAL;
Expand Down Expand Up @@ -470,6 +499,7 @@ int joold_advertise(struct xlator *jool)
spin_unlock_bh(&queue->lock);

send_to_userspace(jool, &prepared);
jstat_inc(jool->stats, JSTAT_JOOLD_ADS);
return 0;
}

Expand All @@ -490,6 +520,7 @@ void joold_ack(struct xlator *jool)
spin_unlock_bh(&queue->lock);

send_to_userspace(jool, &prepared);
jstat_inc(jool->stats, JSTAT_JOOLD_ACKS);
}

/**
Expand Down
Loading

0 comments on commit b073d34

Please sign in to comment.