diff options
Diffstat (limited to 'src/tools/irm')
27 files changed, 862 insertions, 332 deletions
diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index ca32e9c7..e5e5c466 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -23,8 +23,12 @@ set(SOURCE_FILES irm_unbind.c irm_bind.c irm_ipcp.c - irm_register.c - irm_unregister.c + irm_name.c + irm_name_create.c + irm_name_destroy.c + irm_name_reg.c + irm_name_unreg.c + irm_name_list.c irm_utils.c ) diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index bc4c2cd9..ba0f4713 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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,8 +49,7 @@ static void usage(void) { printf("Usage: irm [OPERATION]\n\n" - "where OPERATION = {ipcp bind unbind\n" - " register unregister}\n"); + "where OPERATION in { ipcp bind unbind name }\n"); } static int do_help(int argc, @@ -70,8 +69,7 @@ static const struct cmd { { "ipcp", ipcp_cmd }, { "bind", bind_cmd }, { "unbind", unbind_cmd }, - { "register", do_register }, - { "unregister", do_unregister }, + { "name", name_cmd }, { "help", do_help }, { NULL, NULL } }; diff --git a/src/tools/irm/irm_bind.c b/src/tools/irm/irm_bind.c index 20a4e077..2e8b14ef 100644 --- a/src/tools/irm/irm_bind.c +++ b/src/tools/irm/irm_bind.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 a30b4192..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 - 2018 + * 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 dbab5c7f..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 - 2018 + * 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 a3d9e4ac..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 - 2018 + * 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 72e32805..63e617d9 100644 --- a/src/tools/irm/irm_ipcp.c +++ b/src/tools/irm/irm_ipcp.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 e1f75956..b8e5c54d 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 - 2018 + * 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,12 +50,12 @@ #include <sys/socket.h> #endif -#define NORMAL "normal" +#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 MD5 "MD5" #define SHA3_224 "SHA3_224" @@ -64,20 +64,22 @@ #define SHA3_512 "SHA3_512" #define DEFAULT_ADDR_SIZE 4 -#define DEFAULT_EID_SIZE 2 +#define DEFAULT_EID_SIZE 8 #define DEFAULT_DDNS 0 #define DEFAULT_TTL 60 #define DEFAULT_ADDR_AUTH ADDR_AUTH_FLAT_RANDOM #define DEFAULT_ROUTING ROUTING_LINK_STATE -#define DEFAULT_PFF PFF_SIMPLE +#define DEFAULT_CONG_AVOID CA_MB_ECN #define DEFAULT_HASH_ALGO DIR_HASH_SHA3_256 #define DEFAULT_ETHERTYPE 0xA000 +#define DEFAULT_UDP_PORT 0x0D6B /* 3435 */ #define FLAT_RANDOM_ADDR_AUTH "flat" #define LINK_STATE_ROUTING "link_state" #define LINK_STATE_LFA_ROUTING "lfa" -#define SIMPLE_PFF "simple" -#define ALTERNATE_PFF "alternate" +#define LINK_STATE_ECM_ROUTING "ecmp" +#define NONE_CA "none" +#define MB_ECN_CA "mb-ecn" static void usage(void) { @@ -86,76 +88,77 @@ static void usage(void) " name <ipcp name>\n" " layer <layer name>\n" " [type [TYPE]]\n" - "where TYPE = {" NORMAL " " LOCAL " " - UDP " " ETH_LLC " " ETH_DIX " " RAPTOR "},\n\n" - "if TYPE == " NORMAL "\n" + "where TYPE in {" UNICAST " " BROADCAST " " LOCAL " " + UDP " " ETH_LLC " " ETH_DIX "},\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" - " [pff [PFF_POLICY] (default: %s)]\n" + " [congestion <CONG_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 "}\n" - " PFF_POLICY = {" SIMPLE_PFF " " ALTERNATE_PFF "}\n" - " ALGORITHM = {" SHA3_224 " " SHA3_256 " " + "where ADDRESS_POLICY in {" FLAT_RANDOM_ADDR_AUTH "}\n" + " ROUTING_POLICY in {" LINK_STATE_ROUTING " " + LINK_STATE_LFA_ROUTING " " LINK_STATE_ECM_ROUTING "}\n" + " CONG_POLICY in {" NONE_CA " " MB_ECN_CA "}\n" + " ALGORITHM in {" SHA3_224 " " SHA3_256 " " SHA3_384 " " SHA3_512 "}\n\n" "if TYPE == " 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 = {" SHA3_224 " " SHA3_256 " " + "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 = {" SHA3_224 " " SHA3_256 " " + "where ALGORITHM in {" 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 " " + "where ALGORITHM in {" 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, SIMPLE_PFF, - SHA3_256, SHA3_256, 0xA000, SHA3_256, SHA3_256, SHA3_256); + FLAT_RANDOM_ADDR_AUTH, LINK_STATE_ROUTING, MB_ECN_CA, + SHA3_256, DEFAULT_UDP_PORT, SHA3_256, 0xA000, SHA3_256, + 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_pff pff_type = DEFAULT_PFF; - 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; + 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; + enum pol_cong_avoid cong_avoid = DEFAULT_CONG_AVOID; + 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_list_info * ipcps; + ssize_t len = 0; + int i = 0; + bool autobind = false; + int cargs; + int port = DEFAULT_UDP_PORT; while (argc > 0) { cargs = 2; @@ -190,7 +193,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)); @@ -202,6 +205,8 @@ 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, "port") == 0) { + port = atoi(*(argv + 1)); } else if (matches(*argv, "autobind") == 0) { autobind = true; cargs = 1; @@ -216,13 +221,17 @@ int do_bootstrap_ipcp(int argc, else if (strcmp(LINK_STATE_LFA_ROUTING, *(argv + 1)) == 0) routing_type = ROUTING_LINK_STATE_LFA; + else if (strcmp(LINK_STATE_ECM_ROUTING, + *(argv + 1)) == 0) + routing_type = ROUTING_LINK_STATE_ECMP; else goto unknown_param; - } else if (matches(*argv, "pff") == 0) { - if (strcmp(SIMPLE_PFF, *(argv + 1)) == 0) - pff_type = PFF_SIMPLE; - else if (strcmp(ALTERNATE_PFF, *(argv + 1)) == 0) - pff_type = PFF_ALTERNATE; + } 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) + cong_avoid = CA_MB_ECN; else goto unknown_param; } else { @@ -248,8 +257,10 @@ int do_bootstrap_ipcp(int argc, } if (ipcp_type != NULL) { - if (strcmp(ipcp_type, NORMAL) == 0) - type = IPCP_NORMAL; + 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, ETH_LLC) == 0) @@ -258,8 +269,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; } @@ -283,47 +292,56 @@ 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_NORMAL) { - printf("Can only bind normal IPCPs, " - "autobind disabled.\n"); + if (autobind && (conf.type != IPCP_UNICAST && + conf.type != IPCP_BROADCAST)) { + printf("Can not bind this IPCP type," + "autobind disabled.\n\n"); autobind = false; } - strcpy(conf.layer_info.layer_name, layer); - if (conf.type != IPCP_UDP) - conf.layer_info.dir_hash_algo = hash_algo; + if (strlen(layer) > LAYER_NAME_SIZE) { + printf("Layer name too long.\n\n"); + goto fail_usage; + } + + strcpy(conf.layer_info.name, layer); + conf.layer_info.dir_hash_algo = hash_algo; switch (conf.type) { - case IPCP_NORMAL: - 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.pff_type = pff_type; + case IPCP_UNICAST: + 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_type = routing_type; + conf.unicast.addr_auth_type = addr_auth_type; + conf.unicast.cong_avoid = cong_avoid; break; case IPCP_UDP: if (ip_addr == 0) goto fail_usage; - conf.ip_addr = ip_addr; - conf.dns_addr = dns_addr; + 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_LOCAL: + case IPCP_BROADCAST: /* FALLTHRU */ - case IPCP_RAPTOR: + case IPCP_LOCAL: break; default: assert(false); diff --git a/src/tools/irm/irm_ipcp_connect.c b/src/tools/irm/irm_ipcp_connect.c index 42c07354..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 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * - * Connect components of normal IPC Processes + * 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 @@ -37,6 +37,7 @@ */ #include <ouroboros/irm.h> +#include <ouroboros/qos.h> #include "irm_ops.h" #include "irm_utils.h" @@ -45,28 +46,34 @@ #include <stdlib.h> #include <string.h> -#define DT "dt" -#define MGMT "mgmt" +#define DT "dt" +#define MGMT "mgmt" static void usage(void) { printf("Usage: irm ipcp connect\n" " name <ipcp name>\n" - " component [COMPONENT]\n" - " dst <name of destination IPCP>\n\n" - "where COMPONENT = {" DT " " MGMT "}\n"); + " dst <name of destination IPCP>\n" + " [component [COMPONENT]]\n" + "where COMPONENT in {" DT " " MGMT "}\n\n" + "if COMPONENT == " DT "\n" + " [qos [QOS]\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 = 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; + 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) { @@ -75,9 +82,11 @@ int do_connect_ipcp(int argc, dst = *(argv + 1); } else if (matches(*argv, "component") == 0) { comp = *(argv + 1); + } else if (matches(*argv, "qos") == 0) { + qos = *(argv + 1); } else { printf("\"%s\" is unknown, try \"irm " - "ipcpi connect\".\n", *argv); + "ipcp connect\".\n", *argv); return -1; } @@ -90,6 +99,21 @@ int do_connect_ipcp(int argc, return -1; } + if (qos != NULL) { + if (strcmp(qos, "best") == 0) + qs = qos_best_effort; + else if (strcmp(qos, "raw") == 0) + qs = qos_raw; + else if (strcmp(qos, "video") == 0) + qs = qos_video; + else if (strcmp(qos, "voice") == 0) + qs = qos_voice; + else if (strcmp(qos, "data") == 0) + qs = qos_data; + else + printf("Unknown QoS cube, defaulting to raw.\n"); + } + len = irm_list_ipcps(&ipcps); for (i = 0; i < len; i++) if (strcmp(ipcps[i].name, ipcp) == 0) @@ -100,14 +124,18 @@ int do_connect_ipcp(int argc, if (pid == -1) return -1; - if (!strcmp(comp, DT)) - comp = DT_COMP; - - if (!strcmp(comp , MGMT)) - comp = MGMT_COMP; + if (wildcard_match(comp, MGMT) == 0) { + component = MGMT_COMP; + /* FIXME: move to qos_data when stable */ + if (irm_connect_ipcp(pid, dst, component, qos_raw)) + return -1; + } - if (irm_connect_ipcp(pid, dst, comp)) - return -1; + if (wildcard_match(comp, DT) == 0) { + component = DT_COMP; + if (irm_connect_ipcp(pid, dst, component, qs)) + return -1; + } return 0; } diff --git a/src/tools/irm/irm_ipcp_create.c b/src/tools/irm/irm_ipcp_create.c index c8866962..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 - 2018 + * 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,29 +44,29 @@ #include "irm_ops.h" #include "irm_utils.h" -#define NORMAL "normal" -#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) { printf("Usage: irm ipcp create\n" " name <ipcp name>\n" " type [TYPE]\n\n" - "where TYPE = {" NORMAL " " 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) { @@ -88,8 +88,10 @@ int do_create_ipcp(int argc, return -1; } - if (strcmp(ipcp_type, NORMAL) == 0) - type = IPCP_NORMAL; + 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) @@ -98,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 cb86b167..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 - 2018 + * 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) { @@ -89,6 +89,7 @@ int do_destroy_ipcp(int argc, break; } + free(ipcps); return 0; fail_destroy: diff --git a/src/tools/irm/irm_ipcp_disconnect.c b/src/tools/irm/irm_ipcp_disconnect.c index 73f1588d..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 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * - * Connect components of normal IPC Processes + * 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 @@ -45,28 +45,29 @@ #include <stdlib.h> #include <string.h> -#define DT "dt" -#define MGMT "mgmt" +#define DT "dt" +#define MGMT "mgmt" static void usage(void) { printf("Usage: irm ipcp disconnect\n" " name <ipcp name>\n" - " component [COMPONENT]\n" - " dst <name of destination IPCP>\n\n" - "where COMPONENT = {" DT " " MGMT "}\n"); + " dst <name of destination IPCP>\n" + " [component [COMPONENT]]\n\n" + "where COMPONENT in {" DT " " MGMT "}\n"); } int do_disconnect_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * dst = NULL; - char * comp = 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) { @@ -77,7 +78,7 @@ int do_disconnect_ipcp(int argc, comp = *(argv + 1); } else { printf("\"%s\" is unknown, try \"irm " - "ipcpi connect\".\n", *argv); + "ipcp connect\".\n", *argv); return -1; } @@ -100,14 +101,17 @@ int do_disconnect_ipcp(int argc, if (pid == -1) return -1; - if (!strcmp(comp, DT)) - comp = DT_COMP; - - if (!strcmp(comp , MGMT)) - comp = MGMT_COMP; + if (wildcard_match(comp, DT) == 0) { + component = DT_COMP; + if (irm_disconnect_ipcp(pid, dst, component)) + return -1; + } - if (irm_disconnect_ipcp(pid, dst, comp)) - return -1; + if (wildcard_match(comp, MGMT) == 0) { + component = MGMT_COMP; + if (irm_disconnect_ipcp(pid, dst, component)) + return -1; + } return 0; } diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c index c1628af6..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 - 2018 + * 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 @@ -46,32 +46,65 @@ #include <string.h> +#define UNICAST "unicast" +#define BROADCAST "broadcast" + static void usage(void) { printf("Usage: irm ipcp enroll\n" " name <ipcp name>\n" - " layer <layer to enroll in>\n" - " [autobind]\n"); + " [layer <layer to enroll with>]\n" + " [dst <destination to enroll with>]\n" + " [type [TYPE], default = " UNICAST "]\n" + " [autobind]\n" + "where TYPE in {" UNICAST " " BROADCAST "}\n"); +} + +static int get_layer_name(const char * ipcp, + char * layer_name) +{ + struct ipcp_list_info * ipcps; + ssize_t len; + ssize_t i; + + len = irm_list_ipcps(&ipcps); + for (i = 0; i < len; i++) + if (strcmp(ipcps[i].name, ipcp) == 0) { + strcpy(layer_name, ipcps[i].layer); + free(ipcps); + return 0; + } + + free(ipcps); + + return -1; } int do_enroll_ipcp(int argc, char ** argv) { - char * ipcp = NULL; - char * layer = NULL; - struct ipcp_info * ipcps; - pid_t pid = -1; - ssize_t len = 0; - int i = 0; - bool autobind = false; - int cargs; + 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; if (matches(*argv, "name") == 0) { ipcp = *(argv + 1); + } else if (matches(*argv, "type") == 0) { + ipcp_type = *(argv + 1); } else if (matches(*argv, "layer") == 0) { layer = *(argv + 1); + } else if (matches(*argv, "dst") == 0) { + dst = *(argv + 1); } else if (matches(*argv, "autobind") == 0) { autobind = true; cargs = 1; @@ -85,19 +118,27 @@ int do_enroll_ipcp(int argc, argv += cargs; } - if (layer == NULL || ipcp == NULL) { + if ((layer == NULL && dst == NULL) || ipcp == NULL) { usage(); return -1; } + if (dst == NULL) + dst = layer; + + if (strcmp(ipcp_type, UNICAST) == 0) + type = IPCP_UNICAST; + else if (strcmp(ipcp_type, BROADCAST) == 0) + type = IPCP_BROADCAST; + len = irm_list_ipcps(&ipcps); for (i = 0; i < len; i++) if (wildcard_match(ipcps[i].name, ipcp) == 0 && - ipcps[i].type == IPCP_NORMAL) + ipcps[i].type == type) pid = ipcps[i].pid; if (pid < 0) { - pid = irm_create_ipcp(ipcp, IPCP_NORMAL); + pid = irm_create_ipcp(ipcp, type); if (pid < 0) goto fail; free(ipcps); @@ -105,25 +146,39 @@ int do_enroll_ipcp(int argc, } for (i = 0; i < len; i++) { - if (ipcps[i].type != IPCP_NORMAL) + char enr_layer[LAYER_NAME_SIZE]; + if (ipcps[i].type != type) continue; - if (wildcard_match(ipcps[i].name, ipcp) == 0) { - pid = ipcps[i].pid; - if (autobind && irm_bind_process(pid, ipcp)) { - printf("Failed to bind %d to %s.\n", pid, ipcp); - goto fail; - } - - if (irm_enroll_ipcp(pid, layer)) { - if (autobind) - irm_unbind_process(pid, ipcp); - goto fail; - } - - if (autobind && irm_bind_process(pid, layer)) { - printf("Failed to bind %d to %s.\n", pid, layer); - goto fail; - } + + if (wildcard_match(ipcps[i].name, ipcp) != 0) + continue; + + 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 (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 5a9ecaff..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 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * - * Create IPC Processes + * 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 NORMAL "normal" -#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) { @@ -59,23 +59,23 @@ static void usage(void) " [name <ipcp name>]\n" " [layer <layer_name>]\n\n" " [type [TYPE]]\n\n" - "where TYPE = {" NORMAL " " LOCAL " " - UDP " " ETH_LLC " " ETH_DIX " " RAPTOR "}\n"); + "where TYPE = {" UNICAST " " LOCAL " " + UDP " " ETH_LLC " " ETH_DIX "}\n"); } static char * str_type(enum ipcp_type type) { switch(type) { - case IPCP_NORMAL: - return NORMAL; + 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) { @@ -109,8 +109,10 @@ int do_list_ipcp(int argc, } if (ipcp_type != NULL) { - if (strcmp(ipcp_type, NORMAL) == 0) - type = IPCP_NORMAL; + 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 new file mode 100644 index 00000000..d60b6c78 --- /dev/null +++ b/src/tools/irm/irm_name.c @@ -0,0 +1,99 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * A tool to instruct the IRM daemon + * + * 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 + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdio.h> + +#include "irm_ops.h" +#include "irm_utils.h" + +static void usage(void) +{ + printf("Usage: irm name [OPERATION]\n\n" + "where OPERATION in {create destroy\n" + " register unregister\n" + " list\n" + " help}\n"); +} + +static int do_help(int argc, char **argv) +{ + (void) argc; + (void) argv; + + usage(); + return 0; +} + +static const struct cmd { + const char * cmd; + int (* func)(int argc, char ** argv); +} cmds[] = { + { "create", do_create_name }, + { "destroy", do_destroy_name }, + { "register", do_reg_name }, + { "unregister", do_unreg_name }, + { "list", do_list_name}, + { "help", do_help }, + { NULL, NULL } +}; + +static int do_cmd(const char * argv0, + int argc, + char ** argv) +{ + const struct cmd * c; + + for (c = cmds; c->cmd; ++c) { + if (matches(argv0, c->cmd) == 0) + return c->func(argc - 1, argv + 1); + } + + fprintf(stderr, "\"%s\" is unknown, try \"irm ipcp help\".\n", argv0); + + return -1; +} + +int name_cmd(int argc, char ** argv) +{ + if (argc < 1) { + usage(); + return -1; + } + + return do_cmd(argv[0], argc, argv); +} diff --git a/src/tools/irm/irm_name_create.c b/src/tools/irm/irm_name_create.c new file mode 100644 index 00000000..a0079cad --- /dev/null +++ b/src/tools/irm/irm_name_create.c @@ -0,0 +1,96 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Create IPC Processes + * + * 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 + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <ouroboros/irm.h> + +#include <stdio.h> +#include <string.h> + +#include "irm_ops.h" +#include "irm_utils.h" + +#define RR "round-robin" +#define SPILL "spillover" + +static void usage(void) +{ + printf("Usage: irm name create\n" + " <name>\n" + " lb [LB_POLICY], default: %s\n\n" + "where LB_POLICY in {" RR " " SPILL "}\n", RR); +} + +int do_create_name(int argc, + char ** argv) +{ + char * name = NULL; + char * lb_pol = RR; + enum pol_balance pol_lb = LB_RR; + + name = *(argv++); + --argc; + + while (argc > 0) { + if (matches(*argv, "lb") == 0) { + lb_pol = *(argv + 1); + } else { + printf("\"%s\" is unknown, try \"irm " + "name create\".\n", *argv); + return -1; + } + + argc -= 2; + argv += 2; + } + + if (name == NULL) { + usage(); + return -1; + } + + if (strcmp(lb_pol, RR) == 0) + pol_lb = LB_RR; + else if (strcmp(lb_pol, SPILL) == 0) + pol_lb = LB_SPILL; + else { + usage(); + return -1; + } + + return irm_create_name(name, pol_lb); +} diff --git a/src/tools/irm/irm_name_destroy.c b/src/tools/irm/irm_name_destroy.c new file mode 100644 index 00000000..d4bd6c82 --- /dev/null +++ b/src/tools/irm/irm_name_destroy.c @@ -0,0 +1,72 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * Create IPC Processes + * + * 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 + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <ouroboros/irm.h> + +#include <stdio.h> +#include <string.h> + +#include "irm_ops.h" +#include "irm_utils.h" + +static void usage(void) +{ + printf("Usage: irm name destroy <name>\n"); +} + +int do_destroy_name(int argc, + char ** argv) +{ + char * name = NULL; + + name = *(argv++); + --argc; + + if (argc > 0) { + printf("\"%s\" is unknown, try \"irm " + "name destroy\".\n", *argv); + return -1; + } + + if (name == NULL) { + usage(); + return -1; + } + + return irm_destroy_name(name); +} diff --git a/src/tools/irm/irm_name_list.c b/src/tools/irm/irm_name_list.c new file mode 100644 index 00000000..a807008c --- /dev/null +++ b/src/tools/irm/irm_name_list.c @@ -0,0 +1,115 @@ +/* + * Ouroboros - Copyright (C) 2016 - 2024 + * + * List names + * + * 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 + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <ouroboros/irm.h> +#include <ouroboros/errno.h> + +#include "irm_ops.h" +#include "irm_utils.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define RR "round-robin" +#define SPILL "spillover" + +static char * str_pol(enum pol_balance p) +{ + switch(p) { + case LB_RR: + return RR; + case LB_SPILL: + return SPILL; + default: + return "UNKNOWN"; + } +}; + +int do_list_name(int argc, + char ** argv) +{ + char * name = NULL; + struct name_info * names; + ssize_t len; + ssize_t i; + + while (argc > 0) { + if (matches(*argv, "list") == 0) { + name = *(argv + 1); + } else { + printf("\"%s\" is unknown, try \"irm " + "name list.\n", *argv); + return -1; + } + + argc -= 2; + argv += 2; + } + + len = irm_list_names(&names); + if (len == 0) { + printf("No names in system.\n\n"); + return 0; + } else if (len == -EIRMD) { + printf("Failed to communicate with the " + "Ouroboros IPC Resource Manager daemon.\n"); + return -1; + } else if (len < 0) + return len; + + printf("+----------------------------------------------------" + "+----------------------+\n"); + printf("| %50s | %20s |\n", "name", "load-balance policy"); + printf("+----------------------------------------------------" + "+----------------------+\n"); + + for (i = 0; i < len; i++) { + if (name != NULL && matches(names[i].name, name)) + continue; + printf("| %50s | %20s |\n", + names[i].name, + str_pol(names[i].pol_lb)); + } + printf("+----------------------------------------------------" + "+----------------------+\n"); + + free(names); + + return 0; +} diff --git a/src/tools/irm/irm_register.c b/src/tools/irm/irm_name_reg.c index 23c65f7d..061ed8be 100644 --- a/src/tools/irm/irm_register.c +++ b/src/tools/irm/irm_name_reg.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * - * Register names in IPCPs + * 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 @@ -38,7 +38,6 @@ #include <ouroboros/irm.h> - #include "irm_ops.h" #include "irm_utils.h" @@ -51,8 +50,7 @@ static void usage(void) { - printf("Usage: irm register\n" - " name <name>\n" + printf("Usage: irm name register <name>\n" " ipcp <ipcp to register with>\n" " [ipcp <ipcp to register with>]\n" " [... (maximum %d ipcps)]\n" @@ -63,23 +61,26 @@ static void usage(void) } -int do_register(int argc, +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 len; - 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; while (argc > 0) { - if (matches(*argv, "name") == 0) { - name = *(argv + 1); - } else if (matches(*argv, "layer") == 0) { + if (matches(*argv, "layer") == 0) { layers[layers_len++] = *(argv + 1); if (layers_len > MAX_LAYERS) { printf("Too many layers specified.\n"); @@ -92,7 +93,7 @@ int do_register(int argc, return -1; } } else { - printf("\"%s\" is unknown, try \"irm " + printf("\"%s\" is unknown, try \"irm name " "register\".\n", *argv); return -1; } @@ -106,33 +107,54 @@ int do_register(int argc, return -1; } - len = irm_list_ipcps(&ipcps); - if (len < 0) - return len; + ipcps_len = irm_list_ipcps(&ipcps); + if (ipcps_len < 0) + return ipcps_len; + + names_len = irm_list_names(&names); + if (names_len < 0) { + free(ipcps); + return names_len; + } + + for (i = 0; i < names_len; ++i) { + if (strcmp(names[i].name, name) == 0) { + name_create = false; + break; + } + } + + if (name_create && irm_create_name(name, LB_SPILL)) { + printf("Error creating name."); + free(ipcps); + free(name); + return -1; + } - for (i = 0; i < len; ++i) { + for (i = 0; i < ipcps_len; ++i) { size_t j; for (j = 0; j < layers_len; j++) { - if (wildcard_match(ipcps[i].layer, layers[j]) == 0) { - if (irm_reg(ipcps[i].pid, name)) { + if (wildcard_match(layers[j], ipcps[i].layer) == 0) { + if (irm_reg_name(name, ipcps[i].pid)) { free(ipcps); + free(names); return -1; } - break; } } for (j = 0; j < ipcp_len; j++) { - if (wildcard_match(ipcps[i].name, ipcp[j]) == 0) { - if (irm_reg(ipcps[i].pid, name)) { + if (wildcard_match(ipcp[j], ipcps[i].name) == 0) { + if (irm_reg_name(name, ipcps[i].pid)) { free(ipcps); + free(names); return -1; } - break; } } } free(ipcps); + free(names); return 0; } diff --git a/src/tools/irm/irm_unregister.c b/src/tools/irm/irm_name_unreg.c index 52491b42..6e579f04 100644 --- a/src/tools/irm/irm_unregister.c +++ b/src/tools/irm/irm_name_unreg.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 @@ -50,8 +50,7 @@ static void usage(void) { - printf("Usage: irm unregister\n" - " name <name>\n" + printf("Usage: irm name unregister <name>\n" " ipcp <ipcp to register with>\n" " [ipcp <ipcp to register with>]\n" " [... (maximum %d ipcps)]\n" @@ -61,21 +60,23 @@ static void usage(void) , MAX_IPCPS, MAX_LAYERS); } -int do_unregister(int argc, char ** argv) +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; - size_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; while (argc > 0) { - if (matches(*argv, "name") == 0) { - name = *(argv + 1); - } else if (matches(*argv, "layer") == 0) { + if (matches(*argv, "layer") == 0) { layers[layers_len++] = *(argv + 1); if (layers_len > MAX_LAYERS) { printf("Too many layers specified.\n"); @@ -103,11 +104,14 @@ int do_unregister(int argc, char ** argv) } len = irm_list_ipcps(&ipcps); - for (i = 0; i < len; ++i) { + if (len < 0) + return -1; + + for (i = 0; i < (size_t) len; ++i) { size_t j; for (j = 0; j < layers_len; j++) { if (wildcard_match(ipcps[i].layer, layers[j]) == 0) { - if (irm_unreg(ipcps[i].pid, name)) { + if (irm_unreg_name(name, ipcps[i].pid)) { free(ipcps); return -1; } @@ -116,7 +120,7 @@ int do_unregister(int argc, char ** argv) } for (j = 0; j < ipcp_len; j++) { if (wildcard_match(ipcps[i].name, ipcp[j]) == 0) { - if (irm_unreg(ipcps[i].pid, name)) { + if (irm_unreg_name(name, ipcps[i].pid)) { free(ipcps); return -1; } diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h index 74035434..e04ffc02 100644 --- a/src/tools/irm/irm_ops.h +++ b/src/tools/irm/irm_ops.h @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 @@ -84,8 +84,20 @@ int do_unbind_process(int argc, int do_unbind_ipcp(int argc, char ** argv); -int do_register(int argc, +int name_cmd(int argc, + char ** argv); + +int do_create_name(int argc, + char ** argv); + +int do_destroy_name(int argc, + char ** argv); + +int do_reg_name(int argc, char ** argv); -int do_unregister(int argc, +int do_unreg_name(int argc, char ** argv); + +int do_list_name(int argc, + char ** argv); diff --git a/src/tools/irm/irm_unbind.c b/src/tools/irm/irm_unbind.c index f7b078f8..d6594d01 100644 --- a/src/tools/irm/irm_unbind.c +++ b/src/tools/irm/irm_unbind.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 9b2a930a..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 - 2018 + * 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 7a1c495d..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 - 2018 + * 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 47cf9255..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 - 2018 + * 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 c5ea9246..9694d647 100644 --- a/src/tools/irm/irm_utils.c +++ b/src/tools/irm/irm_utils.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 03113f12..27a0b941 100644 --- a/src/tools/irm/irm_utils.h +++ b/src/tools/irm/irm_utils.h @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * 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 |
