Skip to content

Commit

Permalink
jool session proxy: Trigger stats server on --stats.port
Browse files Browse the repository at this point in the history
Since --stats.address has a sensible default, it was weird that
--stats.port wasn't enough to kickstart the stats server.
  • Loading branch information
ydahhrk committed Aug 3, 2024
1 parent 7299898 commit 01a534c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions docs/en/usr-flags-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ Same as `IP_MULTICAST_TTL`. From `man 7 ip`:
#### `--stats.address`

- Type: String (IPv4/v6 address)
- Default: None (Stats server not started if absent)
- Default: "::"

Address for statistics server. It's optional; if you don't configure it, `jool session proxy` will not start it.
Address for statistics server. It's optional; if you don't configure `--stats.address` and/or `--stats.port`, `jool session proxy` will not start the server.

It's presently rudimentary, as it was spawned by a debugging session. Sample query:

Expand Down
27 changes: 25 additions & 2 deletions src/usr/argp/wargp/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ int handle_session_proxy(char *iname, int argc, char **argv, void const *arg)
netcfg.out_interface = pargs.net_dev_out.value;
netcfg.ttl = pargs.net_ttl;

statcfg.enabled = pargs.stats_addr.value != NULL;
statcfg.address = pargs.stats_addr.value;
statcfg.enabled = pargs.stats_addr.value || pargs.stats_port.value;
statcfg.address = (pargs.stats_addr.value != NULL)
? pargs.stats_addr.value
: "::";
statcfg.port = (pargs.stats_port.value != NULL)
? pargs.stats_port.value
: "6401";
Expand Down Expand Up @@ -287,6 +289,27 @@ int joold_start(char const *iname, struct netsocket_cfg *netcfg,
{
int error;

iname = iname ? iname : "default";

printf("Config:\n");
printf(" mod.instance: %s\n", iname);
if (netcfg->enabled) {
printf(" net.mcast.addr: %s\n", netcfg->mcast_addr);
printf(" net.mcast.port: %s\n", netcfg->mcast_port);
printf(" net.dev.in: %s\n", netcfg->in_interface);
printf(" net.dev.out: %s\n", netcfg->out_interface);
printf(" net.ttl: %d\n", netcfg->ttl);
}
if (statcfg->enabled) {
printf(" stats.addr: %s\n", statcfg->address);
printf(" stats.port: %s\n", statcfg->port);
}

printf("\n");
printf("joold is intended as a daemon, so it outputs straight to syslog.\n");
printf("The standard streams will mostly shut up from now on.\n");
printf("---------------------------------------------\n");

openlog("joold", 0, LOG_DAEMON);

error = modsocket_setup(iname);
Expand Down
37 changes: 9 additions & 28 deletions src/usr/joold/joold.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ static int netsocket_config(char const *file, struct netsocket_cfg *cfg)
cJSON *json;
int error;

cfg->enabled = true;

error = read_json(file, &json);
if (error)
return error;
Expand Down Expand Up @@ -63,8 +61,15 @@ static void statsocket_config(char *port, struct statsocket_cfg *cfg)
int main(int argc, char **argv)
{
char *iname = "default";
struct netsocket_cfg netcfg = { .enabled = true, .ttl = 1 };
struct statsocket_cfg statcfg = { .address = "::" };
struct netsocket_cfg netcfg = {
.mcast_port = "6400",
.enabled = true,
.ttl = 1,
};
struct statsocket_cfg statcfg = {
.address = "::",
.port = "6401",
};
int error;

fprintf(stderr, "Warning: `joold` is deprecated. See `jool session proxy --help`.\n");
Expand All @@ -83,29 +88,5 @@ int main(int argc, char **argv)
if (argc >= 4)
statsocket_config(argv[3], &statcfg);

if (!netcfg.mcast_port)
netcfg.mcast_port = "6400";
if (!statcfg.port)
statcfg.port = "6401";

printf("Config:\n");
printf(" mod.instance: %s\n", iname);
if (netcfg.enabled) {
printf(" net.mcast.addr: %s\n", netcfg.mcast_addr);
printf(" net.mcast.port: %s\n", netcfg.mcast_port);
printf(" net.dev.in: %s\n", netcfg.in_interface);
printf(" net.dev.out: %s\n", netcfg.out_interface);
printf(" net.ttl: %d\n", netcfg.ttl);
}
if (statcfg.enabled) {
printf(" stats.addr: %s\n", statcfg.address);
printf(" stats.port: %s\n", statcfg.port);
}

printf("\n");
printf("joold is intended as a daemon, so it outputs straight to syslog.\n");
printf("The standard streams will mostly shut up from now on.\n");
printf("---------------------------------------------\n");

return joold_start(iname, &netcfg, &statcfg);
}

0 comments on commit 01a534c

Please sign in to comment.