]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Use log.h functions, replace some u_int* vars, and fix a few headers
authorpcarana <pc.moreno2099@gmail.com>
Tue, 30 Apr 2019 15:04:05 +0000 (10:04 -0500)
committerpcarana <pc.moreno2099@gmail.com>
Tue, 30 Apr 2019 15:04:05 +0000 (10:04 -0500)
16 files changed:
src/crypto/base64.c
src/json_parser.c
src/notify.c
src/rtr/db/roa.c
src/rtr/db/roa.h
src/rtr/err_pdu.c
src/rtr/pdu.c
src/rtr/pdu.h
src/rtr/pdu_handler.c
src/rtr/pdu_sender.c
src/rtr/primitive_reader.c
src/rtr/rtr.c
src/slurm_loader.c
src/slurm_parser.c
src/slurm_parser.h
src/updates_daemon.c

index f5969880d32a33a85c8f61c6dd08d13d6cc47120..6f8394b2d286e40324c5e924a667c9bedf802419 100644 (file)
@@ -2,7 +2,6 @@
 
 #include <openssl/err.h>
 #include <openssl/evp.h>
-#include <err.h>
 #include <errno.h>
 #include <string.h>
 
@@ -165,7 +164,6 @@ base64url_decode(char const *str_encoded, unsigned char **result,
        /* Now decode as regular base64 */
        encoded =  BIO_new_mem_buf(str_copy, -1);
        if (encoded == NULL) {
-               warnx("BIO_new() returned NULL");
                error = -EINVAL;
                goto free_copy;
        }
@@ -184,7 +182,6 @@ base64url_decode(char const *str_encoded, unsigned char **result,
                goto free_all;
 
        if (dec_len == 0) {
-               warnx("'%s' couldn't be decoded", str_encoded);
                error = -EINVAL;
                goto free_all;
        }
index 60977401d202eaeb82d36734908aa41d34b1aaaf..e868716be88d2da4e6f5af50f4bc43385fea6ccf 100644 (file)
@@ -1,7 +1,7 @@
 #include "json_parser.h"
 
-#include <err.h>
 #include <errno.h>
+#include "log.h"
 
 /*
  * Try to get member @name from @parent as a char const *. On success, set
@@ -22,9 +22,8 @@ json_get_string(json_t *parent, char const *name, char const **result)
        }
 
        if (!json_is_string(child)) {
-               warnx("The '%s' element is not a JSON string.", name);
                *result = NULL;
-               return -EINVAL;
+               return pr_err("The '%s' element is not a JSON string.", name);
        }
 
        *result = json_string_value(child);
@@ -47,10 +46,8 @@ json_get_int(json_t *parent, char const *name, json_int_t *result)
        if (child == NULL)
                return -ENOENT;
 
-       if (!json_is_integer(child)) {
-               warnx("The '%s' element is not a JSON integer.", name);
-               return -EINVAL;
-       }
+       if (!json_is_integer(child))
+               return pr_err("The '%s' element is not a JSON integer.", name);
 
        *result = json_integer_value(child);
        return 0;
@@ -62,12 +59,11 @@ json_get_array(json_t *parent, char const *name)
        json_t *child;
 
        child = json_object_get(parent, name);
-       if (child == NULL) {
+       if (child == NULL)
                return NULL;
-       }
 
        if (!json_is_array(child)) {
-               warnx("The '%s' element is not a JSON array.", name);
+               pr_err("The '%s' element is not a JSON array.", name);
                return NULL;
        }
 
@@ -84,7 +80,7 @@ json_get_object(json_t *parent, char const *name)
                return NULL;
 
        if (!json_is_object(child)) {
-               warnx("The '%s' element is not a JSON object.", name);
+               pr_err("The '%s' element is not a JSON object.", name);
                return NULL;
        }
 
index db19f7e9933cfb2db3ae93a822b0db8892564ad6..f7f8bea2f288427ded05324d8687b2d1da5a085a 100644 (file)
@@ -32,6 +32,6 @@ notify_clients(void)
                error = send_notify(ptr->fd, ptr->rtr_version);
                /* Error? Log it */
                if (error)
-                       warnx("Error sending notify PDU to client");
+                       pr_warn("Error sending notify PDU to client");
        }
 }
index b40bda2e2502dab41ebe5382ae14ec5d2462a7d6..187dcb39b928b6aa9d97c3e5febcb269bbad804e 100644 (file)
@@ -16,7 +16,7 @@ v6_address_destroy(struct v6_address *addr)
 }
 
 int
-roa_create(u_int32_t as, struct roa **_result)
+roa_create(uint32_t as, struct roa **_result)
 {
        struct roa *result;
        int error;
index 8271d9b82cb4e1d7c7145878a02981ee53c6a4db..e49f735c2eb26c2e5e54357e925ff1348424cb6c 100644 (file)
@@ -23,7 +23,7 @@ struct roa {
        struct v6_addresses addrs6;
 };
 
-int roa_create(u_int32_t, struct roa **);
+int roa_create(uint32_t, struct roa **);
 void roa_destroy(struct roa *);
 
 int roa_add_v4(struct roa *, uint32_t, struct ipv4_prefix const *, uint8_t);
index ce52e8ba491723a2da2f805a81cd1fc44dca3385..c18b23028744a9c765cd7d498c1a0099dbbe9ba5 100644 (file)
@@ -1,6 +1,5 @@
 #include "err_pdu.h"
 
-#include <err.h>
 #include <unistd.h>
 #include "pdu_sender.h"
 #include "log.h"
@@ -14,7 +13,7 @@ err_pdu_send(int fd, uint8_t version, uint16_t code, void *err_pdu_header,
        error = send_error_report_pdu(fd, version, code, err_pdu_header,
            message);
        if (err_pdu_is_fatal(code)) {
-               warnx("Fatal error report PDU sent [code %u], closing socket.",
+               pr_warn("Fatal error report PDU sent [code %u], closing socket.",
                    code);
                close(fd);
        }
index b2b101f9433a203a9734c75830229f305ff5accd..da216c3b02f6f35b32b8f04a7d87ba0057842def 100644 (file)
@@ -1,12 +1,12 @@
 #include "pdu.h"
 
-#include <err.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
 
-#include "../common.h"
-#include "pdu_handler.h"
+#include "common.h"
+#include "log.h"
+#include "rtr/pdu_handler.h"
 
 static int     pdu_header_from_stream(int, struct pdu_header *);
 static int     serial_notify_from_stream(struct pdu_header *, int, void *);
@@ -184,7 +184,7 @@ error_report_destroy(void *pdu_void)
        if (sub_meta)
                sub_meta->destructor(pdu->erroneous_pdu);
        else
-               warnx("Unknown PDU type (%u).", sub_hdr->pdu_type);
+               pr_warn("Unknown PDU type (%u).", sub_hdr->pdu_type);
 
        free(pdu->error_message);
        free(pdu_void);
index c34cc4c4dc1770b4ac2b0a6bf82f395b97bcc39a..54424bede4fdbbe728f7f60cb20b0415f6d1fd5f 100644 (file)
@@ -3,8 +3,8 @@
 
 #include <netinet/in.h>
 
-#include "../common.h"
-#include "primitive_reader.h"
+#include "common.h"
+#include "rtr/primitive_reader.h"
 
 #define RTR_V0 0
 #define RTR_V1 1
@@ -83,7 +83,7 @@ struct router_key_pdu {
        struct  pdu_header header;
        unsigned char   *ski;
        size_t          ski_len;
-       u_int32_t       asn;
+       uint32_t        asn;
        unsigned char   *spki;
        size_t          spki_len;
 };
index d31145c7d7a16bc0c182b2f9294327d3ce2ac376..f0c0320ea20a36855aae4e6b6c35bb12f186eaf5 100644 (file)
@@ -1,6 +1,5 @@
 #include "pdu_handler.h"
 
-#include <err.h>
 #include <errno.h>
 #include <stddef.h>
 #include <unistd.h>
@@ -14,7 +13,7 @@ static int
 warn_unexpected_pdu(int fd, void *pdu, char const *pdu_name)
 {
        struct pdu_header *pdu_header = pdu;
-       warnx("Unexpected %s PDU received", pdu_name);
+       pr_warn("Unexpected %s PDU received", pdu_name);
        err_pdu_send(fd, pdu_header->protocol_version, ERR_PDU_UNSUP_PDU_TYPE,
            pdu_header, "Unexpected PDU received");
        return -EINVAL;
@@ -101,7 +100,7 @@ handle_serial_query_pdu(int fd, void *pdu)
                return send_end_of_data_pdu(&common);
        }
 
-       warnx("Reached 'unreachable' code");
+       pr_warn("Reached 'unreachable' code");
        return -EINVAL;
 }
 
@@ -135,7 +134,7 @@ handle_reset_query_pdu(int fd, void *pdu)
                break;
        }
 
-       warnx("Reached 'unreachable' code");
+       pr_warn("Reached 'unreachable' code");
        return -EINVAL;
 }
 
@@ -181,7 +180,7 @@ handle_error_report_pdu(int fd, void *pdu)
        struct error_report_pdu *received = pdu;
 
        if (err_pdu_is_fatal(received->header.m.error_code)) {
-               warnx("Fatal error report PDU received [code %u], closing socket.",
+               pr_warn("Fatal error report PDU received [code %u], closing socket.",
                    received->header.m.error_code);
                close(fd);
        }
index 7f8571f160ffd77fcf8f731f369bf1d614525b74..93c61c89ff29caaadb161fd2e3e0bea81bc07a0b 100644 (file)
@@ -1,6 +1,5 @@
 #include "pdu_sender.h"
 
-#include <err.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -8,6 +7,7 @@
 #include <unistd.h>
 
 #include "config.h"
+#include "log.h"
 #include "rtr/pdu_serializer.h"
 #include "rtr/db/vrps.h"
 
@@ -101,18 +101,16 @@ send_large_response(int fd, struct data_buffer *buffer)
        ptr = buffer->data;
        while (pending > 0) {
                tmp_buffer = calloc(pending, sizeof(unsigned char));
-               if (tmp_buffer == NULL) {
-                       warnx("Couldn't allocate temp buffer");
-                       return -ENOMEM;
-               }
+               if (tmp_buffer == NULL)
+                       return pr_enomem();
+
                memcpy(tmp_buffer, ptr, buf_size);
 
                written = write(fd, tmp_buffer, buf_size);
                free(tmp_buffer);
-               if (written < 0) {
-                       warnx("Error sending response");
-                       return -EINVAL;
-               }
+               if (written < 0)
+                       return pr_err("Error sending response");
+
                pending -= buf_size;
                ptr += buf_size;
                buf_size = pending > buffer->capacity ? buffer->capacity :
@@ -136,10 +134,9 @@ send_response(int fd, unsigned char *data, size_t data_len)
        if (data_len <= buffer.capacity) {
                error = write(fd, buffer.data, buffer.len);
                free_buffer(&buffer);
-               if (error < 0) {
-                       warnx("Error sending response");
-                       return -EINVAL;
-               }
+               if (error < 0)
+                       return pr_err("Error sending response");
+
                return 0;
        }
 
@@ -317,7 +314,7 @@ struct pdu_header *err_pdu_header, char const *message)
        if (message != NULL) {
                pdu.error_message = malloc(strlen(message) + 1);
                if (pdu.error_message == NULL)
-                       warn("Error message couldn't be allocated, removed from PDU");
+                       pr_warn("Error message couldn't be allocated, removed from PDU");
                else {
                        pdu.error_message_length = strlen(message) + 1;
                        strcpy(pdu.error_message, message);
index 0b8f71d81627a68337ed0cd52f7c2d2e349997d5..64701a71f2a6cfcdccb9d3fd8e7702e4cfd1c21b 100644 (file)
@@ -22,12 +22,11 @@ read_exact(int fd, unsigned char *buffer, size_t buffer_len)
 
        for (offset = 0; offset < buffer_len; offset += read_result) {
                read_result = read(fd, &buffer[offset], buffer_len - offset);
-               if (read_result == -1) {
-                       warn("Client socket read interrupted");
-                       return -errno;
-               }
+               if (read_result == -1)
+                       return -pr_errno(errno, "Client socket read interrupted");
+
                if (read_result == 0) {
-                       warnx("Stream ended mid-PDU.");
+                       pr_warn("Stream ended mid-PDU.");
                        return -EPIPE;
                }
        }
index 66316b6f9095ccf9bc40af3a7e1a2052e54717f2..4a2f46e668fc031a6d7adb49bbfbddb9742edaec 100644 (file)
@@ -1,6 +1,5 @@
 #include "rtr.h"
 
-#include <err.h>
 #include <errno.h>
 #include <netdb.h>
 #include <pthread.h>
@@ -15,6 +14,7 @@
 
 #include "config.h"
 #include "clients.h"
+#include "log.h"
 #include "updates_daemon.h"
 #include "rtr/err_pdu.h"
 #include "rtr/pdu.h"
@@ -48,12 +48,10 @@ init_addrinfo(struct addrinfo **result)
        service = config_get_server_port();
 
        error = getaddrinfo(hostname, service, &hints, result);
-       if (error) {
-               warnx("Could not infer a bindable address out of address '%s' and port '%s': %s",
+       if (error)
+               return pr_err("Could not infer a bindable address out of address '%s' and port '%s': %s",
                    (hostname != NULL) ? hostname : "any", service,
                    gai_strerror(error));
-               return error;
-       }
 
        return 0;
 }
@@ -83,12 +81,12 @@ create_server_socket(int *result)
 
                fd = socket(addr->ai_family, SOCK_STREAM, 0);
                if (fd < 0) {
-                       warn("socket() failed");
+                       pr_errno(errno, "socket() failed");
                        continue;
                }
 
                if (bind(fd, addr->ai_addr, addr->ai_addrlen) < 0) {
-                       warn("bind() failed");
+                       pr_errno(errno, "bind() failed");
                        continue;
                }
 
@@ -98,9 +96,8 @@ create_server_socket(int *result)
                return 0; /* Happy path */
        }
 
-       warnx("None of the addrinfo candidates could be bound.");
        freeaddrinfo(addrs);
-       return -EINVAL;
+       return pr_err("None of the addrinfo candidates could be bound.");
 }
 
 /*
@@ -153,7 +150,7 @@ handle_accept_result(int client_fd, int err)
 #pragma GCC diagnostic pop
 
        errno = err;
-       warn("Connection acceptor thread interrupted");
+       pr_warn("Connection acceptor thread interrupted");
        return VERDICT_EXIT;
 }
 
@@ -256,7 +253,7 @@ handle_client_connections(int server_fd)
 
                new_thread = malloc(sizeof(struct thread_node));
                if (new_thread == NULL) {
-                       warnx("Couldn't create thread struct");
+                       pr_err("Couldn't create thread struct");
                        close(client_fd);
                        continue;
                }
@@ -270,7 +267,7 @@ handle_client_connections(int server_fd)
                    client_thread_cb, &arg);
                pthread_attr_destroy(&attr);
                if (errno) {
-                       warn("Could not spawn the client's thread");
+                       pr_errno(errno, "Could not spawn the client's thread");
                        free(new_thread);
                        close(client_fd);
                        continue;
@@ -302,7 +299,7 @@ init_signal_handler(void)
 
        error = sigaction(SIGINT, &act, NULL);
        if (error) {
-               warn("Error initializing signal handler");
+               pr_errno(errno, "Error initializing signal handler");
                error = -errno;
        }
        return error;
index df249a5cccffe71e2878124c9fb7bd6f885e52a7..add42e59b5dfccf1bcd024af8fb9030f6993429c 100644 (file)
@@ -1,11 +1,11 @@
 #include "slurm_loader.h"
 
-#include <err.h>
 #include <errno.h>
 #include <dirent.h>
 #include <stdlib.h>
 #include <string.h>
 
+#include "log.h"
 #include "config.h"
 #include "slurm_db.h"
 #include "slurm_parser.h"
@@ -25,24 +25,23 @@ single_slurm_load(const char *dir_name, const char *file_name)
 
        /* Get the full file path */
        tmp = strdup(dir_name);
-       if (tmp == NULL) {
-               warn("Couldn't create temporal char for SLURM");
-               return -errno;
-       }
+       if (tmp == NULL)
+               return -pr_errno(errno,
+                   "Couldn't create temporal char for SLURM");
+
        tmp = realloc(tmp, strlen(tmp) + 1 + strlen(file_name) + 1);
-       if (tmp == NULL) {
-               warn("Couldn't reallocate temporal char for SLURM");
-               return -errno;
-       }
+       if (tmp == NULL)
+               return -pr_errno(errno,
+                   "Couldn't reallocate temporal char for SLURM");
 
        strcat(tmp, "/");
        strcat(tmp, file_name);
        fullpath = realpath(tmp, NULL);
        if (fullpath == NULL) {
-               warn("Error getting real path for file '%s' at dir '%s'",
-                   dir_name, file_name);
                free(tmp);
-               return -errno;
+               return -pr_errno(errno,
+                   "Error getting real path for file '%s' at dir '%s'",
+                   dir_name, file_name);
        }
 
        error = slurm_parse(fullpath);
@@ -69,23 +68,21 @@ slurm_load(void)
                return error;
 
        dir_loc = opendir(slurm_dir);
-       if (dir_loc == NULL) {
-               warn("Couldn't open dir %s", slurm_dir);
-               return -errno;
-       }
+       if (dir_loc == NULL)
+               return -pr_errno(errno, "Couldn't open dir %s", slurm_dir);
 
        errno = 0;
        while ((dir_ent = readdir(dir_loc)) != NULL) {
                error = single_slurm_load(slurm_dir, dir_ent->d_name);
                if (error) {
-                       warnx("The error was at SLURM file %s",
+                       pr_err("The error was at SLURM file %s",
                            dir_ent->d_name);
                        goto end;
                }
                errno = 0;
        }
        if (errno) {
-               warn("Error reading dir %s", slurm_dir);
+               pr_err("Error reading dir %s", slurm_dir);
                error = -errno;
        }
 end:
index fed754632f6ee3fa9de1fa92382b91fa6c51f07c..d879ece5735e69d391020f8ef46b7babde7560c2 100644 (file)
@@ -1,6 +1,5 @@
 #include "slurm_parser.h"
 
-#include <err.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -8,6 +7,7 @@
 #include <openssl/evp.h>
 
 #include "crypto/base64.h"
+#include "log.h"
 #include "address.h"
 #include "json_parser.h"
 #include "slurm_db.h"
 #define ROUTER_PUBLIC_KEY              "routerPublicKey"
 #define COMMENT                                "comment"
 
-#define CHECK_REQUIRED(element, name)                          \
-       if (element == NULL) {                                  \
-               warnx("SLURM member '%s' is required", name);   \
-               return -EINVAL;                                 \
-       }
+#define CHECK_REQUIRED(element, name)                                  \
+       if (element == NULL)                                            \
+               return pr_err("SLURM member '%s' is required", name);
 
 static int handle_json(json_t *);
 
@@ -47,7 +45,7 @@ slurm_parse(char const *location)
        json_root = json_load_file(location, JSON_REJECT_DUPLICATES,
            &json_error);
        if (json_root == NULL) {
-               warnx("SLURM JSON error on line %d, column %d: %s",
+               pr_err("SLURM JSON error on line %d, column %d: %s",
                    json_error.line, json_error.column, json_error.text);
                return -ENOENT;
        }
@@ -58,11 +56,6 @@ slurm_parse(char const *location)
        return error;
 }
 
-/*
- * TODO Maybe some of the parsing functions can be on a common place, since
- * csv.c also does a similar parsing
- */
-
 static int
 parse_prefix4(char *text, struct ipv4_prefix *prefixv4)
 {
@@ -99,36 +92,33 @@ valid_members_count(json_t *object, size_t expected_size)
 }
 
 static int
-set_asn(json_t *object, bool is_assertion, u_int32_t *result,
-    u_int8_t *flag, size_t *members_loaded)
+set_asn(json_t *object, bool is_assertion, uint32_t *result, uint8_t *flag,
+    size_t *members_loaded)
 {
        json_int_t int_tmp;
        int error;
 
        error = json_get_int(object, ASN, &int_tmp);
        if (error == -ENOENT) {
-               if (is_assertion) {
-                       warnx("ASN is required");
-                       return -EINVAL;
-               } else
+               if (is_assertion)
+                       return pr_err("ASN is required");
+               else
                        return 0; /* Optional for filters */
        } else if (error)
                return error;
 
        /* An underflow or overflow will be considered here */
-       if (int_tmp < 0 || UINT32_MAX < int_tmp) {
-               warnx("ASN (%lld) is out of range [0 - %u].", int_tmp,
+       if (int_tmp < 0 || UINT32_MAX < int_tmp)
+               return pr_err("ASN (%lld) is out of range [0 - %u].", int_tmp,
                    UINT32_MAX);
-               return -EINVAL;
-       }
        *flag = *flag | SLURM_COM_FLAG_ASN;
-       *result = (u_int32_t) int_tmp;
+       *result = (uint32_t) int_tmp;
        (*members_loaded)++;
        return 0;
 }
 
 static int
-set_comment(json_t *object, char const **comment, u_int8_t *flag,
+set_comment(json_t *object, char const **comment, uint8_t *flag,
     size_t *members_loaded)
 {
        char const *tmp;
@@ -161,19 +151,16 @@ set_prefix(json_t *object, bool is_assertion, struct slurm_prefix *result,
        /* First part: Prefix in string format */
        error = json_get_string(object, PREFIX, &str_prefix);
        if (error && error == -ENOENT) {
-               if (is_assertion) {
-                       warnx("SLURM assertion prefix is required");
-                       return -EINVAL;
-               } else
+               if (is_assertion)
+                       return pr_err("SLURM assertion prefix is required");
+               else
                        return 0; /* Optional for filters */
        } else if (error)
                return error;
 
        clone = strdup(str_prefix);
-       if (clone == NULL) {
-               warn("Couldn't allocate string to parse prefix");
-               return -errno;
-       }
+       if (clone == NULL)
+               return -pr_errno(errno, "Couldn't allocate string to parse prefix");
 
        token = strtok(clone, "/");
        isv4 = strchr(token, ':') == NULL;
@@ -217,8 +204,8 @@ set_prefix(json_t *object, bool is_assertion, struct slurm_prefix *result,
 }
 
 static int
-set_max_prefix_length(json_t *object, bool is_assertion, u_int8_t addr_fam,
-    u_int8_t *result, u_int8_t *flag, size_t *members_loaded)
+set_max_prefix_length(json_t *object, bool is_assertion, uint8_t addr_fam,
+    uint8_t *result, uint8_t *flag, size_t *members_loaded)
 {
        json_int_t int_tmp;
        int error;
@@ -231,19 +218,16 @@ set_max_prefix_length(json_t *object, bool is_assertion, u_int8_t addr_fam,
                return error;
 
        /* Unsupported by filters */
-       if (!is_assertion) {
-               warnx("Prefix filter can't have a max prefix length");
-               return -EINVAL;
-       }
+       if (!is_assertion)
+               return pr_err("Prefix filter can't have a max prefix length");
 
        /* An underflow or overflow will be considered here */
-       if (int_tmp <= 0 || (addr_fam == AF_INET ? 32 : 128) < int_tmp) {
-               warnx("Max prefix length (%lld) is out of range [1 - %d].",
+       if (int_tmp <= 0 || (addr_fam == AF_INET ? 32 : 128) < int_tmp)
+               return pr_err("Max prefix length (%lld) is out of range [1 - %d].",
                    int_tmp, (addr_fam == AF_INET ? 32 : 128));
-               return -EINVAL;
-       }
+
        *flag = *flag | SLURM_PFX_FLAG_MAX_LENGTH;
-       *result = (u_int8_t) int_tmp;
+       *result = (uint8_t) int_tmp;
        (*members_loaded)++;
        return 0;
 
@@ -257,10 +241,8 @@ validate_base64url_encoded(const char *encoded)
         * routerPublicKey members): "{..} whose value is the Base64 encoding
         * without trailing '=' (Section 5 of [RFC4648])"
         */
-       if (strrchr(encoded, '=') != NULL) {
-               warnx("The base64 encoded value has trailing '='");
-               return -EINVAL;
-       }
+       if (strrchr(encoded, '=') != NULL)
+               return pr_err("The base64 encoded value has trailing '='");
 
        /*
         * IMHO there's an error at RFC 8416 regarding the use of base64
@@ -288,10 +270,9 @@ set_ski(json_t *object, bool is_assertion, struct slurm_bgpsec *result,
 
        error = json_get_string(object, SKI, &str_encoded);
        if (error && error == -ENOENT) {
-               if (is_assertion) {
-                       warnx("SLURM assertion %s is required", SKI);
-                       return -EINVAL;
-               } else
+               if (is_assertion)
+                       return pr_err("SLURM assertion %s is required", SKI);
+               else
                        return 0; /* Optional for filters */
        } else if (error)
                return error;
@@ -306,9 +287,8 @@ set_ski(json_t *object, bool is_assertion, struct slurm_bgpsec *result,
 
        /* Validate that's at least 20 octects long */
        if (result->ski_len != 20) {
-               warnx("The decoded SKI must be 20 octets long");
                free(result->ski);
-               return -EINVAL;
+               return pr_err("The decoded SKI must be 20 octets long");
        }
 
        result->data_flag = result->data_flag | SLURM_BGPS_FLAG_SKI;
@@ -329,18 +309,14 @@ set_router_pub_key(json_t *object, bool is_assertion,
 
        /* Required by assertions */
        if (error && is_assertion) {
-               if (error == -ENOENT) {
-                       warnx("SLURM assertion %s is required", ROUTER_PUBLIC_KEY);
-                       return -EINVAL;
-               }
+               if (error == -ENOENT)
+                       return pr_err("SLURM assertion %s is required", ROUTER_PUBLIC_KEY);
                return error;
        }
 
        /* Unsupported by filters */
-       if (!is_assertion) {
-               warnx("BGPsec filter can't have a router public key");
-               return -EINVAL;
-       }
+       if (!is_assertion)
+               return pr_err("BGPsec filter can't have a router public key");
 
        error = validate_base64url_encoded(str_encoded);
        if (error)
@@ -349,7 +325,7 @@ set_router_pub_key(json_t *object, bool is_assertion,
        error = base64url_decode(str_encoded, &result->router_public_key,
            &result->router_public_key_len);
        if (error)
-               return error;
+               return pr_err("'%s' couldn't be decoded", str_encoded);
 
        /*
         * TODO Validate that 'routerPublicKey' is: "the equivalent to the
@@ -393,10 +369,8 @@ load_single_prefix(json_t *object, bool is_assertion)
        size_t member_count;
        int error;
 
-       if (!json_is_object(object)) {
-               warnx("Not a valid JSON object");
-               return -EINVAL;
-       }
+       if (!json_is_object(object))
+               return pr_err("Not a valid JSON object");
 
        init_slurm_prefix(&result);
        member_count = 0;
@@ -422,7 +396,7 @@ load_single_prefix(json_t *object, bool is_assertion)
 
        /* A single comment isn't valid */
        if (result.data_flag == SLURM_COM_FLAG_COMMENT) {
-               warnx("Single comments aren't valid");
+               pr_err("Single comments aren't valid");
                error = -EINVAL;
                goto release_comment;
        }
@@ -431,14 +405,14 @@ load_single_prefix(json_t *object, bool is_assertion)
        if (!is_assertion) {
                if ((result.data_flag &
                    (SLURM_COM_FLAG_ASN | SLURM_PFX_FLAG_PREFIX)) == 0) {
-                       warnx("Prefix filter must have an asn and/or prefix");
+                       pr_err("Prefix filter must have an asn and/or prefix");
                        error = -EINVAL;
                        goto release_comment;
                }
 
                /* Validate expected members */
                if (!valid_members_count(object, member_count)) {
-                       warnx("Prefix filter has unknown members (see RFC 8416 section 3.3.1)");
+                       pr_err("Prefix filter has unknown members (see RFC 8416 section 3.3.1)");
                        error = -EINVAL;
                        goto release_comment;
                }
@@ -457,7 +431,7 @@ load_single_prefix(json_t *object, bool is_assertion)
 
        if ((result.data_flag & SLURM_PFX_FLAG_MAX_LENGTH) > 0)
                if (result.prefix_length > result.max_prefix_length) {
-                       warnx(
+                       pr_err(
                            "Prefix length is greater than max prefix length");
                        error = -EINVAL;
                        goto release_comment;
@@ -465,7 +439,7 @@ load_single_prefix(json_t *object, bool is_assertion)
 
        /* Validate expected members */
        if (!valid_members_count(object, member_count)) {
-               warnx("Prefix assertion has unknown members (see RFC 8416 section 3.4.1)");
+               pr_err("Prefix assertion has unknown members (see RFC 8416 section 3.4.1)");
                error = -EINVAL;
                goto release_comment;
        }
@@ -491,13 +465,13 @@ load_prefix_array(json_t *array, bool is_assertion)
                error = load_single_prefix(element, is_assertion);
                if (error) {
                        if (error == -EEXIST)
-                               warnx(
+                               pr_err(
                                    "The prefix %s element #%d, is duplicated or covered by another %s; SLURM loading will be stopped",
                                    (is_assertion ? "assertion" : "filter"),
                                    index + 1,
                                    (is_assertion ? "assertion" : "filter"));
                        else
-                               warnx(
+                               pr_err(
                                    "Error at prefix %s, element #%d, SLURM loading will be stopped",
                                    (is_assertion ? "assertions" : "filters"),
                                    index + 1);
@@ -528,10 +502,8 @@ load_single_bgpsec(json_t *object, bool is_assertion)
        size_t member_count;
        int error;
 
-       if (!json_is_object(object)) {
-               warnx("Not a valid JSON object");
-               return -EINVAL;
-       }
+       if (!json_is_object(object))
+               return pr_err("Not a valid JSON object");
 
        init_slurm_bgpsec(&result);
        member_count = 0;
@@ -557,7 +529,7 @@ load_single_bgpsec(json_t *object, bool is_assertion)
 
        /* A single comment isn't valid */
        if (result.data_flag == SLURM_COM_FLAG_COMMENT) {
-               warnx("Single comments aren't valid");
+               pr_err("Single comments aren't valid");
                error = -EINVAL;
                goto release_comment;
        }
@@ -566,14 +538,14 @@ load_single_bgpsec(json_t *object, bool is_assertion)
        if (!is_assertion) {
                if ((result.data_flag &
                    (SLURM_COM_FLAG_ASN | SLURM_BGPS_FLAG_SKI)) == 0) {
-                       warnx("BGPsec filter must have an asn and/or SKI");
+                       pr_err("BGPsec filter must have an asn and/or SKI");
                        error = -EINVAL;
                        goto release_comment;
                }
 
                /* Validate expected members */
                if (!valid_members_count(object, member_count)) {
-                       warnx("BGPsec filter has unknown members (see RFC 8416 section 3.3.2)");
+                       pr_err("BGPsec filter has unknown members (see RFC 8416 section 3.3.2)");
                        error = -EINVAL;
                        goto release_comment;
                }
@@ -587,7 +559,7 @@ load_single_bgpsec(json_t *object, bool is_assertion)
 
        /* Validate expected members */
        if (!valid_members_count(object, member_count)) {
-               warnx("BGPsec assertion has unknown members (see RFC 8416 section 3.4.2)");
+               pr_err("BGPsec assertion has unknown members (see RFC 8416 section 3.4.2)");
                error = -EINVAL;
                goto release_comment;
        }
@@ -617,13 +589,13 @@ load_bgpsec_array(json_t *array, bool is_assertion)
                error = load_single_bgpsec(element, is_assertion);
                if (error) {
                        if (error == -EEXIST)
-                               warnx(
+                               pr_err(
                                    "The bgpsec %s element #%d, is duplicated or covered by another %s; SLURM loading will be stopped",
                                    (is_assertion ? "assertion" : "filter"),
                                    index + 1,
                                    (is_assertion ? "assertion" : "filter"));
                        else
-                               warnx(
+                               pr_err(
                                    "Error at bgpsec %s, element #%d, SLURM loading will be stopped",
                                    (is_assertion ? "assertions" : "filters"),
                                    index + 1);
@@ -647,10 +619,8 @@ load_version(json_t *root)
                return error;
 
        /* Validate data */
-       if (version != 1) {
-               warnx("'%s' must be 1", SLURM_VERSION);
-               return -EINVAL;
-       }
+       if (version != 1)
+               return pr_err("'%s' must be 1", SLURM_VERSION);
 
        return 0;
 }
@@ -672,13 +642,11 @@ load_filters(json_t *root)
        CHECK_REQUIRED(bgpsec, BGPSEC_FILTERS)
 
        expected_members = 2;
-       if (!valid_members_count(filters, expected_members)) {
-               warnx(
+       if (!valid_members_count(filters, expected_members))
+               return pr_err(
                    "SLURM '%s' must contain only %lu members (RFC 8416 section 3.2)",
                    VALIDATION_OUTPUT_FILTERS,
                    expected_members);
-               return -EINVAL;
-       }
 
        /* Arrays loaded, now iterate */
        error = load_prefix_array(prefix, false);
@@ -709,13 +677,11 @@ load_assertions(json_t *root)
        CHECK_REQUIRED(bgpsec, BGPSEC_ASSERTIONS)
 
        expected_members = 2;
-       if (!valid_members_count(assertions, expected_members)) {
-               warnx(
+       if (!valid_members_count(assertions, expected_members))
+               return pr_err(
                    "SLURM '%s' must contain only %lu members (RFC 8416 section 3.2)",
                    LOCALLY_ADDED_ASSERTIONS,
                    expected_members);
-               return -EINVAL;
-       }
 
        error = load_prefix_array(prefix, true);
        if (error)
@@ -734,10 +700,8 @@ handle_json(json_t *root)
        size_t expected_members;
        int error;
 
-       if (!json_is_object(root)) {
-               warnx("The root of the SLURM is not a JSON object.");
-               return -EINVAL;
-       }
+       if (!json_is_object(root))
+               return pr_err("The root of the SLURM is not a JSON object.");
 
        error = load_version(root);
        if (error)
@@ -752,12 +716,10 @@ handle_json(json_t *root)
                return error;
 
        expected_members = 3;
-       if (!valid_members_count(root, expected_members)) {
-               warnx(
+       if (!valid_members_count(root, expected_members))
+               return pr_err(
                    "SLURM root must have only %lu members (RFC 8416 section 3.2)",
                    expected_members);
-               return -EINVAL;
-       }
 
        return 0;
 }
index 2c1c965a08f47bfe8fd0003cefc2b0a42c19d5f1..86bc73c448f3c10a40fc24943f9d799305c3fb68 100644 (file)
 #define SLURM_BGPS_FLAG_ROUTER_KEY     0x08
 
 struct slurm_prefix {
-       u_int8_t        data_flag;
-       u_int32_t       asn;
+       uint8_t         data_flag;
+       uint32_t        asn;
        union {
                struct  in_addr ipv4_prefix;
                struct  in6_addr ipv6_prefix;
        };
-       u_int8_t        prefix_length;
-       u_int8_t        max_prefix_length;
-       u_int8_t        addr_fam;
+       uint8_t         prefix_length;
+       uint8_t         max_prefix_length;
+       uint8_t         addr_fam;
        char const      *comment;
 };
 
 struct slurm_bgpsec {
-       u_int8_t        data_flag;
-       u_int32_t       asn;
+       uint8_t         data_flag;
+       uint32_t        asn;
        unsigned char   *ski;
        size_t          ski_len;
        unsigned char   *router_public_key;
index 9c07a5128b5ae60b1fe7a23711af3e8c029b7da6..8e34c8d022fc597f769be066033e0a52730320aa 100644 (file)
@@ -1,6 +1,5 @@
 #include "updates_daemon.h"
 
-#include <err.h>
 #include <errno.h>
 #include <pthread.h>
 #include <stdbool.h>
@@ -131,10 +130,9 @@ updates_daemon_start(void)
        pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
        errno = pthread_create(&thread, NULL, check_vrps_updates, NULL);
        pthread_attr_destroy(&attr);
-       if (errno) {
-               warn("Could not spawn the update daemon thread");
-               return -errno;
-       }
+       if (errno)
+               return -pr_errno(errno,
+                   "Could not spawn the update daemon thread");
 
        return 0;
 }