]> git.ipfire.org Git - thirdparty/FORT-validator.git/commitdiff
Fix unit tests, create common function to print IP addresses.
authorpcarana <pc.moreno2099@gmail.com>
Tue, 29 Oct 2019 20:57:41 +0000 (14:57 -0600)
committerpcarana <pc.moreno2099@gmail.com>
Thu, 31 Oct 2019 19:19:14 +0000 (13:19 -0600)
-Add missing getters at configuration impersonator.
-Create a common function to print IPv4 and IPv6 addresses, the function already existed but it was created multiple times at distinct sources.

src/address.c
src/common.c
src/common.h
src/output_printer.c
src/rtr/pdu_sender.c
src/slurm/db_slurm.c
test/address_test.c
test/client_test.c
test/impersonator.c
test/rtr/db/db_table_test.c
test/rtr/pdu_test.c

index 3276469631b7faff5764d249da1f766b4a620c37..86b4d410097e89c3b275eeb63118b274930f2f58 100644 (file)
@@ -5,6 +5,7 @@
 #include <arpa/inet.h> /* inet_ntop */
 #include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
 #include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include "common.h"
 #include "log.h"
 #include "thread_var.h"
 
@@ -386,18 +387,6 @@ range6_decode(IPAddressRange_t const *input, struct ipv6_range *result)
        return check_encoding6(result);
 }
 
-static char const *
-addr2str4(struct in_addr *addr, char *buffer)
-{
-       return inet_ntop(AF_INET, addr, buffer, INET_ADDRSTRLEN);
-}
-
-static char const *
-addr2str6(struct in6_addr *addr, char *buffer)
-{
-       return inet_ntop(AF_INET6, addr, buffer, INET6_ADDRSTRLEN);
-}
-
 static int
 str2addr4(const char *addr, struct in_addr *dst)
 {
index 5083adc7d55b4b2789df92bc0bf491cf3e0f938e..1282603c49d99ca63cab8e4975c20742006eefe5 100644 (file)
@@ -4,6 +4,8 @@
 #include <dirent.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
 #include <sys/stat.h>
 
 #include "log.h"
@@ -179,3 +181,15 @@ process_file_or_dir(char const *location, char const *file_ext,
 
        return process_dir_files(location, file_ext, cb, arg);
 }
+
+char const *
+addr2str4(struct in_addr const *addr, char *buffer)
+{
+       return inet_ntop(AF_INET, addr, buffer, INET_ADDRSTRLEN);
+}
+
+char const *
+addr2str6(struct in6_addr const *addr, char *buffer)
+{
+       return inet_ntop(AF_INET6, addr, buffer, INET6_ADDRSTRLEN);
+}
index c636968c98cc23239ba79a14851997d6992cd178..409520acc1fa12231da0d7efc1791792cc5eb984 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <pthread.h>
 #include <semaphore.h>
+#include <arpa/inet.h>
 
 /* "I think that this is not supposed to be implemented." */
 #define ENOTSUPPORTED 3172
@@ -40,4 +41,7 @@ void close_thread(pthread_t thread, char const *what);
 typedef int (*process_file_cb)(char const *, void *);
 int process_file_or_dir(char const *, char const *, process_file_cb, void *);
 
+char const *addr2str4(struct in_addr const *, char *);
+char const *addr2str6(struct in6_addr const *, char *);
+
 #endif /* SRC_RTR_COMMON_H_ */
index 37a44909a114acba45e6473dec7715c7db49c886..2ef122e5ed63f0ed7c85150b83df4b5afbf47a98 100644 (file)
@@ -1,8 +1,7 @@
 #include "output_printer.h"
 
 #include <arpa/inet.h>
-#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
-#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include "common.h"
 #include "config.h"
 #include "file.h"
 #include "log.h"
 
 char addr_buf[INET6_ADDRSTRLEN];
 
-static char const *
-strv4addr(struct in_addr const *addr)
-{
-       return inet_ntop(AF_INET, addr, addr_buf, INET6_ADDRSTRLEN);
-}
-
-static char const *
-strv6addr(struct in6_addr const *addr)
-{
-       return inet_ntop(AF_INET6, addr, addr_buf, INET6_ADDRSTRLEN);
-}
-
 static int
 load_output_file(char const *output, FILE **result, bool *fopen)
 {
@@ -60,12 +47,12 @@ print_roa(struct vrp const *vrp, void *arg)
        switch(vrp->addr_fam) {
        case AF_INET:
                fprintf(out, "AS%u,%s/%u,%u\n", vrp->asn,
-                   strv4addr(&vrp->prefix.v4), vrp->prefix_length,
+                   addr2str4(&vrp->prefix.v4, addr_buf), vrp->prefix_length,
                    vrp->max_prefix_length);
                break;
        case AF_INET6:
                fprintf(out, "AS%u,%s/%u,%u\n", vrp->asn,
-                   strv6addr(&vrp->prefix.v6), vrp->prefix_length,
+                   addr2str6(&vrp->prefix.v6, addr_buf), vrp->prefix_length,
                    vrp->max_prefix_length);
                break;
        default:
index a0cfe9bef371a88e4d351cb0f870cd09d0eecab0..edd7355aa06b5cbbc38b61ff0e24081677a91583 100644 (file)
@@ -5,11 +5,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <arpa/inet.h> /* inet_ntop */
-#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
-#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
+#include <arpa/inet.h> /* INET_ADDRSTRLEN */
 
 #include "clients.h"
+#include "common.h"
 #include "config.h"
 #include "log.h"
 #include "rtr/pdu_serializer.h"
@@ -102,13 +101,9 @@ static void
 pr_debug_prefix4(struct ipv4_prefix_pdu *pdu)
 {
        char buffer[INET_ADDRSTRLEN];
-       char const *addr_str;
 
-       addr_str = inet_ntop(AF_INET, &pdu->ipv4_prefix, buffer,
-           INET_ADDRSTRLEN);
-
-       pr_debug("Encoded prefix %s/%u into a PDU.", addr_str,
-           pdu->prefix_length);
+       pr_debug("Encoded prefix %s/%u into a PDU.",
+           addr2str4(&pdu->ipv4_prefix, buffer), pdu->prefix_length);
 }
 
 static int
@@ -142,13 +137,9 @@ static void
 pr_debug_prefix6(struct ipv6_prefix_pdu *pdu)
 {
        char buffer[INET6_ADDRSTRLEN];
-       char const *addr_str;
-
-       addr_str = inet_ntop(AF_INET6, &pdu->ipv6_prefix, buffer,
-           INET6_ADDRSTRLEN);
 
-       pr_debug("Encoded prefix %s/%u into a PDU.", addr_str,
-           pdu->prefix_length);
+       pr_debug("Encoded prefix %s/%u into a PDU.",
+           addr2str6(&pdu->ipv6_prefix, buffer), pdu->prefix_length);
 }
 
 static int
index 06297beed9f28c861513efd86defb6570269d352..99b39125b8da5dcd6aec56df61ac751be4d73ab7 100644 (file)
@@ -3,12 +3,11 @@
 #include <string.h>
 #include <time.h>
 #include <arpa/inet.h>
-#include <sys/types.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
-#include <sys/socket.h> /* AF_INET, AF_INET6 (needed in OpenBSD) */
 
 #include "crypto/base64.h"
 #include "data_structure/array_list.h"
 #include "object/router_key.h"
+#include "common.h"
 
 struct slurm_prefix_ctx {
        struct slurm_prefix element;
@@ -359,18 +358,6 @@ db_slurm_update_time(struct db_slurm *db)
        db->loaded_date_set = true;
 }
 
-static char const *
-strv4addr(struct in_addr const *addr)
-{
-       return inet_ntop(AF_INET, addr, addr_buf, INET6_ADDRSTRLEN);
-}
-
-static char const *
-strv6addr(struct in6_addr const *addr)
-{
-       return inet_ntop(AF_INET6, addr, addr_buf, INET6_ADDRSTRLEN);
-}
-
 static int
 print_prefix_data(struct slurm_prefix *prefix, void *arg)
 {
@@ -384,12 +371,12 @@ print_prefix_data(struct slurm_prefix *prefix, void *arg)
                switch(prefix->vrp.addr_fam) {
                case AF_INET:
                        pr_info("%s Prefix: %s/%u", pad,
-                           strv4addr(&prefix->vrp.prefix.v4),
+                           addr2str4(&prefix->vrp.prefix.v4, addr_buf),
                            prefix->vrp.prefix_length);
                        break;
                case AF_INET6:
                        pr_info("%s Prefix: %s/%u", pad,
-                           strv6addr(&prefix->vrp.prefix.v6),
+                           addr2str6(&prefix->vrp.prefix.v6, addr_buf),
                            prefix->vrp.prefix_length);
                        break;
                default:
index 780ab15b6ea37bd8f51df42bcf167fd9776fe926..d370294efca4569f3b95be1535ec8a0e183c7665 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 
 #include "address.c"
+#include "common.c"
 #include "log.c"
 #include "impersonator.c"
 
index 4bcdd56c9342016099e4eddec470b19a3cce3358..b626920e379ec913bdbb2e213d560f6c4a087f44 100644 (file)
@@ -7,7 +7,7 @@
 #include "impersonator.c"
 
 static int
-handle_foreach(struct client const *client, void *arg)
+handle_foreach(struct client *client, void *arg)
 {
        unsigned int *state = arg;
 
index b790bd399989c1335aac787787b6bb100010ec30..13d7d3eea771273240a5b5924045620ca2415634 100644 (file)
@@ -119,6 +119,24 @@ config_get_output_bgpsec(void)
        return NULL;
 }
 
+uint8_t
+config_get_log_level(void)
+{
+       return 3; /* LOG_ERR */
+}
+
+enum log_output
+config_get_log_output(void)
+{
+       return CONSOLE;
+}
+
+unsigned int
+config_get_asn1_decode_max_stack(void)
+{
+       return 4096;
+}
+
 enum incidence_action
 incidence_get_action(enum incidence_id id)
 {
index f83c5e15c78c7af030aba9a4be0edda86259bd7c..449e38e723e41055853fdd81aeb1db925f7059b8 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 
 #include "address.c"
+#include "common.c"
 #include "log.c"
 #include "impersonator.c"
 #include "object/router_key.c"
index e1392776be1c91a054043f4ad1600e1fce9ceb02..896571c4440f720d66bfd361b723a74c326cef17 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <unistd.h>
 
+#include "common.c"
 #include "log.c"
 #include "impersonator.c"
 #include "rtr/stream.c"