summaryrefslogtreecommitdiff
path: root/src/lib/irm.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2023-03-04 03:48:48 +0100
committerSander Vrijders <[email protected]>2023-03-08 15:59:37 +0100
commit89b58eaa2706c54aeb0a48252d1cfbd2b5ae01b7 (patch)
tree891c4a2de37e06fdb8879741911a6b7ff2f1b4b8 /src/lib/irm.c
parentf16b4a1954ab4fbca0ec403f6a04c80375328921 (diff)
downloadouroboros-89b58eaa2706c54aeb0a48252d1cfbd2b5ae01b7.tar.gz
ouroboros-89b58eaa2706c54aeb0a48252d1cfbd2b5ae01b7.zip
irmd: Add configuration file support
This adds initial support for configuration files using the C99 TOML parser (to be installed separately from https://github.com/cktan/tomlc99). The default location for the IRMd configuration file is /etc/ouroboros/irmd.conf. This is configurable at build time. An example file will be installed in the configuration directory with the name irmd.conf.example. Config file support can be disabled using the DISABLE_CONFIGFILE build option. There were some refactors and changes to the configuration messages and protobuf files. This works towards consolidation of protobuf C as an option for more generic handling of serialization/deserialization of various messages. Signed-off-by: Dimitri Staessens <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/lib/irm.c')
-rw-r--r--src/lib/irm.c63
1 files changed, 10 insertions, 53 deletions
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 2a8aa05c..75071260 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -31,6 +31,7 @@
#include <ouroboros/irm.h>
#include <ouroboros/utils.h>
#include <ouroboros/sockets.h>
+#include <ouroboros/protobuf.h>
#include <stdbool.h>
#include <string.h>
@@ -98,15 +99,9 @@ int irm_destroy_ipcp(pid_t pid)
int irm_bootstrap_ipcp(pid_t pid,
const struct ipcp_config * conf)
{
- irm_msg_t msg = IRM_MSG__INIT;
- ipcp_config_msg_t cfg_msg = IPCP_CONFIG_MSG__INIT;
- layer_info_msg_t layer_info_msg = LAYER_INFO_MSG__INIT;
- dt_config_msg_t dt_cfg_msg = DT_CONFIG_MSG__INIT;
- uni_config_msg_t uni_cfg_msg = UNI_CONFIG_MSG__INIT;
- eth_config_msg_t eth_cfg_msg = ETH_CONFIG_MSG__INIT;
- udp_config_msg_t udp_cfg_msg = UDP_CONFIG_MSG__INIT;
- irm_msg_t * recv_msg = NULL;
- int ret = -1;
+ irm_msg_t msg = IRM_MSG__INIT;
+ irm_msg_t * recv_msg;
+ int ret;
if (pid == -1 || conf == NULL)
return -EINVAL;
@@ -114,48 +109,10 @@ int irm_bootstrap_ipcp(pid_t pid,
msg.code = IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP;
msg.has_pid = true;
msg.pid = pid;
-
- cfg_msg.ipcp_type = conf->type;
- layer_info_msg.layer_name = (char *) conf->layer_info.layer_name;
- layer_info_msg.dir_hash_algo = conf->layer_info.dir_hash_algo;
-
- switch (conf->type) {
- case IPCP_UNICAST:
- dt_cfg_msg.addr_size = conf->unicast.dt.addr_size;
- dt_cfg_msg.eid_size = conf->unicast.dt.eid_size;
- dt_cfg_msg.max_ttl = conf->unicast.dt.max_ttl;
- dt_cfg_msg.routing_type = conf->unicast.dt.routing_type;
- uni_cfg_msg.dt = &dt_cfg_msg;
- uni_cfg_msg.addr_auth_type = conf->unicast.addr_auth_type;
- uni_cfg_msg.cong_avoid = conf->unicast.cong_avoid;
- cfg_msg.unicast = &uni_cfg_msg;
- break;
- case IPCP_UDP:
- udp_cfg_msg.ip_addr = conf->udp.ip_addr;
- udp_cfg_msg.dns_addr = conf->udp.dns_addr;
- udp_cfg_msg.port = conf->udp.port;
- cfg_msg.udp = &udp_cfg_msg;
- break;
- case IPCP_LOCAL:
- /* FALLTHRU */
- case IPCP_BROADCAST:
- break;
- case IPCP_ETH_DIX:
- eth_cfg_msg.has_ethertype = true;
- eth_cfg_msg.ethertype = conf->eth.ethertype;
- /* FALLTHRU */
- case IPCP_ETH_LLC:
- eth_cfg_msg.dev = conf->eth.dev;
- cfg_msg.eth = &eth_cfg_msg;
- break;
- default:
- return -EIPCPTYPE;
- }
-
- cfg_msg.layer_info = &layer_info_msg;
- msg.conf = &cfg_msg;
+ msg.conf = ipcp_config_s_to_msg(conf);
recv_msg = send_recv_irm_msg(&msg);
+ ipcp_config_msg__free_unpacked(msg.conf, NULL);
if (recv_msg == NULL)
return -EIRMD;
@@ -175,8 +132,7 @@ int irm_connect_ipcp(pid_t pid,
const char * component,
qosspec_t qs)
{
- irm_msg_t msg = IRM_MSG__INIT;
- qosspec_msg_t qs_msg = QOSSPEC_MSG__INIT;
+ irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg;
int ret;
@@ -186,10 +142,11 @@ int irm_connect_ipcp(pid_t pid,
msg.comp = (char *) component;
msg.has_pid = true;
msg.pid = pid;
- qs_msg = spec_to_msg(&qs);
- msg.qosspec = &qs_msg;
+ msg.qosspec = qos_spec_s_to_msg(&qs);
recv_msg = send_recv_irm_msg(&msg);
+ qosspec_msg__free_unpacked(msg.qosspec, NULL);
+
if (recv_msg == NULL)
return -EIRMD;