diff --git a/Makefile b/Makefile index 6bedab14a..e0f5f654e 100644 --- a/Makefile +++ b/Makefile @@ -50,7 +50,9 @@ CFLAGS += -Wall -Werror -fdiagnostics-color=auto LDFLAGS += -L$(BUILDDIR) # Some tools -PKGCONFIG := PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:$(PKG_CONFIG_PATH) pkg-config +PKG_CONFIG_PATH := $(PKG_CONFIG_PATH):/opt/local/lib/pkgconfig:/usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig + +PKGCONFIG := PKG_CONFIG_PATH=:$(PKG_CONFIG_PATH) pkg-config SHELL := bash # We must compile without optimizations for gcov! @@ -104,7 +106,7 @@ else endif # pkg-config dependencies -PKGS = libconfig +PKGS = libconfig openssl ######## Targets ######## @@ -132,7 +134,7 @@ escape = $(shell echo $1 | tr a-z- A-Z_ | tr -dc ' A-Z0-9_') CFLAGS += -DV=$(V) -DPREFIX=\"$(PREFIX)\" CFLAGS += -DBUILDID=\"$(VERSION)-$(GIT_REV)-$(VARIANT)\" -CFLAGS += -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE=1 +CFLAGS += -D_POSIX_C_SOURCE=200809L -D_GNU_SOURCE=1 -D_DARWIN_C_SOURCE CFLAGS += $(addprefix -DWITH_, $(call escape,$(PKGS))) install: $(addprefix install-,$(filter-out thirdparty doc clients,$(MODULES))) diff --git a/include/villas/compat.h b/include/villas/compat.h index 0c40bf005..9d8377eb5 100644 --- a/include/villas/compat.h +++ b/include/villas/compat.h @@ -24,4 +24,18 @@ #if JANSSON_VERSION_HEX < 0x020A00 size_t json_dumpb(const json_t *json, char *buffer, size_t size, size_t flags); -#endif \ No newline at end of file +#endif + +#ifdef __MACH__ + #include + + #define le16toh(x) OSSwapLittleToHostInt16(x) + #define le32toh(x) OSSwapLittleToHostInt32(x) + #define be16toh(x) OSSwapBigToHostInt16(x) + #define be32toh(x) OSSwapBigToHostInt32(x) + + #define htole16(x) OSSwapHostToLittleInt16(x) + #define htole32(x) OSSwapHostToLittleInt32(x) + #define htobe16(x) OSSwapHostToBigInt16(x) + #define htobe32(x) OSSwapHostToBigInt32(x) +#endif /* __MACH__ */ diff --git a/include/villas/fpga/ip.h b/include/villas/fpga/ip.h index 36f540acd..4b93e3f61 100644 --- a/include/villas/fpga/ip.h +++ b/include/villas/fpga/ip.h @@ -30,11 +30,10 @@ #pragma once #include +#include #include "common.h" -#include "nodes/fpga.h" - #include "fpga/vlnv.h" #include "fpga/ips/dma.h" diff --git a/include/villas/list.h b/include/villas/list.h index 456fbbdd6..a3afb062e 100644 --- a/include/villas/list.h +++ b/include/villas/list.h @@ -30,10 +30,11 @@ } #define LIST_INIT_STATIC(l) \ -__attribute__((constructor(105))) static void UNIQUE(__ctor)() {\ - list_init(l); \ +__attribute__((constructor(100))) static void UNIQUE(__ctor)() {\ + if ((l)->state == STATE_DESTROYED) \ + list_init(l); \ } \ -__attribute__((destructor(105))) static void UNIQUE(__dtor)() { \ +__attribute__((destructor(100))) static void UNIQUE(__dtor)() { \ list_destroy(l, NULL, false); \ } @@ -108,4 +109,4 @@ int list_contains(struct list *l, void *p); void list_sort(struct list *l, cmp_cb_t cmp); /** Set single element in list */ -int list_set(struct list *l, int index, void *value); \ No newline at end of file +int list_set(struct list *l, int index, void *value); diff --git a/include/villas/nodes/socket.h b/include/villas/nodes/socket.h index bd6692a18..ea19cdd9a 100644 --- a/include/villas/nodes/socket.h +++ b/include/villas/nodes/socket.h @@ -33,9 +33,12 @@ #include #include -#include #include +#ifdef __linux__ + #include +#endif + #include "node.h" enum socket_layer { @@ -55,8 +58,10 @@ union sockaddr_union { struct sockaddr_storage ss; struct sockaddr_in sin; struct sockaddr_in6 sin6; - struct sockaddr_ll sll; struct sockaddr_un sun; +#ifdef __linux__ + struct sockaddr_ll sll; +#endif }; struct socket { diff --git a/include/villas/plugin.h b/include/villas/plugin.h index 2a3ad3d81..2771c00d5 100644 --- a/include/villas/plugin.h +++ b/include/villas/plugin.h @@ -27,13 +27,18 @@ #include "api.h" #include "common.h" #include "utils.h" +#include "node_type.h" -#include "fpga/ip.h" +#ifdef WITH_FPGA + #include "fpga/ip.h" +#endif #include "nodes/cbuilder.h" #define REGISTER_PLUGIN(p) \ __attribute__((constructor(110))) static void UNIQUE(__ctor)() {\ + if (plugins.state == STATE_DESTROYED) \ + list_init(&plugins); \ list_push(&plugins, p); \ } \ __attribute__((destructor(110))) static void UNIQUE(__dtor)() { \ @@ -66,7 +71,9 @@ struct plugin { union { struct api_action api; struct node_type node; +#ifdef WITH_FPGA struct fpga_ip_type ip; +#endif struct hook_type hook; struct cbuilder_model cb; }; diff --git a/include/villas/timing.h b/include/villas/timing.h index b04dfdab4..d2bc1ca25 100644 --- a/include/villas/timing.h +++ b/include/villas/timing.h @@ -27,7 +27,10 @@ #include #include -#include + +#ifdef __linux__ + #include +#endif /** Create a new timer with the given rate. */ int timerfd_create_rate(double rate); diff --git a/include/villas/utils.h b/include/villas/utils.h index d681fcb79..8c097e691 100644 --- a/include/villas/utils.h +++ b/include/villas/utils.h @@ -170,6 +170,7 @@ char * vstrcatf(char **dest, const char *fmt, va_list va) #define strf(fmt, ...) strcatf(&(char *) { NULL }, fmt, ##__VA_ARGS__) #define vstrf(fmt, va) vstrcatf(&(char *) { NULL }, fmt, va) +#ifdef __linux__ /** Convert integer to cpu_set_t. * * @param set An integer number which is used as the mask @@ -199,6 +200,7 @@ int cpulist_parse(const char *str, cpu_set_t *set, int fail); * The output format is a list of CPUs with ranges (for example, "0,1,3-9"). */ char * cpulist_create(char *str, size_t len, cpu_set_t *set); +#endif /** Allocate and initialize memory. */ void * alloc(size_t bytes); diff --git a/lib/Makefile.villas-ext.inc b/lib/Makefile.villas-ext.inc index 9bf373b7c..28e043c72 100644 --- a/lib/Makefile.villas-ext.inc +++ b/lib/Makefile.villas-ext.inc @@ -30,7 +30,11 @@ LIBEXT_SRCS += $(addprefix lib/, sample.c queue.c queue_signalled.c \ ) LIBEXT_LDFLAGS = -shared -LIBEXT_LDLIBS = -ldl -lrt -Wl,-soname,$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION) +LIBEXT_LDLIBS = + +ifeq ($(shell uname),Linux) + LIBEXT_LDLIBS += -ldl -lrt -Wl,-soname,$(LIBEXT_NAME).so.$(LIBEXT_ABI_VERSION) +endif LIBEXT_OBJS = $(patsubst %.c, $(BUILDDIR)/%.o, $(LIBEXT_SRCS)) diff --git a/lib/Makefile.villas.inc b/lib/Makefile.villas.inc index 62de6791b..eb55dd943 100644 --- a/lib/Makefile.villas.inc +++ b/lib/Makefile.villas.inc @@ -25,7 +25,7 @@ LIB_ABI_VERSION = 1 LIB = $(BUILDDIR)/$(LIB_NAME).so.$(LIB_ABI_VERSION) # Object files for libvillas -LIB_SRCS += $(addprefix lib/nodes/, file.c cbuilder.c shmem.c signal.c loopback.c) \ +LIB_SRCS += $(addprefix lib/nodes/, cbuilder.c loopback.c) \ $(addprefix lib/kernel/, kernel.c rt.c) \ $(addprefix lib/, sample.c path.c node.c hook.c \ log.c log_config.c utils.c super_node.c hist.c timing.c pool.c \ @@ -36,20 +36,36 @@ LIB_SRCS += $(addprefix lib/nodes/, file.c cbuilder.c shmem.c signal.c loopback. ) LIB_LDFLAGS = -shared -LIB_LDLIBS = $(LDLIBS) -ldl -lrt -Wl,-soname,$(LIB_NAME).so.$(LIB_ABI_VERSION) +LIB_LDLIBS = $(LDLIBS) -LIB_PKGS += libwebsockets openssl +ifeq ($(shell uname),Linux) + LIB_LDLIBS += -ldl -lrt -Wl,-soname,$(LIB_NAME).so.$(LIB_ABI_VERSION) +endif + +LIB_PKGS = libwebsockets openssl libcurl + +######## Features ########## + +ifeq ($(shell uname),Linux) + CFLAGS += -DWITH_FPGA +endif ######## Node-types ######## +ifeq ($(shell uname),Linux) + LIB_SRCS += $(addprefix lib/nodes/,file.c shmem.c signal.c) +endif + # Enable Socket node type when libnl3 is available ifndef WITHOUT_SOCKET -ifeq ($(shell $(PKGCONFIG) libnl-route-3.0; echo $$?),0) LIB_SRCS += $(addprefix lib/nodes/, socket.c) - LIB_SRCS += $(addprefix lib/kernel/, nl.c tc.c if.c) LIB_SRCS += $(addprefix lib/, msg.c) - LIB_PKGS += libnl-route-3.0 -endif + + # libnl3 is optional but required for network emulation and IRQ pinning + ifeq ($(shell $(PKGCONFIG) libnl-route-3.0; echo $$?),0) + LIB_SRCS += $(addprefix lib/kernel/, nl.c tc.c if.c) + LIB_PKGS += libnl-route-3.0 + endif endif # Enable nanomsg node type when libnanomsg is available @@ -73,6 +89,7 @@ endif # Enable VILLASfpga support when libxil is available ifndef WITHOUT_FPGA +ifeq ($(shell uname),Linux) ifeq ($(shell $(PKGCONFIG) libxil; echo $$?),0) LIB_SRCS += $(addprefix lib/nodes/, fpga.c) \ $(addprefix lib/kernel/, pci.c vfio.c) \ @@ -82,14 +99,17 @@ ifeq ($(shell $(PKGCONFIG) libxil; echo $$?),0) LIB_PKGS += libxil endif endif +endif # Enable NGSI support ifndef WITHOUT_NGSI +ifeq ($(shell uname),Linux) ifeq ($(shell $(PKGCONFIG) libcurl jansson; echo $$?),0) LIB_SRCS += lib/nodes/ngsi.c LIB_PKGS += libcurl jansson endif endif +endif # Enable WebSocket support ifeq ($(shell $(PKGCONFIG) libwebsockets jansson; echo $$?),0) @@ -99,6 +119,7 @@ endif # Enable OPAL-RT Asynchronous Process support (will result in 32bit binary!!!) ifdef WITH_OPAL +ifeq ($(shell uname),Linux) ifneq ($(wildcard thirdparty/libopal/include/opal/AsyncApi.h),) LIB_OBJS += opal.o @@ -112,6 +133,7 @@ ifneq ($(wildcard thirdparty/libopal/include/opal/AsyncApi.h),) BUILDDIR := $(BUILDDIR) endif endif +endif # Add flags by pkg-config LIB_LDLIBS += $(shell $(PKGCONFIG) --libs $(LIB_PKGS)) diff --git a/lib/hooks/convert.c b/lib/hooks/convert.c index 8e34cf85f..db83afe65 100644 --- a/lib/hooks/convert.c +++ b/lib/hooks/convert.c @@ -26,6 +26,7 @@ #include "hook.h" #include "plugin.h" +#include "sample.h" struct convert { enum { diff --git a/lib/hooks/drop.c b/lib/hooks/drop.c index 4420d1002..443e90605 100644 --- a/lib/hooks/drop.c +++ b/lib/hooks/drop.c @@ -28,6 +28,7 @@ #include "plugin.h" #include "stats.h" #include "path.h" +#include "sample.h" struct drop { struct sample *prev; diff --git a/lib/hooks/fix_ts.c b/lib/hooks/fix_ts.c index 9f7249e4e..80f75cc63 100644 --- a/lib/hooks/fix_ts.c +++ b/lib/hooks/fix_ts.c @@ -27,6 +27,7 @@ #include "hook.h" #include "plugin.h" #include "timing.h" +#include "sample.h" int fix_ts_read(struct hook *h, struct sample *smps[], size_t *cnt) { diff --git a/lib/hooks/jitter_calc.c b/lib/hooks/jitter_calc.c index b33ea2903..5d04faff6 100644 --- a/lib/hooks/jitter_calc.c +++ b/lib/hooks/jitter_calc.c @@ -29,6 +29,7 @@ #include "hook.h" #include "plugin.h" #include "timing.h" +#include "sample.h" #define CALC_GPS_NTP_DELAY 0 /* @todo move to global config file */ #define GPS_NTP_DELAY_WIN_SIZE 16 diff --git a/lib/hooks/map.c b/lib/hooks/map.c index 434eade3c..1c203ccd8 100644 --- a/lib/hooks/map.c +++ b/lib/hooks/map.c @@ -29,6 +29,7 @@ #include "list.h" #include "utils.h" #include "path.h" +#include "sample.h" struct map { struct mapping mapping; diff --git a/lib/hooks/restart.c b/lib/hooks/restart.c index 2ae249611..827542778 100644 --- a/lib/hooks/restart.c +++ b/lib/hooks/restart.c @@ -27,6 +27,7 @@ #include "hook.h" #include "plugin.h" #include "path.h" +#include "sample.h" struct restart { struct sample *prev; diff --git a/lib/hooks/shift_seq.c b/lib/hooks/shift_seq.c index ad16b4ca5..78930fce0 100644 --- a/lib/hooks/shift_seq.c +++ b/lib/hooks/shift_seq.c @@ -26,6 +26,7 @@ #include "hook.h" #include "plugin.h" +#include "sample.h" struct shift { int offset; diff --git a/lib/hooks/shift_ts.c b/lib/hooks/shift_ts.c index cff2e4fc8..b07e638f7 100644 --- a/lib/hooks/shift_ts.c +++ b/lib/hooks/shift_ts.c @@ -27,6 +27,7 @@ #include "hook.h" #include "plugin.h" #include "timing.h" +#include "sample.h" struct shift_ts { struct timespec offset; diff --git a/lib/hooks/skip_first.c b/lib/hooks/skip_first.c index 6ff5504b9..067a5ae42 100644 --- a/lib/hooks/skip_first.c +++ b/lib/hooks/skip_first.c @@ -29,6 +29,7 @@ #include "hook.h" #include "plugin.h" #include "timing.h" +#include "sample.h" struct skip_first { enum { diff --git a/lib/hooks/stats_send.c b/lib/hooks/stats_send.c index 5c2fb7921..6a95105a5 100644 --- a/lib/hooks/stats_send.c +++ b/lib/hooks/stats_send.c @@ -29,6 +29,8 @@ #include "stats.h" #include "path.h" #include "super_node.h" +#include "sample.h" +#include "node.h" struct stats_send { struct node *dest; diff --git a/lib/hooks/ts.c b/lib/hooks/ts.c index 704e942bf..9e3b44a42 100644 --- a/lib/hooks/ts.c +++ b/lib/hooks/ts.c @@ -27,6 +27,7 @@ #include "hook.h" #include "plugin.h" #include "timing.h" +#include "sample.h" static int ts_read(struct hook *h, struct sample *smps[], size_t *cnt) { diff --git a/lib/kernel/kernel.c b/lib/kernel/kernel.c index cb07bd727..d181d462d 100644 --- a/lib/kernel/kernel.c +++ b/lib/kernel/kernel.c @@ -26,7 +26,6 @@ #include #include -#include #include #include #include @@ -36,6 +35,17 @@ #include "config.h" #include "kernel/kernel.h" +int kernel_get_cacheline_size() +{ +#ifdef __linux__ + return sysconf(_SC_LEVEL1_ICACHE_LINESIZE); +#else + return 64; /** @todo fixme */ +#endif +} + +#ifdef __linux__ + int kernel_module_set_param(const char *module, const char *param, const char *value) { FILE *f; @@ -154,11 +164,6 @@ out: return -1; /* not found or error */ } -int kernel_get_cacheline_size() -{ - return sysconf(_SC_LEVEL1_ICACHE_LINESIZE); -} - int kernel_get_page_size() { return sysconf(_SC_PAGESIZE); @@ -273,3 +278,5 @@ int kernel_irq_setaffinity(unsigned irq, uintmax_t new, uintmax_t *old) return ret; } + +#endif /* __linux__ */ diff --git a/lib/kernel/rt.c b/lib/kernel/rt.c index c4a403a80..d296cbde0 100644 --- a/lib/kernel/rt.c +++ b/lib/kernel/rt.c @@ -35,7 +35,7 @@ int rt_init(int priority, int affinity) info("Initialize real-time sub-system"); { INDENT - +#ifdef __linux__ int is_rt; /* Use FIFO scheduler with real time priority */ @@ -52,12 +52,16 @@ int rt_init(int priority, int affinity) rt_set_affinity(affinity); else warn("You might want to use the 'affinity' setting to pin VILLASnode to dedicate CPU cores"); - +#else + warn("This platform is not optimized for real-time execution"); +#endif } return 0; } +#ifdef __linux__ + int rt_set_affinity(int affinity) { char isolcpus[255]; @@ -121,4 +125,6 @@ int rt_set_priority(int priority) int rt_is_preemptible() { return access(SYSFS_PATH "/kernel/realtime", R_OK); -} \ No newline at end of file +} + +#endif /* __linux__ */ diff --git a/lib/memory.c b/lib/memory.c index 69839c873..44b52d208 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -23,6 +23,8 @@ #include #include #include +#include + #include #include #include diff --git a/lib/nodes/nanomsg.c b/lib/nodes/nanomsg.c index a34d0c24c..a092e7d61 100644 --- a/lib/nodes/nanomsg.c +++ b/lib/nodes/nanomsg.c @@ -231,7 +231,7 @@ int nanomsg_write(struct node *n, struct sample *smps[], unsigned cnt) static struct plugin p = { .name = "nanomsg", - .description = "scalability protocols library", + .description = "scalability protocols library (libnanomsg)", .type = PLUGIN_TYPE_NODE, .node = { .vectorize = 0, diff --git a/lib/nodes/socket.c b/lib/nodes/socket.c index 2872edc39..37d076574 100644 --- a/lib/nodes/socket.c +++ b/lib/nodes/socket.c @@ -23,22 +23,31 @@ #include #include #include -#include #include -#include + +#if defined(__linux__) + #include + #include +#endif #include "nodes/socket.h" #include "config.h" #include "utils.h" -#include "kernel/if.h" -#include "kernel/nl.h" -#include "kernel/tc.h" +#ifdef WITH_LIBNL_ROUTE_30 + #include "kernel/if.h" + #include "kernel/nl.h" + #include "kernel/tc.h" + + #define WITH_NETEM +#endif /* WITH_LIBNL_ROUTE_30 */ + #include "msg.h" #include "msg_format.h" #include "sample.h" #include "queue.h" #include "plugin.h" +#include "compat.h" /* Forward declartions */ static struct plugin p; @@ -48,6 +57,7 @@ struct list interfaces = { .state = STATE_DESTROYED }; int socket_init(struct super_node *sn) { +#ifdef WITH_NETEM int ret; nl_init(); /* Fill link cache */ @@ -94,12 +104,14 @@ found: list_push(&i->sockets, s); if_start(i); } +#endif /* WITH_NETEM */ return 0; } int socket_deinit() { +#ifdef WITH_NETEM for (size_t j = 0; j < list_length(&interfaces); j++) { struct interface *i = list_at(&interfaces, j); @@ -107,6 +119,7 @@ int socket_deinit() } list_destroy(&interfaces, (dtor_cb_t) if_destroy, false); +#endif /* WITH_NETEM */ return 0; } @@ -184,6 +197,7 @@ int socket_start(struct node *n) if (ntohs(s->local.sin.sin_port) != ntohs(s->remote.sin.sin_port)) error("IP protocol numbers of local and remote must match!"); } +#ifdef __linux__ else if (s->layer == SOCKET_LAYER_ETH) { if (ntohs(s->local.sll.sll_protocol) != ntohs(s->remote.sll.sll_protocol)) error("Ethertypes of local and remote must match!"); @@ -191,12 +205,15 @@ int socket_start(struct node *n) if (ntohs(s->local.sll.sll_protocol) <= 0x5DC) error("Ethertype must be large than %d or it is interpreted as an IEEE802.3 length field!", 0x5DC); } +#endif /* __linux__ */ /* Create socket */ switch (s->layer) { case SOCKET_LAYER_UDP: s->sd = socket(s->local.sa.sa_family, SOCK_DGRAM, IPPROTO_UDP); break; case SOCKET_LAYER_IP: s->sd = socket(s->local.sa.sa_family, SOCK_RAW, ntohs(s->local.sin.sin_port)); break; +#ifdef __linux__ case SOCKET_LAYER_ETH: s->sd = socket(s->local.sa.sa_family, SOCK_DGRAM, s->local.sll.sll_protocol); break; +#endif /* __linux__ */ default: error("Invalid socket type!"); } @@ -209,6 +226,7 @@ int socket_start(struct node *n) if (ret < 0) serror("Failed to bind socket"); +#ifdef __linux__ /* Set fwmark for outgoing packets if netem is enabled for this node */ if (s->mark) { ret = setsockopt(s->sd, SOL_SOCKET, SO_MARK, &s->mark, sizeof(s->mark)); @@ -217,13 +235,14 @@ int socket_start(struct node *n) else debug(LOG_SOCKET | 4, "Set FW mark for socket (sd=%u) to %u", s->sd, s->mark); } - +#endif /* __linux__ */ + if (s->multicast.enabled) { ret = setsockopt(s->sd, IPPROTO_IP, IP_MULTICAST_LOOP, &s->multicast.loop, sizeof(s->multicast.loop)); if (ret) serror("Failed to set multicast loop option"); - ret = setsockopt(s->sd, IPPROTO_IP, IP_MULTICAST_TTL, &s->multicast.ttl, sizeof(s->multicast.ttl)); + ret = setsockopt(s->sd, IPPROTO_IP, IP_MULTICAST_TTL, &s->multicast.ttl, sizeof(s->multicast.ttl)); if (ret) serror("Failed to set multicast ttl option"); @@ -245,12 +264,16 @@ int socket_start(struct node *n) break; default: +#ifdef __linux__ prio = SOCKET_PRIO; if (setsockopt(s->sd, SOL_SOCKET, SO_PRIORITY, &prio, sizeof(prio))) serror("Failed to set socket priority"); else debug(LOG_SOCKET | 4, "Set socket priority for node %s to %d", node_name(n), prio); break; +#else + { } +#endif /* __linux__ */ } return 0; @@ -287,10 +310,12 @@ int socket_stop(struct node *n) int socket_destroy(struct node *n) { +#ifdef WITH_NETEM struct socket *s = n->_vd; rtnl_qdisc_put(s->tc_qdisc); rtnl_cls_put(s->tc_classifier); +#endif /* WITH_NETEM */ return 0; } @@ -538,7 +563,7 @@ int socket_write(struct node *n, struct sample *smps[], unsigned cnt) int socket_parse(struct node *n, config_setting_t *cfg) { - config_setting_t *cfg_netem, *cfg_multicast; + config_setting_t *cfg_multicast; const char *local, *remote, *layer, *hdr, *endian; int ret; @@ -548,10 +573,12 @@ int socket_parse(struct node *n, config_setting_t *cfg) if (!config_setting_lookup_string(cfg, "layer", &layer)) s->layer = SOCKET_LAYER_UDP; else { - if (!strcmp(layer, "eth")) - s->layer = SOCKET_LAYER_ETH; - else if (!strcmp(layer, "ip")) + if (!strcmp(layer, "ip")) s->layer = SOCKET_LAYER_IP; +#ifdef __linux__ + else if (!strcmp(layer, "eth")) + s->layer = SOCKET_LAYER_ETH; +#endif /*__linux__ */ else if (!strcmp(layer, "udp")) s->layer = SOCKET_LAYER_UDP; else @@ -644,6 +671,9 @@ int socket_parse(struct node *n, config_setting_t *cfg) s->multicast.ttl = ttl; } +#ifdef WITH_NETEM + config_setting_t *cfg_netem; + cfg_netem = config_setting_get_member(cfg, "netem"); if (cfg_netem) { int enabled = 1; @@ -654,6 +684,7 @@ int socket_parse(struct node *n, config_setting_t *cfg) } else s->tc_qdisc = NULL; +#endif /* WITH_NETEM */ return 0; } @@ -673,11 +704,13 @@ char * socket_print_addr(struct sockaddr *saddr) inet_ntop(AF_INET, &sa->sin.sin_addr, buf, 64); break; +#ifdef __linux__ case AF_PACKET: strcatf(&buf, "%02x", sa->sll.sll_addr[0]); for (int i = 1; i < sa->sll.sll_halen; i++) strcatf(&buf, ":%02x", sa->sll.sll_addr[i]); break; +#endif /* __linux__ */ default: error("Unknown address family: '%u'", sa->sa.sa_family); @@ -690,6 +723,7 @@ char * socket_print_addr(struct sockaddr *saddr) strcatf(&buf, ":%hu", ntohs(sa->sin.sin_port)); break; +#ifdef __linux__ case AF_PACKET: { struct nl_cache *cache = nl_cache_mngt_require("route/link"); struct rtnl_link *link = rtnl_link_get(cache, sa->sll.sll_ifindex); @@ -700,6 +734,7 @@ char * socket_print_addr(struct sockaddr *saddr) strcatf(&buf, ":%hu", ntohs(sa->sll.sll_protocol)); break; } +#endif /* __linux__ */ } return buf; @@ -713,6 +748,7 @@ int socket_parse_addr(const char *addr, struct sockaddr *saddr, enum socket_laye char *copy = strdup(addr); int ret; +#ifdef __linux__ if (layer == SOCKET_LAYER_ETH) { /* Format: "ab:cd:ef:12:34:56%ifname:protocol" */ /* Split string */ char *node = strtok(copy, "%"); @@ -741,6 +777,7 @@ int socket_parse_addr(const char *addr, struct sockaddr *saddr, enum socket_laye ret = 0; } else { /* Format: "192.168.0.10:12001" */ +#endif /* __linux__ */ struct addrinfo hint = { .ai_flags = flags, .ai_family = AF_UNSPEC @@ -785,8 +822,9 @@ int socket_parse_addr(const char *addr, struct sockaddr *saddr, enum socket_laye memcpy(sa, result->ai_addr, result->ai_addrlen); freeaddrinfo(result); } +#ifdef __linux__ } - +#endif /* __linux__ */ free(copy); return ret; @@ -817,6 +855,7 @@ int socket_compare_addr(struct sockaddr *x, struct sockaddr *y) return memcmp(xu->sin6.sin6_addr.s6_addr, yu->sin6.sin6_addr.s6_addr, sizeof(xu->sin6.sin6_addr.s6_addr)); +#ifdef __linux__ case AF_PACKET: CMP(ntohs(xu->sll.sll_protocol), ntohs(yu->sll.sll_protocol)); CMP(xu->sll.sll_ifindex, yu->sll.sll_ifindex); @@ -825,7 +864,7 @@ int socket_compare_addr(struct sockaddr *x, struct sockaddr *y) CMP(xu->sll.sll_halen, yu->sll.sll_halen); return memcmp(xu->sll.sll_addr, yu->sll.sll_addr, xu->sll.sll_halen); - +#endif /* __linux__ */ default: return -1; } @@ -835,7 +874,7 @@ int socket_compare_addr(struct sockaddr *x, struct sockaddr *y) static struct plugin p = { .name = "socket", - .description = "BSD network sockets", + .description = "BSD network sockets for Ethernet / IP / UDP (libnl3)", .type = PLUGIN_TYPE_NODE, .node = { .vectorize = 0, diff --git a/lib/nodes/zeromq.c b/lib/nodes/zeromq.c index ce7bbf6b1..5c14ba682 100644 --- a/lib/nodes/zeromq.c +++ b/lib/nodes/zeromq.c @@ -471,7 +471,7 @@ fail: static struct plugin p = { .name = "zeromq", - .description = "ZeroMQ Distributed Messaging", + .description = "ZeroMQ Distributed Messaging (libzmq)", .type = PLUGIN_TYPE_NODE, .node = { .vectorize = 0, diff --git a/lib/path.c b/lib/path.c index f4dda1bf5..50fd6b6d9 100644 --- a/lib/path.c +++ b/lib/path.c @@ -38,6 +38,7 @@ #include "super_node.h" #include "memory.h" #include "stats.h" +#include "node.h" static void path_read(struct path *p) { diff --git a/lib/plugin.c b/lib/plugin.c index 2674e21f2..5bd37292e 100644 --- a/lib/plugin.c +++ b/lib/plugin.c @@ -25,7 +25,7 @@ #include "plugin.h" /** Global list of all known plugins */ -struct list plugins; +struct list plugins = { .state = STATE_DESTROYED }; LIST_INIT_STATIC(&plugins) diff --git a/lib/timing.c b/lib/timing.c index c2cb1e1ac..0a5bdb997 100644 --- a/lib/timing.c +++ b/lib/timing.c @@ -21,10 +21,11 @@ *********************************************************************************/ #include -#include #include "timing.h" +#ifdef __linux__ + int timerfd_create_rate(double rate) { int fd, ret; @@ -69,6 +70,8 @@ uint64_t timerfd_wait_until(int fd, const struct timespec *until) return timerfd_wait(fd); } +#endif /* __linux__ */ + struct timespec time_now() { struct timespec ts; diff --git a/lib/utils.c b/lib/utils.c index fea90a9d2..14bbc2d1c 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -113,6 +113,8 @@ char * vstrcatf(char **dest, const char *fmt, va_list ap) return *dest; } +#ifdef __linux__ + void cpuset_to_integer(cpu_set_t *cset, uintmax_t *set) { *set = 0; @@ -231,6 +233,7 @@ char *cpulist_create(char *str, size_t len, cpu_set_t *set) return str; } +#endif /* __linux__ */ void * alloc(size_t bytes) { diff --git a/lib/web.c b/lib/web.c index 26351ebcd..fc450a4b3 100644 --- a/lib/web.c +++ b/lib/web.c @@ -22,8 +22,6 @@ #include #include - -#include #include #include "utils.h" diff --git a/lib/webmsg.c b/lib/webmsg.c index 45be95df6..d23684213 100644 --- a/lib/webmsg.c +++ b/lib/webmsg.c @@ -20,7 +20,11 @@ * along with this program. If not, see . *********************************************************************************/ -#include +#ifdef __MACH__ + #include "compat.h" +#elif defined(__linux__) + #include +#endif #include "webmsg.h" #include "webmsg_format.h" diff --git a/src/node.c b/src/node.c index 9ccdcf54c..acffd9f4a 100644 --- a/src/node.c +++ b/src/node.c @@ -113,10 +113,12 @@ int main(int argc, char *argv[]) info("This is VILLASnode %s (built on %s, %s)", CLR_BLD(CLR_YEL(BUILDID)), CLR_BLD(CLR_MAG(__DATE__)), CLR_BLD(CLR_MAG(__TIME__))); +#ifdef __linux__ /* Checks system requirements*/ struct version kver, reqv = { KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN }; if (kernel_get_version(&kver) == 0 && version_cmp(&kver, &reqv) < 0) error("Your kernel version is to old: required >= %u.%u", KERNEL_VERSION_MAJ, KERNEL_VERSION_MIN); +#endif /* __linux__ */ signals_init(quit); log_init(&sn.log, V, LOG_ALL); diff --git a/thirdparty/Makefile.inc b/thirdparty/Makefile.inc index 757a8ac0c..81b3a4b32 100644 --- a/thirdparty/Makefile.inc +++ b/thirdparty/Makefile.inc @@ -46,7 +46,7 @@ $(DEPS_AUTOCONF): | $(BUILDDIR)/thirdparty/$$@/ # Install & compile CMake based projects $(DEPS_CMAKE): | $(BUILDDIR)/thirdparty/$$@/ cmake -DCMAKE_INSTALL_PREFIX:PATH=$(PREFIX) \ - -DCMAKE_INSTALL_LIBDIR=$(PREFIX)/lib64 -DLIB_SUFFIX=64 \ + -DCMAKE_INSTALL_LIBDIR=lib64 -DLIB_SUFFIX=64 \ -H$(SRCDIR)/thirdparty/$@ \ -B$(BUILDDIR)/thirdparty/$@ $(CMAKE_OPTS) make -C$(BUILDDIR)/thirdparty/$@