From d21c4d5b0e7f42fe09784f11fa5776ff305e4fdf Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 28 Aug 2023 10:22:43 +0200 Subject: ipcpd: Set IPCP states in common sources The state of the IPCP was set and checked in the main files, but it's more convenient to do it in the common source. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/ipcpd/ipcp.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/ipcpd/ipcp.c') diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c index b32e7cda..f40c70e6 100644 --- a/src/ipcpd/ipcp.c +++ b/src/ipcpd/ipcp.c @@ -267,6 +267,8 @@ static void handle_bootstrap(ipcp_config_msg_t * conf_msg, { struct ipcp_config conf; + assert(ipcp_get_state() == IPCP_INIT); + if (ipcpi.ops->ipcp_bootstrap == NULL) { log_err("Bootstrap unsupported."); ret_msg->result = -ENOTSUP; @@ -281,8 +283,10 @@ static void handle_bootstrap(ipcp_config_msg_t * conf_msg, conf = ipcp_config_msg_to_s(conf_msg); ret_msg->result = ipcpi.ops->ipcp_bootstrap(&conf); - if (ret_msg->result == 0) + if (ret_msg->result == 0) { ret_msg->layer_info = layer_info_s_to_msg(&conf.layer_info); + ipcp_set_state(IPCP_OPERATIONAL); + } } static void handle_enroll(const char * dst, @@ -290,6 +294,8 @@ static void handle_enroll(const char * dst, { struct layer_info info; + assert(ipcp_get_state() == IPCP_INIT); + if (ipcpi.ops->ipcp_enroll == NULL) { log_err("Enroll unsupported."); ret_msg->result = -ENOTSUP; @@ -303,8 +309,10 @@ static void handle_enroll(const char * dst, } ret_msg->result = ipcpi.ops->ipcp_enroll(dst, &info); - if (ret_msg->result == 0) + if (ret_msg->result == 0) { ret_msg->layer_info = layer_info_s_to_msg(&info); + ipcp_set_state(IPCP_OPERATIONAL); + } } static void handle_connect(const char * dst, @@ -760,6 +768,8 @@ int ipcp_init(int argc, pthread_condattr_destroy(&cattr); + ipcp_set_state(IPCP_INIT); + return 0; fail_tpm_create: @@ -802,8 +812,6 @@ int ipcp_start(void) if (tpm_start(ipcpi.tpm)) goto fail_tpm_start; - ipcp_set_state(IPCP_INIT); - if (pthread_create(&ipcpi.acceptor, NULL, acceptloop, NULL)) { log_err("Failed to create acceptor thread."); goto fail_acceptor; -- cgit v1.2.3