]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Replace 'server.disabled' by 'mode' (server or standalone)
authorpcarana <pc.moreno2099@gmail.com>
Fri, 14 Jun 2019 23:07:49 +0000 (18:07 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Fri, 14 Jun 2019 23:07:49 +0000 (18:07 -0500)
docs/doc/usage.md
man/fort.8
src/Makefile.am
src/config.c
src/config.h
src/config/mode.c [new file with mode: 0644]
src/config/mode.h [new file with mode: 0644]
src/rtr/rtr.c
test/impersonator.c

index 98ac0cf171773279663c1f309fd4c6354905bab6..1e540058d36a3c5253f2e085d7feb2be5857213a 100644 (file)
@@ -23,7 +23,7 @@ command: fort
                4. [`root-except-ta`](#root-except-ta)
        7. [`--shuffle-uris`](#--shuffle-uris)
        8. [`--maximum-certificate-depth`](#--maximum-certificate-depth)
-       9. [`--server.disabled`](#--serverdisabled)
+       9. [`--mode`](#--mode)
        10. [`--server.address`](#--serveraddress)
        11. [`--server.port`](#--serverport)
        12. [`--server.backlog`](#--serverbacklog)
@@ -53,7 +53,7 @@ command: fort
         [--sync-strategy=off|strict|root|root-except-ta]
         [--shuffle-uris]
         [--maximum-certificate-depth=<unsigned integer>]
-        [--server.disabled]
+        [--mode=server|standalone]
         [--server.address=<string>]
         [--server.port=<string>]
         [--server.backlog=<unsigned integer>]
@@ -244,14 +244,15 @@ Maximum allowable RPKI tree height. Meant to protect Fort from iterating infinit
 
 Fort's tree traversal is actually iterative (not recursive), so there should be no risk of stack overflow, regardless of this value.
 
-### `--server.disabled`
+### `--mode`
 
-- **Type:** None
+- **Type:** Enumeration (`server`, `standalone`)
 - **Availability:** `argv` and JSON
+- **Default:** `server`
 
-Disable the RTR server.
-
-If the flag is set, the server is disabled, the rest of the `server.*` arguments are ignored, and Fort performs an in-place standalone RPKI validation.
+Run mode, commands the way Fort executes the validation. The two possible values and its behavior are:
+- `server`: Enables the RTR server using the `server.*` arguments ([`server.address`](#--serveraddress), [`server.port`](#--serverport), [`server.backlog`](#--serverbacklog), [`server.validation-interval`](#--servervalidation-interval)).
+- `standalone`:  Disables the RTR server, the `server.*` arguments are ignored, and Fort performs an in-place standalone RPKI validation.
 
 ### `--server.address`
 
@@ -379,9 +380,9 @@ The configuration options are mostly the same as the ones from the `argv` interf
        "<a href="#--sync-strategy">sync-strategy</a>": "root",
        "<a href="#--shuffle-uris">shuffle-uris</a>": true,
        "<a href="#--slurm">slurm</a>": "/tmp/test.slurm",
+       "<a href="#--mode">mode</a>": "server",
 
        "server": {
-               "<a href="#--serverdisabled">disabled</a>": false,
                "<a href="#--serveraddress">address</a>": "192.0.2.1",
                "<a href="#--serverport">port</a>": "8323",
                "<a href="#--serverbacklog">backlog</a>": 16,
index 6eeeb73da3aca19795a24e2093025df4062a854d..1eca286531a84fa64ab47680ed90042f9ea540ee 100644 (file)
@@ -305,13 +305,22 @@ See more about SLURM configuration at FORT's web docs.
 .RE
 .P
 
-.B \-\-server.disabled
+.B \-\-mode=(\fIserver\fR|\fIstandalone\fR)
 .RS 4
-Disable the RTR server implemented by FORT. If this flag is set, the rest of
-the configuration options "\fIserver.*\fR" are ignored and FORT performs an
-in-place standalone RPKI validation.
+Commands the way FORT executes the validation, its possible values are:
 .P
-By default, the RTR server is enabled.
+.I server
+.RS 4
+Enable the RTR server using the \fIserver.*\fR arguments.
+.RE
+.P
+.I standalone
+.RS 4
+Disable the RTR server, the configuration options \fIserver.*\fR are ignored
+and FORT performs an in-place standalone validation.
+.RE
+.P
+By default, the mode is \fIserver\fR.
 .RE
 .P
 
@@ -412,7 +421,7 @@ custom repository directory as well, and binding the RTR server to port 9323.
 .RE
 .P
 
-.B fort \-t /tmp/tal \-r /tmp/repository \-\-server.disabled \-\-output.roa -
+.B fort \-t /tmp/tal \-r /tmp/repository \-\-mode=standalone \-\-output.roa -
 .RS 4
 Run FORT as standalone and output ROAs CSV to the console.
 .RE
@@ -420,7 +429,7 @@ Run FORT as standalone and output ROAs CSV to the console.
 
 .nf
 \fBfort \-t /tmp/tal \-r /tmp/repository \\
-     \-\-server.disabled \\
+     \-\-mode=standalone \\
      \-\-slurm /tmp/myslurm.slurm\fR
 .fi
 .RS 4
@@ -458,9 +467,9 @@ to a specific value:
   "sync-strategy": "root",
   "shuffle-uris": true,
   "maximum-certificate-depth": 32,
+  "mode": "server",
   "slurm": "test.slurm",
   "server": {
-    "disabled": false,
     "address": "192.0.2.1",
     "port": "8323",
     "backlog": 64,
index 2c5660a1e6171b58488d436611de6d282f7abafe..76913ec239b794b8cc6d804b8d4d405aa21eb391 100644 (file)
@@ -42,6 +42,7 @@ fort_SOURCES += asn1/signed_data.h asn1/signed_data.c
 
 fort_SOURCES += config/boolean.c config/boolean.h
 fort_SOURCES += config/filename_format.h config/filename_format.c
+fort_SOURCES += config/mode.c config/mode.h
 fort_SOURCES += config/incidences.h config/incidences.c
 fort_SOURCES += config/str.c config/str.h
 fort_SOURCES += config/string_array.h config/string_array.c
index 3198944f03bd0014f4437f6b15a0e10aa2ea2504..f90ac9d8ec8766559e6e9544d5589628ca63fbcc 100644 (file)
@@ -47,10 +47,10 @@ struct rpki_config {
        unsigned int maximum_certificate_depth;
        /** File or directory where the .slurm file(s) is(are) located */
        char *slurm;
+       /* Run as RTR server or standalone validation */
+       enum mode mode;
 
        struct {
-               /** Disable the RTR server. */
-               bool disabled;
                /** The bound listening address of the RTR server. */
                char *address;
                /** The bound listening port of the RTR server. */
@@ -194,29 +194,29 @@ static const struct option_field options[] = {
                .type = &gt_string,
                .offset = offsetof(struct rpki_config, slurm),
                .doc = "Path to the SLURM file or SLURMs directory (files must have the extension .slurm)",
+       }, {
+               .id = 1004,
+               .name = "mode",
+               .type = &gt_mode,
+               .offset = offsetof(struct rpki_config, mode),
+               .doc = "Run mode: 'server' (run as RTR server), 'standalone' (run validation once and exit)",
        },
 
        /* Server fields */
        {
                .id = 5000,
-               .name = "server.disabled",
-               .type = &gt_bool,
-               .offset = offsetof(struct rpki_config, server.disabled),
-               .doc = "Disable the RTR server.",
-       }, {
-               .id = 5001,
                .name = "server.address",
                .type = &gt_string,
                .offset = offsetof(struct rpki_config, server.address),
                .doc = "Address to which RTR server will bind itself to. Can be a name, in which case an address will be resolved.",
        }, {
-               .id = 5002,
+               .id = 5001,
                .name = "server.port",
                .type = &gt_string,
                .offset = offsetof(struct rpki_config, server.port),
                .doc = "Port to which RTR server will bind itself to. Can be a string, in which case a number will be resolved.",
        }, {
-               .id = 5003,
+               .id = 5002,
                .name = "server.backlog",
                .type = &gt_uint,
                .offset = offsetof(struct rpki_config, server.backlog),
@@ -224,7 +224,7 @@ static const struct option_field options[] = {
                .min = 1,
                .max = SOMAXCONN,
        }, {
-               .id = 5004,
+               .id = 5003,
                .name = "server.validation-interval",
                .type = &gt_uint,
                .offset = offsetof(struct rpki_config,
@@ -462,7 +462,6 @@ set_default_values(void)
         * duplicates.
         */
 
-       rpki_config.server.disabled = false;
        rpki_config.server.address = NULL;
        rpki_config.server.port = strdup("323");
        if (rpki_config.server.port == NULL)
@@ -483,6 +482,7 @@ set_default_values(void)
        rpki_config.sync_strategy = SYNC_ROOT;
        rpki_config.shuffle_tal_uris = false;
        rpki_config.maximum_certificate_depth = 32;
+       rpki_config.mode = SERVER;
 
        rpki_config.rsync.program = strdup("rsync");
        if (rpki_config.rsync.program == NULL) {
@@ -494,7 +494,7 @@ set_default_values(void)
            recursive_rsync_args, ARRAY_LEN(recursive_rsync_args));
        if (error)
                goto revert_rsync_program;
-       /* Simply remove --recursive and --delete. */
+
        error = string_array_init(&rpki_config.rsync.args.flat,
            flat_rsync_args, ARRAY_LEN(flat_rsync_args));
        if (error)
@@ -637,10 +637,10 @@ get_option_metadatas(void)
        return options;
 }
 
-bool
-config_get_server_disabled(void)
+enum mode
+config_get_mode(void)
 {
-       return rpki_config.server.disabled;
+       return rpki_config.mode;
 }
 
 char const *
index dd28cb2e957311cf99c84894e1906a8e7e1983b0..581cc38218b5aed5d2e5e07d93e17770e289bb01 100644 (file)
@@ -5,6 +5,7 @@
 #include <stdint.h>
 
 #include "config/filename_format.h"
+#include "config/mode.h"
 #include "config/sync_strategy.h"
 #include "config/string_array.h"
 #include "config/types.h"
@@ -14,7 +15,6 @@ int handle_flags_config(int , char **);
 void free_rpki_config(void);
 
 /* Getters */
-bool config_get_server_disabled(void);
 char const *config_get_server_address(void);
 char const *config_get_server_port(void);
 int config_get_server_queue(void);
@@ -26,6 +26,7 @@ char const *config_get_local_repository(void);
 enum sync_strategy config_get_sync_strategy(void);
 bool config_get_shuffle_tal_uris(void);
 unsigned int config_get_max_cert_depth(void);
+enum mode config_get_mode(void);
 bool config_get_color_output(void);
 enum filename_format config_get_filename_format(void);
 char *config_get_rsync_program(void);
diff --git a/src/config/mode.c b/src/config/mode.c
new file mode 100644 (file)
index 0000000..4584a95
--- /dev/null
@@ -0,0 +1,64 @@
+#include "config/mode.h"
+
+#include <getopt.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "log.h"
+#include "config/str.h"
+
+#define VALUE_SERVER           "server"
+#define VALUE_STANDALONE       "standalone"
+
+#define DEREFERENCE(void_value) (*((enum mode *) void_value))
+
+static void
+print_mode(struct option_field const *field, void *value)
+{
+       char const *str = "<unknown>";
+
+       switch (DEREFERENCE(value)) {
+       case SERVER:
+               str = VALUE_SERVER;
+               break;
+       case STANDALONE:
+               str = VALUE_STANDALONE;
+               break;
+       }
+
+       pr_info("%s: %s", field->name, str);
+}
+
+static int
+parse_argv_mode(struct option_field const *field, char const *str,
+    void *result)
+{
+       if (strcmp(str, VALUE_SERVER) == 0)
+               DEREFERENCE(result) = SERVER;
+       else if (strcmp(str, VALUE_STANDALONE) == 0)
+               DEREFERENCE(result) = STANDALONE;
+       else
+               return pr_err("Unknown mode: '%s'", str);
+
+       return 0;
+}
+
+static int
+parse_json_mode(struct option_field const *opt, struct json_t *json,
+    void *result)
+{
+       char const *string;
+       int error;
+
+       error = parse_json_string(json, opt->name, &string);
+       return error ? error : parse_argv_mode(opt, string, result);
+}
+
+const struct global_type gt_mode = {
+       .has_arg = required_argument,
+       .size = sizeof(enum mode),
+       .print = print_mode,
+       .parse.argv = parse_argv_mode,
+       .parse.json = parse_json_mode,
+       .arg_doc = VALUE_SERVER "|" VALUE_STANDALONE,
+};
diff --git a/src/config/mode.h b/src/config/mode.h
new file mode 100644 (file)
index 0000000..2cfd6ef
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef SRC_CONFIG_MODE_H_
+#define SRC_CONFIG_MODE_H_
+
+#include "config/types.h"
+
+/**
+ * FORT Run mode
+ */
+enum mode {
+       /**
+        * Run as an RTR server
+        */
+       SERVER,
+       /*
+        * Run standalone validation (run validation once and exit)
+        */
+       STANDALONE,
+};
+
+extern const struct global_type gt_mode;
+
+#endif /* SRC_CONFIG_MODE_H_ */
index 81d3f4faffa61d3434ab722ea3fe6389ba0e4590..46561b595d26f25f2e2a87d12e93b043102707d9 100644 (file)
@@ -352,7 +352,7 @@ join_thread(pthread_t tid, void *arg)
 
 /*
  * Starts the server, using the current thread to listen for RTR client
- * requests. If configuration parameter 'server.disabled' is true, then the
+ * requests. If configuration parameter 'mode' is STANDALONE, then the
  * server runs "one time" (a.k.a. run the validation just once), it doesn't
  * waits for clients requests.
  *
@@ -373,7 +373,7 @@ rtr_listen(void)
        if (error)
                return error;
 
-       if (config_get_server_disabled()) {
+       if (config_get_mode() == STANDALONE) {
                error = vrps_update(&changed);
                if (error)
                        pr_err("Error %d while trying to update the ROA database.",
index a38a1bd9536a0c99ee1dd449e66ac4ea1acc5ea0..d4175e3acae5c25cdeeb849381a2d1da0780ed87 100644 (file)
@@ -95,10 +95,10 @@ config_get_slurm(void)
        return NULL;
 }
 
-bool
-config_get_server_disabled(void)
+enum mode
+config_get_mode(void)
 {
-       return true;
+       return STANDALONE;
 }
 
 char const *