From 269f25d3bac5ab871d8044935eacc15cfeadeec6 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sun, 12 Feb 2023 21:05:40 +0100 Subject: ipcpd: refactor IPCP configuration The ipcp configuration struct now has internal structures for the different IPCPs and for IPCP components of the unicast IPCP. Split the very long IPCP main loop into individual handler functions. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/common/enroll.c | 50 +++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 23 deletions(-) (limited to 'src/ipcpd/common/enroll.c') diff --git a/src/ipcpd/common/enroll.c b/src/ipcpd/common/enroll.c index c71dc4cc..745829e7 100644 --- a/src/ipcpd/common/enroll.c +++ b/src/ipcpd/common/enroll.c @@ -74,7 +74,9 @@ static int send_rcv_enroll_msg(int fd) ssize_t delta_t; struct timespec t0; struct timespec rtt; - +#ifdef BUILD_IPCP_UNICAST + uni_config_msg_t * uni_cfg_msg; +#endif req.code = ENROLL_CODE__ENROLL_REQ; len = enroll_msg__get_packed_size(&req); @@ -132,12 +134,14 @@ static int send_rcv_enroll_msg(int fd) reply->conf->layer_info->layer_name); enroll.conf.type = reply->conf->ipcp_type; #ifdef BUILD_IPCP_UNICAST - enroll.conf.addr_size = reply->conf->addr_size; - enroll.conf.eid_size = reply->conf->eid_size; - enroll.conf.max_ttl = reply->conf->max_ttl; - enroll.conf.addr_auth_type = reply->conf->addr_auth_type; - enroll.conf.routing_type = reply->conf->routing_type; - enroll.conf.cong_avoid = reply->conf->cong_avoid; + uni_cfg_msg = reply->conf->unicast; + + enroll.conf.unicast.dt.addr_size = uni_cfg_msg->dt->addr_size; + enroll.conf.unicast.dt.eid_size = uni_cfg_msg->dt->eid_size; + enroll.conf.unicast.dt.max_ttl = uni_cfg_msg->dt->max_ttl; + enroll.conf.unicast.dt.routing_type = uni_cfg_msg->dt->routing_type; + enroll.conf.unicast.addr_auth_type = uni_cfg_msg->addr_auth_type; + enroll.conf.unicast.cong_avoid = uni_cfg_msg->cong_avoid; #endif enroll.conf.layer_info.dir_hash_algo = reply->conf->layer_info->dir_hash_algo; @@ -151,6 +155,10 @@ static ssize_t enroll_pack(uint8_t ** buf) enroll_msg_t msg = ENROLL_MSG__INIT; ipcp_config_msg_t config = IPCP_CONFIG_MSG__INIT; layer_info_msg_t layer_info = LAYER_INFO_MSG__INIT; +#ifdef BUILD_IPCP_UNICAST + dt_config_msg_t dt_cfg_msg = DT_CONFIG_MSG__INIT; + uni_config_msg_t uni_cfg_msg = UNI_CONFIG_MSG__INIT; +#endif struct timespec now; ssize_t len; @@ -161,28 +169,24 @@ static ssize_t enroll_pack(uint8_t ** buf) msg.t_sec = now.tv_sec; msg.has_t_nsec = true; msg.t_nsec = now.tv_nsec; - msg.conf = &config; - config.ipcp_type = enroll.conf.type; + config.ipcp_type = enroll.conf.type; #ifdef BUILD_IPCP_UNICAST - config.has_addr_size = true; - config.addr_size = enroll.conf.addr_size; - config.has_eid_size = true; - config.eid_size = enroll.conf.eid_size; - config.has_max_ttl = true; - config.max_ttl = enroll.conf.max_ttl; - config.has_addr_auth_type = true; - config.addr_auth_type = enroll.conf.addr_auth_type; - config.has_routing_type = true; - config.routing_type = enroll.conf.routing_type; - config.has_cong_avoid = true; - config.cong_avoid = enroll.conf.cong_avoid; + dt_cfg_msg.addr_size = enroll.conf.unicast.dt.addr_size; + dt_cfg_msg.eid_size = enroll.conf.unicast.dt.eid_size; + dt_cfg_msg.max_ttl = enroll.conf.unicast.dt.max_ttl; + dt_cfg_msg.routing_type = enroll.conf.unicast.dt.routing_type; + uni_cfg_msg.dt = &dt_cfg_msg; + uni_cfg_msg.addr_auth_type = enroll.conf.unicast.addr_auth_type; + uni_cfg_msg.cong_avoid = enroll.conf.unicast.cong_avoid; + config.unicast = &uni_cfg_msg; #endif - config.layer_info = &layer_info; - layer_info.layer_name = (char *) enroll.conf.layer_info.layer_name; layer_info.dir_hash_algo = enroll.conf.layer_info.dir_hash_algo; + config.layer_info = &layer_info; + msg.conf = &config; + len = enroll_msg__get_packed_size(&msg); *buf = malloc(len); -- cgit v1.2.3