Skip to content

Commit

Permalink
Fix joold advertise, abandoned attempt
Browse files Browse the repository at this point in the history
For #410.

I more or less finished the implementation (albeit not the testing),
but the unit tests revealed that one of my assumptions regarding Generic
Netlink is incorrect.

nla_put() cannot be trusted to respect the allocated packet size,
because alloc_skb() can reserve more tail area than it's requested.
This means ss-max-payload has to be enforced manually.

And this by itself wouldn't be enough to justify another rewrite, but
after thinking about it, I realized a more natural implementation would
also reduce the range of the spinlock... which is currently not the
best. Lots of performance to be gained from switching.

So checkpointing. I might have to return to this implementation if the
new one turns out unviable.
  • Loading branch information
ydahhrk committed Aug 10, 2023
1 parent 8c78ed4 commit 07e6fd9
Show file tree
Hide file tree
Showing 24 changed files with 784 additions and 415 deletions.
2 changes: 1 addition & 1 deletion docs/en/usr-flags-global.md
Expand Up @@ -670,7 +670,7 @@ If SS cannot keep up with the amount of traffic it needs to multicast, this maxi

Watch out for this message in the kernel logs:

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

### `ss-max-payload`

Expand Down
1 change: 1 addition & 0 deletions src/abbreviations.md
Expand Up @@ -9,6 +9,7 @@ Some shortcuts used while naming variables and functions through the code or doc

- 4to6 = translation from IPv4 to IPv6
- 6to4 = translation from IPv6 to IPv4
- ad = advertise (if verb), advertisement (if noun)
- alloc = memory allocation
- addr = address
- ADF = Address-Dependent Filtering
Expand Down
18 changes: 18 additions & 0 deletions src/common/types.h
Expand Up @@ -88,6 +88,8 @@ const char *l3proto_to_string(l3_protocol proto);
* We do not use IPPROTO_TCP and friends because I want the compiler to pester
* me during defaultless `switch`s. Also, the zero-based index is convenient in
* the Translate Packet module.
*
* Please don't change the order; there's at least one for that relies on it.
*/
typedef enum l4_protocol {
/** Signals the presence of a TCP header. */
Expand Down Expand Up @@ -135,6 +137,11 @@ struct ipv4_transport_addr {
__u16 l4;
};

/* IPv4 Transport Address Prink Pattern */
#define TA4PP "%pI4#%u"
/* IPv4 Transport Address Prink Arguments */
#define TA4PA(ta) &(ta).l3, (ta).l4

/**
* A layer-3 (IPv6) identifier attached to a layer-4 identifier.
* Because they're paired all the time in this project.
Expand All @@ -146,6 +153,11 @@ struct ipv6_transport_addr {
__u16 l4;
};

/* IPv6 Transport Address Prink Pattern */
#define TA6PP "%pI6c#%u"
/* IPv6 Transport Address Prink Arguments */
#define TA6PA(ta) &(ta).l3, (ta).l4

struct taddr4_tuple {
struct ipv4_transport_addr src;
struct ipv4_transport_addr dst;
Expand Down Expand Up @@ -218,6 +230,12 @@ struct bib_entry {
bool is_static;
};

/* BIB Entry Printk Pattern */
#define BEPP "[" TA6PP ", " TA4PP ", %s]"
/* BIB Entry Printk Arguments */
#define BEPA(b) TA6PA((b)->addr6), TA4PA((b)->addr4), \
l4proto_to_string((b)->l4_proto)

bool port_range_equals(const struct port_range *r1,
const struct port_range *r2);
bool port_range_touches(const struct port_range *r1,
Expand Down
34 changes: 12 additions & 22 deletions src/mod/common/db/bib/db.c
Expand Up @@ -477,12 +477,11 @@ static void log_bib(struct xlator *jool, struct tabled_bib *bib, char *action)

tsec = ktime_get_real_seconds();
time64_to_tm(tsec, 0, &time);
log_info("%s %ld/%d/%d %d:%d:%d (GMT) - %s %pI6c#%u to %pI4#%u (%s)",
log_info("%s %ld/%d/%d %d:%d:%d (GMT) - %s " TA6PP " to " TA4PP " (%s)",
jool->iname,
1900 + time.tm_year, time.tm_mon + 1, time.tm_mday,
time.tm_hour, time.tm_min, time.tm_sec, action,
&bib->src6.l3, bib->src6.l4,
&bib->src4.l3, bib->src4.l4,
TA6PA(bib->src6), TA4PA(bib->src4),
l4proto_to_string(bib->proto));
}

Expand All @@ -503,14 +502,12 @@ static void log_session(struct xlator *jool,

tsec = ktime_get_real_seconds();
time64_to_tm(tsec, 0, &time);
log_info("%s %ld/%d/%d %d:%d:%d (GMT) - %s %pI6c#%u|%pI6c#%u|"
"%pI4#%u|%pI4#%u|%s", jool->iname,
log_info("%s %ld/%d/%d %d:%d:%d (GMT) - %s " TA6PP "|" TA6PP "|"
TA4PP "|" TA4PP "|%s", jool->iname,
1900 + time.tm_year, time.tm_mon + 1, time.tm_mday,
time.tm_hour, time.tm_min, time.tm_sec, action,
&session->bib->src6.l3, session->bib->src6.l4,
&session->dst6.l3, session->dst6.l4,
&session->bib->src4.l3, session->bib->src4.l4,
&session->dst4.l3, session->dst4.l4,
TA6PA(session->bib->src6), TA6PA(session->dst6),
TA4PA(session->bib->src4), TA4PA(session->dst4),
l4proto_to_string(session->bib->proto));
}

Expand Down Expand Up @@ -2262,9 +2259,7 @@ static int __bib_add_static(struct xlator *jool, struct bib_entry *new,
struct tree_slot slot6;
struct tree_slot slot4;

__log_debug(jool, "Adding static BIB entry (%pI6c#%u, %pI4#%u).",
&new->addr6.l3, new->addr6.l4,
&new->addr4.l3, new->addr4.l4);
__log_debug(jool, "Adding static BIB entry " BEPP ".", BEPA(new));

table = get_table(jool->nat64.bib, new->l4_proto);
if (!table)
Expand Down Expand Up @@ -2328,11 +2323,8 @@ int bib_add_static(struct xlator *jool, struct bib_entry *new)
case 0:
break;
case -EEXIST:
log_err("Entry %pI4#%u|%pI6c#%u collides with %pI4#%u|%pI6c#%u.",
&new->addr4.l3, new->addr4.l4,
&new->addr6.l3, new->addr6.l4,
&old.addr4.l3, old.addr4.l4,
&old.addr6.l3, old.addr6.l4);
log_err("Entry " BEPP " collides with " BEPP ".",
BEPA(new), BEPA(&old));
break;
default:
log_err("Unknown error code: %d", error);
Expand Down Expand Up @@ -2452,9 +2444,8 @@ static void print_session(struct rb_node *node, int tabs, char *prefix)

session = node2session(node);
print_tabs(tabs);
pr_cont("[%s] %pI4#%u %pI6c#%u\n", prefix,
&session->dst4.l3, session->dst4.l4,
&session->dst6.l3, session->dst6.l4);
pr_cont("[%s] " TA4PP " " TA6PP "\n", prefix, TA4PA(session->dst4),
TA6PA(session->dst6));

print_session(node->rb_left, tabs + 1, "L"); /* "Left" */
print_session(node->rb_right, tabs + 1, "R"); /* "Right" */
Expand All @@ -2470,8 +2461,7 @@ static void print_bib(struct rb_node *node, int tabs)

bib = bib4_entry(node);
print_tabs(tabs);
pr_cont("%pI4#%u %pI6c#%u\n", &bib->src4.l3, bib->src4.l4,
&bib->src6.l3, bib->src6.l4);
pr_cont(TA4PP " " TA6PP "\n", TA4PA(bib->src4), TA6PA(bib->src6));

print_session(bib->sessions.rb_node, tabs + 1, "T"); /* "Tree" */
print_bib(node->rb_left, tabs + 1);
Expand Down
12 changes: 8 additions & 4 deletions src/mod/common/db/bib/entry.h
Expand Up @@ -27,9 +27,7 @@ struct session_entry {
* unfortunate, as they only make sense in the 6-to-4 direction.
*
* @src6 is the remote IPv6 node's transport address.
* We used to call it "remote6".
* @dst6 is the address the NAT64 is using to mask the IPv4 endpoint.
* We used to call it "local6".
*/
struct ipv6_transport_addr src6;
struct ipv6_transport_addr dst6;
Expand All @@ -41,9 +39,7 @@ struct session_entry {
* unfortunate, as they only make sense in the 6-to-4 direction.
*
* @src4 is the address the NAT64 is using to mask the IPv6 endpoint.
* We used to call it "local4".
* @dst4 is the remote IPv4 node's transport address.
* We used to call it "remote4".
*/
struct ipv4_transport_addr src4;
struct ipv4_transport_addr dst4;
Expand All @@ -66,6 +62,14 @@ struct session_entry {
bool has_stored;
};

/* Session Entry Printk Pattern */
#define SEPP "[" TA6PP ", " TA6PP ", " TA4PP ", " TA4PP ", %s]"
/* Session Entry Printk Arguments */
#define SEPA(s) \
TA6PA((s)->src6), TA6PA((s)->dst6), \
TA4PA((s)->src4), TA4PA((s)->dst4), \
l4proto_to_string((s)->proto)

struct bib_session {
/** Are @session.src6, @session.src4, @session.proto set? */
bool bib_set;
Expand Down

0 comments on commit 07e6fd9

Please sign in to comment.