diff options
Diffstat (limited to 'src/tools')
40 files changed, 562 insertions, 471 deletions
diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index e5e5c466..7acd5396 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -4,7 +4,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_BINARY_DIR}/include) -set(SOURCE_FILES +set(TOOLS_IRM_SOURCE_FILES # Add source files here irm.c irm_bind_program.c @@ -32,8 +32,11 @@ set(SOURCE_FILES irm_utils.c ) -add_executable(irm ${SOURCE_FILES}) +add_executable(irm ${TOOLS_IRM_SOURCE_FILES}) target_link_libraries(irm LINK_PUBLIC ouroboros-irm) install(TARGETS irm RUNTIME DESTINATION ${CMAKE_INSTALL_SBINDIR}) + +# enable when we have tests +# add_subdirectory(tests) diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index 2388bfd9..ba0f4713 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A tool to instruct the IRM daemon * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -49,7 +49,7 @@ static void usage(void) { printf("Usage: irm [OPERATION]\n\n" - "where OPERATION = {ipcp bind unbind name}\n"); + "where OPERATION in { ipcp bind unbind name }\n"); } static int do_help(int argc, diff --git a/src/tools/irm/irm_bind.c b/src/tools/irm/irm_bind.c index 2715b48e..2e8b14ef 100644 --- a/src/tools/irm/irm_bind.c +++ b/src/tools/irm/irm_bind.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Bind names in the processing system * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,7 +47,7 @@ static void usage(void) { printf("Usage: irm bind [OPERATION]\n" "\n" - "where OPERATION = {program process ipcp help}\n"); + "where OPERATION in {program process ipcp help}\n"); } static int do_help(int argc, diff --git a/src/tools/irm/irm_bind_ipcp.c b/src/tools/irm/irm_bind_ipcp.c index 4f3f11b2..7d5dd636 100644 --- a/src/tools/irm/irm_bind_ipcp.c +++ b/src/tools/irm/irm_bind_ipcp.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Bind IPCP Instance to a name * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -55,11 +55,11 @@ static void usage(void) int do_bind_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * name = NULL; - struct ipcp_info * ipcps; - ssize_t len; - ssize_t i; + char * ipcp = NULL; + char * name = NULL; + struct ipcp_list_info * ipcps; + ssize_t len; + ssize_t i; while (argc > 0) { if (matches(*argv, "name") == 0) { diff --git a/src/tools/irm/irm_bind_process.c b/src/tools/irm/irm_bind_process.c index a45942b0..fffd5fe9 100644 --- a/src/tools/irm/irm_bind_process.c +++ b/src/tools/irm/irm_bind_process.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Bind a process to a name * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_bind_program.c b/src/tools/irm/irm_bind_program.c index 7c62f6a1..8a0dc33c 100644 --- a/src/tools/irm/irm_bind_program.c +++ b/src/tools/irm/irm_bind_program.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Bind programs to a name * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_ipcp.c b/src/tools/irm/irm_ipcp.c index 12e79c29..63e617d9 100644 --- a/src/tools/irm/irm_ipcp.c +++ b/src/tools/irm/irm_ipcp.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A tool to instruct the IRM daemon * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,10 +44,11 @@ static void usage(void) { printf("Usage: irm ipcp [OPERATION]\n\n" - "where OPERATION = {create destroy\n" - " bootstrap enroll\n" - " connect disconnect\n" - " list help}\n"); + "where OPERATION in {create destroy\n" + " bootstrap enroll\n" + " connect disconnect\n" + " list\n" + " help}\n"); } static int do_help(int argc, char **argv) diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c index 84b6759a..4bbb9725 100644 --- a/src/tools/irm/irm_ipcp_bootstrap.c +++ b/src/tools/irm/irm_ipcp_bootstrap.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Bootstrap IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -50,117 +50,146 @@ #include <sys/socket.h> #endif -#define UNICAST "unicast" -#define BROADCAST "broadcast" -#define UDP "udp" -#define ETH_LLC "eth-llc" -#define ETH_DIX "eth-dix" -#define LOCAL "local" -#define RAPTOR "raptor" +#define UNICAST "unicast" +#define BROADCAST "broadcast" +#define IP_UDP "udp" +#define ETH_LLC "eth-llc" +#define ETH_DIX "eth-dix" +#define LOCAL "local" -#define MD5 "MD5" -#define SHA3_224 "SHA3_224" -#define SHA3_256 "SHA3_256" -#define SHA3_384 "SHA3_384" -#define SHA3_512 "SHA3_512" +#define MD5 "MD5" +#define SHA3_224 "SHA3_224" +#define SHA3_256 "SHA3_256" +#define SHA3_384 "SHA3_384" +#define SHA3_512 "SHA3_512" -#define DEFAULT_ADDR_SIZE 4 -#define DEFAULT_EID_SIZE 2 -#define DEFAULT_DDNS 0 -#define DEFAULT_TTL 60 -#define DEFAULT_ADDR_AUTH ADDR_AUTH_FLAT_RANDOM -#define DEFAULT_ROUTING ROUTING_LINK_STATE -#define DEFAULT_HASH_ALGO DIR_HASH_SHA3_256 -#define DEFAULT_ETHERTYPE 0xA000 -#define DEFAULT_CLIENT_PORT 0x0000 /* random port */ -#define DEFAULT_SERVER_PORT 0x0D6B /* 3435 */ +#define FLAT_RANDOM "flat" +#define DHT_DIR "DHT" +#define LINK_STATE "link_state" +#define LINK_STATE_LFA "lfa" +#define LINK_STATE_ECM "ecmp" +#define NONE_CA "none" +#define MB_ECN_CA "mb-ecn" -#define FLAT_RANDOM_ADDR_AUTH "flat" -#define LINK_STATE_ROUTING "link_state" -#define LINK_STATE_LFA_ROUTING "lfa" -#define LINK_STATE_ECM_ROUTING "ecmp" +#define DT(x) default_dt_config.x +#define DHT(x) default_dht_config.params.x +#define UNI(x) default_uni_config.x +#define DIX(x) eth_dix_default_conf.eth.x +#define LLC(x) eth_llc_default_conf.eth.x +#define UDP(x) udp_default_conf.udp.x + +static char * usage_str = \ + "Usage: irm ipcp bootstrap\n" + " name <ipcp name>\n" + " layer <layer name>\n" + " [type [TYPE]]\n" + "where TYPE in {" UNICAST " " BROADCAST " " LOCAL " " + IP_UDP " " ETH_LLC " " ETH_DIX "},\n\n" + "if TYPE == " UNICAST "\n" + " [addr_auth <ADDRESS_POLICY> (default: %s)]\n" + " [directory <DIRECTORY_POLICY> (default: %s)]\n" + " [hash [ALGORITHM] (default: %s)]\n" + " [routing <ROUTING_POLICY> (default: %s)]\n" + " [congestion <CONG_POLICY> (default: %s)]\n" + " [autobind]\n\n" + "where ADDRESS_POLICY in {" FLAT_RANDOM "}\n" + " DIRECTORY_POLICY in {" DHT_DIR "}\n" + " ALGORITHM in {" SHA3_224 " " SHA3_256 " " + SHA3_384 " " SHA3_512 "}\n" + " ROUTING_POLICY in {" LINK_STATE " " + LINK_STATE_LFA " " LINK_STATE_ECM "}\n" + " CONG_POLICY in {" NONE_CA " " MB_ECN_CA "}\n" + " [Data Transfer Constants]\n" + " [addr <address size> (default: %d)]\n" + " [eid <eid size> (default: %d)]\n" + " [ttl <max time-to-live>, default: %d)]\n\n" + "if DIRECTORY_POLICY == " DHT_DIR "\n" + " [dht_alpha <search factor> (default: %u)]\n" + " [dht_k <replication factor> (default: %u)]\n" + " [dht_t_expire <expiration (s)> (default: %u)]\n" + " [dht_t_refresh <contact refresh (s)> (default: %u)]\n" + " [dht_t_replicate <replication (s)> (default: %u)]\n\n" + "if ROUTING_POLICY == " LINK_STATE "\n" + " [ls_t_recalc <pff recalc interval (s)> (default: %ld)]\n" + " [ls_t_update <LSA update interval (s)> (default: %ld)]\n" + " [ls_t_timeo <link timeout (s)> (default: %ld)]\n\n" + "if TYPE == " IP_UDP "\n" + " ip <IP address in dotted notation>\n" + " [port <UDP port> (default: %d)]\n" + " [dns <DDNS IP address in dotted notation>" + " (default: none)]\n\n" + "if TYPE == " ETH_LLC "\n" + " dev <interface name>\n" + " [hash [ALGORITHM] (default: %s)]\n" + "where ALGORITHM in {" SHA3_224 " " SHA3_256 " " + SHA3_384 " " SHA3_512 "}\n\n" + "if TYPE == " ETH_DIX "\n" + " dev <interface name>\n" + " [ethertype <ethertype> (default: 0x%4X)]\n" + " [hash [ALGORITHM] (default: %s)]\n" + "where ALGORITHM in {" SHA3_224 " " SHA3_256 " " + SHA3_384 " " SHA3_512 "}\n\n" + "if TYPE == " LOCAL "\n" + " [hash [ALGORITHM] (default: %s)]\n" + "where ALGORITHM in {" SHA3_224 " " SHA3_256 " " + SHA3_384 " " SHA3_512 "}\n\n" + "if TYPE == " BROADCAST "\n" + " [autobind]\n\n"; static void usage(void) { /* FIXME: Add ipcp_config stuff. */ - printf("Usage: irm ipcp bootstrap\n" - " name <ipcp name>\n" - " layer <layer name>\n" - " [type [TYPE]]\n" - "where TYPE = {" UNICAST " " BROADCAST " " LOCAL " " - UDP " " ETH_LLC " " ETH_DIX " " RAPTOR "},\n\n" - "if TYPE == " UNICAST "\n" - " [addr <address size> (default: %d)]\n" - " [eid <eid size> (default: %d)]\n" - " [ttl (max time-to-live value, default: %d)]\n" - " [addr_auth <ADDRESS_POLICY> (default: %s)]\n" - " [routing <ROUTING_POLICY> (default: %s)]\n" - " [hash [ALGORITHM] (default: %s)]\n" - " [autobind]\n" - "where ADDRESS_POLICY = {"FLAT_RANDOM_ADDR_AUTH"}\n" - " ROUTING_POLICY = {"LINK_STATE_ROUTING " " - LINK_STATE_LFA_ROUTING " " LINK_STATE_ECM_ROUTING "}\n" - " ALGORITHM = {" SHA3_224 " " SHA3_256 " " - SHA3_384 " " SHA3_512 "}\n\n" - "if TYPE == " UDP "\n" - " ip <IP address in dotted notation>\n" - " [cport <client port> (default: random)]\n" - " [sport <server port> (default: %d)]\n" - " [dns <DDNS IP address in dotted notation>" - " (default: none)]\n\n" - "if TYPE == " ETH_LLC "\n" - " dev <interface name>\n" - " [hash [ALGORITHM] (default: %s)]\n" - "where ALGORITHM = {" SHA3_224 " " SHA3_256 " " - SHA3_384 " " SHA3_512 "}\n\n" - "if TYPE == " ETH_DIX "\n" - " dev <interface name>\n" - " [ethertype <ethertype> (default: 0x%4X)]\n" - " [hash [ALGORITHM] (default: %s)]\n" - "where ALGORITHM = {" SHA3_224 " " SHA3_256 " " - SHA3_384 " " SHA3_512 "}\n\n" - "if TYPE == " LOCAL "\n" - " [hash [ALGORITHM] (default: %s)]\n" - "where ALGORITHM = {" SHA3_224 " " SHA3_256 " " - SHA3_384 " " SHA3_512 "}\n\n" - "if TYPE == " RAPTOR "\n" - " [hash [ALGORITHM] (default: %s)]\n" - "where ALGORITHM = {" SHA3_224 " " SHA3_256 " " - SHA3_384 " " SHA3_512 "}\n\n" - "if TYPE == " BROADCAST "\n" - " [autobind]\n\n", - DEFAULT_ADDR_SIZE, DEFAULT_EID_SIZE, DEFAULT_TTL, - FLAT_RANDOM_ADDR_AUTH, LINK_STATE_ROUTING, - SHA3_256, DEFAULT_SERVER_PORT, SHA3_256, 0xA000, SHA3_256, - SHA3_256, SHA3_256); + printf(usage_str, + /* unicast */ + FLAT_RANDOM, DHT_DIR, SHA3_256, LINK_STATE, MB_ECN_CA, + /* dt */ + DT(addr_size), DT(eid_size), DT(max_ttl), + /* dht */ + DHT(alpha), DHT(k), DHT(t_expire), + DHT(t_refresh), DHT(t_replicate), + /* ls */ + default_ls_config.t_recalc, default_ls_config.t_update, + default_ls_config.t_timeo, + /* udp */ + UDP(port), + /* eth_llc */ + SHA3_256, + /* eth_dix */ + DIX(ethertype), + SHA3_256, + /* local */ + SHA3_256, + /* broadcast */ + SHA3_256); } int do_bootstrap_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - pid_t pid = -1; - struct ipcp_config conf; - uint8_t addr_size = DEFAULT_ADDR_SIZE; - uint8_t eid_size = DEFAULT_EID_SIZE; - uint8_t max_ttl = DEFAULT_TTL; - enum pol_addr_auth addr_auth_type = DEFAULT_ADDR_AUTH; - enum pol_routing routing_type = DEFAULT_ROUTING; - enum pol_dir_hash hash_algo = DEFAULT_HASH_ALGO; - uint32_t ip_addr = 0; - uint32_t dns_addr = DEFAULT_DDNS; - char * ipcp_type = NULL; - enum ipcp_type type = IPCP_INVALID; - char * layer = NULL; - char * dev = NULL; - uint16_t ethertype = DEFAULT_ETHERTYPE; - struct ipcp_info * ipcps; - ssize_t len = 0; - int i = 0; - bool autobind = false; - int cargs; - int cport = DEFAULT_CLIENT_PORT; - int sport = DEFAULT_SERVER_PORT; + char * ipcp = NULL; + pid_t pid = -1; + struct ipcp_config conf; + struct dir_config dir_config = default_dir_config; + uint8_t addr_size = DT(addr_size); + uint8_t eid_size = DT(eid_size); + uint8_t max_ttl = DT(max_ttl); + struct routing_config routing = default_routing_config; + enum pol_addr_auth addr_auth_type = UNI(addr_auth_type); + enum pol_cong_avoid cong_avoid = UNI(cong_avoid); + enum pol_dir_hash hash_algo = DIR_HASH_SHA3_256; + uint32_t ip_addr = 0; + uint32_t dns_addr = UDP(dns_addr); + int port = UDP(port); + char * ipcp_type = NULL; + enum ipcp_type type = IPCP_INVALID; + char * layer = NULL; + char * dev = NULL; + uint16_t ethertype = DIX(ethertype); + struct ipcp_list_info * ipcps; + ssize_t len = 0; + int i = 0; + bool autobind = false; + int cargs; while (argc > 0) { cargs = 2; @@ -195,7 +224,7 @@ int do_bootstrap_ipcp(int argc, ethertype = strtol(*(argv + 1), NULL, 0); else ethertype = strtol(*(argv + 1), NULL, 16); - if (ethertype < 0x0600 || ethertype == 0xFFFF) { + if (ethertype < 0x0600 || ethertype >= 0xFFFF) { printf("Invalid Ethertype: \"%s\".\n" "Recommended range: 0xA000-0xEFFF.\n", *(argv + 1)); @@ -207,27 +236,56 @@ int do_bootstrap_ipcp(int argc, eid_size = atoi(*(argv + 1)); } else if (matches(*argv, "ttl") == 0) { max_ttl = atoi(*(argv + 1)); - } else if (matches(*argv, "cport") == 0) { - cport = atoi(*(argv + 1)); - } else if (matches(*argv, "sport") == 0) { - sport = atoi(*(argv + 1)); + } else if (matches(*argv, "port") == 0) { + port = atoi(*(argv + 1)); } else if (matches(*argv, "autobind") == 0) { autobind = true; cargs = 1; } else if (matches(*argv, "addr_auth") == 0) { - if (strcmp(FLAT_RANDOM_ADDR_AUTH, *(argv + 1)) == 0) + if (strcmp(FLAT_RANDOM, *(argv + 1)) == 0) addr_auth_type = ADDR_AUTH_FLAT_RANDOM; else goto unknown_param; + } else if (matches(*argv, "directory") == 0) { + if (strcmp(DHT_DIR, *(argv + 1)) == 0) + dir_config.pol = DIR_DHT; + else + goto unknown_param; + } else if (matches(*argv, "dht_alpha") == 0) { + dir_config.dht.params.alpha = atoi(*(argv + 1)); + } else if (matches(*argv, "dht_k") == 0) { + dir_config.dht.params.k = atoi(*(argv + 1)); + } else if (matches(*argv, "dht_t_expire") == 0) { + dir_config.dht.params.t_expire = atoi(*(argv + 1)); + } else if (matches(*argv, "dht_t_refresh") == 0) { + dir_config.dht.params.t_refresh = atoi(*(argv + 1)); + } else if (matches(*argv, "dht_t_replicate") == 0) { + dir_config.dht.params.t_replicate = atoi(*(argv + 1)); } else if (matches(*argv, "routing") == 0) { - if (strcmp(LINK_STATE_ROUTING, *(argv + 1)) == 0) - routing_type = ROUTING_LINK_STATE; - else if (strcmp(LINK_STATE_LFA_ROUTING, - *(argv + 1)) == 0) - routing_type = ROUTING_LINK_STATE_LFA; - else if (strcmp(LINK_STATE_ECM_ROUTING, + if (strcmp(LINK_STATE, *(argv + 1)) == 0) { + routing.pol = ROUTING_LINK_STATE; + routing.ls.pol = LS_SIMPLE; + } else if (strcmp(LINK_STATE_LFA, *(argv + 1)) == 0) { + routing.pol = ROUTING_LINK_STATE; + routing.ls.pol = LS_LFA; + } else if (strcmp(LINK_STATE_ECM, *(argv + 1)) == 0) { + routing.pol = ROUTING_LINK_STATE; + routing.ls.pol = LS_ECMP; + } else { + goto unknown_param; + } + } else if (matches(*argv, "ls_t_timeo") == 0) { + routing.ls.t_timeo = atoi(*(argv + 1)); + } else if (matches(*argv, "ls_t_update") == 0) { + routing.ls.t_update = atoi(*(argv + 1)); + } else if (matches(*argv, "ls_t_recalc") == 0) { + routing.ls.t_recalc = atoi(*(argv + 1)); + } else if (matches(*argv, "congestion") == 0) { + if (strcmp(NONE_CA, *(argv + 1)) == 0) + cong_avoid = CA_NONE; + else if (strcmp(MB_ECN_CA, *(argv + 1)) == 0) - routing_type = ROUTING_LINK_STATE_ECMP; + cong_avoid = CA_MB_ECN; else goto unknown_param; } else { @@ -257,7 +315,7 @@ int do_bootstrap_ipcp(int argc, type = IPCP_UNICAST; else if (strcmp(ipcp_type, BROADCAST) == 0) type = IPCP_BROADCAST; - else if (strcmp(ipcp_type, UDP) == 0) + else if (strcmp(ipcp_type, IP_UDP) == 0) type = IPCP_UDP; else if (strcmp(ipcp_type, ETH_LLC) == 0) type = IPCP_ETH_LLC; @@ -265,8 +323,6 @@ int do_bootstrap_ipcp(int argc, type = IPCP_ETH_DIX; else if (strcmp(ipcp_type, LOCAL) == 0) type = IPCP_LOCAL; - else if (strcmp(ipcp_type, RAPTOR) == 0) - type = IPCP_RAPTOR; else goto fail_usage; } @@ -290,6 +346,7 @@ int do_bootstrap_ipcp(int argc, printf("Types do not match.\n\n"); goto fail; } + conf.type = ipcps[i].type; if (autobind && (conf.type != IPCP_UNICAST && @@ -300,46 +357,46 @@ int do_bootstrap_ipcp(int argc, } if (strlen(layer) > LAYER_NAME_SIZE) { - printf("Layer name too big.\n\n"); + printf("Layer name too long.\n\n"); goto fail_usage; } - strcpy(conf.layer_info.layer_name, layer); - if (conf.type != IPCP_UDP) - conf.layer_info.dir_hash_algo = hash_algo; + strcpy(conf.layer_info.name, layer); + conf.layer_info.dir_hash_algo = hash_algo; switch (conf.type) { case IPCP_UNICAST: - conf.addr_size = addr_size; - conf.eid_size = eid_size; - conf.max_ttl = max_ttl; - conf.addr_auth_type = addr_auth_type; - conf.routing_type = routing_type; + conf.unicast.dt.addr_size = addr_size; + conf.unicast.dt.eid_size = eid_size; + conf.unicast.dt.max_ttl = max_ttl; + conf.unicast.dt.routing = routing; + conf.unicast.addr_auth_type = addr_auth_type; + conf.unicast.cong_avoid = cong_avoid; + conf.unicast.dir = dir_config; break; case IPCP_UDP: if (ip_addr == 0) goto fail_usage; - conf.ip_addr = ip_addr; - conf.dns_addr = dns_addr; - conf.clt_port = cport; - conf.srv_port = sport; + conf.udp.ip_addr = ip_addr; + conf.udp.dns_addr = dns_addr; + conf.udp.port = port; break; + case IPCP_ETH_DIX: + conf.eth.ethertype = ethertype; + /* FALLTHRU */ case IPCP_ETH_LLC: if (dev == NULL) goto fail_usage; - conf.dev = dev; - break; - case IPCP_ETH_DIX: - if (dev == NULL) + if (strlen(dev) > DEV_NAME_SIZE) { + printf("Device name too long.\n\n"); goto fail_usage; - conf.dev = dev; - conf.ethertype = ethertype; + } + + strcpy(conf.eth.dev, dev); break; case IPCP_BROADCAST: /* FALLTHRU */ case IPCP_LOCAL: - /* FALLTHRU */ - case IPCP_RAPTOR: break; default: assert(false); diff --git a/src/tools/irm/irm_ipcp_connect.c b/src/tools/irm/irm_ipcp_connect.c index 12541b2c..68e13bd0 100644 --- a/src/tools/irm/irm_ipcp_connect.c +++ b/src/tools/irm/irm_ipcp_connect.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Connect components of unicast or broadcast IPC processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -55,25 +55,25 @@ static void usage(void) " name <ipcp name>\n" " dst <name of destination IPCP>\n" " [component [COMPONENT]]\n" - "where COMPONENT = {" DT " " MGMT "}\n\n" + "where COMPONENT in {" DT " " MGMT "}\n\n" "if COMPONENT == " DT "\n" " [qos [QOS]\n" - "where QOS = {raw, best, voice, video, data}\n\n"); + "where QOS in {raw, best, voice, video, data}\n"); } int do_connect_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * dst = NULL; - char * comp = "*"; - char * component = NULL; - char * qos = NULL; - struct ipcp_info * ipcps; - ssize_t len = 0; - pid_t pid = -1; - ssize_t i; - qosspec_t qs = qos_raw; + char * ipcp = NULL; + char * dst = NULL; + char * comp = "*"; + char * component = NULL; + char * qos = NULL; + struct ipcp_list_info * ipcps; + ssize_t len = 0; + pid_t pid = -1; + ssize_t i; + qosspec_t qs = qos_raw; while (argc > 0) { if (matches(*argv, "name") == 0) { diff --git a/src/tools/irm/irm_ipcp_create.c b/src/tools/irm/irm_ipcp_create.c index ae2c2289..35d33782 100644 --- a/src/tools/irm/irm_ipcp_create.c +++ b/src/tools/irm/irm_ipcp_create.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Create IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,30 +44,29 @@ #include "irm_ops.h" #include "irm_utils.h" -#define UNICAST "unicast" +#define UNICAST "unicast" #define BROADCAST "broadcast" #define UDP "udp" #define ETH_LLC "eth-llc" #define ETH_DIX "eth-dix" #define LOCAL "local" -#define RAPTOR "raptor" static void usage(void) { printf("Usage: irm ipcp create\n" " name <ipcp name>\n" " type [TYPE]\n\n" - "where TYPE = {" UNICAST " " BROADCAST " " LOCAL " " - UDP " " ETH_LLC " " RAPTOR "}\n"); + "where TYPE in {" UNICAST " " BROADCAST " " LOCAL " " + UDP " " ETH_LLC " " ETH_DIX "}\n"); } int do_create_ipcp(int argc, char ** argv) { - char * ipcp_type = NULL; - char * ipcp_name = NULL; - enum ipcp_type type = 0; - pid_t pid; + char * ipcp_type = NULL; + char * ipcp_name = NULL; + enum ipcp_type type = 0; + pid_t pid; while (argc > 0) { if (matches(*argv, "type") == 0) { @@ -101,15 +100,14 @@ int do_create_ipcp(int argc, type = IPCP_ETH_LLC; else if (strcmp(ipcp_type, ETH_DIX) == 0) type = IPCP_ETH_DIX; - else if (strcmp(ipcp_type, RAPTOR) == 0) - type = IPCP_RAPTOR; else { + printf("IPCP type \"%s\" is unknown.\n", ipcp_type); usage(); return -1; } pid = irm_create_ipcp(ipcp_name, type); - if (pid <= 0) + if (pid < 0) return -1; return 0; diff --git a/src/tools/irm/irm_ipcp_destroy.c b/src/tools/irm/irm_ipcp_destroy.c index be03df00..1a5e564e 100644 --- a/src/tools/irm/irm_ipcp_destroy.c +++ b/src/tools/irm/irm_ipcp_destroy.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Destroy IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -55,10 +55,10 @@ static void usage(void) int do_destroy_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - struct ipcp_info * ipcps; - ssize_t len; - int i; + char * ipcp = NULL; + struct ipcp_list_info * ipcps; + ssize_t len; + int i; while (argc > 0) { if (matches(*argv, "name") == 0) { diff --git a/src/tools/irm/irm_ipcp_disconnect.c b/src/tools/irm/irm_ipcp_disconnect.c index d92d56eb..7ce724e1 100644 --- a/src/tools/irm/irm_ipcp_disconnect.c +++ b/src/tools/irm/irm_ipcp_disconnect.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Connect components of unicast or broadcast IPC processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -54,20 +54,20 @@ static void usage(void) " name <ipcp name>\n" " dst <name of destination IPCP>\n" " [component [COMPONENT]]\n\n" - "where COMPONENT = {" DT " " MGMT "}\n"); + "where COMPONENT in {" DT " " MGMT "}\n"); } int do_disconnect_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * dst = NULL; - char * comp = "*"; - char * component = NULL; - struct ipcp_info * ipcps; - ssize_t len = 0; - pid_t pid = -1; - ssize_t i; + char * ipcp = NULL; + char * dst = NULL; + char * comp = "*"; + char * component = NULL; + struct ipcp_list_info * ipcps; + ssize_t len = 0; + pid_t pid = -1; + ssize_t i; while (argc > 0) { if (matches(*argv, "name") == 0) { diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c index ebb1da43..86a22a71 100644 --- a/src/tools/irm/irm_ipcp_enroll.c +++ b/src/tools/irm/irm_ipcp_enroll.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Enroll IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,15 +57,15 @@ static void usage(void) " [dst <destination to enroll with>]\n" " [type [TYPE], default = " UNICAST "]\n" " [autobind]\n" - "where TYPE = {" UNICAST " " BROADCAST "}\n"); + "where TYPE in {" UNICAST " " BROADCAST "}\n"); } static int get_layer_name(const char * ipcp, char * layer_name) { - struct ipcp_info * ipcps; - size_t len; - size_t i; + struct ipcp_list_info * ipcps; + ssize_t len; + ssize_t i; len = irm_list_ipcps(&ipcps); for (i = 0; i < len; i++) @@ -83,17 +83,17 @@ static int get_layer_name(const char * ipcp, int do_enroll_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * layer = NULL; - char * dst = NULL; - struct ipcp_info * ipcps; - pid_t pid = -1; - ssize_t len = 0; - int i = 0; - bool autobind = false; - int cargs; - char * ipcp_type = UNICAST; - enum ipcp_type type = IPCP_INVALID; + char * ipcp = NULL; + char * layer = NULL; + char * dst = NULL; + struct ipcp_list_info * ipcps; + pid_t pid = -1; + ssize_t len = 0; + int i = 0; + bool autobind = false; + int cargs; + char * ipcp_type = UNICAST; + enum ipcp_type type = IPCP_INVALID; while (argc > 0) { cargs = 2; @@ -146,40 +146,39 @@ int do_enroll_ipcp(int argc, } for (i = 0; i < len; i++) { + char enr_layer[LAYER_NAME_SIZE]; if (ipcps[i].type != type) continue; - if (wildcard_match(ipcps[i].name, ipcp) == 0) { - char enr_layer[LAYER_NAME_SIZE]; + if (wildcard_match(ipcps[i].name, ipcp) != 0) + continue; - pid = ipcps[i].pid; + pid = ipcps[i].pid; + + if (irm_enroll_ipcp(pid, dst)) { + printf("Failed to enroll IPCP.\n"); + goto fail; + } + + if (get_layer_name(ipcps[i].name, enr_layer)) { + printf("Could not get layer name.\n"); + goto fail; + } - if (irm_enroll_ipcp(pid, dst)) { - printf("Failed to enroll IPCP.\n"); - goto fail; - } - - if (get_layer_name(ipcps[i].name, enr_layer)) { - printf("Could not get layer name.\n"); - goto fail; - } - - if (layer != NULL && strcmp(enr_layer, layer)) { - printf("Enrollment destination does not " - "match requested layer.\n"); - goto fail; - } - - if (autobind && irm_bind_process(pid, ipcp)) { - printf("Failed to bind %d to %s.\n", pid, ipcp); - goto fail; - } - - if (autobind && irm_bind_process(pid, enr_layer)) { - printf("Failed to bind %d to %s.\n", - pid, enr_layer); - goto fail; - } + if (layer != NULL && strcmp(enr_layer, layer)) { + printf("Enrollment destination does not " + "match requested layer.\n"); + goto fail; + } + + if (autobind && irm_bind_process(pid, ipcp)) { + printf("Failed to bind %d to %s.\n", pid, ipcp); + goto fail; + } + + if (autobind && irm_bind_process(pid, enr_layer)) { + printf("Failed to bind %d to %s.\n", pid, enr_layer); + goto fail; } } diff --git a/src/tools/irm/irm_ipcp_list.c b/src/tools/irm/irm_ipcp_list.c index 3b8612ed..dfa3099f 100644 --- a/src/tools/irm/irm_ipcp_list.c +++ b/src/tools/irm/irm_ipcp_list.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * List IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -46,12 +46,12 @@ #include <stdlib.h> #include <string.h> -#define UNICAST "unicast" -#define UDP "udp" -#define ETH_LLC "eth-llc" -#define ETH_DIX "eth-dix" -#define LOCAL "local" -#define RAPTOR "raptor" +#define UNICAST "unicast" +#define BROADCAST "broadcast" +#define UDP "udp" +#define ETH_LLC "eth-llc" +#define ETH_DIX "eth-dix" +#define LOCAL "local" static void usage(void) { @@ -60,7 +60,7 @@ static void usage(void) " [layer <layer_name>]\n\n" " [type [TYPE]]\n\n" "where TYPE = {" UNICAST " " LOCAL " " - UDP " " ETH_LLC " " ETH_DIX " " RAPTOR "}\n"); + UDP " " ETH_LLC " " ETH_DIX "}\n"); } static char * str_type(enum ipcp_type type) @@ -68,14 +68,14 @@ static char * str_type(enum ipcp_type type) switch(type) { case IPCP_UNICAST: return UNICAST; + case IPCP_BROADCAST: + return BROADCAST; case IPCP_ETH_LLC: return ETH_LLC; case IPCP_ETH_DIX: return ETH_DIX; case IPCP_UDP: return UDP; - case IPCP_RAPTOR: - return RAPTOR; case IPCP_LOCAL: return LOCAL; default: @@ -86,12 +86,12 @@ static char * str_type(enum ipcp_type type) int do_list_ipcp(int argc, char ** argv) { - char * ipcp_type = NULL; - char * ipcp_name = NULL; - enum ipcp_type type = -1; - struct ipcp_info * ipcps; - ssize_t len; - ssize_t i; + char * ipcp_type = NULL; + char * ipcp_name = NULL; + enum ipcp_type type = -1; + struct ipcp_list_info * ipcps; + ssize_t len; + ssize_t i; while (argc > 0) { if (matches(*argv, "type") == 0) { @@ -111,6 +111,8 @@ int do_list_ipcp(int argc, if (ipcp_type != NULL) { if (strcmp(ipcp_type, UNICAST) == 0) type = IPCP_UNICAST; + else if (strcmp(ipcp_type, BROADCAST) == 0) + type = IPCP_BROADCAST; else if (strcmp(ipcp_type, UDP) == 0) type = IPCP_UDP; else if (strcmp(ipcp_type, LOCAL) == 0) @@ -119,8 +121,6 @@ int do_list_ipcp(int argc, type = IPCP_ETH_LLC; else if (strcmp(ipcp_type, ETH_DIX) == 0) type = IPCP_ETH_DIX; - else if (strcmp(ipcp_type, RAPTOR) == 0) - type = IPCP_RAPTOR; else { usage(); return -1; diff --git a/src/tools/irm/irm_name.c b/src/tools/irm/irm_name.c index 3a615b00..d60b6c78 100644 --- a/src/tools/irm/irm_name.c +++ b/src/tools/irm/irm_name.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A tool to instruct the IRM daemon * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,9 +44,10 @@ static void usage(void) { printf("Usage: irm name [OPERATION]\n\n" - "where OPERATION = {create destroy\n" - " register unregister\n" - " list help}\n"); + "where OPERATION in {create destroy\n" + " register unregister\n" + " list\n" + " help}\n"); } static int do_help(int argc, char **argv) diff --git a/src/tools/irm/irm_name_create.c b/src/tools/irm/irm_name_create.c index 9b7e6a36..a0079cad 100644 --- a/src/tools/irm/irm_name_create.c +++ b/src/tools/irm/irm_name_create.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Create IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -52,7 +52,7 @@ static void usage(void) printf("Usage: irm name create\n" " <name>\n" " lb [LB_POLICY], default: %s\n\n" - "where LB_POLICY = {" RR " " SPILL "}\n", RR); + "where LB_POLICY in {" RR " " SPILL "}\n", RR); } int do_create_name(int argc, diff --git a/src/tools/irm/irm_name_destroy.c b/src/tools/irm/irm_name_destroy.c index 70f801b2..d4bd6c82 100644 --- a/src/tools/irm/irm_name_destroy.c +++ b/src/tools/irm/irm_name_destroy.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Create IPC Processes * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_name_list.c b/src/tools/irm/irm_name_list.c index 2e4c3194..a807008c 100644 --- a/src/tools/irm/irm_name_list.c +++ b/src/tools/irm/irm_name_list.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * List names * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_name_reg.c b/src/tools/irm/irm_name_reg.c index 52bf911b..061ed8be 100644 --- a/src/tools/irm/irm_name_reg.c +++ b/src/tools/irm/irm_name_reg.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Register names with IPCPs * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -64,17 +64,17 @@ static void usage(void) int do_reg_name(int argc, char ** argv) { - char * name = NULL; - char * layers[MAX_LAYERS]; - size_t layers_len = 0; - char * ipcp[MAX_IPCPS]; - size_t ipcp_len = 0; - struct ipcp_info * ipcps; - ssize_t ipcps_len; - struct name_info * names; - ssize_t names_len; - bool name_create = true; - ssize_t i; + char * name = NULL; + char * layers[MAX_LAYERS]; + size_t layers_len = 0; + char * ipcp[MAX_IPCPS]; + size_t ipcp_len = 0; + struct ipcp_list_info * ipcps; + ssize_t ipcps_len; + struct name_info * names; + ssize_t names_len; + bool name_create = true; + ssize_t i; name = *(argv++); --argc; diff --git a/src/tools/irm/irm_name_unreg.c b/src/tools/irm/irm_name_unreg.c index 48253143..6e579f04 100644 --- a/src/tools/irm/irm_name_unreg.c +++ b/src/tools/irm/irm_name_unreg.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Unregister names from IPCPs * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -63,14 +63,14 @@ static void usage(void) int do_unreg_name(int argc, char ** argv) { - char * name = NULL; - char * layers[MAX_LAYERS]; - size_t layers_len = 0; - char * ipcp[MAX_IPCPS]; - size_t ipcp_len = 0; - struct ipcp_info * ipcps; - ssize_t len; - size_t i; + char * name = NULL; + char * layers[MAX_LAYERS]; + size_t layers_len = 0; + char * ipcp[MAX_IPCPS]; + size_t ipcp_len = 0; + struct ipcp_list_info * ipcps; + ssize_t len; + size_t i; name = *(argv++); --argc; diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h index 7c1b1a8f..e04ffc02 100644 --- a/src/tools/irm/irm_ops.h +++ b/src/tools/irm/irm_ops.h @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Functions of the IRM tool that are one level deep * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_unbind.c b/src/tools/irm/irm_unbind.c index 05838235..d6594d01 100644 --- a/src/tools/irm/irm_unbind.c +++ b/src/tools/irm/irm_unbind.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Unbind names in the processing system * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -47,7 +47,7 @@ static void usage(void) { printf("Usage: irm unbind [OPERATION]\n" "\n" - "where OPERATION = {program process ipcp help}\n"); + "where OPERATION in {program process ipcp help}\n"); } static int do_help(int argc, diff --git a/src/tools/irm/irm_unbind_ipcp.c b/src/tools/irm/irm_unbind_ipcp.c index d121b2dc..53a2d16c 100644 --- a/src/tools/irm/irm_unbind_ipcp.c +++ b/src/tools/irm/irm_unbind_ipcp.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Unbind name from IPCP Instance * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -57,11 +57,11 @@ static void usage(void) int do_unbind_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * name = NULL; - struct ipcp_info * ipcps; - ssize_t len; - ssize_t i; + char * ipcp = NULL; + char * name = NULL; + struct ipcp_list_info * ipcps; + ssize_t len; + ssize_t i; while (argc > 0) { if (matches(*argv, "name") == 0) { diff --git a/src/tools/irm/irm_unbind_process.c b/src/tools/irm/irm_unbind_process.c index d5b96141..264ed538 100644 --- a/src/tools/irm/irm_unbind_process.c +++ b/src/tools/irm/irm_unbind_process.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Unbind process names * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_unbind_program.c b/src/tools/irm/irm_unbind_program.c index 382c5d8a..0c751e80 100644 --- a/src/tools/irm/irm_unbind_program.c +++ b/src/tools/irm/irm_unbind_program.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Unbind programs * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c index 0620e374..9694d647 100644 --- a/src/tools/irm/irm_utils.c +++ b/src/tools/irm/irm_utils.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Handy helper functions for the IRM tool * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -109,7 +109,7 @@ int wildcard_match(const char * pattern, return 0; /* General case, use recursion. */ - while ((c = *string) != '\0') { + while (*string != '\0') { if (!wildcard_match(pattern, string)) return 0; ++string; diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h index 925a9da6..27a0b941 100644 --- a/src/tools/irm/irm_utils.h +++ b/src/tools/irm/irm_utils.h @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Handy helper functions for the IRM tool * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/obc/obc.c b/src/tools/obc/obc.c index 256cb84e..462cbea9 100644 --- a/src/tools/obc/obc.c +++ b/src/tools/obc/obc.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A simple broadcast application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/ocbr/ocbr.c b/src/tools/ocbr/ocbr.c index e2a23c4a..775bcaac 100644 --- a/src/tools/ocbr/ocbr.c +++ b/src/tools/ocbr/ocbr.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * CBR traffic generator * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -76,6 +76,7 @@ static void usage(void) " -s, --size packet size (B, max %ld B)\n" " -r, --rate Rate (b/s)\n" " --sleep Sleep in between sending packets\n" + " --spin Spin CPU between sending packets\n" "\n\n" " --help Display this help text and exit\n", BUF_SIZE); @@ -87,7 +88,7 @@ int main(int argc, char ** argv) int size = 1000; /* 1000 byte packets */ long rate = 1000000; /* 1 Mb/s */ bool flood = false; - bool sleep = false; + bool sleep = true; int ret = 0; char * rem = NULL; char * s_apn = NULL; @@ -138,6 +139,8 @@ int main(int argc, char ** argv) flood = true; } else if (strcmp(*argv, "--sleep") == 0) { sleep = true; + } else if (strcmp(*argv, "--spin") == 0) { + sleep = false; } else { usage(); return 0; @@ -152,17 +155,22 @@ int main(int argc, char ** argv) if (s_apn == NULL) { printf("No server specified.\n"); usage(); - return 0; + return 1; } if (size > BUF_SIZE) { printf("Maximum size: %ld.\n", BUF_SIZE); - return 0; + return 1; } if (size < 0) { printf("Size overflow.\n"); - return 0; + return 1; + } + + if (rate <= 0) { + printf("Invalid rate.\n"); + return 1; } ret = client_main(s_apn, duration, size, rate, flood, sleep); diff --git a/src/tools/ocbr/ocbr_client.c b/src/tools/ocbr/ocbr_client.c index 6120e1fd..eada6e60 100644 --- a/src/tools/ocbr/ocbr_client.c +++ b/src/tools/ocbr/ocbr_client.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A simple CBR generator * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -129,7 +129,7 @@ int client_main(char * server, ++seqnr; - if (ts_diff_us(&start, &end) / MILLION >= duration) + if (ts_diff_us(&end, &start) / MILLION >= duration) stop = true; } } else { /* flood */ @@ -142,7 +142,7 @@ int client_main(char * server, ++seqnr; - if (ts_diff_us(&start, &end) / MILLION + if (ts_diff_us(&end, &start) / MILLION >= (long) duration) stop = true; } @@ -151,7 +151,7 @@ int client_main(char * server, clock_gettime(CLOCK_REALTIME, &end); - ms = ts_diff_ms(&start, &end); + ms = ts_diff_ms(&end, &start); printf("sent statistics: " "%9ld packets, %12ld bytes in %9d ms, %4.4f Mb/s\n", diff --git a/src/tools/ocbr/ocbr_server.c b/src/tools/ocbr/ocbr_server.c index 583f226c..34c4fa94 100644 --- a/src/tools/ocbr/ocbr_server.c +++ b/src/tools/ocbr/ocbr_server.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A simple CBR generator * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -83,6 +83,7 @@ static void handle_flow(int fd) struct timespec now; struct timespec alive; struct timespec intv = {server_settings.interval, 0}; + struct timespec tic = {0, 100 * MILLION}; struct timespec iv_start; struct timespec iv_end; @@ -99,7 +100,8 @@ static void handle_flow(int fd) alive = iv_start; ts_add(&iv_start, &intv, &iv_end); - fccntl(fd, FLOWSFLAGS, FLOWFRNOBLOCK | FLOWFRDWR | FLOWFRNOPART); + fccntl(fd, FLOWSFLAGS, FLOWFRDWR | FLOWFRNOPART); + fccntl(fd, FLOWSRCVTIMEO, &tic); while (!stop) { clock_gettime(CLOCK_REALTIME, &now); @@ -112,14 +114,14 @@ static void handle_flow(int fd) bytes_read += count; } - if (ts_diff_us(&alive, &now) + if (ts_diff_us(&now, &alive) > server_settings.timeout * MILLION) { printf("Test on flow %d timed out\n", fd); stop = true; } - if (stop || ts_diff_ms(&now, &iv_end) < 0) { - long us = ts_diff_us(&iv_start, &now); + if (stop || ts_diff_ms(&now, &iv_end) > 0) { + long us = ts_diff_us(&now, &iv_start); printf("Flow %4d: %9ld packets (%12ld bytes) in %9ld ms" " => %9.4f pps, %9.4f Mbps\n", fd, @@ -140,6 +142,11 @@ static void handle_flow(int fd) flow_dealloc(fd); } +static void __cleanup_mutex_unlock(void * mutex) +{ + pthread_mutex_unlock((pthread_mutex_t *) mutex); +} + static void * worker(void * o) { int cli_fd; @@ -148,8 +155,7 @@ static void * worker(void * o) while (true) { pthread_mutex_lock(&fds_lock); - pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock, - (void *) &fds_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &fds_lock); while (fds[fds_index] == -1) pthread_cond_wait(&fds_signal, &fds_lock); @@ -182,8 +188,7 @@ static void * listener(void * o) while (true) { pthread_mutex_lock(&fds_lock); - pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock, - (void *) &fds_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &fds_lock); while (fds_count == THREADS_SIZE) { printf("Can't accept any more flows, waiting.\n"); diff --git a/src/tools/oecho/oecho.c b/src/tools/oecho/oecho.c index a44b8b76..d5d03027 100644 --- a/src/tools/oecho/oecho.c +++ b/src/tools/oecho/oecho.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * A simple echo application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/operf/operf.c b/src/tools/operf/operf.c index ed07323c..10896bd5 100644 --- a/src/tools/operf/operf.c +++ b/src/tools/operf/operf.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros perf application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/operf/operf_client.c b/src/tools/operf/operf_client.c index 004a8965..7060ce5b 100644 --- a/src/tools/operf/operf_client.c +++ b/src/tools/operf/operf_client.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros ping application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -133,7 +133,7 @@ void * writer(void * o) clock_gettime(CLOCK_REALTIME, &start); clock_gettime(CLOCK_REALTIME, &now); - while (!stop && ts_diff_ms(&start, &now) < client.duration) { + while (!stop && ts_diff_ms(&now, &start) > client.duration) { if (!client.flood) { clock_gettime(CLOCK_REALTIME, &now); ts_add(&now, &intv, &end); @@ -230,10 +230,10 @@ int client_main(void) printf("%ld received, ", client.rcvd); printf("%ld%% packet loss, ", client.sent == 0 ? 0 : 100 - ((100 * client.rcvd) / client.sent)); - printf("time: %.3f ms, ", ts_diff_us(&tic, &toc) / 1000.0); + printf("time: %.3f ms, ", ts_diff_us(&toc, &tic) / 1000.0); printf("bandwidth: %.3lf Mb/s.\n", (client.rcvd * client.size * 8) - / (double) ts_diff_us(&tic, &toc)); + / (double) ts_diff_us(&toc, &tic)); } flow_dealloc(fd); diff --git a/src/tools/operf/operf_server.c b/src/tools/operf/operf_server.c index f3ca8b19..a611f79c 100644 --- a/src/tools/operf/operf_server.c +++ b/src/tools/operf/operf_server.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros perf application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -66,7 +66,7 @@ void * cleaner_thread(void * o) pthread_mutex_lock(&server.lock); for (i = 0; i < OPERF_MAX_FLOWS; ++i) if (fset_has(server.flows, i) && - ts_diff_ms(&server.times[i], &now) + ts_diff_ms(&now, &server.times[i]) > server.timeout) { printf("Flow %d timed out.\n", i); fset_del(server.flows, i); diff --git a/src/tools/oping/oping.c b/src/tools/oping/oping.c index ca685292..ed3529e5 100644 --- a/src/tools/oping/oping.c +++ b/src/tools/oping/oping.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros ping application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -60,14 +60,31 @@ #include <errno.h> #include <float.h> -#define OPING_BUF_SIZE 1500 - -#define ECHO_REQUEST 0 -#define ECHO_REPLY 1 - +#define OPING_BUF_SIZE 1500 +#define ECHO_REQUEST 0 +#define ECHO_REPLY 1 #define OPING_MAX_FLOWS 256 -struct c { +#define USAGE_STRING \ +"Usage: oping [OPTION]...\n" \ +"\n" \ +"Checks liveness between a client and a server\n" \ +"and reports the Round Trip Time (RTT)\n" \ +"\n" \ +" -l, --listen Run in server mode\n" \ +"\n" \ +" -c, --count Number of packets\n" \ +" -d, --duration Duration of the test (default 1s)\n" \ +" -i, --interval Interval (default 1000ms)\n" \ +" -n, --server-name Name of the oping server\n" \ +" -q, --qos QoS (raw, raw_crypt, best, video, voice, data)\n" \ +" -s, --size Payload size (B, default 64)\n" \ +" -Q, --quiet Only print final statistics\n" \ +" -D, --timeofday Print time of day before each line\n" \ +"\n" \ +" --help Display this help text and exit\n" \ + +struct { char * s_apn; int interval; uint32_t count; @@ -90,12 +107,14 @@ struct c { pthread_t writer_pt; } client; -struct s { +struct { struct timespec times[OPING_MAX_FLOWS]; fset_t * flows; fqueue_t * fq; pthread_mutex_t lock; + bool quiet; + pthread_t cleaner_pt; pthread_t accept_pt; pthread_t server_pt; @@ -114,22 +133,7 @@ struct oping_msg { static void usage(void) { - printf("Usage: oping [OPTION]...\n" - "Checks liveness between a client and a server\n" - "and reports the Round Trip Time (RTT)\n\n" - " -l, --listen Run in server mode\n" - "\n" - " -c, --count Number of packets\n" - " -d, --duration Duration of the test (default 1s)\n" - " -i, --interval Interval (default 1000ms)\n" - " -n, --server-name Name of the oping server\n" - " -q, --qos QoS (raw, best, video, voice, data)" - "\n" - " -s, --size Payload size (B, default 64)\n" - " -Q, --quiet Only print final statistics\n" - " -D, --timeofday Print time of day before each line" - "\n" - " --help Display this help text and exit\n"); + printf(USAGE_STRING); } /* Times are in ms. */ @@ -170,32 +174,39 @@ int main(int argc, client.timestamp = false; client.qs = qos_raw; client.quiet = false; + server.quiet = false; while (argc > 0) { - if (strcmp(*argv, "-i") == 0 || - strcmp(*argv, "--interval") == 0) { + if ((strcmp(*argv, "-i") == 0 || + strcmp(*argv, "--interval") == 0) && + argc > 1) { client.interval = strtol(*(++argv), &rem, 10); client.interval *= time_mul(rem); --argc; - } else if (strcmp(*argv, "-n") == 0 || - strcmp(*argv, "--server-name") == 0) { + } else if ((strcmp(*argv, "-n") == 0 || + strcmp(*argv, "--server-name") == 0) && + argc > 1) { client.s_apn = *(++argv); --argc; - } else if (strcmp(*argv, "-c") == 0 || - strcmp(*argv, "--count") == 0) { + } else if ((strcmp(*argv, "-c") == 0 || + strcmp(*argv, "--count") == 0) && + argc > 1) { client.count = strtol(*(++argv), &rem, 10); --argc; - } else if (strcmp(*argv, "-d") == 0 || - strcmp(*argv, "--duration") == 0) { + } else if ((strcmp(*argv, "-d") == 0 || + strcmp(*argv, "--duration") == 0) && + argc > 1) { duration = strtol(*(++argv), &rem, 10); duration *= time_mul(rem); --argc; - } else if (strcmp(*argv, "-s") == 0 || - strcmp(*argv, "--size") == 0) { + } else if ((strcmp(*argv, "-s") == 0 || + strcmp(*argv, "--size") == 0) && + argc > 1) { client.size = strtol(*(++argv), &rem, 10); --argc; - } else if (strcmp(*argv, "-q") == 0 || - strcmp(*argv, "--qos") == 0) { + } else if ((strcmp(*argv, "-q") == 0 || + strcmp(*argv, "--qos") == 0) && + argc > 1) { qos = *(++argv); --argc; } else if (strcmp(*argv, "-l") == 0 || @@ -207,7 +218,7 @@ int main(int argc, } else if (strcmp(*argv, "-Q") == 0 || strcmp(*argv, "--quiet") == 0) { client.quiet = true; - + server.quiet = true; } else { goto fail; } diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c index d0255b7c..5a9e03dc 100644 --- a/src/tools/oping/oping_client.c +++ b/src/tools/oping/oping_client.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros ping application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -100,7 +100,7 @@ void * reader(void * o) sent.tv_sec = msg->tv_sec; sent.tv_nsec = msg->tv_nsec; - ms = ts_diff_us(&sent, &now) / 1000.0; + ms = ts_diff_us(&now, &sent) / 1000.0; if (id < exp_id) ++client.ooo; @@ -163,7 +163,7 @@ void * writer(void * o) printf("Pinging %s with %d bytes of data (%u packets):\n\n", client.s_apn, client.size, client.count); - pthread_cleanup_push((void (*) (void *)) free, buf); + pthread_cleanup_push(free, buf); while (!stop && client.sent < client.count) { nanosleep(&wait, NULL); @@ -177,9 +177,7 @@ void * writer(void * o) if (flow_write(*fdp, buf, client.size) < 0) { printf("Failed to send packet.\n"); - flow_dealloc(*fdp); - free(buf); - return (void *) -1; + stop = true; } } @@ -234,7 +232,7 @@ static int client_main(void) fd = flow_alloc(client.s_apn, &client.qs, NULL); if (fd < 0) { - printf("Failed to allocate flow.\n"); + printf("Failed to allocate flow: %d.\n", fd); client_fini(); return -1; } @@ -258,7 +256,7 @@ static int client_main(void) printf("%zd out-of-order, ", client.ooo); printf("%.0lf%% packet loss, ", client.sent == 0 ? 0 : ceil(100 - (100 * (client.rcvd / (float) client.sent)))); - printf("time: %.3f ms\n", ts_diff_us(&tic, &toc) / 1000.0); + printf("time: %.3f ms\n", ts_diff_us(&toc, &tic) / 1000.0); if (client.rcvd > 0) { printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f/", diff --git a/src/tools/oping/oping_server.c b/src/tools/oping/oping_server.c index 5cc347cb..3adce244 100644 --- a/src/tools/oping/oping_server.c +++ b/src/tools/oping/oping_server.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros ping application * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,6 +36,8 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ + #include <ouroboros/hash.h> + void shutdown_server(int signo, siginfo_t * info, void * c) { (void) info; @@ -61,16 +63,21 @@ void * cleaner_thread(void * o) while (true) { clock_gettime(CLOCK_REALTIME, &now); - pthread_mutex_lock(&server.lock); + for (i = 0; i < OPING_MAX_FLOWS; ++i) - if (fset_has(server.flows, i) && - ts_diff_ms(&server.times[i], &now) > deadline_ms) { - printf("Flow %d timed out.\n", i); - fset_del(server.flows, i); - flow_dealloc(i); + if (fset_has(server.flows, i)) { + time_t diff; + + pthread_mutex_lock(&server.lock); + diff = ts_diff_ms(&now, &server.times[i]); + pthread_mutex_unlock(&server.lock); + + if (diff > deadline_ms) { + printf("Flow %d timed out.\n", i); + fset_del(server.flows, i); + flow_dealloc(i); + } } - - pthread_mutex_unlock(&server.lock); sleep(1); } } @@ -95,13 +102,15 @@ void * server_thread(void *o) if (msg_len < 0) continue; + if (!server.quiet) + printf("Received %d bytes on fd %d.\n", + msg_len, fd); + if (ntohl(msg->type) != ECHO_REQUEST) { printf("Invalid message on fd %d.\n", fd); continue; } - printf("Received %d bytes on fd %d.\n", msg_len, fd); - clock_gettime(CLOCK_REALTIME, &now); pthread_mutex_lock(&server.lock); @@ -139,8 +148,9 @@ void * accept_thread(void * o) clock_gettime(CLOCK_REALTIME, &now); - pthread_mutex_lock(&server.lock); fset_add(server.flows, fd); + + pthread_mutex_lock(&server.lock); server.times[fd] = now; pthread_mutex_unlock(&server.lock); diff --git a/src/tools/ovpn/ovpn.c b/src/tools/ovpn/ovpn.c index 02501d52..5333ff40 100644 --- a/src/tools/ovpn/ovpn.c +++ b/src/tools/ovpn/ovpn.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Ouroboros VPN * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/tools/time_utils.h b/src/tools/time_utils.h index 48d694c1..a4117f44 100644 --- a/src/tools/time_utils.h +++ b/src/tools/time_utils.h @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2020 + * Ouroboros - Copyright (C) 2016 - 2024 * * Time utilities * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -53,17 +53,17 @@ #include <sys/time.h> /* functions for timespecs */ -#define ts_diff_ns(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * BILLION \ +#define ts_diff_ns(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * BILLION \ + ((tx)->tv_nsec - (t0)->tv_nsec)) -#define ts_diff_us(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ +#define ts_diff_us(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ + ((tx)->tv_nsec - (t0)->tv_nsec) / 1000L) -#define ts_diff_ms(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ +#define ts_diff_ms(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ + ((tx)->tv_nsec - (t0)->tv_nsec) / MILLION) /* functions for timevals are the same */ -#define tv_diff_us(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ +#define tv_diff_us(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * MILLION \ + ((tx)->tv_usec - (t0)->tv_usec) / 1000L) -#define tv_diff_ms(t0, tx) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ +#define tv_diff_ms(tx, t0) (((tx)->tv_sec - (t0)->tv_sec) * 1000L \ + ((tx)->tv_usec - (t0)->tv_usec) / MILLION) /* functions for timespecs */ |