summaryrefslogtreecommitdiff
path: root/src/ipcpd/shim-eth-llc/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipcpd/shim-eth-llc/main.c')
-rw-r--r--src/ipcpd/shim-eth-llc/main.c55
1 files changed, 35 insertions, 20 deletions
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index b7b9f783..3f3c0e1e 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -31,7 +31,6 @@
#include <ouroboros/bitmap.h>
#include <ouroboros/dev.h>
#include <ouroboros/ipcp-dev.h>
-#include <ouroboros/fcntl.h>
#include <ouroboros/fqueue.h>
#include <ouroboros/logs.h>
@@ -625,18 +624,22 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
(void) o;
- while (true) {
- if (flow_event_wait(eth_llc_data.np1_flows,
- eth_llc_data.fq,
- &timeout) == -ETIMEDOUT)
- continue;
+ while (flow_event_wait(eth_llc_data.np1_flows,
+ eth_llc_data.fq,
+ &timeout)) {
+ pthread_rwlock_rdlock(&ipcpi.state_lock);
+
+ if (ipcp_get_state() != IPCP_ENROLLED) {
+ pthread_rwlock_unlock(&ipcpi.state_lock);
+ return (void *) -1; /* -ENOTENROLLED */
+ }
while ((fd = fqueue_next(eth_llc_data.fq)) >= 0) {
if (ipcp_flow_read(fd, &sdb)) {
LOG_ERR("Bad read from fd %d.", fd);
continue;
}
- pthread_rwlock_rdlock(&ipcpi.state_lock);
+
pthread_rwlock_rdlock(&eth_llc_data.flows_lock);
ssap = reverse_bits(eth_llc_data.fd_to_ef[fd].sap);
@@ -646,7 +649,6 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
MAC_SIZE);
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
- pthread_rwlock_unlock(&ipcpi.state_lock);
eth_llc_ipcp_send_frame(r_addr, dsap, ssap,
shm_du_buff_head(sdb),
@@ -654,6 +656,8 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
- shm_du_buff_head(sdb));
ipcp_flow_del(sdb);
}
+
+ pthread_rwlock_unlock(&ipcpi.state_lock);
}
return (void *) 1;
@@ -673,7 +677,11 @@ void ipcp_sig_handler(int sig, siginfo_t * info, void * c)
pthread_rwlock_wrlock(&ipcpi.state_lock);
- ipcp_set_state(IPCP_SHUTDOWN);
+ if (ipcp_get_state() == IPCP_INIT)
+ ipcp_set_state(IPCP_NULL);
+
+ if (ipcp_get_state() == IPCP_ENROLLED)
+ ipcp_set_state(IPCP_SHUTDOWN);
pthread_rwlock_unlock(&ipcpi.state_lock);
}
@@ -702,9 +710,6 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
assert(conf);
assert(conf->type == THIS_TYPE);
- /* this IPCP doesn't need to maintain its dif_name */
- free(conf->dif_name);
-
if (conf->if_name == NULL) {
LOG_ERR("Interface name is NULL.");
return -1;
@@ -831,7 +836,6 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
if (ipcp_get_state() != IPCP_INIT) {
pthread_rwlock_unlock(&ipcpi.state_lock);
LOG_ERR("IPCP in wrong state.");
- close(skfd);
return -1;
}
@@ -855,6 +859,9 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
pthread_rwlock_unlock(&ipcpi.state_lock);
+ /* this IPCP doesn't need to maintain its dif_name */
+ free(conf->dif_name);
+
LOG_DBG("Bootstrapped shim IPCP over Ethernet with LLC with api %d.",
getpid());
@@ -1043,6 +1050,13 @@ static int eth_llc_ipcp_flow_dealloc(int fd)
ipcp_flow_fini(fd);
pthread_rwlock_rdlock(&ipcpi.state_lock);
+
+ if (ipcp_get_state() != IPCP_ENROLLED) {
+ pthread_rwlock_unlock(&ipcpi.state_lock);
+ LOG_DBG("Won't register with non-enrolled IPCP.");
+ return -1; /* -ENOTENROLLED */
+ }
+
pthread_rwlock_wrlock(&eth_llc_data.flows_lock);
flow_set_del(eth_llc_data.np1_flows, fd);
@@ -1056,11 +1070,11 @@ static int eth_llc_ipcp_flow_dealloc(int fd)
eth_llc_data.ef_to_fd[sap] = -1;
+ flow_dealloc(fd);
+
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
pthread_rwlock_unlock(&ipcpi.state_lock);
- flow_dealloc(fd);
-
LOG_DBG("Flow with fd %d deallocated.", fd);
return 0;
@@ -1135,11 +1149,12 @@ int main(int argc, char * argv[])
ipcp_fini();
- pthread_cancel(eth_llc_data.sdu_reader);
- pthread_cancel(eth_llc_data.sdu_writer);
-
- pthread_join(eth_llc_data.sdu_writer, NULL);
- pthread_join(eth_llc_data.sdu_reader, NULL);
+ if (ipcp_get_state() == IPCP_SHUTDOWN) {
+ pthread_cancel(eth_llc_data.sdu_reader);
+ pthread_cancel(eth_llc_data.sdu_writer);
+ pthread_join(eth_llc_data.sdu_writer, NULL);
+ pthread_join(eth_llc_data.sdu_reader, NULL);
+ }
eth_llc_data_fini();