Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CC ?= gcc

LIBS = -lpthread -lrt -ldl
LIBS = -lpthread
CFLAGS ?= -O2 -fPIC
CFLAGS += -D_GNU_SOURCE -fno-strict-aliasing -Wall -Wextra \
-Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations \
Expand All @@ -9,6 +9,11 @@ CFLAGS += -D_GNU_SOURCE -fno-strict-aliasing -Wall -Wextra \
CPPFLAGS ?=
INCLUDES = -Incrx

UNAME := $(shell uname)
ifneq ($(UNAME), OpenBSD)
LIBS += -lrt -ldl
endif

debug debug32: CFLAGS += -O0 -gdwarf-4 -fno-omit-frame-pointer \
-fstack-protector-all -fsanitize=address \
-fsanitize=undefined
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ own custom output module.
## Building netconsd

The default Makefile target intended for production use has no external
dependencies besides glibc. To build it, just say `make`: you'll end up with a
single executable in this directory called `netconsd`, and a `*.so` file for every
module in the `modules/` directory.
dependencies besides glibc. To build it, just say `make` (or `gmake` on BSD):
you'll end up with a single executable in this directory called `netconsd`, and
a `*.so` file for every module in the `modules/` directory.

The Makefile includes a few other handy targets:

Expand Down
1 change: 1 addition & 0 deletions include/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define __LISTENER_H__

#include "threads.h"
#include <pthread.h>

#define RCVBUF_SIZE 1024

Expand Down
2 changes: 1 addition & 1 deletion listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static int get_listen_socket(struct sockaddr_in6 *bindaddr)
if (ret == -1)
fatal("Couldn't set SO_REUSEPORT on socket: %m\n");

ret = bind(fd, bindaddr, sizeof(*bindaddr));
ret = bind(fd, (const struct sockaddr *)bindaddr, sizeof(*bindaddr));
if (ret == -1)
fatal("Couldn't bind: %m\n");

Expand Down
6 changes: 3 additions & 3 deletions modules/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ LDFLAGS ?=

override CFLAGS += -fPIC
override CXXFLAGS += -std=c++11 -fPIC
override LDFLAGS += -shared -static-libstdc++ -static-libgcc
override LDFLAGS += -shared
INCLUDES = -I../ncrx -I../include

mods = printer.so logger.so

all: $(mods)

%.so: %.c
$(CC) $< $(CPPFLAGS) $(CFLAGS) $(INCLUDES) $(LDFLAGS) -c -o $(<:.c=.o)
$(CC) $< $(CPPFLAGS) $(CFLAGS) $(INCLUDES) -c -o $(<:.c=.o)
$(CC) $(<:.c=.o) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@

%.so: %.cc
$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) $(LDFLAGS) -c -o $(<:.cc=.o)
$(CXX) $< $(CPPFLAGS) $(CXXFLAGS) $(INCLUDES) -c -o $(<:.cc=.o)
$(CXX) $(<:.cc=.o) $(CPPFLAGS) $(CXXFLAGS) $(LDFLAGS) -o $@

clean:
Expand Down
8 changes: 5 additions & 3 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "include/output.h"

static void *output_dlhandles[MAXOUTS];
static const char *output_dlpaths[MAXOUTS];
static void (*outputs[MAXOUTS])(int, struct in6_addr *, struct msg_buf *,
struct ncrx_msg *);
static int nr_outputs;
Expand Down Expand Up @@ -59,6 +60,7 @@ int register_output_module(char *path, int nr_workers)

log("Module '%s' registered (#%d@%p)\n", path, nr_outputs, dlsym_addr);
output_dlhandles[nr_outputs] = dl;
output_dlpaths[nr_outputs] = strdup(path);
outputs[nr_outputs] = dlsym_addr;
nr_outputs++;
return 0;
Expand All @@ -72,11 +74,9 @@ void destroy_output_modules(void)
{
int i, ret;
void (*mod_exit)(void);
char path[PATH_MAX] = {0};

for (i = 0; i < nr_outputs; i++) {
if (dlinfo(output_dlhandles[i], RTLD_DI_ORIGIN, path))
strncpy(path, dlerror(), PATH_MAX - 1);
const char *path = output_dlpaths[i];

mod_exit = dlsym(output_dlhandles[i], "netconsd_output_exit");
if (mod_exit) {
Expand All @@ -88,6 +88,8 @@ void destroy_output_modules(void)
ret = dlclose(output_dlhandles[i]);
if (ret)
warn("dlclose() failed: %s\n", dlerror());

free((void *)path);
}
}

Expand Down
26 changes: 17 additions & 9 deletions util/netconsblaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@
#include <pthread.h>
#include <unistd.h>
#include <getopt.h>
#include <inttypes.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip6.h>
#include <netinet/udp.h>

#ifndef __linux__
#error Sorry, SOCK_RAW is not portable
#endif

#define fatal(...) \
do { \
printf(__VA_ARGS__); \
Expand Down Expand Up @@ -183,17 +190,17 @@ static void make_packet(struct netcons_packet *pkt, const struct in6_addr *src,
pkt->l3.ip6_plen = htons(sizeof(pkt->l4) + len);
pkt->l3.ip6_hlim = 64;

nr = snprintf(pkt->payload, len - 1, "%d,%lu,%lu,%s;", md->lvl, md->seq,
md->ts, contflag(md->cont));
nr = snprintf(pkt->payload, len - 1, "%d,%" PRIu64 ",%" PRIu64 ",%s;",
md->lvl, md->seq, md->ts, contflag(md->cont));
if (nr < len)
snprintf(pkt->payload + nr, len - nr, "%s", filler);
pkt->payload[len - 1] = '\n';

pkt->l4.source = htons(6666);
pkt->l4.dest = htons(*dst_port);
pkt->l4.len = htons(sizeof(pkt->l4) + len);
pkt->l4.check = htons(udp_csum(&pkt->l3.ip6_src, &pkt->l4,
sizeof(pkt->l4) + len));
pkt->l4.uh_sport = htons(6666);
pkt->l4.uh_dport = htons(*dst_port);
pkt->l4.uh_ulen = htons(sizeof(pkt->l4) + len);
pkt->l4.uh_sum = htons(udp_csum(&pkt->l3.ip6_src, &pkt->l4,
sizeof(pkt->l4) + len));
}

static int write_packet(int sockfd, struct netcons_packet *pkt)
Expand All @@ -204,7 +211,8 @@ static int write_packet(int sockfd, struct netcons_packet *pkt)
};

memcpy(&bogus.sin6_addr, &pkt->l3.ip6_dst, sizeof(pkt->l3.ip6_dst));
return sendto(sockfd, pkt, len, 0, &bogus, sizeof(bogus)) != len;
return sendto(sockfd, pkt, len, 0, (const struct sockaddr *)&bogus,
sizeof(bogus)) != len;
}

static int get_raw_socket(void)
Expand Down Expand Up @@ -457,7 +465,7 @@ int main(int argc, char **argv)
}
finish = now_epoch_ms();

printf("Wrote %lu packets (%lu pkts/sec)\n", count,
printf("Wrote %" PRIu64 " packets (%" PRIu64 " pkts/sec)\n", count,
count / (finish - start) * 1000UL);
return 0;
}
Loading