From 0c0508619959b5ac98b31b4389fcfadf5ee26d9b Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Wed, 27 Jul 2016 16:46:23 +0200 Subject: ipcpd: normal: Provide initial steps for enrollment This provides the normal IPCP with bootstrapping and the initial steps for enrollment. Next step is actually reacting to an enrollment request and sending the data transfer constants. --- src/ipcpd/normal/main.c | 62 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 4 deletions(-) (limited to 'src/ipcpd/normal/main.c') diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 2d97f435..54ebd674 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -1,3 +1,25 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Normal IPC Process + * + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + #define OUROBOROS_PREFIX "normal-ipcp" #include @@ -108,16 +130,48 @@ static int normal_ipcp_name_unreg(char * name) static int normal_ipcp_enroll(char * dif_name) { - LOG_MISSING; + pthread_rwlock_rdlock(&_ipcp->state_lock); - return -1; + if (_ipcp->state != IPCP_INIT) { + pthread_rwlock_unlock(&_ipcp->state_lock); + LOG_DBGF("Won't enroll an IPCP that is not in INIT."); + return -1; /* -ENOTINIT */ + } + + if (fmgr_mgmt_flow(dif_name)) { + pthread_rwlock_unlock(&_ipcp->state_lock); + LOG_ERR("Failed to establish management flow."); + return -1; + } + + _ipcp->state = IPCP_ENROLLED; + + pthread_rwlock_unlock(&_ipcp->state_lock); + + return 0; } static int normal_ipcp_bootstrap(struct dif_config * conf) { - LOG_MISSING; + pthread_rwlock_rdlock(&_ipcp->state_lock); + + if (_ipcp->state != IPCP_INIT) { + pthread_rwlock_unlock(&_ipcp->state_lock); + LOG_DBGF("Won't bootstrap an IPCP that is not in INIT."); + return -1; /* -ENOTINIT */ + } + + if (ribmgr_bootstrap(conf)) { + pthread_rwlock_unlock(&_ipcp->state_lock); + LOG_ERR("Failed to bootstrap RIB manager."); + return -1; + } + + _ipcp->state = IPCP_ENROLLED; - return -1; + pthread_rwlock_unlock(&_ipcp->state_lock); + + return 0; } static struct ipcp_ops normal_ops = { -- cgit v1.2.3