summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2017-02-10 07:59:45 +0000
committerSander Vrijders <sander.vrijders@intec.ugent.be>2017-02-10 07:59:45 +0000
commit4051a5afbfc92873af44d47ae6613d7bd17f7433 (patch)
tree09afe1ad6bded8815a058ef6476ea4481d9a032a
parent0557bc02b963bab6f690b410fe937a9f487a84ba (diff)
parentaa1643ae393d9460bea8e2922c9cc0a3e6caf63d (diff)
downloadouroboros-4051a5afbfc92873af44d47ae6613d7bd17f7433.tar.gz
ouroboros-4051a5afbfc92873af44d47ae6613d7bd17f7433.zip
Merged in dstaesse/ouroboros/be-bsd (pull request #368)
Be bsd
-rw-r--r--src/ipcpd/normal/enroll.c8
-rw-r--r--src/ipcpd/normal/main.c5
-rw-r--r--src/ipcpd/shim-eth-llc/main.c1
-rw-r--r--src/ipcpd/tests/timerwheel_test.c1
-rw-r--r--src/ipcpd/timerwheel.c24
-rw-r--r--src/lib/byte_order.h8
-rw-r--r--src/lib/rib.c12
-rw-r--r--src/lib/tests/rib_test.c2
-rw-r--r--src/tools/cbr/cbr.c1
9 files changed, 39 insertions, 23 deletions
diff --git a/src/ipcpd/normal/enroll.c b/src/ipcpd/normal/enroll.c
index fb4ff3c3..16bfc592 100644
--- a/src/ipcpd/normal/enroll.c
+++ b/src/ipcpd/normal/enroll.c
@@ -115,7 +115,7 @@ int enroll_handle(int fd)
return -1;
}
- log_dbg("Packed %s (%lu bytes).", name, len);
+ log_dbg("Packed %s (%zu bytes).", name, len);
free(name);
@@ -186,7 +186,7 @@ int enroll_boot(char * dst_name)
return -1;
}
- log_dbg("Packed information received (%lu bytes).", len);
+ log_dbg("Packed information received (%zu bytes).", len);
if (rib_unpack(data, len, UNPACK_CREATE)) {
log_warn("Error unpacking RIB data.");
@@ -214,7 +214,7 @@ int enroll_boot(char * dst_name)
return -1;
}
- log_dbg("Packed information received (%lu bytes).", len);
+ log_dbg("Packed information received (%zu bytes).", len);
if (rib_unpack(data, len, UNPACK_CREATE)) {
log_warn("Error unpacking RIB data.");
@@ -242,7 +242,7 @@ int enroll_boot(char * dst_name)
return -1;
}
- log_dbg("Packed information received (%lu bytes).", len);
+ log_dbg("Packed information received (%zu bytes).", len);
if (rib_unpack(data, len, UNPACK_CREATE)) {
log_warn("Error unpacking RIB data.");
diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c
index b69bfe28..69f24fce 100644
--- a/src/ipcpd/normal/main.c
+++ b/src/ipcpd/normal/main.c
@@ -47,6 +47,7 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
+#include <inttypes.h>
#define DLR "/"
#define DIF_PATH DLR DIF_NAME
@@ -146,7 +147,7 @@ static int boot_components(void)
len = rib_read(DIF_PATH, &buf, 256);
if (len < 0) {
- log_err("Failed to read DIF name: %ld.", len);
+ log_err("Failed to read DIF name: %zd.", len);
return -1;
}
@@ -182,7 +183,7 @@ static int boot_components(void)
return -1;
}
- log_dbg("IPCP got address %lu.", ipcpi.address);
+ log_dbg("IPCP got address %" PRIu64 ".", ipcpi.address);
log_dbg("Starting ribmgr.");
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index 15482f87..f96c6e8a 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -773,7 +773,6 @@ static int eth_llc_ipcp_bootstrap(struct dif_config * conf)
memcpy(LLADDR(&device), ifr.ifr_addr.sa_data, MAC_SIZE);
device.sdl_alen = MAC_SIZE;
/* TODO: replace socket calls with bpf for BSD */
- LOG_MISSING;
skfd = socket(AF_LINK, SOCK_RAW, 0);
#else
device.sll_ifindex = idx;
diff --git a/src/ipcpd/tests/timerwheel_test.c b/src/ipcpd/tests/timerwheel_test.c
index 1ace1371..23de403a 100644
--- a/src/ipcpd/tests/timerwheel_test.c
+++ b/src/ipcpd/tests/timerwheel_test.c
@@ -24,6 +24,7 @@
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
#define MAX_ELEMENTS 100
#define MAX_RESOLUTION 10 /* ms */
diff --git a/src/ipcpd/timerwheel.c b/src/ipcpd/timerwheel.c
index 6e5b7da9..ef79bc14 100644
--- a/src/ipcpd/timerwheel.c
+++ b/src/ipcpd/timerwheel.c
@@ -24,10 +24,6 @@
#include <ouroboros/errno.h>
#include <ouroboros/list.h>
-#define OUROBOROS_PREFIX "timerwheel"
-
-#include <ouroboros/logs.h>
-
#include <pthread.h>
#include <stdlib.h>
#include <assert.h>
@@ -127,7 +123,7 @@ static void * worker(void * o)
struct timespec dl;
struct timespec now;
- clock_gettime(CLOCK_MONOTONIC, &now);
+ clock_gettime(PTHREAD_COND_CLOCK, &now);
ts_add(&now, &tw->intv, &dl);
@@ -207,6 +203,8 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
struct timerwheel * tw;
+ pthread_condattr_t cattr;
+
assert(resolution != 0);
tw = malloc(sizeof(*tw));
@@ -235,22 +233,28 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
list_head_init(&tw->wq);
if (pthread_mutex_init(&tw->lock, NULL)) {
- log_dbg("Could not init mutex.");
free(tw->wheel);
free(tw);
return NULL;
}
if (pthread_mutex_init(&tw->s_lock, NULL)) {
- log_dbg("Could not init mutex.");
pthread_mutex_destroy(&tw->lock);
free(tw->wheel);
free(tw);
return NULL;
}
- if (pthread_cond_init(&tw->work, NULL)) {
- log_dbg("Could not init cond.");
+ if (pthread_condattr_init(&cattr)) {
+ pthread_mutex_destroy(&tw->lock);
+ free(tw->wheel);
+ free(tw);
+ return NULL;
+ }
+#ifndef __APPLE__
+ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
+#endif
+ if (pthread_cond_init(&tw->work, &cattr)) {
pthread_mutex_destroy(&tw->s_lock);
pthread_mutex_destroy(&tw->lock);
free(tw->wheel);
@@ -271,7 +275,6 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_create(&tw->worker, NULL, worker, (void *) tw)) {
- log_dbg("Could not create worker.");
pthread_cond_destroy(&tw->work);
pthread_mutex_destroy(&tw->s_lock);
pthread_mutex_destroy(&tw->lock);
@@ -281,7 +284,6 @@ struct timerwheel * timerwheel_create(unsigned int resolution,
}
if (pthread_create(&tw->ticker, NULL, movement, (void *) tw)) {
- log_dbg("Could not create timer.");
tw_set_state(tw, TW_DESTROY);
pthread_join(tw->worker, NULL);
pthread_cond_destroy(&tw->work);
diff --git a/src/lib/byte_order.h b/src/lib/byte_order.h
index 9ee082af..364b06cc 100644
--- a/src/lib/byte_order.h
+++ b/src/lib/byte_order.h
@@ -49,7 +49,9 @@
#include <stdlib.h>
#ifdef __GLIBC__
-# include <endian.h>
+#include <endian.h>
+#elif defined(__FreeBSD__)
+#include <sys/endian.h>
#endif
/* if x86 compatible cpu */
@@ -131,7 +133,8 @@ static inline uint32_t bswap_32(uint32_t x) {
#if defined(__GNUC__) && (__GNUC__ >= 4) && \
(__GNUC__ > 4 || __GNUC_MINOR__ >= 3)
#define bswap_64(x) __builtin_bswap64(x)
-#elif !defined(__STRICT_ANSI__)
+#elif !defined (bswap64)
+#if !defined(__STRICT_ANSI__)
static inline uint64_t bswap_64(uint64_t x) {
union {
uint64_t ll;
@@ -145,6 +148,7 @@ static inline uint64_t bswap_64(uint64_t x) {
#else
#error "bswap_64 unsupported"
#endif
+#endif
#ifdef CPU_BIG_ENDIAN
#define be2me_32(x) (x)
diff --git a/src/lib/rib.c b/src/lib/rib.c
index e0456b6f..af4abccf 100644
--- a/src/lib/rib.c
+++ b/src/lib/rib.c
@@ -778,11 +778,19 @@ static struct rib_sub * rib_get_sub(uint32_t sid)
static struct rib_sub * rib_sub_create(uint32_t sid)
{
+ pthread_condattr_t cattr;
struct rib_sub * sub = malloc(sizeof(*sub));
if (sub == NULL)
return NULL;
- if (pthread_cond_init(&sub->cond, NULL)) {
+ if (pthread_condattr_init(&cattr)) {
+ free(sub);
+ return NULL;
+ }
+#ifndef __APPLE__
+ pthread_condattr_setclock(&cattr, PTHREAD_COND_CLOCK);
+#endif
+ if (pthread_cond_init(&sub->cond, &cattr)) {
free(sub);
return NULL;
}
@@ -1136,7 +1144,7 @@ int rib_event_wait(ro_set_t * set,
if (ret != -ETIMEDOUT)
list_move(&rq->events, &sub->events);
- pthread_rwlock_wrlock(&rib.lock);
+ pthread_rwlock_unlock(&rib.lock);
return ret;
}
diff --git a/src/lib/tests/rib_test.c b/src/lib/tests/rib_test.c
index efc35d63..a7ae7311 100644
--- a/src/lib/tests/rib_test.c
+++ b/src/lib/tests/rib_test.c
@@ -52,7 +52,7 @@ int rib_test(int argc,
uint8_t * buf;
ssize_t buf_len;
- struct timespec t = {0, 100 * BILLION};
+ struct timespec t = {0, 100 * MILLION};
(void) argc;
(void) argv;
diff --git a/src/tools/cbr/cbr.c b/src/tools/cbr/cbr.c
index 752395da..ef8a58ba 100644
--- a/src/tools/cbr/cbr.c
+++ b/src/tools/cbr/cbr.c
@@ -21,6 +21,7 @@
*/
#define _POSIX_C_SOURCE 199506L
+#define __XSI_VISIBLE 500
#include <stdio.h>
#include <string.h>