summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ipcpd/normal/CMakeLists.txt1
-rw-r--r--src/ipcpd/normal/path.c77
-rw-r--r--src/ipcpd/normal/path.h35
-rw-r--r--src/ipcpd/normal/pol/flat.c35
-rw-r--r--src/ipcpd/normal/ribmgr.c6
5 files changed, 138 insertions, 16 deletions
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt
index c4525b1a..ca7e1ae2 100644
--- a/src/ipcpd/normal/CMakeLists.txt
+++ b/src/ipcpd/normal/CMakeLists.txt
@@ -30,6 +30,7 @@ set(SOURCE_FILES
fmgr.c
frct.c
main.c
+ path.c
ribmgr.c
shm_pci.c
# Add policies last
diff --git a/src/ipcpd/normal/path.c b/src/ipcpd/normal/path.c
new file mode 100644
index 00000000..08d33347
--- /dev/null
+++ b/src/ipcpd/normal/path.c
@@ -0,0 +1,77 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Functions to construct pathnames
+ *
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * 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 "pathnames"
+
+#include <ouroboros/config.h>
+#include <ouroboros/logs.h>
+#include <ouroboros/errno.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "path.h"
+
+char * pathname_create(const char * name)
+{
+ char * tmp;
+
+ assert(name);
+
+ tmp = malloc(strlen(name) + strlen(PATH_DELIMITER));
+ if (tmp == NULL)
+ return NULL;
+
+ strcpy(tmp, PATH_DELIMITER);
+ strcat(tmp, name);
+
+ return tmp;
+}
+
+char * pathname_append(char * pname,
+ const char * name)
+{
+ char * tmp;
+
+ assert(pname);
+ assert(name);
+
+ tmp = malloc(strlen(pname) +
+ strlen(PATH_DELIMITER) +
+ strlen(name));
+ if (tmp == NULL)
+ return NULL;
+
+ strcpy(tmp, pname);
+ strcat(tmp, PATH_DELIMITER);
+ strcat(tmp, name);
+
+ free(pname);
+
+ return tmp;
+}
+
+void pathname_destroy(char * pname)
+{
+ free(pname);
+}
diff --git a/src/ipcpd/normal/path.h b/src/ipcpd/normal/path.h
new file mode 100644
index 00000000..022120d9
--- /dev/null
+++ b/src/ipcpd/normal/path.h
@@ -0,0 +1,35 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Functions to construct pathnames
+ *
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * 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.
+ */
+
+#ifndef OUROBOROS_PATHNAME
+#define OUROBOROS_PATHNAME
+
+#define PATH_DELIMITER "/"
+
+char * pathname_create(const char * name);
+
+char * pathname_append(char * pname,
+ const char * name);
+
+void pathname_destroy(char * pname);
+
+#endif
diff --git a/src/ipcpd/normal/pol/flat.c b/src/ipcpd/normal/pol/flat.c
index 544d4f7e..bbfc85a4 100644
--- a/src/ipcpd/normal/pol/flat.c
+++ b/src/ipcpd/normal/pol/flat.c
@@ -36,8 +36,9 @@
#include "shm_pci.h"
#include "ribmgr.h"
#include "ro.h"
+#include "path.h"
-#define POL_RO_ROOT "/flat_addr"
+#define POL_RO_ROOT "flat_addr"
#define TIMEOUT 100 /* ms */
#define STR_SIZE 100
@@ -59,20 +60,18 @@ struct {
pthread_mutex_t lock;
} flat;
-static char * my_name(void)
+static char * addr_name(void)
{
char * name;
- char addr_name[100];
+ char addr_name[100];
- name = malloc(STR_SIZE);
+ sprintf(addr_name, "%lu", (unsigned long) flat.addr);
+
+ name = pathname_create(POL_RO_ROOT);
if (name == NULL)
return NULL;
- sprintf(addr_name, "%lu", (unsigned long) flat.addr);
- strcpy(name, POL_RO_ROOT);
- strcat(name, "/");
- strcat(name, addr_name);
-
+ name = pathname_append(name, addr_name);
return name;
}
@@ -105,7 +104,7 @@ static void ro_updated(const char * name,
assert(data);
assert(len >= sizeof(*msg));
- ro_name = my_name();
+ ro_name = addr_name();
if (ro_name == NULL) {
free(data);
return;
@@ -134,6 +133,7 @@ int flat_init(void)
{
struct ro_attr rattr;
pthread_condattr_t cattr;
+ char * name;
srand(time(NULL));
flat.addr_in_use = false;
@@ -155,13 +155,23 @@ int flat_init(void)
return -1;
}
- if (ro_create(POL_RO_ROOT, &rattr, NULL, 0)) {
+ name = pathname_create(POL_RO_ROOT);
+ if (name == NULL) {
+ pthread_cond_destroy(&flat.cond);
+ pthread_mutex_destroy(&flat.lock);
+ ro_unsubscribe(flat.sid);
+ return -1;
+ }
+
+ if (ro_create(name, &rattr, NULL, 0)) {
LOG_ERR("Could not create RO.");
+ pathname_destroy(name);
pthread_cond_destroy(&flat.cond);
pthread_mutex_destroy(&flat.lock);
ro_unsubscribe(flat.sid);
return -1;
}
+ pathname_destroy(name);
return 0;
}
@@ -211,8 +221,7 @@ uint64_t flat_address(void)
msg->code = FLAT_ADDR_REQ;
msg->addr = flat.addr;
- /* FIXME: We may require functions to construct pathnames */
- ro_name = my_name();
+ ro_name = addr_name();
if (ro_name == NULL)
return INVALID_ADDR;
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
index 5f9ea301..0f76d960 100644
--- a/src/ipcpd/normal/ribmgr.c
+++ b/src/ipcpd/normal/ribmgr.c
@@ -44,6 +44,7 @@
#include "ipcp.h"
#include "cdap_request.h"
#include "ro.h"
+#include "path.h"
#include "static_info.pb-c.h"
typedef StaticInfoMsg static_info_msg_t;
@@ -58,9 +59,8 @@ typedef RoMsg ro_msg_t;
#define ENROLLMENT "enrollment"
-#define RIBMGR_PREFIX "/ribmgr"
-#define STAT_INFO "/statinfo"
-#define PATH_DELIMITER "/"
+#define RIBMGR_PREFIX PATH_DELIMITER "ribmgr"
+#define STAT_INFO PATH_DELIMITER "statinfo"
/* RIB objects */
struct rnode {