summaryrefslogtreecommitdiff
path: root/src/ipcpd/ipcp.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2023-08-28 10:22:43 +0200
committerSander Vrijders <[email protected]>2023-08-30 10:33:19 +0200
commitd21c4d5b0e7f42fe09784f11fa5776ff305e4fdf (patch)
tree2c31bb7d066101f7a29bec1f78f54faa622b333b /src/ipcpd/ipcp.c
parent24bb41dd02b9a2a03ebdeb35d81da9061ffc4604 (diff)
downloadouroboros-d21c4d5b0e7f42fe09784f11fa5776ff305e4fdf.tar.gz
ouroboros-d21c4d5b0e7f42fe09784f11fa5776ff305e4fdf.zip
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 <[email protected]> Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src/ipcpd/ipcp.c')
-rw-r--r--src/ipcpd/ipcp.c16
1 files changed, 12 insertions, 4 deletions
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;