2017-11-30 15:23:50 +00:00
|
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
#
|
2018-01-03 20:58:00 +00:00
|
|
|
# Copyright (C) 2015-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
|
2017-11-30 15:23:50 +00:00
|
|
|
|
2017-01-04 18:28:28 +00:00
|
|
|
PKG_CONFIG ?= pkg-config
|
2015-06-05 13:58:00 +00:00
|
|
|
PREFIX ?= /usr
|
|
|
|
DESTDIR ?=
|
2017-01-05 18:57:50 +00:00
|
|
|
SYSCONFDIR ?= /etc
|
2015-06-05 13:58:00 +00:00
|
|
|
BINDIR ?= $(PREFIX)/bin
|
|
|
|
LIBDIR ?= $(PREFIX)/lib
|
|
|
|
MANDIR ?= $(PREFIX)/share/man
|
2017-01-04 06:05:56 +00:00
|
|
|
BASHCOMPDIR ?= $(PREFIX)/share/bash-completion/completions
|
2017-01-04 18:28:28 +00:00
|
|
|
SYSTEMDUNITDIR ?= $(shell $(PKG_CONFIG) --variable=systemdsystemunitdir systemd 2>/dev/null || echo "$(PREFIX)/lib/systemd/system")
|
wg: first additions of userspace integration
This is designed to work with a server that follows this:
struct sockaddr_un addr = {
.sun_family = AF_UNIX,
.sun_path = "/var/run/wireguard/wguserspace0.sock"
};
int fd, ret;
ssize_t len;
socklen_t socklen;
struct wgdevice *device;
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
exit(1);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
exit(1);
for (;;) {
/* First we look at how big the next message is, so we know how much to
* allocate. Note on BSD you can instead use ioctl(fd, FIONREAD, &len). */
len = recv(fd, NULL, 0, MSG_PEEK | MSG_TRUNC);
if (len < 0) {
handle_error();
continue;
}
/* Next we allocate a buffer for the received data. */
device = NULL;
if (len) {
device = malloc(len);
if (!device) {
handle_error();
continue;
}
}
/* Finally we receive the data, storing too the return address. */
socklen = sizeof(addr);
len = recvfrom(fd, device, len, 0, (struct sockaddr *)&addr, (socklen_t *)&socklen);
if (len < 0) {
handle_error();
free(device);
continue;
}
if (!len) { /* If len is zero, it's a "get" request, so we send our device back. */
device = get_current_wireguard_device(&len);
sendto(fd, device, len, 0, (struct sockaddr *)&addr, socklen);
} else { /* Otherwise, we just received a wgdevice, so we should "set" and send back the return status. */
ret = set_current_wireguard_device(device);
sendto(fd, &ret, sizeof(ret), 0, (struct sockaddr *)&addr, socklen);
free(device);
}
}
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-19 13:26:56 +00:00
|
|
|
RUNSTATEDIR ?= /var/run
|
2017-01-04 18:28:28 +00:00
|
|
|
WITH_BASHCOMPLETION ?=
|
|
|
|
WITH_WGQUICK ?=
|
|
|
|
WITH_SYSTEMDUNITS ?=
|
|
|
|
|
|
|
|
ifeq ($(WITH_BASHCOMPLETION),)
|
2017-01-04 20:14:16 +00:00
|
|
|
ifneq ($(strip $(wildcard $(BASHCOMPDIR))),)
|
2017-01-04 18:28:28 +00:00
|
|
|
WITH_BASHCOMPLETION := yes
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifeq ($(WITH_WGQUICK),)
|
2017-01-04 20:14:16 +00:00
|
|
|
ifneq ($(strip $(wildcard $(BINDIR)/bash)),)
|
2017-01-04 18:28:28 +00:00
|
|
|
WITH_WGQUICK := yes
|
|
|
|
endif
|
|
|
|
ifneq ($(strip $(wildcard $(DESTDIR)/bin/bash)),)
|
|
|
|
WITH_WGQUICK := yes
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifeq ($(WITH_SYSTEMDUNITS),)
|
2017-01-04 20:14:16 +00:00
|
|
|
ifneq ($(strip $(wildcard $(SYSTEMDUNITDIR))),)
|
2017-01-04 18:28:28 +00:00
|
|
|
WITH_SYSTEMDUNITS := yes
|
|
|
|
endif
|
|
|
|
endif
|
2015-06-05 13:58:00 +00:00
|
|
|
|
2018-05-14 16:14:55 +00:00
|
|
|
PLATFORM ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
|
|
|
|
2016-07-21 14:38:56 +00:00
|
|
|
CFLAGS ?= -O3
|
2017-05-17 16:34:23 +00:00
|
|
|
CFLAGS += -std=gnu11 -D_GNU_SOURCE
|
2017-01-10 03:50:42 +00:00
|
|
|
CFLAGS += -Wall -Wextra
|
2016-07-22 12:58:30 +00:00
|
|
|
CFLAGS += -MMD -MP
|
wg: first additions of userspace integration
This is designed to work with a server that follows this:
struct sockaddr_un addr = {
.sun_family = AF_UNIX,
.sun_path = "/var/run/wireguard/wguserspace0.sock"
};
int fd, ret;
ssize_t len;
socklen_t socklen;
struct wgdevice *device;
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
exit(1);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
exit(1);
for (;;) {
/* First we look at how big the next message is, so we know how much to
* allocate. Note on BSD you can instead use ioctl(fd, FIONREAD, &len). */
len = recv(fd, NULL, 0, MSG_PEEK | MSG_TRUNC);
if (len < 0) {
handle_error();
continue;
}
/* Next we allocate a buffer for the received data. */
device = NULL;
if (len) {
device = malloc(len);
if (!device) {
handle_error();
continue;
}
}
/* Finally we receive the data, storing too the return address. */
socklen = sizeof(addr);
len = recvfrom(fd, device, len, 0, (struct sockaddr *)&addr, (socklen_t *)&socklen);
if (len < 0) {
handle_error();
free(device);
continue;
}
if (!len) { /* If len is zero, it's a "get" request, so we send our device back. */
device = get_current_wireguard_device(&len);
sendto(fd, device, len, 0, (struct sockaddr *)&addr, socklen);
} else { /* Otherwise, we just received a wgdevice, so we should "set" and send back the return status. */
ret = set_current_wireguard_device(device);
sendto(fd, &ret, sizeof(ret), 0, (struct sockaddr *)&addr, socklen);
free(device);
}
}
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-19 13:26:56 +00:00
|
|
|
CFLAGS += -DRUNSTATEDIR="\"$(RUNSTATEDIR)\""
|
2017-10-03 15:16:37 +00:00
|
|
|
ifeq ($(DEBUG_TOOLS),y)
|
|
|
|
CFLAGS += -g
|
|
|
|
endif
|
2018-05-14 16:14:55 +00:00
|
|
|
ifeq ($(PLATFORM),linux)
|
2016-11-02 10:50:52 +00:00
|
|
|
LIBMNL_CFLAGS := $(shell $(PKG_CONFIG) --cflags libmnl 2>/dev/null)
|
|
|
|
LIBMNL_LDLIBS := $(shell $(PKG_CONFIG) --libs libmnl 2>/dev/null || echo -lmnl)
|
wg: first additions of userspace integration
This is designed to work with a server that follows this:
struct sockaddr_un addr = {
.sun_family = AF_UNIX,
.sun_path = "/var/run/wireguard/wguserspace0.sock"
};
int fd, ret;
ssize_t len;
socklen_t socklen;
struct wgdevice *device;
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
exit(1);
if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) < 0)
exit(1);
for (;;) {
/* First we look at how big the next message is, so we know how much to
* allocate. Note on BSD you can instead use ioctl(fd, FIONREAD, &len). */
len = recv(fd, NULL, 0, MSG_PEEK | MSG_TRUNC);
if (len < 0) {
handle_error();
continue;
}
/* Next we allocate a buffer for the received data. */
device = NULL;
if (len) {
device = malloc(len);
if (!device) {
handle_error();
continue;
}
}
/* Finally we receive the data, storing too the return address. */
socklen = sizeof(addr);
len = recvfrom(fd, device, len, 0, (struct sockaddr *)&addr, (socklen_t *)&socklen);
if (len < 0) {
handle_error();
free(device);
continue;
}
if (!len) { /* If len is zero, it's a "get" request, so we send our device back. */
device = get_current_wireguard_device(&len);
sendto(fd, device, len, 0, (struct sockaddr *)&addr, socklen);
} else { /* Otherwise, we just received a wgdevice, so we should "set" and send back the return status. */
ret = set_current_wireguard_device(device);
sendto(fd, &ret, sizeof(ret), 0, (struct sockaddr *)&addr, socklen);
free(device);
}
}
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2016-07-19 13:26:56 +00:00
|
|
|
CFLAGS += $(LIBMNL_CFLAGS)
|
|
|
|
LDLIBS += $(LIBMNL_LDLIBS)
|
|
|
|
endif
|
2015-06-05 13:58:00 +00:00
|
|
|
|
2017-10-03 15:16:37 +00:00
|
|
|
ifneq ($(V),1)
|
|
|
|
BUILT_IN_LINK.o := $(LINK.o)
|
2017-10-14 03:17:40 +00:00
|
|
|
LINK.o = @echo " LD $$(pwd)/$@";
|
2017-10-03 15:16:37 +00:00
|
|
|
LINK.o += $(BUILT_IN_LINK.o)
|
|
|
|
BUILT_IN_COMPILE.c := $(COMPILE.c)
|
2017-10-14 03:17:40 +00:00
|
|
|
COMPILE.c = @echo " CC $$(pwd)/$@";
|
2017-10-03 15:16:37 +00:00
|
|
|
COMPILE.c += $(BUILT_IN_COMPILE.c)
|
|
|
|
endif
|
|
|
|
|
2015-06-05 13:58:00 +00:00
|
|
|
wg: $(patsubst %.c,%.o,$(wildcard *.c))
|
|
|
|
|
2017-10-03 15:16:37 +00:00
|
|
|
ifneq ($(V),1)
|
2015-06-05 13:58:00 +00:00
|
|
|
clean:
|
2017-10-14 03:17:40 +00:00
|
|
|
@echo " CLEAN $$(pwd)/{wg,*.o,*.d}"
|
2017-10-03 15:16:37 +00:00
|
|
|
@$(RM) wg *.o *.d
|
|
|
|
else
|
|
|
|
clean:
|
|
|
|
$(RM) wg *.o *.d
|
|
|
|
endif
|
2015-06-05 13:58:00 +00:00
|
|
|
|
|
|
|
install: wg
|
2017-01-04 06:05:56 +00:00
|
|
|
@install -v -d "$(DESTDIR)$(BINDIR)" && install -m 0755 -v wg "$(DESTDIR)$(BINDIR)/wg"
|
2018-05-14 16:14:55 +00:00
|
|
|
@install -v -d "$(DESTDIR)$(MANDIR)/man8" && install -m 0644 -v man/wg.8 "$(DESTDIR)$(MANDIR)/man8/wg.8"
|
2017-01-04 18:28:28 +00:00
|
|
|
@[ "$(WITH_BASHCOMPLETION)" = "yes" ] || exit 0; \
|
|
|
|
install -v -d "$(DESTDIR)$(BASHCOMPDIR)" && install -m 0644 -v completion/wg.bash-completion "$(DESTDIR)$(BASHCOMPDIR)/wg"
|
|
|
|
@[ "$(WITH_WGQUICK)" = "yes" ] || exit 0; \
|
2018-05-14 16:14:55 +00:00
|
|
|
install -m 0755 -v wg-quick/$(PLATFORM).bash "$(DESTDIR)$(BINDIR)/wg-quick" && install -m 0700 -v -d "$(DESTDIR)$(SYSCONFDIR)/wireguard"
|
2017-01-04 18:28:28 +00:00
|
|
|
@[ "$(WITH_WGQUICK)" = "yes" ] || exit 0; \
|
2018-05-14 16:14:55 +00:00
|
|
|
install -m 0644 -v man/wg-quick.8 "$(DESTDIR)$(MANDIR)/man8/wg-quick.8"
|
2017-01-04 18:28:28 +00:00
|
|
|
@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_BASHCOMPLETION)" = "yes" ] || exit 0; \
|
|
|
|
install -m 0644 -v completion/wg-quick.bash-completion "$(DESTDIR)$(BASHCOMPDIR)/wg-quick"
|
|
|
|
@[ "$(WITH_WGQUICK)" = "yes" -a "$(WITH_SYSTEMDUNITS)" = "yes" ] || exit 0; \
|
2018-05-14 16:14:55 +00:00
|
|
|
install -v -d "$(DESTDIR)$(SYSTEMDUNITDIR)" && install -m 0644 -v systemd/wg-quick@.service "$(DESTDIR)$(SYSTEMDUNITDIR)/wg-quick@.service"
|
2015-06-05 13:58:00 +00:00
|
|
|
|
2017-01-04 17:20:08 +00:00
|
|
|
help:
|
|
|
|
@cat INSTALL
|
|
|
|
|
|
|
|
.PHONY: clean install check help
|
2015-06-05 13:58:00 +00:00
|
|
|
|
|
|
|
-include *.d
|